Summary
This is a demonstration of a complicated bug that involves the sample values being half of what they should be when using a single channel ScriptProcessorNode with a MediaElementSourceNode connected to a multi channel input with echoCancellation disabled with navigator.getUserMedia and the Web Audio API.
To reproduce you need to have an audio interface that has at least two independent inputs.
- Plug an instrument into the first input (left channel). It should preferrably be some sort of synthesizer or sampler where the output will be a consistent level.
- Press the capture button on the top section below (using a ScriptProcessorNode configured to have 2 input channels), and observe how the level is reported at the correct level
- Press the capture button on the bottom section below (using a ScriptProcessorNode configured to have 1 input channel), and observe how the level is exactly half the level of the level from step 2
Notes
- For some reason using a built in mono computer microphone works fine in both cases
- Keeping echoCancellation on (default) causes the levels to be consistent, but that does not allow you to get independent signals from the left and right inputs
- Hardcoding the ScriptProcessorNode to have 2 input channels even when knowing there is only something connected to one of the channels fixes the issue as well
- Also FWIW Firefox reports the same level in both cases although I do not think Firefox even accepts stereo input at all right now