signal/buffer
Buffer
(Buffer)
a fixed-length array of samples, shared by handle.
buffer-new
(buffer-new [n :int] :)
a buffer of `n` silent samples.
| n | length in samples, clamped to [1, 16777216] |
A Buffer of n zeros.
(buffer-len (buffer-new 64)) ; => 64
buffer-len
(buffer-len [buf : Buffer] :)
number of samples in a buffer.
| buf | the buffer |
The length in samples.
(buffer-len (buffer-new 64)) ; => 64
buffer-get
(buffer-get [buf : Buffer i :int] :)
the sample at index `i`, wrapping out-of-range indices.
| buf | the buffer | |
| i | index; taken modulo the length, so -1 is the last sample |
The stored sample.
(buffer-get buf 0)
buffer-set!
(buffer-set! [buf : Buffer i :int x :float] :)
store sample `x` at index `i`, wrapping like `buffer-get`.
| buf | the buffer | |
| i | index; taken modulo the length | |
| x | the sample to store |
(buffer-set! buf 0 1.0)
buffer-read
(buffer-read [buf : Buffer pos :float] :)
linearly interpolated read at a position in buffer lengths.
| buf | the buffer | |
| pos | read position; wraps, so any float is valid |
The interpolated sample.
(buffer-read buf 0.5) ;; the middle of the buffer
buffer-read-nearest
(buffer-read-nearest [buf : Buffer pos :float] :)
the sample nearest a position in buffer lengths.
| buf | the buffer | |
| pos | read position; wraps, so any float is valid |
The nearest stored sample.
;; a 4-sample buffer: 0.3 * 4 = 1.2 rounds to sample 1 (buffer-read-nearest buf 0.3)
Since: signal v0.1.0
buffer-read-cubic
(buffer-read-cubic [buf : Buffer pos :float] :)
cubic-interpolated read at a position in buffer lengths.
| buf | the buffer | |
| pos | read position; wraps, so any float is valid |
The interpolated sample.
(buffer-read-cubic buf 0.5) ;; the middle of the buffer
Since: signal v0.1.0
buffer-read-sinc
(buffer-read-sinc [buf : Buffer pos :float] :)
band-limited read at a position in buffer lengths.
| buf | the buffer | |
| pos | read position; wraps, so any float is valid |
The interpolated sample.
(buffer-read-sinc buf 0.5) ;; the middle of the buffer
Since: signal v0.1.0
buffer-render
(buffer-render [sample-rate :float n :int ^fat sig : (fn [float])
record `n` samples of a signal into a new buffer.
| sample-rate | the rate to sample `sig` at, in Hz | |
| n | length in samples, clamped to [1, 16777216] | |
| sig | the signal to record |
A new Buffer.
;; one cycle of a 1 Hz sine over 2048 samples: a wavetable (buffer-render 2048.0 2048 ((sine 1.0 0.0) (constant 0.0)))
scan
(scan [buf : Buffer])
read a buffer at the position given by the input signal.
| buf | the buffer to scan |
SF Sample Sample: position -> sample. Stateless.
((scan table) ((sawtooth 220.0) (constant 0.0)))
scan-nearest
(scan-nearest [buf : Buffer])
`scan` with no interpolation: each position reads the
| buf | the buffer to scan |
SF Sample Sample: position -> nearest sample. Stateless.
((scan-nearest steps) ((sawtooth 2.0) (constant 0.0)))
Since: signal v0.1.0
scan-cubic
(scan-cubic [buf : Buffer])
`scan` with 4-point cubic Hermite interpolation
| buf | the buffer to scan |
SF Sample Sample: position -> interpolated sample. Stateless.
((scan-cubic table) ((sawtooth 220.0) (constant 0.0)))
Since: signal v0.1.0
scan-sinc
(scan-sinc [buf : Buffer])
`scan` with 32-tap windowed-sinc interpolation
| buf | the buffer to scan |
SF Sample Sample: position -> interpolated sample. Stateless.
((scan-sinc recording) ((sawtooth 1.0) (constant 0.0)))
Since: signal v0.1.0
Internal definitions
__buffer_alloc-- allocate a zeroed buffer of `n` samples (clamped).__buffer_fill-- write sig(k / sample-rate) into every slot, in order.