5.1 audio file output (6 channels)

I am trying to route stereo audio through channelsplitter to 6 channels with gain controls and then back to channelMerger to control all 6 channels of 5.1 set. The set is connected via HDMI, and the windows go out to all 6 channels correctly (a screen on which you can allow all 6 speakers to play 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 initializing the audio context, my default Channel is 2, and maxChannelCount is 6.

I use the following code to create a splitter, merge and strengthen between them:

 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 tried this in chrome (39.0.2171.71 m), where maxChannelCount is 6. Firefox 2 outputs.

Edit: After messing around with channelSplitter, I found out that all outputs except the first two remain silent. This is true to specification when using channel β€œspeakers”. This would mean that I should fill in the channels myself, perhaps using the algorithms described here here. I still need to check if chrome outputs all 6 channels correctly.

+5
source share
1 answer

The problem is caused by the fact that channelSplitter does not output to all channels (what I expected). Although this behavior is correct according to the specification. So we need to write our own stereo amplifier up to 5.1. But for testing the sound, I used the left channel, and I was able to independently output to all 6 channels. I ran into only one problem. The input parameter (third) of the connection method does not determine the output order, as shown here . The order in which .connect() is called determines the output order. However, the 3rd number must be present and different from the others I called .connect (but within the number of inputs).

Another thing I noticed is that channelCount in the merge and splitter is 2. However, I found that it doesn't matter if the channelCountMode parameter is set to max

Besides all of the above, I messed around with all of these settings, but they have no inpact. The only thing that is important to do is set the channelCount in the target node to maxChannelCount.

However, without connecting all channels to the channel merge, the merge combines the incoming signals in accordance with these rules. When you set the explicit expression for channelInterpretation you still get the result of the upstream mix, whereas according to the specification it should fill the channels and leave each channel without input empty (and thus only output the first channel to the left channel and leave the right output quiet).

Below is a snippet where you can play with stereo channels.

 onload = function(){ window.context = new AudioContext(); window.source = context.createMediaElementSource(document.getElementById('player')); window.splitter = context.createChannelSplitter(2); source.connect(splitter); window.merger = context.createChannelMerger(2); window.leftGain = context.createGain(); window.rightGain = context.createGain(); splitter.connect(leftGain, 0, 0); splitter.connect(rightGain, 1, 0); //--------try (de)commenting things below------- leftGain.connect(merger, 0, 0); rightGain.connect(merger, 0, 1); //merger.channelInterpretation = 'discrete' //doesn't seem to have influcence.. //merger.channelCountMode = 'explicit' //makes everything only output to the left channel //-------until here------ merger.connect(context.destination); var leftRange = document.querySelector('#left'); var rightRange = document.querySelector('#right'); leftRange.oninput = function(){leftGain.gain.value = this.value} rightRange.oninput = function(){rightGain.gain.value = this.value} } 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <audio src="http://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg" controls autoplay id="player" preload></audio><br /> <label for="left">Left channel</label> <input type="range" min=0 max=1 step=.01 value=1 id="left" /><br /> <label for="right">Right channel</label> <input type="range" min=0 max=1 step=.01 value=1 id="right" /> </body> </html> 
+4
source

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


All Articles