summaryrefslogtreecommitdiff
path: root/src/abi.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:07:07 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitcddefdd6e5c7fb632088d504d2ed96368fa44e0f (patch)
tree3ae5bf53be2f5dc5746c9d3ece5e90786c3637b6 /src/abi.zig
parentfe0cee90f9bd4caa60b907e502aec4cc0daa4b60 (diff)
downloadsketchbook-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/abi.zig')
-rw-r--r--src/abi.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/abi.zig b/src/abi.zig
index f0abdb3..3c47e69 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -632,6 +632,8 @@ pub const Host = struct {
/// WAV, FLAC or Ogg Vorbis bytes in memory. Not cached. `.none` if
/// they do not decode.
decodeSound: *const fn (*anyopaque, []const u8) Audio,
+ /// Samples a sketch made, copied: see `Host.newSound`.
+ newSound: *const fn (*anyopaque, [*]const f32, usize) callconv(.c) Audio,
/// A loaded sound's samples: mono, at `Input.sample_rate`, alive as
/// long as the host. Empty for `.none`.
samples: *const fn (*anyopaque, Audio) []const f32,
@@ -696,6 +698,14 @@ pub const Host = struct {
pub fn decodeSound(h: Host, wav: []const u8) Audio {
return h.vtable.decodeSound(h.ctx, wav);
}
+ /// Mono samples at `Input.sample_rate`, copied into the host: a sound
+ /// for `Voice.audio` like a loaded one (synthesised one-shots become
+ /// voices, reconciled and replay-safe). Kept for the life of the host,
+ /// like every sound: make each once (in `setup`, or cached in Session).
+ /// `.none` if a sample is not finite.
+ pub fn newSound(h: Host, sound: []const f32) Audio {
+ return h.vtable.newSound(h.ctx, sound.ptr, sound.len);
+ }
pub fn samples(h: Host, audio: Audio) []const f32 {
return h.vtable.samples(h.ctx, audio);
}