own ofSoundStream objects? - how to use audioIn properly with multiple inputs

Hi there,
I am trying to create several soundStream objects for different input devices. (eg. 4 different usb microphones).
Initializing with the following method and listening to audioIn:

ofSoundStreamSetup(0, 1, 44100, 256, 1);  
void testApp::audioIn(float *input, int bufferSize, int nChannels, int deviceID, unsigned long long tickCount){  

does work. But that way i can use only one input.
But if i want to use an own object of the ofSoundStream class, like:

in testApp.h:  
class testApp : public ofBaseApp{  
	ofSoundStream soundStream;  
in testApp.m  
soundStream.setup(0, 1, 44100, 256, 1);  

then the audioIn() listener inside testApp.m won’t trigger.

Do i need to attach my soundStream object to the application somehow?
Or can I grab input data in a another way than only via audioIn() ?

Alternatively I would need to set the deviceID each time audioIn() was called to cycle through the microphones, or can I use simply several ofSoundStream objects, as i intended?


[using oF 0.8 on OS X 10.7]

ofSoundStream has setInput and setOutput functions. Or The first parameter in the setup is a pointer to the soundInput and soundoutput.

Thanks! Your hint was helpful, after setting my soundStream objects input to “this”, I was able to use audioIn():


But when I got multiple ofSoundStream objects, each setup with a different valid deviceID, I only get the input from the first setup object.

	void testApp::setup(){  
	soundStream2.setup(0, 1, 44100, 255, 1);  
	soundStream1.setup(0, 1, 44100, 255, 1);  
	gotInput = -1;  
void testApp::audioIn(float *input, int bufferSize, int nChannels, int deviceID, unsigned long long tickCount){  
	microInput = input;  
	gotInput = deviceID;  
	cout << "got input from deviceID " << deviceID << endl;  
void testApp::draw(){  
	//float lineLength = ofGetWidth()/255;  
	if(gotInput > -1){  
		//cout << gotInput << endl;  
		if(gotInput == 3){  
		} else {  
		for(int i=0; i<255-1; i++){  
			//cout << microInput[i];  
			ofLine((i), ofGetWidth()/(gotInput+2) + microInput[i]*1000, ((i+1)), ofGetWidth()/(gotInput+2) + microInput[i+1]*1000);  
		fill_n(microInput, 255, 0);  
		gotInput = -1;  

-> The deviceID from the 4th argument of audioIn(…) is 0 every time, with the above setup.

It appears only the internal microphone (MacBook Pro 2008) is active, although in the system settings and in the listDevices() list, they are active.
Is it the proper way to listen for multiple input devices/microphones or what am I dong wrong?


1 Like

try calling setDevice before setup. This code works:

    soundStream1.setup(this, 0, 1, 44100, 512, 3);  
    soundStream2.setup(this, 0, 1, 44100, 512, 3);  

also your bufferSize should be a power of 2, and the number of buffers should be between 2 and 4 otherwise you will drop audio.

thank you! That’s it.
Have a nice week.