diff options
Diffstat (limited to 'src/sketch')
| -rw-r--r-- | src/sketch/root.zig | 7 | ||||
| -rw-r--r-- | src/sketch/web.zig | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/sketch/root.zig b/src/sketch/root.zig index d15046d..0ab04a7 100644 --- a/src/sketch/root.zig +++ b/src/sketch/root.zig @@ -219,6 +219,13 @@ pub const Frame = struct { pub fn audio(f: *Frame, key: u32, samples: []const f32, options: struct { clear: bool = false }) void { f.emit(.{ .audio = .{ .key = key, .samples = samples, .clear = options.clear } }); } + /// Streams `count` samples a compute shader wrote to `buffer` (f32 from + /// `offset`) on stream `key`, as `audio` streams samples: a GPU synth's + /// output, heard without a readback of the sketch's own. Make + /// `in.lead -| in.stream(key).queued` of them a frame. + pub fn audioBuffer(f: *Frame, key: u32, buffer: abi.Buffer, options: struct { offset: u32 = 0, count: u32 }) void { + f.emit(.{ .audio_buffer = .{ .key = key, .buffer = buffer, .offset = options.offset, .count = options.count } }); + } pub fn pixels(f: *Frame, img: Image, w: u32, h: u32, rgba: []const u8, options: struct { premultiplied: bool = false }) void { f.emit(.{ .pixels = .{ .image = img, .w = w, .h = h, .rgba = rgba, .premultiplied = options.premultiplied } }); } diff --git a/src/sketch/web.zig b/src/sketch/web.zig index 62a173a..a035117 100644 --- a/src/sketch/web.zig +++ b/src/sketch/web.zig @@ -48,6 +48,8 @@ const js = struct { extern "gpu" fn download(id: u32, offset: u32, size: u32, key: u32) void; extern "audio" fn rate() u32; extern "audio" fn push(key: u32, ptr: [*]const f32, len: usize, clear: u32) void; + /// `count` samples from a GPU buffer, queued on arrival. + extern "audio" fn buffer(key: u32, id: u32, offset: u32, count: u32) void; extern "audio" fn queued(key: u32) u32; /// Keeps the microphone open; it answers through `sk_microphone`. extern "audio" fn listen() void; @@ -225,6 +227,10 @@ fn Driver(comptime App: type) type { s.pushed += v.samples.len; js.push(v.key, v.samples.ptr, v.samples.len, @intFromBool(v.clear)); }, + .audio_buffer => |v| { + stream(v.key).pushed += v.count; + js.buffer(v.key, @backingInt(v.buffer), v.offset, v.count); + }, .microphone => js.listen(), .upload => |v| _ = js.write(@backingInt(v.buffer), v.offset, v.bytes.ptr, v.bytes.len), .compute => |v| { |
