summaryrefslogtreecommitdiff
path: root/examples/micscope/shaders/waveform.comp
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:19:38 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitc37f1b3b1374df2a2a434d16cd772a4bb00c567e (patch)
tree4feccf16cf1f6808bae6ba26602705d557ab2fb7 /examples/micscope/shaders/waveform.comp
parent9bd77e54943d954291b5faef287ccca5dcebd7a4 (diff)
downloadsketchbook-c37f1b3b1374df2a2a434d16cd772a4bb00c567e.tar.gz
sketchbook-c37f1b3b1374df2a2a434d16cd772a4bb00c567e.zip
micscope: on the scope module, its copy of the scope code gone
micscope carried the code the scope module was lifted from: seven shaders byte for byte, its layouts but for a comment, and a private live view (Live, analyseLive, drawLive) that was Scope.push, scroll and spectrum. Now the live view is ss.live, a scope.Scope, pushed the microphone and drawn with the panel's world rects and the camera (Views.camera), every frame, clipped away while a recording stands in for it so its columns keep up as before; the tuner reads its history from ss.live.gpu.tape. The take panels run scope.kernels and scope.pipelines over the tape with scope.layouts' blocks, wavePass and spectrogramPass inlined at their one use; maxFreq, min_freq and floor_db are the scope's. src/layouts.zig keeps only the tuner's blocks, the build compiles only the tuner's two shaders, and the tuner names notes with scope.midi, scope.hz and scope.note_names. Takes, transport and tuner are as they were. 1003 lines out, 91 in. Tests: zig build test, 67/67 steps, 10/10 tests (the live history's own test went with it; the scope module tests the same). Pictures: the four scripts' 18 screenshots, captured before and after with the same scripts and compared pixel by pixel (two runs before differ by themselves wherever wall-clock playback or microphone timing shows: the playheads, how far the live view has filled). The one difference not of that kind is the live spectrum: micscope made every image at most 132 rows, so its 184-row spectrum was stretched from 132; the scope makes it at its size, so the live spectrum's lines come out crisp (at most 86 in a channel, inside its rect). The take spectra keep micscope's 132. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/micscope/shaders/waveform.comp')
-rw-r--r--examples/micscope/shaders/waveform.comp72
1 files changed, 0 insertions, 72 deletions
diff --git a/examples/micscope/shaders/waveform.comp b/examples/micscope/shaders/waveform.comp
deleted file mode 100644
index d1d64e5..0000000
--- a/examples/micscope/shaders/waveform.comp
+++ /dev/null
@@ -1,72 +0,0 @@
-#version 450
-#extension GL_GOOGLE_include_directive : require
-// One workgroup per waveform column: the lowest and highest the signal goes
-// in it, and its RMS. Each column also includes the linearly interpolated
-// signal at its own edges, which it shares with its neighbours, so that
-// zoomed in past one sample per column the columns still join into one
-// continuous line.
-layout(local_size_x = 64) in;
-
-#include "WaveParams.glsl"
-
-layout(set = 0, binding = 0) readonly buffer Tape { float tape[]; };
-// x: min, y: max, z: RMS, w: 1 where the column has tape under it.
-layout(set = 1, binding = 0) buffer Columns { vec4 columns[]; };
-
-const uint THREADS = 64;
-shared float lows[THREADS];
-shared float highs[THREADS];
-shared float squares[THREADS];
-
-float sample_at(int i) {
- return i >= 0 && i < int(u.samples) ? tape[u.offset + uint(i)] : 0.0;
-}
-
-// The signal at `t` samples after `u.first`, between samples linearly.
-float signal(float t) {
- float whole = floor(t);
- int i = int(u.first) + int(whole);
- return mix(sample_at(i), sample_at(i + 1), t - whole);
-}
-
-void main() {
- uint c = gl_WorkGroupID.x;
- uint t = gl_LocalInvocationID.x;
- float start = float(c) * u.spp;
- float end = start + u.spp;
- int first = int(ceil(start));
- int last = min(int(floor(end)), int(u.samples) - int(u.first) - 1);
-
- float lo = 1e9;
- float hi = -1e9;
- float sq = 0.0;
- for (int i = first + int(t); i <= last; i += int(THREADS)) {
- float v = tape[u.offset + u.first + uint(i)];
- lo = min(lo, v);
- hi = max(hi, v);
- sq += v * v;
- }
- if (t == 0u) {
- float a = signal(start);
- float b = signal(min(end, float(u.samples - u.first - 1u)));
- lo = min(lo, min(a, b));
- hi = max(hi, max(a, b));
- }
- lows[t] = lo;
- highs[t] = hi;
- squares[t] = sq;
- barrier();
- for (uint stride = THREADS / 2u; stride > 0u; stride >>= 1u) {
- if (t < stride) {
- lows[t] = min(lows[t], lows[t + stride]);
- highs[t] = max(highs[t], highs[t + stride]);
- squares[t] += squares[t + stride];
- }
- barrier();
- }
- if (t == 0u) {
- float count = float(max(last - first + 1, 1));
- float inside = float(u.first) + start < float(u.samples) ? 1.0 : 0.0;
- columns[(u.slot + c) % u.ring] = vec4(lows[0], highs[0], sqrt(squares[0] / count), inside);
- }
-}