Skip to content

feat(resynthesis): add humanize and flex-tune controls - #45

Merged
byteland-app merged 5 commits into
mainfrom
stitch/add-humanize-and-flex-tune-controls-jm0-6bdd1b4d-19b4-4af9-8033-69151f60266e
Nov 26, 2026
Merged

byteland-app merged 5 commits into
mainfrom
stitch/add-humanize-and-flex-tune-controls-jm0-6bdd1b4d-19b4-4af9-8033-69151f60266e

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

  • Add humanize (0.0..=1.0, default 0.0) and flex_tune (0.0..=1.0, default 0.0) to CorrectionConfig in Rust, WebAssembly and TypeScript.
  • Mark humanize and flexTune with serde(default, deserialize_with = "deserialize_zero_f32") and tsify(optional, type = "number | undefined") under all(feature = "wasm", target_arch = "wasm32") so both omitted and undefined JavaScript values decode to 0 and pass exactOptionalPropertyTypes alongside HarmonyConfig.voices.
  • Validate resynthesis.correction.humanize and resynthesis.correction.flex_tune in 0.0..=1.0 before state changes in Processor and Tunelet.
  • Smooth the humanize transition in half-life space: interpolate Q20 half-life milliseconds from retune_ms to retune_ms + (400 - retune_ms) * humanize with the Hermite ramp u^3 * (4 - 3 * u), and convert to a Q14 decay coefficient with a Padé (1, 1) quotient clamped to correction_decay..=sustained_decay. Reset dwell on (scale_index, octave) bin changes, non-positive shifted periods, step.restarted, pitch_ratio changes, target reloads and audio resets.
  • Factor select_target_ratio in update_correction to apply full pull inside the inner 1 - flex_tune fraction of each half-bin around periods[scale_index] and soften pull toward 0 across the outer flex_tune fraction up to midpoints.
  • Skip dwell ramp and soft-zone math when humanize == 0.0 and flex_tune == 0.0 to preserve bit-identical PCM output at 44.1 kHz and 48 kHz.

Verification

DSP Verification Plots

  • Bit-identical default output: Verified 0 sample differences across 4,974,288 rendered i16 PCM samples against main (v0.3.4) at 44.1 kHz and 48 kHz (latency_frames = 1,593, tail_frames unchanged).
  • Smooth humanize half-life curve: Verified strict monotonicity across all Q14 dwell steps 0..=16,384 (ramping smoothly through 125 ms at dwell = 0.5 and 379 ms at dwell = 0.9 up to 400 ms with zero jump at dwell = 1.0).
  • Sustained vibrato depth: At retune_ms = 10.0 on a sustained D4 vocal with 5.5 Hz, 70-cent vibrato, humanize = 0.0 retains 41.8% depth (37.3% at 48 kHz), while humanize = 0.8 and humanize = 1.0 retain 98.0% at 44.1 kHz and 98.3% at 48 kHz (> 80% threshold).
  • Step transition convergence: At retune_ms = 10.0, scale-note step transitions reach 90% convergence in 22.1 ms at 44.1 kHz and 21.1 ms at 48 kHz (<= 35 ms target).
  • Flex-Tune outer soft zone: Verified full pull inside the inner 1 - flex_tune zone near the target and softened pull toward 0 near midpoint boundaries via Processor::set_config and ControlEvent::Resynthesis.
  • CI, Wasm & TypeScript checks: Verified 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 and npm run verify:pack (all four exactOptionalPropertyTypes profiles, omitted and undefined optional fields, HTTP loaders, and both .tgz archives).

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

- Add humanize and flex_tune fields to CorrectionConfig.
- Accept absent humanize and flexTune fields in JavaScript.
- Validate both fields in 0..=1 before state changes.
- Relax the correction decay on sustained target bins.
- Reset the dwell progress on target changes and restarts.
- Reduce the target pull outside the inner flex-tune zone.
- Preserve the default audio output at both sample rates.
- Document the controls in rustdoc, wasm and the README.
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Good humanize and flex-tune additions, non-breaking and bit-exact when both are 0.0. Please make these adjustments before merge:

  1. Rebase onto current main (21 commits behind, no CI run yet) and update stale comments; coordinate with feat(resynthesis): split vibrato from the mean pitch contour #57 in update_correction if merged after it.
  2. Smooth the humanize transition curve: linear interpolation in decay-coefficient space with dwell^2 causes half-life to stay ~1.8 ms until dwell > 0.9 and then jump abruptly.
  3. Clarify the flex_tune docs: calling it an 'expressive deadband' is misleading because it applies full pull near the target and softens pull toward the midpoint boundary.

- Interpolate the humanize half-life in Q20 with a Hermite ramp.
- Convert the half-life to Q14 decay with a Pade (1, 1) quotient.
- Factor select_target_ratio and reset dwell on pitch_ratio changes.
- Describe flex_tune as an outer soft zone, not a deadband.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed all three points in 20d4310 (synced with main at 451ea1e / v0.3.3):

  1. Synced with current main, updated comments, and aligned update_correction with feat(resynthesis): split vibrato from the mean pitch contour #57:
    • Merged main (v0.3.3, including CI workflow, i64 saturating fixed-point math, 1,593-frame dry alignment, and shifted-period bounds) into the branch.
    • Updated configure_coefficients and update_correction comments, reset dwell on pitch_ratio changes and all non-positive shifted-period exits, and extracted select_target_ratio(&mut self, period: Q6) -> Option<(Q14, Q14)> + reset_dwell so update_correction stays a minimal wrapper compatible with feat(resynthesis): split vibrato from the mean pitch contour #57's select_target_ratio split.
  2. Smoothed the humanize transition curve in half-life space:
    • Replaced linear decay-coefficient interpolation (dwell^2 in Q14 decay space) with humanize_decay(), which interpolates half-life directly in Q20 milliseconds via the monotonic Hermite curve u^3 * (4 - 3 * u) ((u * u * u * (65_536 - 3 * u)) >> 42) and converts half-life to Q14 decay via the Padé (1, 1) quotient ((half_life - c) << 14) / (half_life + c) clamped to correction_decay..=sustained_decay.
    • Effective half-life now climbs smoothly across the full dwell range (e.g., 125 ms at dwell = 0.5 and 379 ms at dwell = 0.9 toward 400 ms, with zero jump at dwell = 1.0), while keeping C4 -> D4 90% step convergence at 22.1 ms (44.1 kHz) / 21.1 ms (48 kHz) and 98.0%..98.3% sustained vibrato retention.
  3. Clarified flex_tune documentation:
    • Replaced the misleading "expressive deadband" wording in CorrectionConfig::flex_tune rustdoc, struct comments, README.md, and the PR summary with "outer soft-zone width", stating explicitly that pitches in the inner 1 - flex_tune fraction around the target period get full pull while pull decreases to zero across the outer flex_tune fraction toward the midpoint boundary.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Approved — the Q20 Hermite + Pade (1,1) humanize ramp, clarified flex_tune docs, and dwell reset are solid and bit-exact at 0.0. Please rebase onto updated main after #123.

…nd-flex-tune-controls-jm0-6bdd1b4d-19b4-4af9-8033-69151f60266e

# Conflicts:
#	README.md
- Decode undefined humanize and flexTune values to 0 in Wasm.
- Emit number | undefined for humanize and flexTune in tsify.
- Check absent and undefined correction fields in verify-pack.mjs.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced with updated main (720690b / v0.3.4, after #123) in 02516a7 and c117e23:

  • Merged main and resolved README.md conflict: Combined the optional-field documentation from fix(wasm): sanitize TypeScript declarations and Wasm exports #123 so README.md documents that optional fields (resynthesis.correction.humanize, resynthesis.correction.flexTune, and resynthesis.harmony.voices) take their defaults when absent or undefined.
  • Aligned humanize and flexTune with fix(wasm): sanitize TypeScript declarations and Wasm exports #123's exactOptionalPropertyTypes and undefined contract: Updated both fields on CorrectionConfig to use serde(default, deserialize_with = "deserialize_zero_f32") and tsify(optional, type = "number | undefined") (matching HarmonyConfig.voices), and extended scripts/verify-pack.mjs to check omitted and undefined humanize and flexTune values at runtime and across all four strict --exactOptionalPropertyTypes TypeScript consumer profiles.
  • Re-verified CI and bit-exactness: Re-ran 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, and the 4,974,288-sample PCM regression check (0 sample diffs at 0.0).

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