Skip to content

fix: restore the initial state on reset without memory allocation - #106

Closed
google-labs-stitch[bot] wants to merge 1 commit into
mainfrom
stitch/restore-processor-reset-state-jm1-12999e08-54db-438d-b7eb-78e9824377f9
Closed

google-labs-stitch[bot] wants to merge 1 commit into
mainfrom
stitch/restore-processor-reset-state-jm1-12999e08-54db-438d-b7eb-78e9824377f9

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

Restores the exact post-Processor::new state in place with zero heap allocation across Processor::reset, ControlEvent::Reset, drain completion, and WasmProcessor::reset (Tunelet.reset()), while keeping mid-stream MidiEvent::AllNotesOff, HarmonyConfig::source changes, stereo_output switches, and Telemetry::formant_generation unchanged.

Changes

  • Scale table (src/scale.rs, src/resynthesis.rs): Split CorrectionTable::release_keys for MidiEvent::AllNotesOff (preserving key 127) and update CorrectionTable::reset to clear all 128 keys and reload CorrectionConfig::notes with the periods for the prepared sample rate (#28).
  • Harmony & resynthesis controllers (src/harmony.rs, src/resynthesis.rs): Move mid-stream MIDI release into HarmonyState::release_notes for AllNotesOff, source switches, and stereo_output switches; restore smoothed_gain, period_output, target_period, current_ratio, MIDI slots, chord state, and scale caches in HarmonyState::reset; clear drift, harmony_gains, modulation_phase, scale_index, and octave, and set control_counter to CONTROL_DUE in Resynthesis::reset.
  • Tracker, numeric state, reverb, and Punch (src/pitch/tracker.rs, src/numeric.rs, src/numeric/rng.rs, src/effects/reverb.rs, src/effects/punch.rs, src/processor.rs): Clear previous_period and best on full tracker reset while keeping PitchTracker::reset_audio for stereo switches; add NumericContext::reset to reset AtanQ14::index to 1 and reseed RandomStream from random_seed as u32; keep Reverb::reset_delay for stereo switches and reset DelayLine::write, lpf1, and lpf2 unconditionally in Reverb::reset; keep Punch::new and Punch::reset initializing drive from gain_db (BASE_DRIVE.mul(self.gain), #111).
  • Documentation (README.md, src/lib.rs, src/processor.rs, src/events.rs, src/wasm.rs): Update lifecycle and API documentation in ASD-STE100.

Verification

  • cargo fmt --check
  • cargo clippy --locked --lib -- -D warnings
  • cargo build --locked --release
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo package --list --locked
  • RUSTDOCFLAGS="-D warnings" npm run check:wasm
  • npm run verify:pack
  • Verified 0 heap allocations across Processor::reset, ControlEvent::Reset, and drain completion, and sample-exact PCM, Feedback, Telemetry, and formant_envelope parity against Processor::new across Rust and WebAssembly at 44.1 kHz and 48 kHz.

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

- Reload the configured correction scale in CorrectionTable::reset
- Clear the harmony envelopes and caches in HarmonyState::reset
- Clear the resynthesis controllers in Resynthesis::reset
- Clear PitchTracker::previous_period and best on a full reset
- Restore NumericContext in Processor::reset
- Clear the reverb filters and write cursor in Reverb::reset
- Restore the initial base drive in Punch::reset
- Update the reset documentation in README.md and rustdoc
@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #75. #75 fixes both full zero-allocation reset and calibrated reverb tail budgets, whereas #106 reverts Punch::reset() back to BASE_DRIVE (losing gain_db for the first 99 frames after reset) and reproduces the 44.1 kHz scale quirk at 48 kHz.

@byteland-app
byteland-app deleted the stitch/restore-processor-reset-state-jm1-12999e08-54db-438d-b7eb-78e9824377f9 branch November 25, 2026 08:04
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Acknowledged — leaving #106 closed in favor of #75 (which covers both zero-allocation reset and calibrated reverb tail budgets).

For completeness on this branch (3598c18, 8da57fe), main (v0.3.3, including #28 and #111) has been merged and both issues noted in the comment are resolved here as well:

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