diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:07:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | cddefdd6e5c7fb632088d504d2ed96368fa44e0f (patch) | |
| tree | 3ae5bf53be2f5dc5746c9d3ece5e90786c3637b6 /src/host/script.zig | |
| parent | fe0cee90f9bd4caa60b907e502aec4cc0daa4b60 (diff) | |
| download | sketchbook-cddefdd6e5c7fb632088d504d2ed96368fa44e0f.tar.gz sketchbook-cddefdd6e5c7fb632088d504d2ed96368fa44e0f.zip | |
host.newSound: samples a sketch made become a sound, played by voices
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
Diffstat (limited to 'src/host/script.zig')
| -rw-r--r-- | src/host/script.zig | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/host/script.zig b/src/host/script.zig index 9e1dddf..a559d76 100644 --- a/src/host/script.zig +++ b/src/host/script.zig @@ -27,7 +27,9 @@ //! holds VALUE, read in its own layout //! expect-log TEXT a recent console line contains TEXT //! expect-no-log TEXT no recent console line does -//! expect-audio KEY stream KEY has received samples +//! expect-audio KEY stream KEY has received samples, or voice +//! KEY sounded since the last check of it +//! expect-no-audio KEY voice KEY did not sound since the last check //! screenshot FILE save the next frame as PNG //! expect-same-screenshot A B [MAX [X Y W H]] //! two saved PNGs match, every channel within MAX @@ -236,7 +238,10 @@ fn step(host: *Host, arena: std.mem.Allocator, command: []const u8, rest: []cons return; } else if (eq(u8, command, "expect-audio")) { const key = try std.fmt.parseInt(u32, rest, 10); - if (host.input.stream(key).pushed == 0) return error.ExpectationFailed; + if (host.input.stream(key).pushed == 0 and !host.audio.sounded(key)) return error.ExpectationFailed; + return; + } else if (eq(u8, command, "expect-no-audio")) { + if (host.audio.sounded(try std.fmt.parseInt(u32, rest, 10))) return error.ExpectationFailed; return; } else if (eq(u8, command, "screenshot")) { if (std.fs.path.dirname(rest)) |dir| try std.Io.Dir.cwd().createDirPath(host.io, dir); |
