Sound in.
State out.
Entrain is a clean-room Go engine for brainwave entrainment. It renders .sbg sessions to WAV, FLAC and MP3, verifies what any renderer put in a file with beatscope — and below, it plays a session live in your browser. Headphones on.
The engine, playing live.
Three sessions from the shipped library, synthesized right here with phase-continuous oscillators — the same plans the CLI renders to audio. Switch mid-glide: retuning never clicks.
Headphones required — binaural beats collapse on speakers. Each ear must receive its own carrier.
Pure Go in the core pipeline.
Packages you can lift, a binary you can ship.
Phase-continuous sine oscillators, binaural L/R pairing, equal-power crossfades and amplitude glide envelopes — retuning never clicks. Float64 end-to-end.
Tone-sets, absolute / NOW / relative times, nested blocks — and sbagen's 30-second changeover crossfades with true tone continuity across segments.
WAV (go-audio), FLAC (mewkiz, bit-exact) and MP3 (pure-Go Shine, level-matched). Shared clip → TPDF-dither → quantize stage, 16/24-bit, deterministic.
White, pink and brown noise with correct spectral slopes, decorrelated stereo and calibrated bed loudness — plus FFT-shaped 1/fα slopes in noisemaker.
STFT carrier/beat detection with L/R pairing and window-voted confidence. Cross-engine validated against sbagen — all five brainwave bands match.
5/5 MATCHNo SBaGen code anywhere — derived from public DSP technique and behavioral comparison. Embed it anywhere, including commercial use.
Install, render, verify, generate.
All from the terminal.
$ go install github.com/desireco/entrain/cmd/entrain@latest
$ go install github.com/desireco/entrain/cmd/beatscope@latest
$ go install github.com/desireco/entrain/cmd/noisemaker@latest
# or grab a prebuilt binary:
# github.com/desireco/entrain/releases
$ entrain render focus.sbg
# 30 minutes only, custom output file
$ entrain render focus.sbg -L 0:30 -o focus-30min.wav
# lossless FLAC at 24-bit
$ entrain render focus.sbg -f flac -b 24
# MP3 at 320 kbps
$ entrain render focus.sbg -f mp3 -q 320
# preview the timeline plan + lint warnings — no audio written
$ entrain focus-10 --dry-run
$ beatscope focus.wav
$ beatscope focus.flac --json
$ beatscope focus.wav --min-confidence 0.6
# reads WAV (16/24-bit) and FLAC. MP3/OGG: convert to WAV first —
# no MP3 decoder in-tree, by design.
$ noisemaker brown 1:30:00 -o bed.flac -b 24
$ noisemaker alpha 2h --alpha 1.4 --level 0.12 --seed 7 -o drift.wav
# white, pink, brown — or any 1/f^α slope with --alpha.
# default level 0.155 RMS, calibrated to sit under binaural tones.
# deterministic with --seed.
Anatomy of a session.
A session is a few lines of plain text you can read, edit and version — no proprietary format, no binary blobs.
01Tone-set line
carrier+beat/amplitude — amplitudes on a 0–100 scale, keep the sum under 100. The engine pairs L/R carriers for a true binaural beat.
02Schedule lines
time name — absolute, NOW, or +mm:ss relative.
03Changeovers
Crossfades happen automatically — 30 seconds, equal-power, with true tone continuity across segments.
04Session library
A small, growing set ships in the repo under examples/ — use as-is or edit in any text editor. Copy one, tweak the numbers, make it yours.
Asked, answered.
Why a rewrite?
SBaGen (Jim Peters) is wonderful 2000s software — powerful, battle-tested, and GPLv2 with a bespoke C codebase. Entrain keeps the functionality and modernizes everything around it: permissive license, static binaries, modern formats. The full rationale is in the migration plan.
Is Entrain affiliated with SBaGen?
No. Entrain is an independent clean-room reimplementation — no SBaGen code was read or copied, and it is not endorsed by Jim Peters. The original tool and its forks have their own SBaGen page.
What's next?
A native TOML session format ("trains"), EMDR bilateral voices, live playback, and a web player — see the roadmap.