Skip to content

feat(resynthesis): split vibrato from the mean pitch contour - #57

Open
google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/vibrato-pitch-contour-split-jm0-12401997-b038-485c-ba0e-4c10978628df
Open

google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/vibrato-pitch-contour-split-jm0-12401997-b038-485c-ba0e-4c10978628df

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

  • Add vibrato_preserve: f32 (0.0..=1.0, default 0.0) to CorrectionConfig with serde(default, deserialize_with = "deserialize_zero_f32") and tsify(optional, type = "number | undefined") so absent or undefined vibratoPreserve values decode to 0 under exactOptionalPropertyTypes.
  • Validate resynthesis.correction.vibrato_preserve in 0.0..=1.0 inside CorrectionConfig::validate before state or output changes across native and Wasm calls, and guard configure_vibrato_preserve inside Resynthesis::apply_config so unchanged configurations leave contour state untouched.
  • Add PeriodFilter (src/resynthesis/vibrato.rs), a Q24 contour filter configured once at construction for the 5-frame tracking cadence (rate / 5) that separates the secular period (-3 dB cutoff ~2.38 Hz <= 3 Hz, group delay ~77 ms < 80 ms) from the 4..=8 Hz vibrato band without heap allocation after construction or floating-point math in process_sample.
  • Select CorrectionTable targets (including humanize dwell decay and flex_tune outer soft zones) from the secular Q6 period, taper the vibrato modulation ratio by the flex_tune pull (Q14::ONE + pull.mul(mod_ratio - Q14::ONE)) so vibrato_preserve > 0 stays continuous with 0.0 at bin midpoints, smooth both ratios with the active correction decay, and keep LATENCY_FRAMES at 1,593.
  • Seed the period filter at pitch acquisition, clear it on restart and reset_audio, and bypass the filter and ratio product when vibrato_preserve == 0.0 to keep Q14 wrap order bit-identical to main.
  • Document vibrato_preserve and optional vibratoPreserve in ASD-STE100 Simplified Technical English across rustdoc, src/wasm.rs, and README.md, and verify optional vibratoPreserve in scripts/verify-pack.mjs.

Verification

Vibrato pitch contour split verification

  • Bit-identical default output: Verified 100% byte-identical stereo i16 PCM output at 44.1 kHz and 48 kHz with vibrato_preserve = 0.0 against main (8880205) across Choir, Harmony, Formant, Punch, Warm, Reverb, ParameterControl, MIDI, and drain paths.
  • Vibrato retention, flex_tune continuity & diff-guards:
    • 5.5 Hz, 100-cent p-p vibrato (+30 cents mean) on Chromatic scale at retune_ms = 0.0: vibrato_preserve = 1.0 retains 99.9% depth (> 85%) and vibrato_preserve = 0.5 retains 49.8% depth with 0 chromatic bin jumps (target_midi_note constant on A3).
    • 4.0 Hz, 5.5 Hz, and 8.0 Hz vibrato at 120 cents p-p (+30 cents mean) on Chromatic scale at retune_ms = 0.0 and 5.0: retains 88.8%..100.9% depth (>= 85%) at both 44.1 kHz and 48 kHz with 0 bin jumps.
    • Near chromatic bin midpoints with flex_tune = 1.0, vibrato_preserve = 0.01 tapers mod_ratio by pull and retains natural vibrato without jumping discontinuously relative to 0.0.
    • Repeated set_config calls with unchanged vibrato_preserve produce bit-identical PCM output via the Resynthesis::apply_config diff-guard.
  • Wasm, JSDoc & TypeScript: Verified defaultConfig() emits vibratoPreserve: 0, omitted or undefined vibratoPreserve defaults to 0, JSDoc normalization (scripts/normalize-jsdoc.mjs) and all four strict exactOptionalPropertyTypes TypeScript profiles in scripts/verify-pack.mjs pass, and invalid values throw Error before state or buffer changes.
  • Builds & lints: cargo fmt --check, cargo rustc --locked --lib --release -- -D warnings, RUSTFLAGS="-D warnings" cargo build --locked --release, cargo clippy --locked --lib -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, cargo package --locked, npm run check:wasm, npm run verify:pack, .githooks, and MSRV 1.88 pass without warnings.

- Add vibrato_preserve to CorrectionConfig with a default of zero.
- Validate vibrato_preserve in 0..=1 before state changes.
- Accept an absent vibratoPreserve field in JavaScript.
- Add a Q24 period filter at the five-frame update cadence.
- Select correction targets from the secular Q6 period.
- Apply the vibrato modulation ratio to the smoothed secular ratio.
- Seed the period filter at acquisition.
- Clear the period filter on a restart and on an audio reset.
- Skip the period filter at zero to keep exact v0.2.0 output.
- Document vibrato_preserve in rustdoc, wasm and the README.
- Merge the latest main branch into the feature branch.
- Keep the widened i64 fixed-point comparisons in target selection.
- Update the correction comments for Q14 quantization.
- Merge the latest main branch into the feature branch.
- Keep the vibrato contour filter and correction configuration.
- Merge the latest main branch into the feature branch.
- Keep the vibrato contour filter and correction configuration.
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Approved in principle — the Q24 + i128 error-feedback vibrato/secular pitch contour split is mathematically solid, zero-allocation, and bit-exact when vibrato_preserve == 0.0. Please rebase onto updated main (minor conflict with #3 in src/resynthesis.rs) and squash the merge commits.

- Merge the latest main branch into the feature branch.
- Return None in select_target_ratio if a shifted period wraps.
- Keep the vibrato contour filter and correction configuration.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Updated main (451ea1e, v0.3.3) is integrated in 694e48d, resolving the conflict with #3 in src/resynthesis.rs:

  • select_target_ratio clears scale_initialized and returns None when a shifted period wraps (target <= Q6::ZERO), setting scale_initialized = true only after normalization succeeds.
  • update_correction resets correction (and secular_correction / vibrato_ratio when vibrato_enabled is active) to unity immediately when select_target_ratio returns None, while keeping the vibrato_preserve == 0.0 path bit-identical to v0.3.3.
  • Re-verified all native Rust, wasm32-unknown-unknown, cargo package --locked, and npm run verify:pack checks (CI verify is green).

Note: Force-pushing is disabled in this automated sandbox environment (git_push only supports fast-forward pushes), so the existing merge commits on this branch cannot be rewritten via git rebase + force-push from here. PR #57 merges cleanly into main via GitHub's Squash and merge; here is a clean ASD-STE100 commit message ready for the squash merge:

feat(resynthesis): split vibrato from the mean pitch contour

- Add vibrato_preserve to CorrectionConfig with a default of zero.
- Validate vibrato_preserve in 0..=1 before state changes.
- Accept an absent vibratoPreserve field in JavaScript.
- Add a Q24 period filter at the five-frame update cadence.
- Select correction targets from the secular Q6 period.
- Return None in select_target_ratio if a shifted period wraps.
- Apply the vibrato modulation ratio to the smoothed secular ratio.
- Seed the period filter at acquisition.
- Clear the period filter on a restart and on an audio reset.
- Skip the period filter at zero to keep exact default output.
- Document vibrato_preserve in rustdoc, wasm and the README.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Approved — clean Q24 + i128 vibrato contour split cleanly merged with #3. Please rebase onto updated main after #92 and #123.

- Merge the latest main branch into the feature branch.
- Keep the shared history imports from #92 in src/resynthesis.rs.
- Decode undefined vibratoPreserve to 0 for #123.
- Check optional vibratoPreserve in scripts/verify-pack.mjs.
- Document undefined optional fields in README.md.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Integrated updated main (720690b, v0.3.4) in a0c6a70, resolving the conflicts and bindings with #92 and #123:

  • refactor: share ring history helpers across pitch and resynthesis #92 (src/resynthesis.rs): Kept pub(crate) mod history; and use history::{clear_dirty_ring, prepare_history, record_history}; alongside mod vibrato; and use vibrato::PeriodFilter;.
  • fix(wasm): sanitize TypeScript declarations and Wasm exports #123 (src/resynthesis.rs, README.md, scripts/verify-pack.mjs): Updated CorrectionConfig::vibrato_preserve with serde(default, deserialize_with = "deserialize_vibrato_preserve") and tsify(optional, type = "number | undefined") so both absent and undefined vibratoPreserve values decode to 0.0 and type-check under exactOptionalPropertyTypes: true; added vibratoPreserve: undefined checks to the runtime and four strict TypeScript consumer profiles in scripts/verify-pack.mjs; and resolved the optional-field documentation conflict in README.md.
  • Verification: All CI checks (verify and msrv on Rust 1.88) are green on a0c6a70, and vibrato_preserve == 0.0 remains 100% bit-identical to v0.3.4 across 44.1 kHz and 48 kHz.

Note: Because force-pushing is disabled in this sandbox environment (git_push supports fast-forward pushes only), PR #57 is ready for GitHub's Squash and merge with this ASD-STE100 commit message:

feat(resynthesis): split vibrato from the mean pitch contour

- Add vibrato_preserve to CorrectionConfig with a default of zero.
- Validate vibrato_preserve in 0..=1 before state changes.
- Decode absent or undefined vibratoPreserve to 0 in JavaScript.
- Add a Q24 period filter at the five-frame update cadence.
- Select correction targets from the secular Q6 period.
- Return None in select_target_ratio if a shifted period wraps.
- Apply the vibrato modulation ratio to the smoothed secular ratio.
- Seed the period filter at acquisition.
- Clear the period filter on a restart and on an audio reset.
- Skip the period filter at zero to keep exact default output.
- Check optional vibratoPreserve in scripts/verify-pack.mjs.
- Document vibrato_preserve in rustdoc, wasm and the README.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved — Q24 + i128 vibrato contour split is bit-exact at 0.0 and cleanly structured. Please rebase onto updated main after #45 (integrating vibrato_preserve alongside humanize/flex_tune in CorrectionConfig and select_target_ratio).

- Share deserialize_zero_f32 for vibrato_preserve in CorrectionConfig.
- Pass the humanize decay from select_target_ratio to vibrato updates.
- Document humanize, flexTune and vibratoPreserve in wasm and README.
- Check absent and undefined correction fields in verify-pack.mjs.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Integrated updated main (0850e25, including #45, #107, #117, #22, and #41) in 56f6107:

  • CorrectionConfig (src/resynthesis.rs): Placed vibrato_preserve alongside humanize and flex_tune, sharing deserialize_zero_f32 and tsify(optional, type = "number | undefined"), and validating all four fields in CorrectionConfig::validate.
  • select_target_ratio & update_correction (src/resynthesis.rs): Consumes (target_ratio, decay) from select_target_ratio so vibrato_preserve == 0.0 stays 100% bit-identical to main, while vibrato_preserve > 0.0 evaluates humanize dwell decay and flex_tune outer soft zones on the secular Q6 period contour.
  • Docs, JSDoc & TypeScript (src/wasm.rs, README.md, scripts/verify-pack.mjs): Documented humanize, flexTune, and vibratoPreserve together, kept vibrato_preserve rustdoc clean under scripts/normalize-jsdoc.mjs, and checked both omitted and undefined values across runtime and strict exactOptionalPropertyTypes TypeScript profiles.
  • CI: All checks (build-wasm, msrv, check-os on Linux/macOS/Windows, and verify) are green on 56f6107.

Here is an ASD-STE100 commit message verified against .githooks/commit-msg for Squash and merge:

feat(resynthesis): split vibrato from the mean pitch contour

- Add vibrato_preserve to CorrectionConfig with a default of zero.
- Share deserialize_zero_f32 for optional vibratoPreserve in Wasm.
- Validate vibrato_preserve in 0..=1 before state changes.
- Add a Q24 period filter at the five-frame update cadence.
- Select correction targets from the secular Q6 period.
- Pass the humanize decay from select_target_ratio to vibrato updates.
- Apply the vibrato modulation ratio to the smoothed secular ratio.
- Seed the period filter at acquisition.
- Clear the period filter on a restart and on an audio reset.
- Skip the period filter at zero to keep exact default output.
- Check absent and undefined vibratoPreserve in verify-pack.mjs.
- Document vibrato_preserve in rustdoc, wasm and the README.

@byteland-app

Copy link
Copy Markdown
Contributor

Review: Q24 + i128 vibrato contour separation is stable and bit-exact at 0.0.

Please sync onto updated main (#139, #131, #104, #61), integrating vibrato_preserve into #61's Resynthesis::apply_config diff-guards (and dropping the redundant self.period_filter.configure(self.rate) call inside configure_coefficients since rate is fixed at construction). Minor note: consider whether mod_ratio should also be tapered by flex_tune pull in Resynthesis::update_correction so vibrato_preserve = 0.01 does not jump discontinuously relative to 0.0 at bin midpoints when flex_tune > 0.

- Merge upstream main with #139, #131, #104 and #61.
- Guard vibrato_preserve updates in Resynthesis::apply_config.
- Drop the duplicate PeriodFilter::configure call after new.
- Taper the vibrato modulation ratio with the flex_tune pull.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced onto main (8880205: #139, #131, #104, #61) in c75fd56 and addressed each review note:

  • Resynthesis::apply_config diff-guard (feat(events)!: add scalar parameter control events #61): Replaced the monolithic reconfiguration block with configure_vibrato_preserve(&mut self), called from configure_all and guarded by if old.correction.vibrato_preserve != config.correction.vibrato_preserve in Resynthesis::apply_config.
  • Dropped duplicate PeriodFilter::configure: Made PeriodFilter::configure private in src/resynthesis/vibrato.rs so coefficients are computed once in PeriodFilter::new(rate) and never recalculated on configuration updates.
  • flex_tune pull tapering on mod_ratio: Extended select_target_ratio to return (target_ratio, decay, pull) (pull = Q14::ZERO when correction is disabled or the scale is empty, Q14::ONE at full pull, and taper^2 in the outer flex_tune zone) and tapered mod_ratio via Q14::ONE + pull.mul(mod_ratio - Q14::ONE) in update_correction. At pull = Q14::ONE, target_mod equals mod_ratio bit-for-bit; near bin midpoints with flex_tune > 0, vibrato_preserve = 0.01 tapers smoothly toward unity without collapsing vibrato relative to 0.0.

Verified bit-exact PCM output at vibrato_preserve = 0.0 against 8880205 at 44.1 kHz and 48 kHz, >= 88.8% 4..=8 Hz vibrato retention with zero chromatic bin jumps, flex_tune midpoint continuity, cargo fmt --check, -D warnings native/Wasm builds/clippy/docs, cargo package --locked, npm run verify:pack, and MSRV 1.88.

Updated squash commit message (verified with .githooks/commit-msg):

feat(resynthesis): add vibrato contour preservation

- Add vibrato_preserve to CorrectionConfig with range validation.
- Split the five-frame Q6 period into secular and vibrato contours.
- Taper the vibrato modulation ratio with the flex_tune pull.
- Guard vibrato_preserve updates in Resynthesis::apply_config.
- Expose optional vibratoPreserve in the WebAssembly wrapper.

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