Stream audio to spectrograph shader too

This commit is contained in:
Skyler Lehmkuhl
2026-02-14 23:58:20 -05:00
parent 04a7f35b84
commit 408343094a
12 changed files with 366 additions and 92 deletions
@@ -18,7 +18,7 @@ struct CqtParams {
tex_width: u32, // waveform texture width (2048)
total_frames: u32, // total audio frames in waveform texture
sample_rate: f32,
_pad0: u32,
column_stride: u32,
_pad1: u32,
_pad2: u32,
}
@@ -46,7 +46,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
return;
}
let global_col = params.column_start + col_rel;
let global_col = params.column_start + col_rel * params.column_stride;
let sample_start = global_col * params.hop_size;
let info = bins[bin_k];
@@ -27,7 +27,8 @@ struct Params {
cache_start_column: f32, // 4 @ 76
cache_valid_start: f32, // 4 @ 80
cache_valid_end: f32, // 4 @ 84
_pad: vec2<f32>, // 8 @ 88, total 96
column_stride: f32, // 4 @ 88
_pad: f32, // 4 @ 92, total 96
}
@group(0) @binding(0) var cache_tex: texture_2d<f32>;
@@ -141,8 +142,8 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
discard;
}
// Map global column to ring buffer position
let ring_pos = global_col - params.cache_start_column;
// Map global column to ring buffer position (accounting for stride)
let ring_pos = (global_col - params.cache_start_column) / params.column_stride;
let cache_x = ring_pos % params.cache_capacity;
// Sample cache texture with bilinear filtering
@@ -63,8 +63,9 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
}
// Fragment X position → audio time
let timeline_time = params.viewport_start_time + (frag_x - params.clip_rect.x) / params.pixels_per_second;
let audio_time = timeline_time - params.clip_start_time + params.trim_start;
// clip_start_time is the screen X of the (unclamped) clip left edge.
// (frag_x - clip_start_time) / pps gives the time offset from the clip's start.
let audio_time = (frag_x - params.clip_start_time) / params.pixels_per_second + params.trim_start;
// Audio time → frame index
let frame_f = audio_time * params.sample_rate - params.segment_start_frame;