<feed xmlns='http://www.w3.org/2005/Atom'>
<title>sketchbook.git/test/voices.script, branch main</title>
<subtitle>A small Zig platform for sketching games and toys</subtitle>
<id>https://git.0x4200.cafe/sketchbook.git/atom?h=main</id>
<link rel='self' href='https://git.0x4200.cafe/sketchbook.git/atom?h=main'/>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/'/>
<updated>2026-11-17T15:15:01Z</updated>
<entry>
<title>sk.sfxr: the sfxr sound-effect generator, from 02-dont-rat-me-out</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T03:09:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=896855648c3371ede3c672bbfa75175fa3a1e42e'/>
<id>urn:sha1:896855648c3371ede3c672bbfa75175fa3a1e42e</id>
<content type='text'>
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 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>host.newSound: samples a sketch made become a sound, played by voices</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T03:07:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=cddefdd6e5c7fb632088d504d2ed96368fa44e0f'/>
<id>urn:sha1:cddefdd6e5c7fb632088d504d2ed96368fa44e0f</id>
<content type='text'>
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 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
</feed>
