Skip to content

feat(harmony): add per-voice mix controls and formant banks - #62

Closed
google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/per-voice-harmony-mix-and-formant-banks-jm0-b8fbdb20-fd2e-46f0-a8cb-e3106517af94
Closed

google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/per-voice-harmony-mix-and-formant-banks-jm0-b8fbdb20-fd2e-46f0-a8cb-e3106517af94

Conversation

@google-labs-stitch

Copy link
Copy Markdown
Contributor

Summary

This change adds per-voice mix controls (lead_gain, voice_gains, voice_pans and voice_mutes) and five separate LPC Formant synthesis banks (SYNTHESIS_BANKS = 5) for the lead voice and the four harmony voices.

Changes

  • ResynthesisConfig (src/resynthesis.rs):
    • Add lead_gain: f32 (0.0..=1.0, default 1.0) with validation in ResynthesisConfig::validate.
    • Apply harmony_gain, voice_gains and voice_mutes in both mono (stereo_output = false) and stereo (stereo_output = true) output modes, with constant-power stereo placement from voice_pans.
    • Run per-voice forward LPC synthesis (Formant::forward_voices) and per-voice glottal de-emphasis (model_glottal with five feedback slots) in Harmony mode before gain and pan summation.
    • Keep Choir mode (render_lead and Choir mix loop), LATENCY_FRAMES (1,593) and tail_frames() unchanged.
  • HarmonyConfig (src/harmony.rs):
    • Add voice_gains: [f32; 4] (0.0..=1.0, default [1.0; 4]), voice_pans: [f32; 4] (-1.0..=1.0, default [-1.0 / 3.0, 1.0 / 3.0, -1.0, 1.0]), voice_mutes: [bool; 4] (default [false; 4]), voice_formant_stretch: [f32; 4] (0.5..=2.0, default [1.0; 4]) and voice_formant_width: [f32; 4] (0.5..=2.0, default [1.0; 4]).
    • Validate all five arrays in HarmonyConfig::validate and scope chord table updates in HarmonyState::apply_config to chord-related fields.
  • Formant (src/formant.rs):
    • Keep one shared 50th-order LPC inverse analysis (ANALYSIS_FRAMES = 441) and preallocate five forward synthesis model rings (66 KB) and five synthesis feedback histories in Formant::new.
    • Convert the shared tract areas into forward PEF coefficients for the lead bank and each harmony bank through areas_to_parcor and parcor_to_pef.
    • Draw one random value from NumericContext per frame for shared aspiration noise so random_seed sequences stay deterministic.
  • Wasm & Documentation (src/wasm.rs, README.md):
    • Accept absent leadGain, voiceGains, voicePans, voiceMutes, voiceFormantStretch and voiceFormantWidth fields in JavaScript and TypeScript configurations.
    • Document the new fields and parameter ranges in rustdoc and README.md.

Verification

  • cargo build --locked --release, cargo fmt --check, cargo clippy --locked --lib -- -D warnings, cargo doc --locked --no-deps and npm run build pass with zero warnings.
  • Verified zero real-time heap allocations across process, process_with_events, set_control, apply_config, reset and drain.
  • Verified byte-identical Choir PCM output, zero clipped mono frames (peak = 0.9708) on -6 dBFS 4-voice Harmony input at harmony_gain = 0.5, distinct per-voice LPC formant envelopes (4.59 dB minimum pairwise RMS separation), single-voice parity with the lead formant bank, and Node.js Wasm configuration roundtrip and validation.

Harmony mix and formant verification


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

- Add lead_gain to ResynthesisConfig with validation.
- Add per-voice gain, pan, mute and formant controls to HarmonyConfig.
- Preallocate five forward synthesis banks and histories in Formant.
- Run per-voice formant synthesis and glottal de-emphasis in Harmony.
- Scale the harmony voices by harmony_gain in mono and stereo modes.
- Accept absent mix and formant fields in the Wasm configuration.
- Document the new controls in the rustdoc and README.md.
- Resolve the merge conflicts in README.md.
- Update Formant synthesis banks for i64 fixed-point saturation.
- Keep per-voice mix and formant controls in Resynthesis.
- Resolve the merge conflict in src/resynthesis.rs.
- Share reader bounds across the five harmony slots.
- If formants are disabled, skip silent slot interpolation.
- Keep per-voice formant synthesis for the five harmony slots.
- Resolve the merge conflict in src/formant.rs.
- Borrow steady models for the five synthesis banks.
- Blend bank pairs on the stack only during transitions.
- Calculate synthesis feedback sums with ring_sum.
- Resolve the merge conflicts in src/formant.rs.
- Keep ORDER-sized inverse banks and four-byte stamps.
- Set dirty state in Formant::forward_voices for resets.
- Iterate the stretch map with enumerate in Formant::prepare_bank
- Iterate the harmony histories as a slice in clear_harmony_history
- Keep the audio output identical across all stages
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

[CI/CD Fix Attempt 1]

Root Cause

GitHub Actions verify runs cargo clippy --locked --lib -- -D warnings on stable Rust 1.100.0 (0ef1bc386), which triggered two clippy::needless_range_loop errors in src/formant.rs (Formant::prepare_bank and Formant::clear_harmony_history) and exited with code 101.

Changes

  • src/formant.rs:
    • Replaced for i in 0..count - 1 in Formant::prepare_bank with for (i, entry) in self.stretch_map[bank][..count - 1].iter_mut().enumerate().
    • Replaced for slot in 1..SYNTHESIS_BANKS in Formant::clear_harmony_history with for history in &mut self.history[1..].
    • Preserved identical fixed-point values and audio output across all stages.

Verification

  • Installed Rust 1.100.0 locally, reproduced the exact exit code 101 Clippy failure, and verified all CI checks pass with zero warnings:
    • cargo fmt --check
    • cargo clippy --locked --lib -- -D warnings
    • cargo build --locked --release
    • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
    • cargo package --list --locked
    • RUSTDOCFLAGS="-D warnings" npm run check:wasm
    • npm run verify:pack

@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #133. #62 ignores the global FormantConfig width/stretch settings in harmony mode, runs all five 110-order IIR filters even for silent voices, and does not deduplicate identical formant banks.

@byteland-app
byteland-app deleted the stitch/per-voice-harmony-mix-and-formant-banks-jm0-b8fbdb20-fd2e-46f0-a8cb-e3106517af94 branch November 25, 2026 08:06
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Thank you for the review. Pull request #62 stays closed because #133 replaces it. #133 combines FormantConfig width and stretch with each voice factor, skips the synthesis filter for silent voices and reuses equal formant banks. We made no more changes on this branch.

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