Skip to content

feat: support native multi-rate DSP from 8 kHz to 192 kHz - #73

Closed
google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/native-multi-rate-dsp-jm1-35672d43-f9ea-47bf-900f-4063eb75af52
Closed

google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/native-multi-rate-dsp-jm1-35672d43-f9ea-47bf-900f-4063eb75af52

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This change adds native multi-rate DSP parameter scaling across all ten standard voice, WebRTC, and studio sample rates (8000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and 192000 Hz) and fixes the initial 48 kHz chromatic correction table.

Changes

  • Initial 48 kHz correction table (src/resynthesis.rs, src/scale.rs): Resynthesis::new now initializes CorrectionTable::new(rate, config.correction.notes) directly with the prepared SampleRate, so default chromatic correction at 48 kHz loads 48 kHz periods immediately instead of 44.1 kHz periods (+46.70 cents sharp detune).
  • Ten discrete sample rates (src/config.rs, src/wasm.rs): Added Hz8000, Hz16000, Hz22050, Hz24000, Hz32000, Hz88200, Hz96000, and Hz192000 to SampleRate and WasmProcessor::new (Tunelet), while unsupported rates such as 44056 return Error::UnsupportedSampleRate before allocation.
  • Pitch tracker scaling (src/pitch/tracker.rs, src/pitch/search.rs, src/pitch.rs): Scaled the acquisition decimation stride (2..=32), low-pass prefilter cutoff, acquisition lag count (105..=160), full-rate tracking lag window (8..=176), and minimum lag threshold (3..=82), while leveraging i64 Fixed::mul and Fixed::div for Q6 periods up to 192 kHz.
  • LPC & formant scaling (src/formant.rs, src/lpc.rs): Scaled analysis_frames (80..=1,920), history_frames, LPC predictor_order (9..=218, keeping the ~882 Hz vocal-tract pole interval), max_synthesis_order (20..=480), and blend_step with i64 saturated Q28 filter sums, and added a 32-bit Q24 internal recursion path in lpc::durbin for order > 50 (48, 88.2, 96, and 192 kHz).
  • Resynthesis histories & choir offsets (src/numeric.rs, src/resynthesis/history.rs, src/resynthesis.rs, src/processor.rs): Replaced fixed HISTORY and OVERLAP_FRAMES array storage with preallocated boxed slices (2,100..=50,368 history frames and 280..=6,718 overlap frames), scaled choir SEEDS and reader lag/margin/crossfade windows, and exposed rate-scaled Processor::latency_frames().
  • Reverb & effect windows (src/effects/reverb.rs, src/effects/punch.rs, src/effects/warm.rs, src/effects/alien.rs): Scaled base (scale(9000.0)) and capacity (scale(17000.0)) in reverb_layout, scaled peak windows in Punch and Warm, and scaled Alien history capacity (32,000..=768,000 frames), boundary fades, and AlienConfig::loop_frames (1..=384,000).

Verification

Multi-rate DSP verification summary

  • Bit-exact 44,100 Hz parity: Rendered 114,688 PCM bytes across default Choir, 8-voice Choir + Formant + Punch + Warm + Alien + LargeHall Reverb + drain, Harmony + MIDI + Binaural Reverb, and mono Harmony + FixedInterval + portamento + harmony_gain match main bit-for-bit (0 byte differences).
  • 48,000 Hz default chromatic correction: A 440.0 Hz vocal locks to target_midi_note == Some(69.0) with resample_ratio == 0.999695 (-0.528 cents, within 1 cent of 1.0).
  • Multi-rate DSP & Wasm checks: Verified 80..=1,000 Hz vocal pitch tracking, Formant stability across 0.5..=2.0 width and stretch, all six ReverbMode topologies up to 192 kHz, zero heap allocations after Processor::new, and Node.js WebAssembly execution across all 10 sample rates.
  • Build, lint & archive checks: cargo build --locked --release, cargo fmt --check, cargo clippy --locked --lib -- -D warnings, cargo doc --locked --no-deps, npm run build, and npm run verify:pack pass with zero warnings.

Automated PR initiated by user @byteland-app via Stitch Loop.

- Load the prepared SampleRate periods in Resynthesis::new.
- Add eight SampleRate variants in config.rs and wasm.rs.
- Scale the PitchTracker stride and lag limits for each rate.
- Scale the Formant buffers and LPC orders for each rate.
- Preallocate the resynthesis histories as boxed slices.
- Scale the choir SEEDS offsets for each sample rate.
- Scale the reverb layout for all ten sample rates.
- Scale the frame windows in Punch, Warm and Alien.
- Update the documentation for the ten sample rates.
- Keep i64 saturated sums in rate-scaled Formant filters.
- Keep slice interpolation with i64 bounds in Resynthesis.
- Use i64 Fixed operations for Q6 periods at all sample rates.
- Keep mono harmony_gain in Resynthesis and README.md.
- Sum contiguous slices with the rate-scaled history in PitchTracker.
- Keep the rate-scaled lag count in PitchTracker::track_contiguous.
- Use the rate-scaled reader margin in Resynthesis::reader_bounds.
- Share reader_bounds and step_reader in Resynthesis::move_reader.
- Keep the rate-scaled lag count in PitchTracker::detect.
- Allow clippy::needless_range_loop in PitchTracker::detect.
- Iterate the active voice positions as a slice in Resynthesis.
- Document the rate-scaled latency in WasmProcessor::latency_frames.
@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #53. Native 192 kHz LPC (order 218 / max 480) inflates CPU cost ~17–19x and memory to ~9+ MB, adds an i32 wrapping_shl(14) overflow risk in Q24 Durbin, silently alters 48 kHz latency/output without a breaking marker, and conflicts with recent main fixes.

@byteland-app
byteland-app deleted the stitch/native-multi-rate-dsp-jm1-35672d43-f9ea-47bf-900f-4063eb75af52 branch November 25, 2026 08:05
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Acknowledged — leaving #73 closed and its remote branch deleted as superseded by #53, which preserves exact 44.1/48 kHz core behavior and avoids high-rate native LPC CPU/memory scaling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant