sound.buffer

sound

buffer(frames, channels) -> buf, err

Create a sample buffer filled with silence

Allocates a block of interleaved float32 samples in [-1, 1]; channels defaults to 2. Frame offsets at the Lua boundary are 1-indexed.

The buffer object has the following methods:

MethodDescription
b:frames() / b:channels()size
b:clear()reset to silence
b:get(frame, ch) / b:set(f, c, v)read/write one sample (1-indexed)
b:mix(src, dst_off, src_off, n, ...g)add n frames of src scaled by gains (mixer core)
b:osc(wave, freq, rate, phase, amp, dst_off, n)additive oscillator → next phase
b:fade(g0, g1, dst_off, n)linear gain ramp (envelope segment)
b:tostring()raw interleaved f32 bytes

mix gains: none → unity; one → master volume; per-channel → pan. A mono source mixed into a stereo destination is duplicated to both channels.