Audio In/Out Routing

Hi all,

I have a question regarding the audio input and output for ofSoundStream class. I want to route the input channel from a microphone to different output channels of my sound interface. Basically, I have two microphones which I want to re-route the input channel to two specific output channels. Say 0->1, 1->0. And while the output channels are routed I want to play a specific sound file to a particular channel output.
Any suggestions on how to get started?, Any help is much appreciated.

try ofxSoundObjects
You should be able to use it in the way you describe quite easily.
let me know if you need any help.


Thank you for the suggestion.

I just started playing with your lib, its great!!, I like that you can easily connect sound filters and many more effects so easily to the output.

What I understand I can do something like this:

stream.setup(2, 2, 44100, 256, 1);


 //load sound files for the mixer

So basically I will be playing the sound input from the mic with a sound file
I still don’t quite understand how would I select the output channel that I want play. Or is that something that I would do in the sound interface


Hi, good to know that it is working for you.

The sound buffers passed through to the output have interleaved samples, so you’ll need to get these uninterleaved and then interleave again with the desired desired order so you get the audio into the channel you want.
Read here about interleaved samples
What I would do is to create a new class that inherits from ofxSoundObject, just like the ones that come as example, and in its process function make this channel routing.
ofSoundBuffer has
/// copy the requested channel of our data to outBuffer. resize outBuffer to fit.
void getChannel(ofSoundBuffer & outBuffer, std::size_t sourceChannel) const;
/// copy data from inBuffer to the given channel. resize ourselves to match inBuffer’s getNumFrames().
void setChannel(const ofSoundBuffer & inBuffer, std::size_t channel);
So you can simply use this functions to route the channels.
If you need to make this switching dynamically I guess that this is the way to go, otherwise I’d just make the adjustments in the sound interface.

hope this helps.

get, thank you!, I will try that.

I am also getting this error :

ofSoundinput::audioOut: input buffer size != output buffer size.

and I am setting up the stream as the following

stream.setup(2, 2, 44100, 256, 4);

and my both input and outputs are:

2ch 24-bit integer 44.1kHz.

are you getting that error just a few times or does it show up constantly. For the first case, dont worry. I´ts just because the internal buffer was not setup. If it is teh second case its not that bad other than annoying. If this is the case, please post the code.