From a3085da09e222238071c4948f6893b21542ac695 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 02:36:42 -0300 Subject: host: a sketch may ask for the sound device's pull, audio_pull Sound a sketch makes leaves for the device about one pull after draw, and SDL opens 1024-sample pulls at 48 kHz (21 ms); 256 leaves in about 6.5 ms, but the audio server then runs every client at that size, and drops out under load. The only way to ask was SDL_AUDIO_DEVICE_SAMPLE_FRAMES in the environment. Now an app declares `pub const audio_pull = 256;` beside its name; abi.Info carries it (0, SDL's own, when it is not declared), and the host sets it as SDL's hint just before it opens the device, at normal priority, so the environment variable still wins. It is read once, at start; the web host has no device to open and ignores it. The sound overlay's header says what the device took: OUTPUT ch1 / ... / pull 256. Test: audio, on SDL's dummy driver: the device opened with nothing asked takes 1024 at once, asked 256 takes 256, and with 512 in SDL's copy of the environment takes 512 though 256 was asked. test-audio: 48/48 steps, 9/9 tests. README: the app table's row, and a paragraph in sound with the trade-off. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/host/overlay.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/host/overlay.zig') diff --git a/src/host/overlay.zig b/src/host/overlay.zig index e1fc45d..ec040e7 100644 --- a/src/host/overlay.zig +++ b/src/host/overlay.zig @@ -111,7 +111,7 @@ pub fn drawMemory(out: *List, arena: std.mem.Allocator, layout: memory.Layout, s } } -pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rate: u32, canvas: [2]u32) !void { +pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rate: u32, pull: u32, canvas: [2]u32) !void { const green: abi.Color = .{ .r = 105, .g = 245, .b = 160 }; const x = @as(f32, @floatFromInt(canvas[0])) - 526; const top = @as(f32, @floatFromInt(canvas[1])) - 130; @@ -119,7 +119,7 @@ pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rat try out.append(arena, .{ .rect = .{ .dst = .{ .x = x, .y = top, .w = 514, .h = 118 }, .color = .{ .r = 24, .g = 24, .b = 24 } } }); try out.append(arena, .{ .rect = .{ .dst = .{ .x = x + 1, .y = mid, .w = 512, .h = 1 }, .color = .{ .r = 60, .g = 85, .b = 65 } } }); const ms = @as(f32, @floatFromInt(samples.len * 1000)) / @as(f32, @floatFromInt(@max(rate, 1))); - try out.append(arena, .{ .text = .{ .x = x + 8, .y = top + 10, .scale = 1, .color = green, .bytes = try std.fmt.allocPrint(arena, "OUTPUT ch1 / {d:.1}ms / overlay sound to hide", .{ms}) } }); + try out.append(arena, .{ .text = .{ .x = x + 8, .y = top + 10, .scale = 1, .color = green, .bytes = try std.fmt.allocPrint(arena, "OUTPUT ch1 / {d:.1}ms / pull {d} / overlay sound to hide", .{ ms, pull }) } }); for (samples, 0..) |sample, i| { const a = std.math.clamp(if (std.math.isFinite(sample)) sample else 0, -1, 1); const previous = samples[i -| 1]; -- cgit v1.3