Module waveform

Module waveform 

Source
Expand description

Waveform pass — MD2 modes 0..7 wired into the renderer.

WaveformRenderer owns four pipelines (alpha vs additive × lines vs dots) that share a uniform + storage layout. Per frame the host:

  1. Smooths the audio samples (CPU IIR) and uploads them to WaveformRenderer::update_wave_samples.
  2. Updates the WaveUniforms payload from WaveParams.
  3. Calls WaveformRenderer::render into the warp output texture so the wave participates in the feedback loop (matches MD2’s order).

Mode 6 (double_line) is drawn in two passes: the second call sets flip_y = 1 so the wave mirrors around wave_y. Modes 0..5 and 7 ignore flip_y.

Structs§

WavePoint
Legacy storage element kept for backwards-compatibility with older tests that referenced WavePoint. The new pipeline streams a flat array<f32> and does NOT consume WavePoint; the type is retained only so external code that still uses it keeps compiling.
WaveUniforms
Per-frame uniforms consumed by the waveform shader. Field order MUST match Uniforms in waveform_advanced.wgsl.
WaveformRenderer
GPU waveform pass — owns its pipelines, uniforms, and a sample storage buffer of fixed length NUM_WAVE_SAMPLES.

Enums§

WaveformMode
MilkDrop 2 waveform mode (nWaveMode, 0..7).

Constants§

DEFAULT_SMOOTHING_ALPHA 🔒
Default IIR smoothing factor when wave_smoothing is 0. MD2 uses a 5-tap moving average; a single-pole IIR with α≈0.5 is a cheap visual match.
NUM_WAVE_SAMPLES
Standard MD2 waveform sample length — 512 samples per channel before downmix. The shader treats wave_samples as mono; the host is responsible for the L/R mix.

Functions§

apply_smoothing
Apply a single-pole IIR low-pass to a buffer of waveform samples, matching MD2’s f_wave_smoothing. smoothing[0, 1]: 0 = no smoothing, 0.9 ≈ heavy attenuation. Mutates in place.
build_uniforms
Build the WaveUniforms payload from a WaveParams snapshot, the current frame’s instantaneous volume (used for b_mod_wave_alpha_by_volume), and the current frame resolution + aspect.
pipeline_index 🔒