buffer(samples: number) → buffer
Buffers. A mono clip is one f32 per frame; a stereo one is L,R per frame.
A zeroed f32 buffer holding `samples` samples.
| arg | type | description |
|---|
| samples | number | |
count(b: buffer) → number
How many f32 samples a buffer holds.
| arg | type | description |
|---|
| b | buffer | |
get(b: buffer, i: number) → number
| arg | type | description |
|---|
| b | buffer | |
| i | number | |
set(b: buffer, i: number, v: number) → void
| arg | type | description |
|---|
| b | buffer | |
| i | number | |
| v | number | |
add(b: buffer, i: number, v: number) → void
| arg | type | description |
|---|
| b | buffer | |
| i | number | |
| v | number | |
fromString(s: string) → buffer
Interpret a binary string of little-endian f32 (what `audio.decode` and a
clip's `:pcm()` return) as a buffer.
| arg | type | description |
|---|
| s | string | |
rng(seed: number) → Rng
A reproducible uniform source in [0, 1). Seed it per clip.
| arg | type | description |
|---|
| seed | number | |
noise(rng: Rng) → number
Uniform noise in [-1, 1).
ad(t: number, dur: number, attack: number, decay: number) → number
Envelopes and curves.
An attack/decay envelope over `t` seconds of a sound `dur` seconds long.
`attack` and `decay` are seconds; the sustain between them is flat.
| arg | type | description |
|---|
| t | number | |
| dur | number | |
| attack | number | |
| decay | number | |
decay(t: number, tau: number) → number
Exponential decay to `-60 dB` at `tau` seconds.
| arg | type | description |
|---|
| t | number | |
| tau | number | |
equalPower(t: number) → void
Equal-power crossfade weights for a position `t` in [0, 1].
| arg | type | description |
|---|
| t | number | |
smooth(t: number) → number
Smoothstep, for curves that should not start or stop abruptly.
| arg | type | description |
|---|
| t | number | |
tone(b: buffer, rate: number, o: ToneOpts) → void
Add a tone to a mono buffer at `rate` Hz.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| o | ToneOpts | |
noiseBurst(b: buffer, rate: number, o: NoiseOpts) → void
Add filtered noise to a mono buffer.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| o | NoiseOpts | |
toMono(b: buffer, channels: number) → buffer
Conditioning: what a take needs before it ships.
Fold an interleaved buffer down to one channel.
| arg | type | description |
|---|
| b | buffer | |
| channels | number | |
peak(b: buffer) → number
The largest absolute sample in a buffer.
| arg | type | description |
|---|
| b | buffer | |
rms(b: buffer) → number
Root-mean-square level of a buffer.
| arg | type | description |
|---|
| b | buffer | |
normalise(b: buffer, target: number) → buffer
Scale a buffer so its loudest sample sits at `target`.
| arg | type | description |
|---|
| b | buffer | |
| target | number | |
dcBlock(b: buffer) → buffer
Remove any constant offset, which a click at the start of playback is
usually made of.
| arg | type | description |
|---|
| b | buffer | |
fadeEnds(b: buffer, rate: number, seconds: number) → buffer
Ramp the first and last `seconds` of a mono buffer in and out, so a
one-shot neither clicks on at the head nor cuts off at the tail.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| seconds | number | |
trimLead(b: buffer, rate: number, threshold: number) → buffer
Drop the silence a generated take opens with: everything before the first
sample above `threshold`, less a short run-up so the attack survives.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| threshold | number | |
trimTail(b: buffer, rate: number, threshold: number, tailSeconds: number) → buffer
Drop the silence a take ends with, keeping `tailSeconds` of it.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| threshold | number | |
| tailSeconds | number | |
seamless(b: buffer, rate: number, seconds: number) → buffer
Turn a finite mono take into a **seamless loop**.
The last `seconds` of the take are crossfaded over its first `seconds` and
then dropped, so the sample after the last one in the result is literally
the sample that followed it in the source: the wrap is continuous in both
value and slope, and there is no click at the seam. This is the reason a
bed does not need loop points — `loopStart` / `loopEnd` are stored by the
clip and read by nothing, so a bed that must loop is built to loop.
| arg | type | description |
|---|
| b | buffer | |
| rate | number | |
| seconds | number | |
mixInto(dst: buffer, src: buffer, gain: number) → void
Mix `src` into `dst` at `gain`, repeating or truncating `src` to fit.
| arg | type | description |
|---|
| dst | buffer | |
| src | buffer | |
| gain | number | |
checkFinite(b: buffer) → void
Every sample finite, which is what `audio.encodePcm` refuses a buffer for.
Returns the count of samples that are not, and the first index.
| arg | type | description |
|---|
| b | buffer | |
limit(b: buffer, ceiling: number) → buffer
Hard-limit a buffer into [-ceiling, ceiling] with a soft knee, so a mix
that peaked over unity does not arrive as square-wave distortion.
| arg | type | description |
|---|
| b | buffer | |
| ceiling | number | |