Reverb logo

Rust · no audio crates · hand-written WAV

Waveforms built
sample by sample.

Reverb is an audio synthesis engine in Rust with oscillators, an ADSR envelope, mixing, and a hand-written WAV file writer. No audio crates, no shortcuts. Here is the real math, running in your browser.

View on GitHub How it works
440 Hz
0.05 s
0.10 s
0.70
0.20 s
How to use this playground

Pick a waveform (sine, square, sawtooth, or triangle) and an octave, then click a key on the on-screen keyboard or press Play note to hear it. The frequency slider tunes the pitch directly in hertz.

The four ADSR sliders shape each note's volume over time: attack (fade in), decay (drop to sustain), sustain (held level), and release (fade out). Adjust them and play again to hear the change, and watch the waveform preview redraw the actual samples. Play melody sequences several notes so you can hear the mixer at work.

What it does

A short pipeline turns a note name into raw audio samples, with nothing borrowed along the way.

1

Oscillators

Sine, square, sawtooth, and triangle waves at any frequency and sample rate, computed directly from phase.

2

ADSR envelope

Attack, decay, sustain, and release shape every note so it fades in and out instead of clicking.

3

Sequencing and mixing

Notes chain into a track, tracks mix together, and the result is normalized to stay in range.

4

WAV, by hand

A RIFF header, fmt chunk, and data chunk written byte by byte. No audio or WAV crates involved.

Why write it all by hand?

The usual Rust audio path leans on crates: hound for WAV files, cpal or rodio for playback, a DSP crate for the math. Reverb does none of that, on purpose.

No crates in the pipeline

Every sample and every WAV byte is computed in this repo. Nothing hides the oscillator math or the RIFF layout behind a dependency.

Small enough to read

Oscillator, envelope, mixer, and WAV writer are a few short files. You can read the whole path from a note name to bytes on disk in one sitting.

The math is the point

Phase accumulation, the four waveform shapes, the ADSR curve, and 16-bit PCM quantization are all in plain view, not wrapped away.

Portable output

Standard 16-bit PCM WAV files that open in any player or editor, written header first by hand with no format library involved.

Render from the command line.

The same oscillator and envelope math you just heard, writing WAV files to disk. Real output below.

$ cargo build --release

$ reverb tone --freq 440 --secs 2 -o out.wav
wrote out.wav (88200 samples)

$ reverb demo -o demo.wav
wrote demo.wav (108045 samples)
tone

A single steady tone

Pick a frequency, a length, and a waveform with --wave (sine, square, sawtooth, triangle), and write it to a WAV file.

demo

A built-in melody

Render the short sequenced track so you can hear the sequencer and mixer without writing a manifest first.

cargo test

The test suite

Checks sample counts and range, WAV header correctness, envelope shape, and the waveform values themselves.

library

Use it as a crate

The oscillator, envelope, sequencer, mixer, and WAV writer are a plain Rust library, the same code this page ports to run in the browser.