From a4d1e3131499c17bd6f73e65154aa0c2b31c62b3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 06:05:00 -0300 Subject: examples/live: the sound, the out tape on the GPU per sample `pub const audio_pull = 256`; each frame `draw` runs synth.comp over as many samples as keep the host's lead queued (`in.lead -| queued`, 8192 at most) and streams the block with f.audioBuffer, as spheres does. Time is a sample clock in Session: set from State's time at every jump (a seek, a step, a replay's start; the queue is dropped then, so the jump is heard at once), and free-running otherwise, so a paused replay keeps sounding its moment. When the out tape differs from the one the last block played, the block crosses from the old tape to the new over its length (`set crossfade false` turns that off, to hear what it saves). The blocks are read back for the scope (an oscilloscope and a spectrum along the bottom) and, after the console's `capture`, appended to the sketch's capture.f32 beside its save. The status line shows the lead. The tapes reach synth.comp in a storage buffer, uploaded per block: two tapes are 4 KiB, and SDL_GPU's Vulkan backend binds a uniform block 4 KiB at a time (MAX_UBO_SECTION_SIZE), so a 4128-byte Synth block read its count as 0 past the cut and the kernel wrote nothing, silently: the probe's first synth numbers timed that. Measured again (RTX 3050, Debug host, two runs): every synth dispatch 0.08-0.14 ms, 60 or 128 instructions, 256 or 1024 samples, fading or not, the empty pass's cost alone; the 4 KiB upload 0.07-0.08. Measured on SDL's dummy driver (nothing audible) from captures: out = 0.3 * sin(t * tau * 220): peak 0.3000, RMS 0.2121, fundamental 220.000 Hz; edited to 330 in one keystroke, 330.000 Hz. The largest sample-to-sample step across the edit: 0.0131 with the crossfade (a 330 Hz sine's own steepest step is 0.0130), 0.3725 without; into the first sound, 0.0011 and 0.2967. The survey's program: peak 0.50, RMS 0.16, its bass at 55.0 Hz. Test: live.script also expects the stream to receive the GPU's blocks, and compares screenshots above the scope. zig build test: 68 of 68 steps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- examples/live/test/live.script | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'examples/live/test/live.script') diff --git a/examples/live/test/live.script b/examples/live/test/live.script index 386ab33..22085bf 100644 --- a/examples/live/test/live.script +++ b/examples/live/test/live.script @@ -1,11 +1,15 @@ # A program typed, its tapes after each line, a broken line and its mend. -# Screenshots land in .zig-cache/live/ for review. +# Screenshots land in .zig-cache/live/ for review; they are compared over +# the picture alone (640,300 600x300: not the text, the scope or the time). frames 2 type out = sin(tau * 220 * t) * 0.3 expect problem.len 0 expect out.len 8 expect out.code[5].op sin expect out.code[7].op mul +# The GPU's blocks reach the speakers' stream (SDL's dummy driver here). +frames 10 +expect-audio 1 key return type color = hsv(x, 0.5, y) expect color.len 4 @@ -22,7 +26,7 @@ expect color.code[2].op hsv expect color.code[2].c 0 frames 2 screenshot .zig-cache/live/edited.png -expect-different-screenshot .zig-cache/live/gradient.png .zig-cache/live/edited.png 640 300 600 380 +expect-different-screenshot .zig-cache/live/gradient.png .zig-cache/live/edited.png 640 300 600 300 # Broken: the tape and the picture stay, the problem is set at its byte. key backspace expect problem.at 52 @@ -30,7 +34,7 @@ expect color.len 3 expect color.code[2].c 0 frames 2 screenshot .zig-cache/live/broken.png -expect-same-screenshot .zig-cache/live/edited.png .zig-cache/live/broken.png 0 640 300 600 380 +expect-same-screenshot .zig-cache/live/edited.png .zig-cache/live/broken.png 0 640 300 600 300 # Mended. type ) expect problem.len 0 -- cgit v1.3