I have been struggling trying to understand what the proper way to mix 
multiple audio sources together is.  I am currently calling 
emscripten_create_audio_context() multiple times to create multiple 
contexts, and then calling emscripten_start_wasm_audio_worklet_thread_async 
with each context..  Similar to the progrmaming example here:

https://emscripten.org/docs/api_reference/wasm_audio_worklets.html

I am basically doing that two times, one for each processor...  So each 
processor has its own RenderAudio callback which looks like:

EM_BOOL RenderAudioCallback(int numInputs, const AudioSampleFrame *inputs,
                      int numOutputs, AudioSampleFrame *outputs,
                      int numParams, const AudioParamFrame *params,
                      void *userData) {
  AudioPackage *audioPackage = static_cast<AudioPackage *>(userData);
  int frames = 128;

  for (int i = 0; i < numOutputs; i++) {
    audioPackage->sampleStreamable->process(outputs[i].data, 
frames*outputs[i].numberOfChannels);
  }

  return EM_TRUE;
}

Both of my processors have this "process" method which generates samples 
and puts them into the outputs[i].data buffer...

The other thing I am doing is, after connecting each worklet node to its 
audio context destination, I am performing a callback to js, where I take 
that source and create a visual analyzer for it and draw an oscilloscope.

If I just create ONE audio context for either source, and run this, 
everything sounds great..  But as soon as I create TWO contexts, (so two 
RenderAudioCallback functions are running), and from my JS, I instruct one 
source to start, so again, two RenderAudioCallback functions are running-- 
but only one of them should be receiving samples..  The visualizer for the 
source that should not be playing has little blips on it, as if the signal 
is bleeding through between the two contexts or something...

So, I am wondering, am I doing something wrong creating two contexts / two 
worklets?  Is there a better way to do this?

Here is a screenshot of my UI..  You can see, on the left, is contextA, 
which I started  playing its audio source-- and have not instructed 
contextB to play its audio source..  Yet, the oscilloscope on the right has 
this little blip in it...  And this is when it is sounding distorted and 
crackly and weird..

[image: Screen Shot 2024-07-10 at 12.04.14 PM.png]

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/60fdd187-5c33-45d8-b3d3-36b103a8fb9dn%40googlegroups.com.

Reply via email to