I have a MediaStreamSource sourced from navigator.getUserMedia, which is connected to a GainNode, which in turn is connected to a ScriptProcessorNode, like so:
[getUserMediaStream] -> [MediaStreamSource] -> [GainNode] -> ScriptProcessorNode -> (destination)
In my application, it's the ScriptProcessorNode that is doing the main work, which is to process and transfer the raw audio stream over a WebSocket to a remote server (my application is basically a web-based audio recorder) for saving. This works fine.
However, now I am trying to introduce a second MediaStreamSource, this time sourced from a WebRTC PeerConnection. The peer connection in itself works fine, and if route the audio into an element, I can hear the audio coming from my peer. However, I want this second MediaStreamSource to also be piped into the ScriptProcessorNode, effectively recording both audio streams.
What I am looking to do is to mix the two audio streams together before they reach the ScriptProcessorNode. I tried connecting the second MediaStreamSource to the same GainNode (and also to the ScriptProcessorNode directly), but this did not work as neither of those nodes accept more than one input node (even though it never returned any errors on trying to connect the superfluous node). I am trying to achieve something like this:
Something like this:
[MediaStreamSource] -> [Intermediary Node(s)?] -> [GainNode] -> [ScriptProcessorNode] -> [Server]
/
[MediaStreamSource] /
I then looked into the WebAudio specification and found that the only node that actually does take multiple inputs is the ChannelMergerNode. However, the specification states that the streams are merged into channels based on the order they are connected to the node, so that the first stream connected on the input will become the left channel of the output and the second stream will become the right channel. From this I take that the result would jus end up being one stream on my left ear and the other on my right. I just want both streams to be merged and mixed equally into a single mono channel.
Is this possible at all with the current WebAudio API?
Thank you very much for the help!
Eirik