sound.buffer

sound

buffer(frames, channels) -> buf, err

Create a sample buffer filled with silence

A buffer holds interleaved float32 samples in [-1, 1]. channels defaults to 2. Frame offsets count from 1.

methoddescription
b:frames(), b:channels()size
b:clear()reset to silence
b:get(frame, ch), b:set(frame, ch, v)read or write one sample
b:mix(src, dst_off, src_off, n, ...)add n frames of src, scaled by the gains after n
b:osc(wave, freq, rate, phase, amp, dst_off, n, seed)add an oscillator; returns the next phase. seed is noise's: with it the same bytes every call, without it the process-wide stream
b:fade(g0, g1, dst_off, n)multiply by a linear gain ramp
b:tostring()the raw interleaved f32 bytes

mix with no gains adds at unity, with one gain scales every channel, and with one gain per channel pans. A mono source mixed into a stereo buffer goes to both channels. mix does not clamp.