diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/voices.script | 29 | ||||
| -rw-r--r-- | test/voices.zig | 28 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/voices.script b/test/voices.script new file mode 100644 index 0000000..43283f7 --- /dev/null +++ b/test/voices.script @@ -0,0 +1,29 @@ +# A sound made with host.newSound is a voice like a loaded one: it sounds +# once for its serial, a replay that keeps declaring that serial does not +# sound it again, and a new serial does. +frames 3 +expect-no-audio 1 +key space +expect serial 1 +expect-audio 1 +frames 10 +expect-no-audio 1 +# Recorded while the blip is declared but finished, then played back, +# stepped and seeked over: the same serial all along, so it stays silent. +console record 0 +frames 20 +console stop +console play 0 +frames 30 +expect-no-audio 1 +console seek start +console step 5 +console seek end +expect-no-audio 1 +console stop +# A new serial starts it again. +key space +expect serial 2 +expect-audio 1 +frames 10 +expect-no-audio 1 diff --git a/test/voices.zig b/test/voices.zig new file mode 100644 index 0000000..9932642 --- /dev/null +++ b/test/voices.zig @@ -0,0 +1,28 @@ +//! A sound the sketch made itself, played as a voice: space bumps the +//! serial that starts it (test/voices.script). +const sk = @import("sketch"); + +pub const name = "voices"; +pub const width = 160; +pub const height = 120; + +pub const State = struct { serial: u32 = 0 }; +pub const Session = struct { blip: sk.Audio = .none }; + +pub fn setup(ss: *Session, init: *sk.Init) !void { + // Shorter than the host's lead (2048 samples), so the first frame that + // declares it mixes all of it. + var samples: [1000]f32 = undefined; + for (&samples, 0..) |*v, i| v.* = 0.5 * @sin(@as(f32, @floatFromInt(i)) * 0.06); + ss.blip = init.host.newSound(&samples); + if (ss.blip == .none) return error.NewSound; +} + +pub fn update(s: *State, in: *const sk.Input) void { + if (in.pressed(sk.Key.space)) s.serial += 1; +} + +pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { + f.clear(0x202020); + if (s.serial != 0) f.voice(.{ .key = 1, .audio = ss.blip, .serial = s.serial }); +} |
