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
@@ -1296,6 +1296,11 @@ impl PianoRollPane {
let vis_col_start = (vis_audio_start * sample_rate as f64 / 512.0).floor() as i64;
let vis_col_end = (vis_audio_end * sample_rate as f64 / 512.0).ceil() as i64 + 1;
// Calculate stride: how many CQT columns per pixel
// When zoomed out, multiple CQT columns map to one pixel — compute every Nth
let cols_per_pixel = sample_rate as f32 / (512.0 * self.pixels_per_second);
let cqt_stride = (cols_per_pixel.ceil() as u32).max(1);
let callback = crate::cqt_gpu::CqtCallback {
pool_index,
params: crate::cqt_gpu::CqtRenderParams {
@@ -1318,12 +1323,14 @@ impl PianoRollPane {
cache_start_column: 0.0,
cache_valid_start: 0.0,
cache_valid_end: 0.0,
_pad: [0.0; 2],
column_stride: 0.0, // filled by prepare()
_pad: 0.0,
},
target_format: shared.target_format,
sample_rate,
visible_col_start: vis_col_start,
visible_col_end: vis_col_end,
stride: cqt_stride,
};
ui.painter().add(egui_wgpu::Callback::new_paint_callback(
@@ -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;
@@ -1255,7 +1255,7 @@ impl TimelinePane {
pixels_per_second: self.pixels_per_second as f32,
audio_duration: audio_file_duration as f32,
sample_rate: *sr as f32,
clip_start_time: instance_start as f32,
clip_start_time: clip_screen_start,
trim_start: preview_trim_start as f32,
tex_width: crate::waveform_gpu::tex_width() as f32,
total_frames: total_frames as f32,