From c37f1b3b1374df2a2a434d16cd772a4bb00c567e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:19:38 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- examples/micscope/src/layouts.zig | 125 ++------------------------------------ 1 file changed, 4 insertions(+), 121 deletions(-) (limited to 'examples/micscope/src/layouts.zig') diff --git a/examples/micscope/src/layouts.zig b/examples/micscope/src/layouts.zig index cd5be65..be95799 100644 --- a/examples/micscope/src/layouts.zig +++ b/examples/micscope/src/layouts.zig @@ -1,124 +1,7 @@ -//! What the shaders read, as Zig structs: the only definition. The shaders -//! include GLSL generated from these (see sketchbook's `glsl.zig`). No -//! imports, so the shader build can compile this alone. - -/// FFT length: the analysis window, zero-padded to twice its size so the -/// spectrum is sampled twice as finely as the window resolves. -pub const fft_size = 8192; -pub const window = 4096; -/// The most columns a view can have; the column buffers hold this many. -pub const max_columns = 2048; -/// The tallest spectrogram; its buffer holds this many rows of -/// `max_columns`. -pub const max_rows = 1024; -// All three analyses read samples `offset + i` of the tape buffer for -// `0 <= i < samples`: the takes share one buffer, and a take's analysis -// never reads its neighbours. -/// The spectrogram's window, zero-padded to `spectrogram_fft` points. -pub const spectrogram_window = 2048; -pub const spectrogram_fft = 4096; - -/// spectrum.comp: the window ending at `end`, and the columns to fill. -pub const SpectrumParams = extern struct { - offset: u32, - /// Sample index one past the window's last sample. - end: u32, - /// Samples on the tape. - samples: u32, - columns: u32, - /// Nonzero: forget the smoothed levels and peaks. - reset: u32, - rate: f32, - min_freq: f32, - max_freq: f32, - /// Seconds since the previous analysis, for smoothing. - dt: f32, - pad0: u32 = 0, - pad1: u32 = 0, - pad2: u32 = 0, - - pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } }; -}; - -/// waveform.comp: column `c` covers samples `first + c * spp` up to the next -/// column's start, and is written to slot `(slot + c) % ring`: the live -/// view writes its newest columns into a ring, the others from slot 0. -pub const WaveParams = extern struct { - offset: u32, - first: u32, - samples: u32, - columns: u32, - spp: f32, - slot: u32, - ring: u32, - pad: u32 = 0, - - pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } }; -}; - -pub const Tint = enum(u32) { take, recording, live }; - -/// waveform.frag. Pixel column `x` shows slot `(x + scroll) % width`; only -/// the last `filled` columns have anything in them. -pub const WaveView = extern struct { - size: [2]f32, - /// Pixels; negative hides it. - playhead: f32, - gain: f32, - /// A `Tint`. - tint: u32, - scroll: u32, - filled: u32, - pad: u32 = 0, - - pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } }; -}; - -/// spectrum.frag. -pub const SpectrumView = extern struct { - size: [2]f32, - floor_db: f32, - ceil_db: f32, - min_freq: f32, - max_freq: f32, - pad: [2]f32 = .{ 0, 0 }, - - pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } }; -}; - -/// spectrogram.comp: the same columns as `WaveParams`, each analysed into -/// `rows` log-spaced frequency rows, row 0 the lowest. -/// Columns land in slots as `WaveParams` says. -pub const SpectrogramParams = extern struct { - offset: u32, - first: u32, - samples: u32, - columns: u32, - rows: u32, - spp: f32, - rate: f32, - min_freq: f32, - max_freq: f32, - slot: u32, - ring: u32, - pad: u32 = 0, - - pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } }; -}; - -/// spectrogram.frag; `scroll` and `filled` as in `WaveView`. -pub const SpectrogramView = extern struct { - size: [2]f32, - floor_db: f32, - ceil_db: f32, - /// Pixels; negative hides it. - playhead: f32, - scroll: u32, - filled: u32, - pad: f32 = 0, - - pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } }; -}; +//! What the tuner's shaders read, as Zig structs: the only definition. The +//! shaders include GLSL generated from these (see sketchbook's `glsl.zig`). +//! No imports, so the shader build can compile this alone. The views' own +//! blocks are the scope module's (`scope.layouts`). /// tuner.comp: the YIN window is the `tuner_window + tuner_lags` samples /// ending at `end`, read like the other analyses (`offset`, `samples`). -- cgit v1.3