First Light: Goura
README.md
dsp
The signal work behind every clip in First Light: Goura.
local Dsp = require("game.sound.dsp")
Pure CPU maths over interleaved f32 buffers — the shape audio.encodePcm
takes, asset.create("soundClip", …, { pcm = … }) takes, and audio.decode
hands back. Nothing here touches an asset, an entity or the mixer, so it runs
the same at author time in an execute, in a headless engine, and in a
browser.
Synthesis
Dsp.tone and Dsp.noiseBurst write into a mono buffer: a frequency (or a
glide between two), an amplitude, a start and a length, an attack, and either
a linear tail or an exponential tau. noiseBurst takes one-pole lowpass
and highpass corners. Both take wrap = true, which writes past the end of
the buffer back at its start — the thing a looping bed's grains need so a
cricket near the seam is not cut in half.
Dsp.rng(seed) is a reproducible uniform source. Every bake on every machine
produces the same bytes, which is what makes re-running the bake a no-op
rather than a new asset checksum.
Conditioning
What a take needs before it can ship: toMono, trimLead / trimTail,
dcBlock, fadeEnds, normalise, limit, and checkFinite — the last
being the read that catches a filter which diverged, before
audio.encodePcm refuses the buffer for it.
Dsp.seamless(buffer, rate, seconds)
The one that makes a loop a loop. It crossfades the last seconds of a take
over its first seconds and drops them, 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 value and in slope, and there is no click at the seam. This
is why the beds need no loop points: a .soundClip's loopStart / loopEnd
are stored and read by nothing, so a bed that must loop is built to.
Consumed by
game.sound.recipes (which builds each clip with it) and game.sound.bake
(which conditions generated takes with it). Nothing at runtime.