Skip to content

feat(pitch)!: enforce vocal range presets and period holdoff - #124

Open
google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/vocal-range-and-voiced-gate-holdoff-jm1-adc77989-9642-41f4-bfc6-13db16310182
Open

google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/vocal-range-and-voiced-gate-holdoff-jm1-adc77989-9642-41f4-bfc6-13db16310182

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

This change adds vocal range presets to PitchConfig, extends decimated pitch acquisition down to 40 Hz at 44.1 kHz and 48 kHz, enforces the active vocal range in PitchTracker, and clears stale fallback periods after a 20 ms holdoff.

  • Add #[non_exhaustive] VocalRange (Custom, Soprano, AltoTenor, BaritoneBass) to PitchConfig and re-export it in Rust, WebAssembly and TypeScript.
  • Make resynthesis.pitch.vocalRange optional in WebAssembly and TypeScript (defaulting to "custom" when absent or undefined), and list it in the optional-fields documentation in src/wasm.rs and README.md.
  • Map Soprano (240..=1100 Hz), AltoTenor (120..=600 Hz), BaritoneBass (45..=360 Hz) and Custom (min_frequency_hz..=max_frequency_hz) to shared inclusive Q6 period limits in PitchConfig::period_bounds, and document the (raw >> 10).max(8) Q6 quantization tolerance for boundary pitch reports.
  • Validate threshold, min_frequency_hz and max_frequency_hz also when vocal_range selects a named preset.
  • Set ACQUISITION_LAGS = 305 and use 2 * ACQUISITION_LAGS - 1 for the decimated ring wrap inside HISTORY = 11_568.
  • Enforce the active Q6 period limits in PitchTracker::set_config, PitchTracker::detection_lag, PitchTracker::process_sample and PitchConfig::report while keeping #61 threshold-only diff guards (PitchTracker::set_threshold).
  • Check fixed-point cycle clarity at each 5-frame period update, clear previous_period on Processor::reset, and expire previous_period to Q6::ZERO after 20 ms without a tracked pitch.
  • Set reader ratios to Q14::ONE (using each secondary choir voice's own delayed period in both move_choir_reader and voices telemetry) and release harmony smoothed_gain with GAIN_RELEASE when the selected period is Q6::ZERO.

Verification

VocalRange Presets and 20 ms Voiced-Gate Holdoff Verification

  • Verified 100% steady-note acquisition across 40.0..=1100.0 Hz (with BaritoneBass 55.00 Hz A1 to 87.31 Hz F2) at 44.1 kHz and 48 kHz.
  • Verified out-of-range inputs (103.83 Hz in Soprano and Custom 200..=800 Hz, 500 Hz in BaritoneBass, 82.41 Hz and 880 Hz in AltoTenor) produce feedback().voiced == false, telemetry().voiced == false, voice_ratios[0] == 1.0 and voice_gains[1..5] == [0.0; 4].
  • Verified a 10 ms glottal gap inside a 220 Hz vowel keeps harmony voice gains at 1.0, while 1.0 s of sibilants or breath decays voice_gains[1..5] to [0.0; 4] and restores voice_ratios[0] == 1.0 in Harmony and Choir (with per-voice delayed unvoiced transitions in Choir Telemetry).
  • Verified Processor::reset clears previous_period and harmony envelopes with 0.000 dB RMS difference (<= 0.1 dB) on post-reset sibilants, and verified zero post-construction heap allocations.
  • Verified JS/TS configurations omitting vocalRange or setting vocalRange: undefined default to "custom" under exactOptionalPropertyTypes: true.
  • Ran cargo fmt --check, cargo rustc --locked --lib --release -- -D warnings, cargo clippy --locked --lib -- -D warnings, RUSTFLAGS="-D warnings" cargo build --locked --release, RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, cargo package --locked, npm run check:wasm, npm run verify:pack, and MSRV 1.88 builds (cargo build --locked --lib and --target wasm32-unknown-unknown --features wasm).

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

- Add VocalRange presets to PitchConfig for Rust and Wasm
- Convert the active vocal range bounds into Q6 period limits
- Increase ACQUISITION_LAGS to 305 for bass pitch acquisition
- Enforce the Q6 period limits in PitchTracker and host reports
- Check the cycle clarity at each 5-frame period update
- Clear previous_period after 20 ms without a tracked pitch
- Clear previous_period and the harmony envelopes on reset
- Release the harmony gains when the output period is zero
- Set the voice ratios to unity when the output period is zero
- Merge main into the vocal range branch
- Keep output peak and dry delay notes in src/lib.rs
- Keep vocal range bounds and cycle clarity checks in PitchTracker
- Use u32::ilog2 for the parabolic shift count in PitchTracker
@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: DSP holdoff, clarity gate, 40 Hz acquisition, and #125/#87 adaptation look solid, but two Round 1 items were missed:

  1. src/pitch.rs: mark VocalRange as #[non_exhaustive].
  2. src/pitch.rs: add #[cfg_attr(all(feature = "wasm", target_arch = "wasm32"), serde(default), tsify(optional))] on PitchConfig::vocal_range (defaulting to Custom) so existing JS/TS callers omitting vocalRange do not break, and list resynthesis.pitch.vocalRange in the optional-fields docs in src/wasm.rs and README.md.
    Please also rebase onto updated main after fix(midi): reset harmony on source change and fix correction keys #46, refactor(pitch): deduplicate history steps and the minimum search #48, and refactor: share ring history helpers across pitch and resynthesis #92 for the 0.4.0 window.

- Merge main 0.3.4 into the vocal range branch
- Use tracking_difference in PitchTracker after the clarity check
- Clear the harmony envelopes before clear_dirty_ring on reset
- Update the reset documentation in Processor for keys 0..=127
- Mark VocalRange as #[non_exhaustive] in src/pitch.rs
- Make PitchConfig::vocal_range optional in Wasm and TypeScript
- Map an absent or undefined vocalRange value to VocalRange::Custom
- Document optional resynthesis.pitch.vocalRange in src/wasm.rs
- Document optional resynthesis.pitch.vocalRange in README.md
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed both Round 1 items and synced with updated main (0.3.4):

  1. VocalRange #[non_exhaustive] (src/pitch.rs): Marked VocalRange as #[non_exhaustive].
  2. Optional PitchConfig::vocal_range & docs (src/pitch.rs, src/wasm.rs, README.md): Added #[cfg_attr(all(feature = "wasm", target_arch = "wasm32"), serde(default, deserialize_with = "deserialize_vocal_range"), tsify(optional, type = "VocalRange | undefined"))] on PitchConfig::vocal_range so JS/TS callers omitting vocalRange or passing undefined default to VocalRange::Custom under #123's exactOptionalPropertyTypes rules (matching HarmonyConfig::voices), and listed resynthesis.pitch.vocalRange in the optional-fields docs in src/wasm.rs and README.md.
  3. Sync with main (0.3.4): Merged updated main (including #46, #48, #92, #102, #120, #123, and #135, since fast-forward-only push prevents force-pushing a history rewrite) and verified all Rust, Wasm, verify:pack, and MSRV 1.88 checks pass.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved for 0.4.0 — thank you for marking VocalRange #[non_exhaustive], making PitchConfig::vocal_range optional with undefined support in Wasm, and updating the docs. Please rebase onto updated main after #22, #45, and #107.

- Keep unity ratio on zero period in Resynthesis::move_choir_reader
- Clear dwell in Resynthesis::apply_config on a pitch restart
- List optional vocalRange with humanize, flexTune and voices in docs
- Map VocalRange and PitchConfig links in scripts/normalize-jsdoc.mjs
- Check optional vocalRange in scripts/verify-pack.mjs
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced the branch with updated main (fa87104, incorporating #20, #22, #41, #45, #81, #93, #107, #117, #121, and #138, using a merge commit since fast-forward-only push prevents force-pushing a history rewrite) and verified all CI checks (verify, build-wasm, msrv, and check-os across Linux, macOS, and Windows) pass:

  1. #22 (src/resynthesis.rs): Applied unity playback ratio (Q14::ONE when period == Q6::ZERO) inside the extracted Resynthesis::move_choir_reader helper.
  2. #45 (src/resynthesis.rs, src/wasm.rs, README.md): Reset self.dwell = Q14::ZERO alongside self.correction = Q14::ONE and self.scale_initialized = false in Resynthesis::apply_config when PitchTracker::set_config restarts tracking due to a narrower VocalRange, and listed resynthesis.pitch.vocalRange alongside humanize, flexTune, and voices in the optional-fields docs.
  3. #107 (scripts/normalize-jsdoc.mjs, scripts/verify-pack.mjs): Added JSDoc normalization mappings for [PitchConfig], [Self::Custom], [VocalRange::Custom], and `vocal_range`, and added runtime/TypeScript checks for optional vocalRange (undefined and omitted) in scripts/verify-pack.mjs.

@byteland-app

Copy link
Copy Markdown
Contributor

Review: VocalRange presets, 40 Hz ACQUISITION_LAGS = 305, clarity >= 0.5 gate, and 20 ms holdoff look solid for 0.4.0.

Please sync onto updated main (#139, #131, #104, #61), preserving #61's stage diff-guards / ParameterControl and #104's Telemetry pitch fields. Two minor points to check while syncing:

  1. PitchConfig::report() reuses period_bounds slop ((raw >> 10).max(8) Q6 bits), which lets reported frequency_hz slightly exceed the documented inclusive bounds (for example ~1,103.4 Hz for Soprano 1,100 Hz at 48 kHz). Either enforce exact Hz bounds in report() or document the quantization tolerance.
  2. In Choir Resynthesis::voices, let unvoiced = self.current_output_period == Q6::ZERO; applies the last choir voice's delayed unvoiced state to all secondary voices in telemetry.

- Merge the latest main branch into the vocal range branch.
- Keep the pitch diff guards and telemetry fields from main.
- Document the Q6 period tolerance for boundary pitch reports.
- Check each choir voice delay for unvoiced ratio telemetry.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Merged main (8880205, including #139, #131, #104, and #61) in b203097 and addressed both review notes:

  1. PitchConfig stage diff-guards & Telemetry pitch fields (#61, #104): Kept PitchTracker::set_threshold for threshold-only updates (ControlEvent::Parameter(ParameterControl::PitchThreshold(_)) and Resynthesis::apply_config when vocal_range, min_frequency_hz, and max_frequency_hz are unchanged), PitchTracker::set_config when the vocal range or bounds change, and the active vocal range docs on Telemetry pitch fields (#104), scripts/normalize-jsdoc.mjs, and scripts/verify-pack.mjs.
  2. PitchConfig::report() boundary quantization tolerance: Documented the (raw >> 10).max(8) Q6 period quantization tolerance in src/pitch.rs, src/processor.rs, src/lib.rs, and README.md so exact boundary notes (such as 45 Hz, 360 Hz, 600 Hz, and 1,100 Hz at 48 kHz and 40 Hz at 44.1 kHz) continue to report voiced = true whenever PitchTracker tracks and resamples them.
  3. Per-voice Choir unvoiced telemetry in Resynthesis::voices: Computed each secondary choir voice's own delayed period (let delay = ring(delayed as i32 - self.delays[voice]); let (period, _) = self.period_for(delay, self.write);) in Resynthesis::voices, matching move_choir_reader so each choir voice transitions to 1.0 at its own delay offset.

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