I am trying to route stereo audio through a channelsplitter
to 6 channels with gain controls, and then back into a channelMerger
, to control all 6 channels of a 5.1 set. The set is connected through HDMI, and windows outputs to all 6 channels correctly (a screen where you can let all 6 speakers play a sound separately).
The only examples I could find have this piece of code:
if (context.destination.maxChannelCount >= 6) {
context.destination.channelCount = 6;
}
else {
context.destination.channelCount = 2;
}
When initialising the audiocontext, my channelCount defaults to 2 and the maxChannelCount is 6.
I use the following code to create the splitter, merger and gains inbetween:
if (context.destination.maxChannelCount >= 6) {
context.destination.channelCount = 6;
}
else {
context.destination.channelCount = 2;
}
context.destination.channelCountMode = "explicit";
context.destination.channelInterpretation = "discrete";
var ammount = context.destination.channelCount;
console.log('Ammount of channels:',ammount); //this outputs 6
window.channelSplitter = context.createChannelSplitter(ammount);
window.channelMerger = context.createChannelMerger(ammount);
postGain.connect(channelSplitter); //postGain is the last node of the audio system
channelMerger.connect(context.destination);
window.channelGains = [];
for(i=0;i<ammount;i++){
channelGains[i] = context.createGain();
channelSplitter.connect(channelGains[i],i,0);
channelGains[i].connect(channelMerger,0,i);
}
I have tried this in chrome(39.0.2171.71 m), where maxChannelCount is 6. Firefox outputs 2.
Edit: After fiddling with the channelSplitter, I found out that all outputs besides the first two are left silent. That is correct according to the spec, when using channelinterpretation 'speakers'. This would mean that I need to fill the channels myself, probably by using the algorithms described here.I still have to check if chrome outputs all 6 channels correctly.