summaryrefslogtreecommitdiff
path: root/examples/live/shaders/synth.comp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/live/shaders/synth.comp')
-rw-r--r--examples/live/shaders/synth.comp26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/live/shaders/synth.comp b/examples/live/shaders/synth.comp
new file mode 100644
index 0000000..9a066a6
--- /dev/null
+++ b/examples/live/shaders/synth.comp
@@ -0,0 +1,26 @@
+#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.
+layout(local_size_x = 64) in;
+
+#include "Synth.glsl"
+#define TAPE(i) u.tape[i]
+#include "vm.glsl"
+
+layout(set = 1, binding = 0) buffer Block { float block[]; };
+
+// A sample the device can take: no NaN or infinity, -1..1.
+float heard(float v) {
+ return isnan(v) || isinf(v) ? 0.0 : clamp(v, -1.0, 1.0);
+}
+
+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));
+ block[n] = v;
+}