Skip to content

feat(wasm): add worklet-safe init and Float32 buffers - #47

Closed
google-labs-stitch[bot] wants to merge 3 commits into
mainfrom
stitch/feat/worklet-wasm-init-float32-jm0-cbbce4f3-79f5-4298-9329-247932680c48
Closed

google-labs-stitch[bot] wants to merge 3 commits into
mainfrom
stitch/feat/worklet-wasm-init-float32-jm0-cbbce4f3-79f5-4298-9329-247932680c48

Conversation

@google-labs-stitch

Copy link
Copy Markdown
Contributor

Summary

Adds headless AudioWorklet initialization and zero-allocation Float32Array and Uint8Array primitives across the Rust, WebAssembly and TypeScript APIs:

  • Internal UTF-8 fallback and initTuneletSync(module): src/utf8.ts installs a UTF-8 TextDecoder and TextEncoder fallback when globalThis omits those classes (such as in AudioWorkletGlobalScope), and src/index.ts imports it before pkg/tunelet.js and exports initTuneletSync(module).
  • Float32 audio methods: Adds process_f32, process_planar_f32, process_mono_in_place_f32, drain_f32, drain_planar_f32 and drain_mono_f32 to Processor, and processFloat32, processMonoFloat32, drainFloat32 and drainMonoFloat32 to Tunelet with reusable Vec<f32> buffers.
  • Packed 3-byte MIDI methods: Adds apply_midi and apply_correction_midi (applyMidi and applyCorrectionMidi in TypeScript) that validate and decode 3-byte MIDI messages with MidiEvent::from_bytes before any state changes.
  • Flat Float32Array meter writers: Adds write_feedback (8 floats) and write_telemetry (45 floats) (writeFeedback and writeTelemetry in TypeScript) with optional peak-window reset and zero Wasm heap allocations.
  • Clear sampleRate error and Web Audio documentation: Reports the rejected sampleRate value in new Tunelet(...) with { sampleRate: 48000 } guidance, and updates README.md and rustdoc.

Verification

  • cargo fmt --check, cargo build --locked --release, cargo clippy --locked --lib -- -D warnings, cargo doc --locked --no-deps and npm run build pass cleanly (along with wasm32-unknown-unknown clippy and rustdoc).
  • Verified in both an isolated unpolyfilled AudioWorkletGlobalScope VM (TextDecoder, TextEncoder, fetch and URL undefined) and real headless Chromium OfflineAudioContext({ sampleRate: 48000 }) + AudioWorklet (hasTextDecoder: false, hasTextEncoder: false, hasFetch: false).
  • Confirmed zero __wbindgen_malloc calls and zero JavaScript Object or Array allocations across 128-frame processFloat32, applyMidi, applyCorrectionMidi, writeFeedback and writeTelemetry.
  • Verified sample-exact Int16Array output preservation (process, processMono, drain, drainMono) against pre-change SHA-256 digests.

Real Chromium AudioWorklet verification


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

- Load an internal UTF-8 fallback before the Wasm glue runs
- Export initTuneletSync for synchronous AudioWorklet initialization
- Add f32 process and drain methods to Processor and Tunelet
- Add applyMidi and applyCorrectionMidi for packed 3-byte MIDI slices
- Add writeFeedback and writeTelemetry for flat Float32Array meters
- Include the rejected rate and Web Audio guidance in sampleRate errors
- Document AudioWorklet initialization, Float32 buffers and 48 kHz rate
- Keep the UTF-8 import and initSync alongside async Node.js loads
- Share process_into and downmix in the f32 processor methods
- Call Processor::check_block in the Float32 Wasm methods
- Add the UTF-8 archive files to scripts/verify-pack.mjs
@byteland-app

Copy link
Copy Markdown
Contributor

Closing as superseded by #84 and #117 for Float32 audio support. This PR bundles five unrelated features, packs 64-bit processed_frames into f32 (losing frame precision after ~5.8 minutes at 48 kHz), and adds an unconditional global UTF-8 polyfill side effect to the package root.

@byteland-app
byteland-app deleted the stitch/feat/worklet-wasm-init-float32-jm0-cbbce4f3-79f5-4298-9329-247932680c48 branch November 25, 2026 08:06
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Understood. Pull request #47 stays closed with no more changes on this branch, because #84 and #117 replace the Float32 audio support. Thank you for the notes on single-topic scope, u64 precision for processed_frames, and package-root side effects.

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