AudioChannelSet::discreteChannels() question


#1

The following code will result in getTotalNumberOfChannels() returning 1 (:slight_smile:)

	AudioProcessor::Bus* outs = getBus (false, 0);
	outs->setCurrentLayout(AudioChannelSet::mono());

yet calling discreteChannels() with 1 causes getTotalNumberOfChannels() to return 2 (:confused:)

	AudioProcessor::Bus* outs = getBus (false, 0);
	outs->setCurrentLayout(AudioChannelSet::discreteChannels(numCsoundChannels));

What is the correct way to set an arbitrary number of channels? Btw, I’m calling these functions in my plugin constructor, which is set up as stereo by default. Maybe that’s part of the problem?


#2

You should never call setCurrentLayout (or similar) from within your AudioProcessor. As a plug-in you have no control over your current layout other than specifying the default layout (which the host may or may not use) - and rejecting/accepting layouts in isBusesLayoutSupported.


#3

Thanks Fabian, that makes sense. So in my simple host, after I create a processor, and before I add it to my AudioProcessorGraph, it’s Ok to call these AudioChannelSet methods so long as they adhere to the processor’s available layouts?


#4

Yes exactly. You should check the return value of setCurrentLayout to check if the layout change was successful.


#5

One last thing, and thank you btw, this has cleared up some long standing confusion for me!

I’ve set up my processor up with AudioChannelSet::octagonal() as I wish to support up to 8 channels. In order to support custom configurations I should make sure my isBusesLayoutSupported() methods returns true for any configuration up to 8 channels? Seems to work, but it would be nice to hear this is a valid approach!


#6

Yes that sounds like a valid approach. Just note that if you don’t really care about the layout of the individual speakers (i.e. the third channel is a centre speaker etc.), then just check the AudioChannelSet's number of channels in your isBusesLayoutSupported method via the size method.


#7

Great. I’m finally getting my head around this now!