summaryrefslogtreecommitdiff
path: root/test/voices.script
Commit message (Collapse)AuthorAge
* sk.sfxr: the sfxr sound-effect generator, from 02-dont-rat-me-outGabriel Schneider115 min.
| | | | | | | | | | | | | | | | | | | | | | | | 02-dont-rat-me-out's synth.zig, a pure and deterministic port of DrPetter's sfxr, moves into the library as src/sketch/sfxr.zig, exposed as sk.sfxr: render(params, rate, out) gives a coin, blip, laser or explosion as samples for host.newSound. Its knobs count in samples at 44.1 kHz, so the one change is the rate: every length (envelope, arpeggio, repeat, phaser offset, period) grows by rate/44.1 kHz and every per-sample step (slides, duty sweep, vibrato, filter coefficients and their ramps) shrinks by it, to first order for the slides and filters; at 44.1 kHz each factor is 1 and the samples are the original's to the bit. Two spellings change without changing a sample: the phaser buffer is @splat (Zig 0.17 has no ** on arrays) and the phaser delay is clamped before it is converted, so a long sweep cannot overflow it. Test: four parameter sets that between them turn every knob render the lengths and Wyhash of the samples the original rendered at 44.1 kHz (run once, outside the repo), and at 48 kHz a sound as long within 1 %. test/voices.zig makes its blip with sfxr in draw, at in.sample_rate, and is the README's example: a blip in six lines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* host.newSound: samples a sketch made become a sound, played by voicesGabriel Schneider115 min.
A sketch that synthesised a one-shot had to stream it (and keep a replay from re-firing it by hand) or encode a WAV for decodeSound. host.newSound (samples) copies mono samples at in.sample_rate into the host and gives an Audio like a loaded one, so the one-shot is a voice: reconciled by key and serial, mixed, faded and limited by the host. It is kept for the life of the host like every sound, and .none if a sample is not finite. The vtable entry is C callconv (pointer and length), as anything new in abi.zig is, for a second host; the web host keeps the copy for samples() (its voices are silent). Tests: a unit test that the sound is a copy and that NaN and infinity are refused; test/voices.zig makes a 1000-sample blip in setup and declares it under a serial space bumps, and test/voices.script checks it sounds once, stays silent through a recording of it played, stepped and seeked, and sounds again for a new serial. For that, expect-audio KEY also passes when voice KEY was mixed since it was last asked, and expect-no-audio KEY says it was not. zig build test-audio runs the script too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T