W3C home > Mailing lists > Public > public-audio@w3.org > July to September 2012

Re: Question about channels and merger on destination

From: Alessandro Saccoia <alessandro.saccoia@gmail.com>
Date: Mon, 23 Jul 2012 01:31:25 +0200
Cc: public-audio@w3.org
Message-Id: <8CC3C7B9-2B0A-41E9-BDB9-EFBE5310FB78@gmail.com>
To: Peter van der Noord <peterdunord@gmail.com>

> Thanks, i figured something like that. 
> Does anyone know if this is the destinationnode that does this, and not the merger? as in:
> - destination sees two channels coming in, sees that one is empty, decides to put the active one over both L&R
> and not:
> - merger (with two input) sees one channel coming in, decides to make it stereo

it's the merger that does this. In your code, the merger has 2 inputs, but the number of output channels is the sum of the number of channels of the -- active -- inputs of the merger. input here means "connected to some source node", and it's consistent, since there is no way to know how many channels the input N has until some other node that provides an audio stream gets connected to it… 
So, until you don't connect some other node to the second input (input 1), the output will remain mono, as long as your source node for the input 0 is mono.
To summarize, for a merger with 2 channels, the input/output configurations are:

Input0    	Input1   	Output
Mono	   -		Mono
Mono	Mono	Stereo
Stereo	   - 		Stereo
Stereo	Mono	3 channels
Stereo	Stereo	4 channels

and so on… (and I sincerely hope this is correct)

> btw, what is the checkNumberOfChannelsForInput exactly?

it's the name of a method that you can find in the source code of webkit… in C++. When I have found something blurry in the Web Audio documentation, I have read the C++ code to understand things more clearly..
"Use the Source Luke" shouldn't apply here, since it is just a detail that is specific to one implementation. Still, it gets really handy.

> Peter
> 2012/7/23 Alessandro Saccoia <alessandro.saccoia@gmail.com>
> Peter,
> I think this is the intended behavior, according to the docs: "There is a single output whose audio stream has a number of channels equal to the sum of the numbers of channels of all the connected inputs."
> You can also check the method checkNumberOfChannelsForInput of AudioChannelMerger.cpp in webkit.
> In order to use the merger as a panner for mono sources, I would use two gain nodes before the merger inputs, ad connect or disconnect the oscillators to/from these gain nodes.
> var osc = context.createOscillator();
> var merger = context.createChannelMerger(2);
> var gainL = context.createGainNode();
> var gainR = context.createGainNode();
> osc.connect(gainL, 0, 0);
> gainL.connect(merger, 0, 0);
> gainR.connect(merger, 0, 1);
> merger.connect(context.destination);
> osc.noteOn(0);​
> best
> /Alessandro
> On Jul 22, 2012, at 10:27 PM, Peter van der Noord wrote:
> > Hmmm, when i add another osc to the other intput, they *do* get split up over left and right.
> >
> > http://jsfiddle.net/e4b42/
> >
> > Is this intended behavior?
> >
> > Peter
> >
> >
> > Does anyone know why i get stereo sound out of this example?
> > http://jsfiddle.net/bJqkm/
> > I have a merger with two inputs, connected to the destination, and i assume
> > that whatever goes into merger in#0 goes to left, and in#1 goes to right,
> > yet the oscillator i connect to an input of the merger sounds in stereo. Am
> > i overlooking something?
> > Peter
Received on Sunday, 22 July 2012 23:31:57 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:03:11 UTC