summaryrefslogtreecommitdiff
path: root/src/sketch/web.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sketch/web.zig')
-rw-r--r--src/sketch/web.zig18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/sketch/web.zig b/src/sketch/web.zig
index 62a173a..804a4df 100644
--- a/src/sketch/web.zig
+++ b/src/sketch/web.zig
@@ -2,7 +2,7 @@
//! the imports below: drawing on a 2D canvas, GPU work on WebGPU, sound and
//! the microphone on Web Audio, files through the page. State, `update` and
//! `draw` are the same Zig as on native. There is no timeline, and nothing
-//! persists: Store lasts as long as the page.
+//! persists.
const std = @import("std");
const abi = @import("abi");
const root = @import("root.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;
@@ -82,8 +84,6 @@ fn Driver(comptime App: type) type {
var ready = false;
var state: G.State = undefined;
var session: G.Session = undefined;
- // No disk on the web: the store lasts as long as the page.
- var store: G.Store = undefined;
var events: [1024]abi.Event = undefined;
var event_count: usize = 0;
var input: abi.Input = .{};
@@ -105,9 +105,7 @@ fn Driver(comptime App: type) type {
.input = &input,
.scratch = scratch.allocator(),
.session = gpa,
- .store = gpa,
.session_root = std.mem.asBytes(&session),
- .store_root = std.mem.asBytes(&store),
.commands = &commands,
};
}
@@ -115,7 +113,6 @@ fn Driver(comptime App: type) type {
fn init() callconv(.c) void {
G.defaults(.state, std.mem.asBytes(&state));
G.defaults(.session, std.mem.asBytes(&session));
- G.defaults(.store, std.mem.asBytes(&store));
input.width = G.description.width;
input.height = G.description.height;
if (input.window_width == 0) {
@@ -225,6 +222,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| {
@@ -414,6 +415,7 @@ fn Driver(comptime App: type) type {
.newSound = newSound,
.samples = samples,
.readFile = readFile,
+ .appendFile = appendFile,
.env = env,
.clock = clock,
};
@@ -478,6 +480,10 @@ fn Driver(comptime App: type) type {
fn readFile(_: *anyopaque, _: []const u8) []const u8 {
return &.{};
}
+ /// No files on the web: nothing is written, and the path is "".
+ fn appendFile(_: *anyopaque, _: [*]const u8, _: usize, _: [*]const u8, _: usize, _: bool) callconv(.c) [*:0]const u8 {
+ return "";
+ }
fn env(_: *anyopaque, _: []const u8) ?[]const u8 {
return null;
}