summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/live/shaders/synth.comp10
-rw-r--r--examples/live/src/Lang.zig6
-rw-r--r--examples/live/src/main.zig13
-rw-r--r--examples/live/src/probe.zig1
-rw-r--r--examples/live/test/live.script22
5 files changed, 40 insertions, 12 deletions
diff --git a/examples/live/shaders/synth.comp b/examples/live/shaders/synth.comp
index 8ae48bb..0e7ab02 100644
--- a/examples/live/shaders/synth.comp
+++ b/examples/live/shaders/synth.comp
@@ -1,8 +1,9 @@
#version 450
#extension GL_GOOGLE_include_directive : require
// One audio block, one thread per sample: the out tape at each sample's
-// time, crossing over the first `fade` samples from the tape it replaces,
-// so an edit does not click. x and y are 0.
+// time, crossing over the first `fade` samples from the tape it replaces
+// (at its own time, which differs after a seek), so an edit or a seek
+// does not click. x and y are 0.
layout(local_size_x = 64) in;
#include "Synth.glsl"
@@ -21,8 +22,7 @@ float heard(float v) {
void main() {
uint n = gl_GlobalInvocationID.x;
if (n >= u.count) return;
- float t = u.start + float(n) / u.rate;
- float v = heard(vm(0u, u.len, t, 0.0, 0.0).x);
- if (n < u.fade) v = mix(heard(vm(MAX_TAPE, u.old_len, t, 0.0, 0.0).x), v, (float(n) + 0.5) / float(u.fade));
+ float v = heard(vm(0u, u.len, u.start + float(n) / u.rate, 0.0, 0.0).x);
+ if (n < u.fade) v = mix(heard(vm(MAX_TAPE, u.old_len, u.old_start + float(n) / u.rate, 0.0, 0.0).x), v, (float(n) + 0.5) / float(u.fade));
block[n] = v;
}
diff --git a/examples/live/src/Lang.zig b/examples/live/src/Lang.zig
index 4f3c3bf..484de54 100644
--- a/examples/live/src/Lang.zig
+++ b/examples/live/src/Lang.zig
@@ -484,10 +484,12 @@ pub const Synth = extern struct {
/// Samples in the block.
count: u32,
fade: u32,
- /// The block's first sample, seconds.
+ /// The block's first sample, seconds; the old tape's, which differs
+ /// after a jump (a seek: the old tape where the device was).
start: f32,
+ old_start: f32,
rate: f32,
- pad: [2]f32 = .{ 0, 0 },
+ pad: f32 = 0,
pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
};
diff --git a/examples/live/src/main.zig b/examples/live/src/main.zig
index 13f89be..965152a 100644
--- a/examples/live/src/main.zig
+++ b/examples/live/src/main.zig
@@ -166,16 +166,20 @@ fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
ss.block = f.host.newBuffer(max_block * @sizeOf(f32));
ss.tapes = f.host.newBuffer(2 * @sizeOf(Lang.Tape.Code));
}
- // A jump is heard at once: what was queued from before it is dropped.
+ // A jump is heard at once: what was queued from before it is dropped,
+ // and the block crosses from where the device was to the new time.
+ const rate: f64 = @floatFromInt(in.sample_rate);
+ var queued = in.stream(stream).queued;
+ const was = ss.clock - @as(f64, @floatFromInt(queued)) / rate;
if (in.jumped) {
ss.clock = s.time;
+ queued = 0;
f.audio(stream, &.{}, .{ .clear = true });
}
- const rate: f64 = @floatFromInt(in.sample_rate);
- const want: u32 = @min(in.lead -| in.stream(stream).queued, max_block);
+ const want: u32 = @min(in.lead -| queued, max_block);
if (want > 0) {
const new = std.mem.sliceAsBytes(s.out.slice());
- const changed = !std.mem.eql(u8, new, std.mem.sliceAsBytes(ss.heard.slice()));
+ const changed = in.jumped or !std.mem.eql(u8, new, std.mem.sliceAsBytes(ss.heard.slice()));
const tapes = f.scratch.create([2]Lang.Tape.Code) catch return;
tapes.* = .{ s.out.code, ss.heard.code };
f.upload(ss.tapes, 0, std.mem.asBytes(tapes));
@@ -190,6 +194,7 @@ fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
.count = want,
.fade = if (changed and s.crossfade) want else 0,
.start = @floatCast(ss.clock),
+ .old_start = @floatCast(if (in.jumped) was else ss.clock),
.rate = @floatCast(rate),
}),
.groups = .{ (want + 63) / 64, 1, 1 },
diff --git a/examples/live/src/probe.zig b/examples/live/src/probe.zig
index 1e2970c..4f816b2 100644
--- a/examples/live/src/probe.zig
+++ b/examples/live/src/probe.zig
@@ -123,6 +123,7 @@ pub fn draw(ss: *Session, f: *sk.Frame) void {
.count = k.count,
.fade = if (k.fade) k.count else 0,
.start = ss.time,
+ .old_start = ss.time,
.rate = 48000,
}),
.groups = .{ (k.count + 63) / 64, 1, 1 },
diff --git a/examples/live/test/live.script b/examples/live/test/live.script
index 22085bf..695d16a 100644
--- a/examples/live/test/live.script
+++ b/examples/live/test/live.script
@@ -1,4 +1,6 @@
-# A program typed, its tapes after each line, a broken line and its mend.
+# A program typed, its tapes after each line, a broken line and its mend;
+# then this run's session played back, and sought to two moments marked as
+# they happened. (A mark ends a clip, `record`, so the session is replayed.)
# Screenshots land in .zig-cache/live/ for review; they are compared over
# the picture alone (640,300 600x300: not the text, the scope or the time).
frames 2
@@ -16,6 +18,7 @@ expect color.len 4
expect color.code[0].op x
expect color.code[3].op hsv
frames 2
+console save typed
screenshot .zig-cache/live/gradient.png
# An edit: y becomes x, and the picture changes.
key backspace
@@ -39,3 +42,20 @@ expect-same-screenshot .zig-cache/live/edited.png .zig-cache/live/broken.png 0 6
type )
expect problem.len 0
expect color.len 3
+console save end
+# Played back from the start, then sought: each moment's text, tapes and
+# time as they were live, leaf by leaf (a mark is taken before its frame's
+# tick: 0.2667 s and 0.4833 s; a seek lands on the last frame at or before).
+console play session 0
+frames 100
+console seek 488
+expect-snapshot end
+console seek 272
+expect-snapshot typed
+expect color.len 4
+screenshot .zig-cache/live/sought.png
+expect-same-screenshot .zig-cache/live/gradient.png .zig-cache/live/sought.png 0 0 0 1000 600
+# Live again from there: the typed program, before its edit.
+console stop
+expect len 53
+expect color.code[3].op hsv