ChannelMergerNode in web audio API does not aggregate channels

I am trying to use the web audio API to create an audio stream with left and right channels generated using different oscillators. The output of the left channel is correct, but the right channel is 0. Based on the specification, I do not see what I am doing wrong.

Tested in Chrome dev.

the code:

var context = new AudioContext(); var l_osc = context.createOscillator(); l_osc.type = "sine"; l_osc.frequency.value = 100; var r_osc = context.createOscillator(); r_osc.type = "sawtooth"; r_osc.frequency.value = 100; // Combine the left and right channels. var merger = context.createChannelMerger(2); merger.channelCountMode = "explicit"; merger.channelInterpretation = "discrete"; l_osc.connect(merger, 0, 0); r_osc.connect(merger, 0, 1); var dest_stream = context.createMediaStreamDestination(); merger.connect(dest_stream); // Dump the generated waveform to a MediaStream output. l_osc.start(); r_osc.start(); var track = dest_stream.stream.getAudioTracks()[0]; var plugin = document.getElementById('plugin'); plugin.postMessage(track); 
+3
source share
1 answer

ChannelInterpretation means that the merge node will mix the stereo generator connections with two channels each, but then, since you have an explicit channelCountMode, it stacks two channels for each connection to get four channels and (since it is explicit), simply dropping the top two channels. Unfortunately, the two second channels are two channels from the second input - therefore, it loses all channels from the second connection.

In general, you don’t have to bother with channelCount interpretation materials, and it will work correctly for stereo.

+1
source

Source: https://habr.com/ru/post/1207907/


All Articles