Skip to content

feat: add adaptive silence drain and flush lifecycle - #65

Closed
google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/adaptive-silence-drain-lifecycle-apis-jm1-aa17d16b-ecf2-4ecb-bb5f-6ea1aa1c040d
Closed

google-labs-stitch[bot] wants to merge 6 commits into
mainfrom
stitch/adaptive-silence-drain-lifecycle-apis-jm1-aa17d16b-ecf2-4ecb-bb5f-6ea1aa1c040d

Conversation

@google-labs-stitch

Copy link
Copy Markdown
Contributor

Summary

  • Initializes Punch directly with Punch::new(rate, config.punch) in Processor::new, so Punch.drive starts at config.punch.gain_db from sample zero without an initial 0 dB transient.
  • Calibrates reverb::tail_frames to the per-mode loop delays from reverb_layout plus one 17,000-frame (DELAY_CAPACITY) ring pass as a finite upper bound against Q14 limit cycles.
  • Adds an integer silence detector in Processor after resynthesis.tail_frames() + alien::tail_frames(config.alien) frames pass, which stops positive drain blocks early after 17,000 consecutive stereo frames within ±24 PCM on both channels.
  • Sets drain_remaining to Some(0) at the end of the final positive drain block, preserves Feedback and Telemetry peaks and processed_frames, and defers self.reset() to the next non-empty (frames > 0) drain call that returns Ok(0).
  • Exposes Processor::drain_remaining and Tunelet.drainRemaining (Option<usize> in Rust, number | undefined in TypeScript).
  • Updates Processor::reset, Tunelet.reset and ControlEvent::Reset to restore all DSP histories, filter memories, pitch tracker buffers, formant banks, keyboard state (0..=127) and NumericContext without memory allocation, matching Processor::new sample for sample from frame zero.
  • Adds Processor::flush, ControlEvent::Flush and Tunelet.flush to clear delay lines, held notes 0..=126 and meters while preserving NumericContext, reverb damping filter memories, harmony release envelopes, choir drift, modulation phase, control timing, pitch previous_period and formant_generation.

Verification

Adaptive Silence Drain and Lifecycle Verification

  • Built and checked Rust, WebAssembly and TypeScript targets cleanly (cargo fmt --check, cargo build --locked --release, cargo clippy --locked --lib -- -D warnings, cargo clippy --locked --target wasm32-unknown-unknown --features wasm --lib -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps and npm run build).
  • Verified zero post-construction heap allocations (0 allocations / 0 bytes via a custom GlobalAlloc harness) across process*, begin_drain, drain*, reset, flush and TimedEvent controls.
  • Verified at both 44.1 kHz and 48 kHz across all six ReverbMode topologies and Node.js WebAssembly bindings that:
    • Punch at -96.0 dB emits zero nonzero PCM frames from sample zero.
    • Silent and impulse clips stop 17,000 frames after holdoff or last frame above ±24 PCM, and post-stop output never exceeds -58 dBFS (41 PCM).
    • drain_remaining / drainRemaining transitions None/undefined → decreasing Some(n)/n → Some(0)/0 → None/undefined, empty drain slices neither advance counters nor run the deferred reset, and Feedback / Telemetry stay intact after the final positive block.
    • reset() matches Processor::new bit for bit from frame zero across maximal multi-stage configurations, flush() preserves live controller continuity, and ControlEvent::Flush validates atomically before any state or buffer change.

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

- Initialize Punch with the configured gain at construction.
- Calibrate reverb tail budgets from the loop delays of each mode.
- Stop active drains after 17,000 silent frames past the initial delays.
- Defer the post-drain reset to the next non-empty drain call.
- Expose drain_remaining and flush in Rust, WebAssembly and TypeScript.
- Reset all DSP, keyboard and random state without memory allocation.
- Merge the latest commits from main.
- Keep telemetry, flush and i64 arithmetic notes in src/lib.rs.
- Merge the latest commits from main.
- Share process_into, downmix and flush_post_resynthesis in Processor.
- Cancel the drain and the silence counters in process_into.
- Merge the latest commits from main.
- Refer to drain for completion in the begin_drain Wasm comment.
- Refer to processMono and drain in the drain_mono Wasm comment.
- Merge the latest commits from main
- Keep the dirty flag across flush and reset in Reverb
- Track audio and analysis changes separately in Formant
- Clear only the active sample and period spans in PitchTracker
- Clear only the active sample and period spans in Resynthesis
@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #75. #75 calibrates exact -60 dBFS reverb tail budgets and fixes processor reset without adding five new public APIs, without breaking Rust exhaustiveness on ControlEvent::Flush, and without heuristic ±24 PCM silence truncation.

@byteland-app
byteland-app deleted the stitch/adaptive-silence-drain-lifecycle-apis-jm1-aa17d16b-ecf2-4ecb-bb5f-6ea1aa1c040d branch November 25, 2026 08:06
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Acknowledged — leaving #65 closed with no further changes in favor of #75, which calibrates the -60 dBFS reverb tail budgets and fixes zero-allocation Processor::reset while keeping the existing public API surface, preserving ControlEvent match exhaustiveness, and avoiding heuristic PCM silence truncation.

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