sound.synth

index ยท sound

Overview

Tiny synthesizer for chiptune-style game audio.

Generates a float32 sample buffer for a single tone: an oscillator (sine/square/saw/triangle/noise) shaped by a linear ADSR envelope. Sample generation and the envelope ramps run in the C core (buffer:osc / buffer:fade); this layer just composes the segments. The result is a plain sound.buffer you hand to mixer:play.

Functions

NameSignature
note_freqnote_freq(name) -> hz
tonetone(opts) -> buf, err

note_freq(name) -> hz

Convert a note name to a frequency

tone(opts) -> buf, err

Generate a tone buffer

opts fielddefaultdescription
freq440frequency, Hz
notenilnote name like "A4", "C#5" (used when freq is absent)
dur0.25duration, seconds
rate48000sample rate, Hz
channels2channel count
wave"sine""sine", "square", "saw", "triangle", or "noise"
amp0.5amplitude, 0..1
attack0.005ADSR attack, seconds
decay0.0ADSR decay, seconds
sustain1.0ADSR sustain level, 0..1
release0.02ADSR release, seconds

Returns a float32 sound.buffer.