Repository navigation
feat: expose Float32 buffers in Wasm for in-place audio - #117
byteland-app merged 6 commits into
Conversation
- 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
- Add f32 process and drain methods to Processor - Convert f32 audio with exact i16 quantization and scale - Allocate fixed-capacity f32 buffers in WasmProcessor::new - Expose inputF32Ptr, leftF32Ptr and rightF32Ptr offsets - Add in-place Float32 process and drain methods to Tunelet - Export TuneletAudioViews to refresh detached memory views - Check Float32 runtime and type exports in verify-pack.mjs - Document Float32 view lifetimes in README and rustdoc
|
Review: Excellent zero-copy in-place Float32 linear memory views (TuneletAudioViews with automatic Memory.grow rebinding) for custom AudioWorklets. Please rebase onto #84 and #99 so we share the same input_f32/left_f32/right_f32 buffers and decode_events path, and update quantize_f32 to use f64 multiplication (matching #84) for exact symmetric quantization. |
- 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
- Merge main into the feature branch. - Pass OutputLayout to Processor::next and Processor::drain_into. - Multiply clamped f32 input samples by 32767.0 in f64. - Share decode_events in Wasm in-place f32 audio calls. - Keep SyncInitInput checks in scripts/verify-pack.mjs.
- 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
|
Addressed in
|
|
Round 2 review: Approved — merging #84 makes this the complete Float32 copy + zero-copy in-place solution (and we closed #84 in favor of this PR). Please rebase onto updated main after #123 and #135, and change 'memory: WebAssembly.Memory' in src/index.ts (TuneletAudioViews) to 'InitOutput["memory"]' so it passes #123's strict ES2023 tsc check without DOM globals. |
|
Addressed in
|
Summary
#84'sProcessorf32audio and drain methods (process_f32,process_planar_f32,process_mono_in_place_f32,drain_f32,drain_planar_f32anddrain_mono_f32) with exact symmetricf64input quantization (NaNto0, clamp-1.0..=1.0, multiply by32767.0inf64with.round(), dividei16outputs by32768.0, passOutputLayout::Stereo/OutputLayout::Mono, and fill unused tail frames with0.0).input_f32,left_f32andright_f32Vec<f32>buffers inWasmProcessor::new(try_reserve_exact) across both#84's copiedFloat32Arraymethods (processF32,processMonoF32,drainF32,drainMonoF32) and#117's zero-copy in-place methods (processF32InPlace,processMonoF32InPlace,drainF32InPlace,drainMonoF32InPlace), exposing safe byte-offset gettersinputF32Ptr,leftF32PtrandrightF32Ptrunder#![forbid(unsafe_code)].#99'sdecode_events(&mut self.events, ...)buffer across allInt16ArrayandFloat32Wasm process paths with atomic validation before buffer or DSP state changes, keepingprocess,processMono,drainanddrainMonounchanged.TuneletAudioViewsfromsrc/index.tsoverInitOutput["memory"](without ambient DOM orWebAssemblyglobals) to cacheFloat32Arrayviews, rebind them ifWebAssembly.Memory.growreplacesmemory.buffer, and clear them indispose()/[Symbol.dispose]().scripts/verify-pack.mjs(including#123'snode,es2023,dom, andwebworkerstricttscprofiles and#135'scontrolActivity()), crate rustdoc andREADME.mdfor both copiedFloat32Arrayand zero-copy in-placeFloat32APIs, view lifetimes andfree()rules.Verification
cargo fmt --check,cargo clippy --locked --lib -- -D warnings,cargo build --locked --release,RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, MSRV1.88(--libandwasm32-unknown-unknown --features wasm), andcargo package --lockedpass.RUSTDOCFLAGS="-D warnings" npm run check:wasmandnpm run verify:packpass across all four stricttscprofiles (node,es2023without DOM globals,dom,webworker) on both unscopedtuneletand scoped@bytelandtechnology/tuneletarchives.Processor::newlive heap stays at2,071,052bytes (2,022.512 KiBon0.3.4) with0post-construction allocations and bit-exact IEEE-754f32match againsti16reference outputs, feedback and telemetry across stereo, planar, mono and1,180,136drain frames.processF32InPlace(128)withouteventsexecutes0Wasm-to-JS imports and allocates0TypedArray.subarrayviews (0/secsteady-state and0/secduring dual-Tuneletcrossfades, down from2,250/secand4,500/sec).OfflineAudioContext+AudioWorkletexecution across standbyTuneletcreation andWebAssembly.Memory.growbuffer detachment rebinding without errors:Automated PR initiated by user @byteland-app via Stitch Loop.