rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.72k stars 1.06k forks source link

Trying to figure out web_sys::AudioWorkletProcessor #2308

Closed SephReed closed 4 years ago

SephReed commented 4 years ago

Summary

I'd like to create and register an AudioWorkletProcessor using Rust. I'm still not sure if it's possible.

Additional Details

I've also put up a question on StackOverflow.

I'm currently stuck on having to extend AudioWorkletProcessor for the sake of overriding the process() function. And I'm also not yet sure if it's going to be possible to access AudioWorkletGlobalScope. On top of all this, I have no idea if it will play well with webpack / or any other bundler. This is what I've got so far:

use wasm_bindgen::prelude::*;
use web_sys::{ AudioWorkletGlobalScope };

#[wasm_bindgen]
pub fn create_worklet_node() {
  AudioWorkletGlobalScope::register_processor(/* MISSING ARGUMENTS */);
}

#[wasm_bindgen]
extern "C" {
  #[wasm_bindgen(extends = web_sys::AudioWorkletProcessor)]
  type MyAudioWorkletProcessor;
}

#[wasm_bindgen]
impl MyAudioWorkletProcessor {
  pub fn process() {
    // this would throw an error if I was doing it right... :/ 
  }
}

Potential Incentive

I think that multi-threaded audio processing is an extremely good example of the power of wasm, so I'd probably not be the only person who could really use an example of how to set up an AudioWorklet using Rust.

Thanks for this project!

alexcrichton commented 4 years ago

I think this is covered by https://github.com/rustwasm/wasm-bindgen/issues/210, so I'm going to close this in favor of that.

(although if it's got pieces which aren't part of that, please feel free to file a new issue!)