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.
| Name | Signature |
|---|---|
| note_freq | note_freq(name) -> hz |
| tone | tone(opts) -> buf, err |
note_freq(
name) ->hz
Convert a note name to a frequency
tone(
opts) ->buf,err
Generate a tone buffer
| opts field | default | description |
|---|---|---|
freq | 440 | frequency, Hz |
note | nil | note name like "A4", "C#5" (used when freq is absent) |
dur | 0.25 | duration, seconds |
rate | 48000 | sample rate, Hz |
channels | 2 | channel count |
wave | "sine" | "sine", "square", "saw", "triangle", or "noise" |
amp | 0.5 | amplitude, 0..1 |
attack | 0.005 | ADSR attack, seconds |
decay | 0.0 | ADSR decay, seconds |
sustain | 1.0 | ADSR sustain level, 0..1 |
release | 0.02 | ADSR release, seconds |
Returns a float32 sound.buffer.