synth
Small DSP primitives that write interleaved mono f32 into a `buffer`, which is what `asset.create("soundClip", …, { pcm = … })` takes. Used by `carrington/sound/clips`; useful on its own for any world that needs sound it can compute rather than fetch.
synth — the kit the film's sound is cut from
Small DSP primitives that write interleaved mono f32 into a buffer, which is
what asset.create("soundClip", …, { pcm = … }) takes. Used by
carrington/sound/clips; useful on its own for any world that needs sound it
can compute rather than fetch.
local S = require("carrington.sound.synth")
local c = S.seconds(4.0, 22050) -- a four-second clip
S.partial(c, 110.0, 0.6, 0.0) -- a sine, snapped so the loop closes
S.beatingPair(c, 220.0, 0.4, 0.3, 1.1)
S.noise(c, 1.0); S.bandpass(c, 300.0, 2000.0)
S.shape(c, function(u) return 0.5 + 0.5 * math.sin(math.pi * 2 * u) end)
S.normalize(c, 0.85)
Three properties worth knowing
A bed made from these is exactly periodic. partial rounds its frequency
onto the clip's own grid (sampleRate / frames) so it comes back to phase zero
at the last sample. lowpass runs the whole buffer once and throws the output
away before it starts keeping any, so the filter enters sample 0 already
carrying the tail — a filtered noise bed therefore joins its own end. grain
writes past the end by wrapping into the head.
A bake is reproducible. The noise source is a seeded LCG (S.seed), so
re-running a recipe writes the same bytes rather than a different clip under
the same name.
Nothing here is real-time. A twelve-second bed takes about 0.6 s to build,
and asset.create writing it stalls the frame loop while it encodes. Bake at
authoring time, never during a take.
Surface
| buffers | new seconds copy rd wr |
| sources | noise partial beatingPair grain |
| filters | lowpass lowpassN highpass bandpass |
| shaping | gain shape mix peak normalize soften |
| envelopes | ad trimEnds |
| noise | seed rand between |
grain(clip, atFrame, lenFrames, amp, kind) takes "tick" (bright crackle),
"thud" (a low body) or "ping" (an inharmonic metallic ring), and always
wraps.
Scoped to this part · feeds back into the world's score.