Skip to content

perf: guard unchanged stage controls and mute drain aspiration - #24

Closed
google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/guard-stage-coeffs-mute-drain-aspiration-jm0-e5600251-1222-49bc-b4d9-8fc2e935020d
Closed

google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/guard-stage-coeffs-mute-drain-aspiration-jm0-e5600251-1222-49bc-b4d9-8fc2e935020d

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

  • Add an internal aspiration_muted flag on Formant and a crate-private Resynthesis::set_aspiration_muted helper so Formant::add_noise returns sample immediately while muted and keeps NumericContext and noise_filter unchanged across forward, forward_mono, and forward_stereo.
  • Replace the two per-block Resynthesis::apply_config calls in Processor::drain_into (used by drain, drain_planar, drain_mono, drain_f32, drain_planar_f32, and drain_mono_f32) with set_aspiration_muted(true) before the next(0, layout) frame loop and set_aspiration_muted(false) after it, while preserving host-visible Processor::config and Processor::control_activity.
  • Separate unconditional initialization in Resynthesis::new, Formant::new, Punch::new, and Reverb::new from incremental stage setters while keeping dirty: false in Formant::new and Reverb::new.
  • Guard pitch.set_config, formant.set_config, harmony.apply_config, and split coefficient helpers in Resynthesis::apply_config (including configure_humanize and configure_flex_tune), with decay_half_step and drift_decay computed once at construction and scale_initialized and dwell cleared as before.
  • Guard width/width_squared, stretch_map, noise_gain, and Design::high_pass by field in Formant::set_config.
  • Store PunchConfig on Punch, compute fast_decay and drive_decay once in Punch::new, and guard per-sample Q30/Q28 slow_decay, attack_decay, gain, and ceiling_gain updates by field.
  • Guard mix, diffuse + hall_diffuse (inside Reverb::prepare_diffusion), decay, and Design::low_pass_one_pole by field in Reverb::set_config.

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, .githooks/pre-commit, .githooks/commit-msg, and MSRV 1.88 builds (cargo +1.88 build --locked --lib and --target wasm32-unknown-unknown --features wasm) pass.
  • Rendered stereo, planar, mono, and f32 PCM frames, humanize and flex_tune automation, mono Choir and Harmony forward_mono drains, MediumHall and LargeHall hall_diffuse updates, Feedback, Telemetry, ControlActivity, formant_envelope, mid-drain cancellation continuation, and full tail drains at 44.1 kHz and 48 kHz match main (0850e25) bit for bit (12,726,860 bytes, fnv1a64 = 0x65b56afb7b530310).
  • Processor::config() returns the configured formant.aspiration_mix unchanged before, during, and after drain, drain_planar, drain_mono, drain_f32, drain_planar_f32, and drain_mono_f32.
  • 48 kHz release benchmarks on 0850e25 confirm elimination of stage recomputation overhead on 120,000 dry_mix ControlEvent::Resynthesis updates across 480,000 frames (506.320 ms → 436.061 ms, -68.532 ms recomputation overhead) and elimination of reconfiguration overhead across 1,863 64-frame Processor::drain calls with formant.aspiration_mix = 0.2 (+2.279 ms → noise floor).

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

- Add an aspiration mute flag on Formant for tail drains.
- Mute formant aspiration in Processor::drain_into directly.
- Initialize all stage tables and filters at construction.
- Guard sub-stage setters and coefficients in Resynthesis.
- Guard width, stretch and aspiration updates in Formant.
- Guard envelope decays and gains in Punch::set_config.
- Guard mix, diffusion, decay and brightness in Reverb.
- Preserve exact fixed-point audio, feedback and telemetry.
- Merge upstream changes from main into the feature branch.
- Update configure_harmony_gain for the mono and stereo harmony paths.
…ion-jm0-e5600251-1222-49bc-b4d9-8fc2e935020d
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Bit-exact stage diff-guards and Formant::aspiration_muted give great CPU savings on drain and frequent control events. Please rebase onto main to resolve conflicts with 7490b83 (dirty flags in Formant::new / Reverb::new) and squash the merge commits. Note: if #61 is merged in 0.4.0, it supersedes these same optimizations.

- Merge main at 0.3.3 into the feature branch
- Keep the dirty flags in Formant::new and Reverb::new
- Update the Punch helpers for per-sample Q30 and Q28 controls
- Pass OutputLayout in Processor::drain_into
- Keep the scale_initialized reset in Resynthesis::apply_config
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced with main at 0.3.3 (451ea1e, commit de5412c) and resolved all upstream conflicts:

  • src/formant.rs & src/effects/reverb.rs (7490b83): Kept dirty: false and one-pass initialization in Formant::new (without calling reset()) and Reverb::new alongside the unconditional prepare_* helpers.
  • src/effects/punch.rs (6f0e33b): Updated Punch::decay and prepare_* helpers to the per-sample Q30 envelope coefficients and Q28 input/ceiling gains, computing fast_decay and drive_decay once in Punch::new.
  • src/processor.rs (4a4110c) & src/resynthesis.rs (e9f81b6): Preserved OutputLayout in Processor::drain_into around set_aspiration_muted and preserved self.scale_initialized = false when pitch_ratio changes in Resynthesis::apply_config.
  • Verification: Verified bit-exact output against main (451ea1e) across stereo/planar/mono PCM, Feedback, Telemetry, formant_envelope, mid-drain cancellation, and full tail drains at 44.1 kHz and 48 kHz (12,600,772 bytes, fnv1a64 = 0x5e59d940dccc3ac5), plus cargo fmt --check, clippy, doc, package, and check:wasm.

(Note: force-pushing is disabled in this automated environment, so origin/main was merged via fast-forward push; GitHub squash-merge will collapse the branch cleanly into a single commit if merged prior to #61 in 0.4.0.)

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Approved — all stage diff-guards and Formant::aspiration_muted are bit-exact and properly adapted to v0.3.3. Please rebase onto updated main after #46 and #86 (placing hall_diffuse updates inside Reverb::prepare_diffusion). Note: if we move straight to 0.4.0 with #61, #61 subsumes these same optimizations.

- Merge main at 0.3.4 into the feature branch
- Update hall_diffuse in Reverb::prepare_diffusion
- Keep the updated reset comment in Resynthesis::reset
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced with updated main at 0.3.4 (720690b, commit 49e016c) after #46, #86, #102, #30, #135, and #120:

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved — stage diff-guards and Formant::aspiration_muted are bit-exact and clean. Please rebase onto updated main after #45 (preserving humanize/flex_tune guards in Resynthesis::apply_config). Note: if we proceed straight to 0.4.0 with #61, #61 subsumes these optimizations.

- Initialize decay_half_step once in Resynthesis::new.
- Guard configure_humanize and configure_flex_tune in apply_config.
- Update configure_humanize when retune_ms or humanize changes.
- Preserve exact audio, feedback, telemetry and f32 drain output.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced with updated main (0850e25, commit 8a9c99d) after #45, #22, #20, #117, #81, and #41:

  • src/resynthesis.rs (feat(resynthesis): add humanize and flex-tune controls #45 & refactor(resynthesis): extract choir reader and glottal helpers #22): Initialized decay_half_step once in Resynthesis::new alongside drift_decay, split out configure_humanize and configure_flex_tune, and guarded them in Resynthesis::apply_config (configure_retune + configure_humanize when retune_ms changes, configure_humanize when humanize changes, and configure_flex_tune when flex_tune changes), while preserving dwell resets and #22's choir reader and glottal helpers.
  • src/processor.rs (feat: expose Float32 buffers in Wasm for in-place audio #117) & src/formant.rs (refactor(formant): unify synthesis, stamp and ring helpers #20): Preserved set_aspiration_muted(true) / set_aspiration_muted(false) in Processor::drain_into (covering both i16 and #117 f32 drain methods) and self.aspiration_muted in Formant::add_noise across #20's unified synthesis helpers.
  • Verification: Verified 100% bit-exact output against main (0850e25) across stereo/planar/mono/f32 PCM, humanize and flex_tune automation, mono forward_mono drains, MediumHall/LargeHall hall_diffuse updates, Feedback, Telemetry, ControlActivity, and formant_envelope at 44.1 kHz and 48 kHz (12,726,860 bytes, fnv1a64 = 0x65b56afb7b530310), with all CI checks (build-wasm, check-os, msrv, verify) passing.

@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #61, which is now merged into main for 0.4.0 and includes the same stage diff-guards and Formant::aspiration_muted drain optimization. Thank you for the bit-exact implementation and verification!

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