Control Volume of MultiChannel Soundfile

Hey there
I am a bit lost as i have no experience with sound stuff. I need to control and mix the volumes of each channel of a 5.1 soundfile and play it back as a mono sound.

any hints where to start looking how to do that would be highly appreciated.

meanwhile i looked into ofxSoundObjects and i understand that i can get the number of channels there like so:

        auto chans = player->getSoundFile().getNumChannels();

but i dont understand how to control the volume of each channel separately.



just gives you a number, so in the case of a 5.1 audio file there would be 6. It does nothing more than that.
What you need to do can definitively be done with ofxSoundObjects. take a look at the matrixMixer example. You can use that same code, ignore the sound input and just leave the sound players, load your sound into it. you will be able to set the volume of each channel of the audio file.
Let me know if this works for you.

Wow thanks, thats definitely what i need and the example is working fine for testing, thanks!
is there somewhere a in-deep documentation for the soundobject? because i dont really understand how i am supposed to connect things if i want to implement it in my app.

in the example in update is the following:

   //mixer.setVolumeForChannel(y, 7, 1);

what does mixer.getConnectionIndexAtInputChannel(7)? do i need to call that before i call:
mixer.setVolumeForChannel(x,y,z) ? or is the latter just fine?

thank you!

Hi, There is some documentation inline and in the readme. But I have not written much for the matrix mixer other than what is in the ofxSoundMatrixMixer.h file. my fault, sorry.

The following line does nothing in this case as the value it returns is not being used. so ignore it.


So, it is a matrix mixer, which is different to a regular mixer in the sense that you have a volume control for each intersection of input and output. This becomes really evident with a multi output sound device.

So, in the following sets how much of the input channel goes to the output channel. the volume value is normalized between 0 and 1.

//setVolumeForChannel(const float& volValue, const size_t& inputChannel, const size_t& outputChannel);
mixer.setVolumeForChannel(v, i, o);

so with such you can control how much of each input channel goes out to each output channel.
When using a sound player, each channel of the player gets its own channel in the matrix mixer.

ok, i have it working now, thanks!

1 Like

let me know if you have more questions about ofxSoundObjects :slight_smile: