-
-
Save admsyn/00ef95aa58a2202ff87d to your computer and use it in GitHub Desktop.
Managing the Matrix Mixer + multichannel audio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is how I did the connections in my test (after setting the stream format, of course) | |
for(size_t i = 0; i < filePlayers.size(); ++i) { | |
filePlayers[i].setFile(ofFilePath::getAbsolutePath("hats.wav")); | |
filePlayers[i].loop(); | |
filePlayers[i].connectTo(mixer, i); // connect file player 0 to mixer input bus 0, etc | |
} | |
mixer.connectTo(output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This demonstrates how to use the MatrixMixerVolumes utility | |
// You'll need to #include "MatrixMixerVolumes.h" in files where you want to use it | |
FILE * debugFile = fopen("/Users/Adam/Desktop/MatrixMixerVolumes.txt", "w"); | |
PrintMatrixMixerVolumes(debugFile, mixer); | |
fclose(debugFile); | |
// It's probably easiest to try this at first with a minimal matrix mixer setup, | |
// or else it'll produce a HUUUUGE file | |
// I used a setup with 4 file players and one 16 channel output and found that | |
// easy enough to understand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of how to set matrix mixer levels | |
Float32 levels[NUMBER_OF_FILE_PLAYERS * 2 + 1][NUMBER_OF_CHANNELS + 1] = {0}; | |
levels[0][NUMBER_OF_CHANNELS] = 0.777; // set the input volume of file player 0 to 0.777 | |
levels[0][5] = 0.999; // set the level of file player 0 in channel 5 to 0.999 | |
levels[NUMBER_OF_FILE_PLAYERS * 2][5] = 0.888; // set the output volume of channel 5 to 0.888 | |
levels[0][3] = 0.666; // set the level of file player 0 in channel 3 to 0.666 | |
levels[NUMBER_OF_FILE_PLAYERS * 2][3] = 0.555; // set the output volume of channel 3 to 0.555 | |
levels[NUMBER_OF_FILE_PLAYERS * 2][NUMBER_OF_CHANNELS] = 1; // setting the global volume to 1 | |
OFXAU_PRINT(AudioUnitSetProperty(mixer, | |
kAudioUnitProperty_MatrixLevels, | |
kAudioUnitScope_Global, | |
0, | |
levels, | |
sizeof(levels)), | |
"setting matrix volume levels"); | |
// Note: I've been trying to get the file player to produce mono audio, to no avail. | |
// It seems to refuse any attempt to set the channel count to 1. So, we'll need to keep the "* 2" | |
// going on in the levels array. So, setting file player 3's level on channel 8 would be: | |
levels[3 * 2][8] = 0.1234; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setting the output unit and the matrix mixer to use the same stream format (in this case, 16 channel audio) | |
output.setDevice("Soundflower (16ch)"); // <- should set the device before the stream format | |
AudioStreamBasicDescription ASBD = { | |
.mSampleRate = 44100, | |
.mFormatID = kAudioFormatLinearPCM, | |
.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical, | |
.mChannelsPerFrame = 16, // <- change this to 24 in your case | |
.mFramesPerPacket = 1, | |
.mBitsPerChannel = sizeof(AudioUnitSampleType) * 8, | |
.mBytesPerPacket = sizeof(AudioUnitSampleType), | |
.mBytesPerFrame = sizeof(AudioUnitSampleType) | |
}; | |
OFXAU_PRINT(AudioUnitSetProperty(output, | |
kAudioUnitProperty_StreamFormat, | |
kAudioUnitScope_Input, | |
0, | |
&ASBD, | |
sizeof(ASBD)), | |
"setting output unit's input ASBD"); | |
// setting mixer to have 960 input busses, 1 output bus and use the | |
// 16 channel stream format on its output bus | |
mixer.setChannelLayout(NUMBER_OF_FILE_PLAYERS, 1, NULL, &ASBD); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment