Skip to content

fix!: calibrate drain budgets and processor resets - #75

Open
google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/calibrate-drain-budgets-and-resets-jm1-bfdbc581-4bdd-4b94-a5d8-1fce4d578d34
Open

google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/calibrate-drain-budgets-and-resets-jm1-bfdbc581-4bdd-4b94-a5d8-1fce4d578d34

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

  • Calibrate reverb::tail_frames from reverb_layout tap distances and a -60 dBFS (1e-3) decay threshold across all six ReverbMode variants, with separate outer comb loop and short allpass section budgets.
  • Defer self.reset() at the end of a drain in Processor::drain_into to the next non-empty zero-frame drain call while keeping #61's Formant::aspiration_muted flag, so the final positive tail block keeps Feedback and Telemetry peaks and processed_frames and empty buffers do not finish the drain.
  • Clear voice envelopes, ratios, periods, MIDI state and scale search state in HarmonyState::reset while MidiEvent::AllNotesOff and HarmonyConfig::source changes keep live release envelopes through HarmonyState::release_all_notes, and preserve #61's stage field-diff guards in Reverb and HarmonyState.
  • Align CorrectionTable::reset and MidiEvent::AllNotesOff in src/scale.rs with #46's 0..=127 key coverage and reload CorrectionConfig::notes for self.rate, and clear drift, harmony_gains, modulation_phase, scale_index and octave with control_counter = CONTROL_DUE in Resynthesis::reset_audio.
  • Reset delay.write, lpf1 and lpf2 in Reverb::reset on #86's fixed delay ring, clear previous_period and correlations in PitchTracker::reset, keep Formant::generation monotonic across Formant::reset, and build NumericContext again from random_seed in Processor::reset with zero memory allocations.
  • Update lifecycle documentation in src/lib.rs, src/processor.rs, src/wasm.rs, README.md and docs/images/lifecycle.svg in ASD-STE100 English.

BREAKING CHANGE: reset now clears all filter, controller and random_seed states so the processor matches new without allocation, and drain* methods defer the completion reset to the next non-empty call that returns 0 so the final positive tail block keeps its Feedback and Telemetry peaks and frame count.

Lifecycle diagram and verification summary

Verification

  • cargo fmt --check
  • 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 ci && RUSTDOCFLAGS="-D warnings" npm run check:wasm && npm run verify:pack && npm run verify:pack -- --ignore-scripts
  • cargo +1.88 build --locked --lib and cargo +1.88 build --locked --lib --target wasm32-unknown-unknown --features wasm
  • Verified 48 kHz reverb::tail_frames budgets (Binaural = 5,926 frames, Schroeder at decay = 0.0 = 102,208 frames, LargeHall default = 249,224 frames and maximum = 2,459,348 frames) and -60 dBFS impulse decay retention across all six ReverbMode variants.
  • Verified final-block peak retention, empty-buffer drain handling, #61 Formant::aspiration_muted preservation and next-call reset across drain, drain_planar, drain_mono, drain_f32, drain_planar_f32, drain_mono_f32 and WebAssembly Tunelet drain methods.
  • Verified bit-exact PCM equality between Processor::reset (and post-drain reset after ParameterControl updates) and Processor::new with zero post-construction heap allocations, 0..=127 correction key coverage on AllNotesOff and reset, #104 Telemetry pitch fields and Float32Array voice slices, and monotonic Telemetry::formant_generation across resets.

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

- Initialize Punch with the configured gain in Processor::new.
- Calibrate reverb tail budgets from the tap layout at -60 dBFS.
- Defer the drain reset to the next non-empty zero-frame drain call.
- Clear the harmony, resynthesis and correction state on a reset.
- Reset the reverb filters, the pitch tracker, formants and the seed.
- Update the lifecycle documentation in Rust, Wasm and the README.
- Resolve the drainMono documentation conflict in src/wasm.rs.
- Keep the random stream across stereo_output changes in Processor.
- Keep the dirty check in Reverb::reset in src/effects/reverb.rs.
- Reset both damping filters inside the dirty block of Reverb::reset.
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Preferred over #65 and #106 — zero public API expansion, accurate -60 dBFS reverb tail budgets, deferred drain reset, and zero-allocation full reset. Please make two small updates after #28 and #111:

  1. Remove the legacy 44.1 kHz scale quirk reproduction in Resynthesis::reset() now that fix(scale): initialize periods for the sample rate #28 initializes periods for self.rate.
  2. Rebase onto fix(effects): use per-sample envelopes and normalize ceiling #111 (3-line overlap in Processor::new) and confirm whether Formant::reset() should keep formant_generation monotonic (like fix: restore the initial state on reset without memory allocation #106) so UI consumers can reliably detect resets.

- Keep Punch::new(rate, config.punch) in Processor::new.
- Load CorrectionConfig::notes for self.rate in Resynthesis::reset.
- Keep Formant::generation unchanged in Formant::reset.
- Update the drain and reset documentation for Wasm and Rust.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Merged main (0.3.3) into the branch and applied both updates:

  1. Scale periods on reset (src/resynthesis.rs): Removed the legacy 44.1 kHz chromatic reproduction in Resynthesis::reset(), calling self.scale.set_notes(self.config.correction.notes) directly for self.rate to match Resynthesis::new after fix(scale): initialize periods for the sample rate #28.
  2. Processor::new (fix(effects): use per-sample envelopes and normalize ceiling #111) and monotonic formant_generation (src/processor.rs, src/formant.rs, src/wasm.rs, src/lib.rs, README.md): Resolved the Processor::new overlap with fix(effects): use per-sample envelopes and normalize ceiling #111 and kept Formant::generation unchanged in Formant::reset() so Telemetry::formant_generation (formantGeneration in Wasm) stays monotonic across resets instead of wrapping back to 0 and colliding with pre-reset generation counts.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Reset equivalence, -60 dBFS reverb tail calibration, deferred drain reset, and #28/#111 alignment all look solid. Two items before merge:

  1. docs/images/lifecycle.svg line 93: the new 68-character label ('after the budget, the next non-empty call returns 0 and calls reset()') is ~442 px wide centered at x=570, which overflows and collides with the vertical return lines at x=370 and x=770 (400 px span). Please shorten the text or wrap it onto two lines.
  2. Rebase onto updated main after fix(midi): reset harmony on source change and fix correction keys #46 and perf(reverb): use a fixed ring with inline taps #86, aligning AllNotesOff in src/scale.rs with fix(midi): reset harmony on source change and fix correction keys #46's 0..=127 key coverage. (We will also confirm whether the full-reset / deferred-drain change ships in 0.3.x or 0.4.0.)

- Align AllNotesOff in src/scale.rs with keys 0..=127.
- Release harmony MIDI notes when HarmonyConfig::source changes.
- Reset the write cursor of the fixed DelayLine ring to zero.
- Keep the ControlActivity queries and the formant envelope cache.
- Wrap the drain reset label onto two tspan lines at x=570.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Merged main (0.3.4) into the branch and addressed both items:

  1. docs/images/lifecycle.svg label width: Wrapped the drain-completion label at x=570 (y=252, dy=16) onto two <tspan> lines (224 px and 158 px wide in Chromium getBBox()), keeping >88 px horizontal clearance from the vertical return wires at x=370 and x=770.
  2. Updated main (#46 and #86) alignment (src/scale.rs, src/harmony.rs, src/effects/reverb.rs, src/resynthesis.rs): Adopted #46's 0..=127 key coverage and configured-mask reload for both CorrectionTable::reset and MidiEvent::AllNotesOff in src/scale.rs, routed all HarmonyConfig::source transitions (old.source != config.source) through HarmonyState::release_all_notes so live source switches keep smooth release envelopes, and reset DelayLine::write to 0 on #86's fixed [Q14; CAPACITY] ring in src/effects/reverb.rs.

- Keep scale and dwell resets in Resynthesis::reset_audio
- Align beginDrain and drainMono docs in src/wasm.rs with main
@byteland-app

Copy link
Copy Markdown
Contributor

Review: The -60 dBFS reverb tail calibration, full reset() equivalence to new(), deferred drain auto-reset, and updated docs/images/lifecycle.svg all look solid.

Because full RNG/filter reset() and deferring drain auto-reset to the next non-empty zero-frame call change documented v0.3.x contracts, and the 0.4.0 breaking window is now open on main (with #104 and #61 merged), please:

  1. Retarget this PR as a breaking 0.4.0 change (fix!: calibrate drain budgets and processor resets with a BREAKING CHANGE summary for release-please).
  2. 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), preserving feat(events)!: add scalar parameter control events #61's Formant::aspiration_muted in Processor::drain_into and stage diff-guards.

- Merge main into the drain budget and reset branch.
- Keep Formant::aspiration_muted in Processor::drain_into.
- Keep the stage diff-guards in Reverb and HarmonyState.
- Defer the drain reset to the next non-empty zero-frame call.
- Clear all filter, MIDI and random states in Processor::reset.
@google-labs-stitch google-labs-stitch Bot changed the title fix: calibrate drain budgets and processor resets fix!: calibrate drain budgets and processor resets Nov 26, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in 073832e:

  1. Retargeted for the 0.4.0 breaking window: Updated the PR title and commit header to fix!: calibrate drain budgets and processor resets and added the BREAKING CHANGE summary to the PR description for release-please.
  2. Synced with updated main (8880205 — #139, #131, #104, #61): Merged main, preserved #61's self.resynthesis.set_aspiration_muted(true) / false in Processor::drain_into alongside deferred drain reset on Some(0) and empty-buffer guards, and preserved #61's stage field-diff guards in Reverb and HarmonyState and #104's Telemetry pitch fields and Float32Array voice slices.

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