Skip to content

feat!: add per-voice channel strips and formant banks - #133

Open
google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/per-voice-channel-strips-formant-banks-jm1-909086ee-3bd5-4c5a-a80b-35856bd26631
Open

google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/per-voice-channel-strips-formant-banks-jm1-909086ee-3bd5-4c5a-a80b-35856bd26631

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

Adds per-voice channel strip controls and five preallocated LPC synthesis banks for Harmony mode:

  • Per-voice mix controls (ResynthesisConfig, HarmonyConfig, ControlActivity):
    • resynthesis.lead_gain (0.0..=1.0, default 1.0) scales or mutes the lead voice in Harmony mode.
    • resynthesis.harmony.voice_gains (0.0..=1.0, default [1.0; 4]), voice_pans (-1.0..=1.0, default [-1.0 / 3.0, 1.0 / 3.0, -1.0, 1.0]), and voice_mutes (default [false; 4]) configure independent gain, constant-power stereo pan, and sample-accurate mute on each harmony voice.
    • ControlActivity (ProcessorConfig::control_activity and Processor::control_activity) exposes lead_gain, harmony_voice_gains, harmony_voice_pans, harmony_voice_mutes, harmony_voice_formant_stretch, and harmony_voice_formant_width, reflecting Harmony mode, HarmonyConfig::voices in interval modes, ResynthesisConfig::stereo_output, and FormantConfig::enabled.
  • Per-voice vocal-tract controls & five synthesis banks (HarmonyConfig, Formant, Resynthesis):
    • resynthesis.harmony.voice_formant_stretch and voice_formant_width (0.5..=2.0, default [1.0; 4]) scale vocal-tract length and width per harmony voice, validated by HarmonyConfig::validate.
    • Formant retains one shared 50th-order LPC inverse analysis (ANALYSIS_FRAMES = 441) and preallocates five forward synthesis banks (66 KB total) and mirrored 220-entry feedback rings in Processor::new.
    • Each LPC design step converts areas into five Q14 forward PEF models and stamps per-voice synthesis at each reader's center frame before the stereo pan sum (or single-channel mono sum) in Harmony mode, while keeping Formant::set_width and Formant::set_stretch (ControlEvent::Parameter) synchronized across all five slots.
    • Silent or muted voices bypass their MAX_ORDER synthesis filter pass and clear feedback history cleanly on mute transitions, Choir ↔ Harmony mode switches (Resynthesis::apply_config), and reset.
    • Aspiration noise consumes at most one random word per frame from NumericContext so random_seed sequences stay deterministic, and honors Formant::aspiration_muted during drain.
    • Choir mode keeps its single lead formant path in render_lead bit-identical, Processor::formant_envelope and Wasm envelope caching document and report the lead (slot 0) analysis and synthesis envelopes (width[0]), Telemetry::voice_gains documents that it reports controller envelopes before channel-strip gain/mute/pan, and nominal latency (1,593 frames) and tail budget remain unchanged.
  • WebAssembly & TypeScript parity (src/wasm.rs, scripts/verify-pack.mjs, README.md):
    • Exposes optional camelCase TypeScript fields (leadGain, voiceGains, voicePans, voiceMutes, voiceFormantStretch, voiceFormantWidth) with | undefined types (exactOptionalPropertyTypes: true), serde deserializers mapping absent or undefined values to defaults, and ControlActivity flags (leadGain, harmonyVoiceGains, harmonyVoicePans, harmonyVoiceMutes, harmonyVoiceFormantStretch, harmonyVoiceFormantWidth).

SemVer Impact

  • API compatibility: ResynthesisConfig, HarmonyConfig, and ControlActivity are #[non_exhaustive], and the new Wasm/TypeScript config fields are optional (| undefined) with serde defaults, so existing Rust and JS/TS callers compile and run without code changes.
  • Sample-exact PCM output (feat!: → 0.4.0):
    • Choir mode (mono/stereo, with or without formants and aspiration) and default mono Harmony mode (formant.enabled = false) remain 100% bit-identical to 0.3.4.
    • Default stereo Harmony (formant.enabled = false) now derives pan fractions from f32 voice_pans = [-1.0 / 3.0, 1.0 / 3.0, -1.0, 1.0] instead of hard-coded f64 thirds, shifting Q14 pan quantization on voices 0 and 1 by up to 1 Q14 LSB (2 PCM i16 LSB at harmony_gain = 0.5).
    • Harmony + Formant (formant.enabled = true) now runs stamped Formant::forward_voice and model_glottal per active voice before channel-strip gain and pan summation rather than a single post-mix forward_stereo pass, changing rendered Harmony + Formant samples even at unity voice_formant_stretch and voice_formant_width.
    • Per AGENTS.md, sample-level output changes on existing configurations are marked as breaking (feat!: / BREAKING CHANGE:), so release-please ("bump-minor-pre-major": true) bumps 0.3.4 → 0.4.0 and records the change under BREAKING CHANGES.

Verification

Per-voice formant envelopes and stereo channel strip verification

  • cargo fmt --check
  • cargo clippy --locked --lib -- -D warnings
  • cargo build --locked --release
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo package --locked
  • RUSTDOCFLAGS="-D warnings" npm run check:wasm
  • npm run verify:pack
  • MSRV 1.88 (cargo build --locked --lib and cargo build --locked --lib --target wasm32-unknown-unknown --features wasm)
  • Verified via external Rust & Node.js harnesses:
    • Zero heap allocations across process (with TimedEvent and ControlEvent::Parameter), control_activity, formant_envelope, feedback, telemetry, set_config (including Choir ↔ Harmony mode switch), drain, and reset (CountingAlloc global allocator).
    • Bit-identical PCM output for Choir mode (6 stereo voices, formants and aspiration enabled), default mono Harmony mode (formants disabled), Harmony → Choir → Harmony mode switches with formants enabled, ControlEvent::Parameter vs ControlEvent::Resynthesis, and Harmony drain tail aspiration muting.
    • Distinct spectral envelopes across isolated harmony voices (voice_formant_stretch = [0.75, 1.50, 1.0, 1.0] -> spectral centroids 655.9 Hz vs 521.2 Hz; voice_formant_width 0.60 vs 1.80 -> 10.01 dB mean spectral difference).
    • Sample-accurate lead_gain = 0.0 and voice_mutes stereo stem isolation, deterministic random_seed aspiration noise across mute states, absent and explicit undefined Wasm option deserialization, ControlActivity flags across modes, Telemetry::voice_gains controller-envelope reporting, and Processor::formant_envelope lead-model reporting.

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

- Add lead_gain to ResynthesisConfig with 0..=1 range validation
- Add per-voice mix and formant controls to HarmonyConfig
- Preallocate five forward synthesis banks and histories in Formant
- Convert LPC tract areas into five forward models at each design step
- Run stamped per-voice LPC synthesis before the Harmony stereo pan sum
- Read at most one aspiration random word per frame in Harmony mode
- Expose optional camelCase TypeScript fields with serde defaults
- Document the new Harmony controls and optional fields in README.md
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Preferred over #40 and #62 for per-voice channel strips and independent formant banks. Please address three items before merge:

  1. In Resynthesis::apply_config, clear previous_output[1..] and bypass_voice(1..5) when switching between Choir and Harmony so stale formant history does not bleed across modes.
  2. Document on Telemetry::voice_gains (src/processor.rs) that it reflects controller envelopes before channel-strip gain/mute.
  3. Clarify SemVer impact (default harmony pan f32 rounding and pre-mix per-voice formant synthesis slightly change default Harmony+Formant output).

- Mirror the five formant feedback rings for contiguous tap sums
- Clear previous_output[1..] when ResynthesisConfig::mode changes
- Call Formant::bypass_voice for slots 1..5 on mode changes

BREAKING CHANGE: default Harmony pan and formant paths change samples.
- State that harmony gains report controller envelopes before mix gains
- List lead_gain, harmony_gain, voice_gains, voice_mutes and stereo pan
@google-labs-stitch google-labs-stitch Bot changed the title feat: add per-voice channel strips and formant banks feat!: add per-voice channel strips and formant banks Nov 25, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed all three items and merged the latest main (0.3.3, mirroring all five formant feedback rings for contiguous tap_sum):

  1. Mode-switch formant history reset (src/resynthesis.rs): In Resynthesis::apply_config, when old.mode != config.mode, cleared self.previous_output[1..] and called self.formant.bypass_voice(slot) for slots 1..5 (b696c4a) so stale harmony glottal and LPC synthesis feedback cannot bleed across Choir ↔ Harmony transitions.
  2. Telemetry::voice_gains documentation (src/processor.rs): Updated the rustdoc on Telemetry::voice_gains (76b37f3) in ASD-STE100 to clarify that harmony entries report the harmony controller envelopes (including MIDI velocity gain, or 0 when inactive) prior to ResynthesisConfig::lead_gain, ResynthesisConfig::harmony_gain, HarmonyConfig::voice_gains, HarmonyConfig::voice_mutes, and stereo pan.
  3. SemVer impact (feat!: → 0.4.0): Marked the PR title feat!: add per-voice channel strips and formant banks, included a BREAKING CHANGE: commit footer, and added a SemVer Impact section to the PR description. While #[non_exhaustive] Rust structs and optional camelCase JS/TS fields remain source-compatible—and Choir mode plus default mono Harmony (formants off) remain 100% bit-identical to 0.3.3—two paths change sample values on existing configurations:
    • Default stereo Harmony pan quantization: Storing default voice_pans = [-1.0 / 3.0, 1.0 / 3.0, -1.0, 1.0] as f32 shifts Q14 pan quantization on voices 0 and 1 by up to 1 Q14 LSB (2 PCM i16 LSB at harmony_gain = 0.5).
    • Harmony + Formant synthesis order: Running stamped per-voice Formant::forward_voice and model_glottal before the channel-strip mix (instead of post-mix forward_stereo) changes rendered Harmony + Formant samples even at unity voice_formant_stretch and voice_formant_width.
    • Under "bump-minor-pre-major": true, release-please will bump 0.3.3 → 0.4.0 and record the sample-level change under BREAKING CHANGES.

- Keep five formant synthesis banks with fused envelope rotations
- Add mono Harmony voice sums into channel zero only
- Map undefined optional Wasm voice controls to their defaults
@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved for 0.4.0 — per-voice channel strips, 5 formant banks with deduplication, mono mix path, and optional Wasm undefined handling are verified. Please rebase onto updated main after #20, #22, #45, and #107. (Note: once #114 lands, replace FORMANT_OFFSET_FRAMES in the per-voice harmony loop with self.formant_offset_frames().)

…nel-strips-formant-banks-jm1-909086ee-3bd5-4c5a-a80b-35856bd26631

- Unify five-voice formant banks with `Stamp` and `ring` helpers.
- Use `apply_glottal` for per-voice Harmony synthesis.
- Normalize new voice and formant intra-doc links for JSDoc.
- Combine optional correction and harmony defaults in docs.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced with updated main (0850e25, incorporating #20, #22, #45, and #107 via fast-forward merge 0d30bb5 since force-push is disabled in this environment):

@byteland-app

Copy link
Copy Markdown
Contributor

Review: The 5-bank formant deduplication, pre-mix Harmony formant synthesis, single-RNG-per-frame aspiration, and default Choir/mono bit-exactness look solid. Four items before merge:

  1. Expose the 6 new conditional controls in ControlActivity (src/config.rs): Add flags for resynthesis.lead_gain, voice_gains, voice_pans, voice_mutes, voice_formant_stretch, and voice_formant_width (reflecting Harmony mode, stereo_output, and formant.enabled activity), with matching rustdoc, Wasm/TS, and README.md updates.
  2. Add Wasm optional-field coverage in scripts/verify-pack.mjs: Verify absent and explicit undefined defaults for leadGain, voiceGains, voicePans, voiceMutes, voiceFormantStretch, and voiceFormantWidth.
  3. Clarify Processor::formant_envelope rustdoc (src/processor.rs): Note that formant_envelope() reflects the lead (slot 0) vocal-tract model rather than per-voice harmony formant offsets.
  4. Sync onto updated main (build(cargo): bump the cargo group with 2 updates #139, ci: deny compiler and rustdoc warnings in scripts and docs #131, feat!: add pitch fields to Telemetry and trim Wasm voice slices #104, feat(events)!: add scalar parameter control events #61): Preserve feat(events)!: add scalar parameter control events #61's Formant::aspiration_muted (inside prepare_noise), stage diff-guards, and ParameterControl, plus feat!: add pitch fields to Telemetry and trim Wasm voice slices #104's Telemetry.

…nel-strips-formant-banks-jm1-909086ee-3bd5-4c5a-a80b-35856bd26631

- Keep Formant::aspiration_muted inside prepare_noise.
- Update all five voice banks on scalar formant width and stretch.
- Guard lead gain and voice channel-strip changes in Resynthesis.
- Keep per-voice envelope docs and Float32Array Telemetry slices.
- Add lead_gain and per-voice harmony flags to ControlActivity.
- Clarify that formant_envelope reports the lead slot 0 model.
- Normalize new ControlActivity JSDoc links and update README.
- Check optional per-voice fields and activity in verify-pack.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed all four review items and merged origin/main (8880205):

  1. ControlActivity (7c4fe09): Added lead_gain, harmony_voice_gains, harmony_voice_pans, harmony_voice_mutes, harmony_voice_formant_stretch, and harmony_voice_formant_width to ControlActivity (src/config.rs), reflecting Harmony mode, HarmonyConfig::voices in interval modes, ResynthesisConfig::stereo_output, and FormantConfig::enabled, with matching Wasm/TS JSDoc normalization (scripts/normalize-jsdoc.mjs) and README.md updates.
  2. Wasm optional-field & activity checks (7c4fe09): Extended scripts/verify-pack.mjs to check absent and explicit undefined inputs for leadGain, voiceGains, voicePans, voiceMutes, voiceFormantStretch, and voiceFormantWidth across new Tunelet, setConfig, TimedEvent (type: "resynthesis"), and exactOptionalPropertyTypes consumer TypeScript profiles, alongside runtime and type checks for all six new controlActivity() flags.
  3. formant_envelope documentation (7c4fe09): Clarified in Processor::formant_envelope, WasmProcessor::formant_envelope, src/lib.rs, and README.md that output reports the lead (slot 0) synthesis envelope after FormantConfig::width and FormantConfig::stretch and does not include HarmonyConfig::voice_formant_width or HarmonyConfig::voice_formant_stretch.
  4. Sync with main (a079933): Merged origin/main (#139, #131, #104, #61) without rebasing, preserving Formant::aspiration_muted inside prepare_noise, stage diff-guards in Resynthesis::apply_config, per-voice tract multiplier sync across Formant::set_width / Formant::set_stretch (ParameterControl), and #104's Telemetry updates.

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