Skip to content

feat: add f32 audio and drain methods to Processor and Tunelet - #84

Closed
google-labs-stitch[bot] wants to merge 2 commits into
mainfrom
stitch/add-float32-audio-methods-jm0-c24407d7-874e-4c13-8e92-3000afe25ad9
Closed

google-labs-stitch[bot] wants to merge 2 commits into
mainfrom
stitch/add-float32-audio-methods-jm0-c24407d7-874e-4c13-8e92-3000afe25ad9

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

Add f32 and Float32Array audio process and drain methods to Processor and Tunelet (WasmProcessor) so browser, Node.js and Rust hosts can pass f32 audio directly while keeping sample-exact fixed-point DSP output, zero post-construction Rust heap allocations and pre-mutation error atomicity.

Changes

  • src/processor.rs:
    • Add process_f32, process_planar_f32, process_mono_in_place_f32, drain_f32, drain_planar_f32 and drain_mono_f32 to Processor, passing OutputLayout::Stereo for stereo calls and OutputLayout::Mono for mono calls.
    • Quantize each f32 input sample on the stack before Processor::next (NaN maps to 0, finite and infinite values clamp to -1.0..=1.0, multiply in f64 by 32_767.0 and round to -32767..=32767).
    • Divide each clipped i16 output sample or mono downmix sample by 32_768.0, and fill unused drain frames with 0.0.
  • src/wasm.rs:
    • Reserve reusable input_f32, left_f32 and right_f32 Vec<f32> buffers of length max_block_frames in WasmProcessor::new with try_reserve_exact.
    • Add processF32, processMonoF32, drainF32 and drainMonoF32 on Tunelet accepting &Float32Array buffers, reusing decode_events(&mut self.events, ...) for timed events and copying via copy_to and copy_from.
    • Keep Int16Array process, processMono, drain and drainMono unchanged.
  • scripts/verify-pack.mjs, src/lib.rs, README.md:
    • Check runtime execution and strict TypeScript declarations for the Float32Array methods across both tunelet and @bytelandtechnology/tunelet archives in scripts/verify-pack.mjs.
    • Document the f32 and Float32Array audio methods and conversion rules in src/lib.rs and README.md.

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
  • Verified Processor::new heap usage remains identical to main (2,071,044 bytes) and post-construction Rust audio/drain calls allocate 0 bytes.
  • Verified sample-exact equivalence (including stereo and post-downmix mono peak meters), reusable decode_events buffer capacity without Wasm memory growth, overlapping buffer safety and pre-mutation error atomicity.

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

- Add f32 process and drain methods to Processor in src/processor.rs
- Quantize f32 input to symmetric i16 PCM on the stack
- Divide clipped i16 and downmix output by 32768.0 for f32 calls
- Reserve reusable f32 buffers in WasmProcessor::new
- Add processF32, processMonoF32, drainF32 and drainMonoF32 to Tunelet
- Check the Float32Array methods and types in scripts/verify-pack.mjs
- Document the f32 and Float32Array methods in src/lib.rs and README.md
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Approved in principle — clean Rust/Wasm Float32 audio and drain API with symmetric f64 quantization matching the internal -32767..=32767 range. Please rebase onto updated main and adapt to two merged changes:

  1. fix: align dry delay, stereo reverb and mono meters #21 added an OutputLayout argument to Processor::next and Processor::drain_into (the new f32 methods need to pass OutputLayout::Stereo / OutputLayout::Mono).
  2. perf(wasm): decode JS events into a reusable buffer #99 added a reusable events buffer in WasmProcessor (please reuse decode_events in processF32 / processMonoF32) and test(npm): check the object arguments of the Wasm initializers #82 updated scripts/verify-pack.mjs.

- Merge main into the f32 audio branch
- Pass OutputLayout::Stereo in stereo f32 calls
- Pass OutputLayout::Mono in mono f32 calls
- Document mono peak measurements after the downmix for f32 calls
- Use decode_events and self.events in processF32 and processMonoF32
- Keep the Wasm initializer checks in scripts/verify-pack.mjs
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Updated and synced with main in 9195b2f (merged origin/main as force-pushing is disabled in this environment):

  1. #21 (OutputLayout): Updated process_f32, process_planar_f32, drain_f32, and drain_planar_f32 to pass OutputLayout::Stereo, and updated process_mono_in_place_f32 and drain_mono_f32 to pass OutputLayout::Mono (reading the downmixed output[0] / frame[0] and aligning the mono peak measurement rustdoc in src/processor.rs and src/wasm.rs).
  2. #99 (decode_events) & #82 (scripts/verify-pack.mjs): Updated processF32 and processMonoF32 in src/wasm.rs to reuse decode_events(&mut self.events, events, frames)?, and merged #82's SyncInitInput / init / initSync checks (along with #118's dual-archive checks) in scripts/verify-pack.mjs, including runtime and TypeScript checks for processF32 and processMonoF32 with events.

google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Merge the #84 branch into this pull request
- Share the f32 Processor methods and symmetric f64 quantization
- Share input_f32, left_f32 and right_f32 across f32 Wasm calls
- Share decode_events across copied and in-place f32 Wasm calls
- Test and document both copied and in-place Float32 APIs
@byteland-app

Copy link
Copy Markdown
Contributor

Closing as strictly superseded by #117. #117 merged #84 and includes all 6 Processor f32 methods and all 4 copying Wasm methods (processF32/processMonoF32/drainF32/drainMonoF32) alongside the zero-copy in-place Float32 views.

@byteland-app
byteland-app deleted the stitch/add-float32-audio-methods-jm0-c24407d7-874e-4c13-8e92-3000afe25ad9 branch November 25, 2026 14:30
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