Controlling two microphones in OF

By the way, just a minor update with following additional function:

setDeviceByName(string deviceName);

This can be handful if you want to avoid identifying the ID manually. Example of use:

myOFXSoundStream.setDeviceByName(“M-Audio: FireWire 410 Multichannel”);


hey, that’s great!

didn’t realize about the id, i suppose it will need a different kind of callback, i suppose having a ofxAudioEventArgs class that has the same vars as ofAudioEventArgs and adds the id will be the solution.

Hi Arturo,

of course! Events! Like the MIDI :wink:
Ok, I did another fix and now events work properly (where not castng properly although audioReceived was being called properly).

Now everything works if I use ofAddEventListener, however when I try to create my own EventArgs Object (see code below), I have a very strange compiler error from POCO no match for operator ‘+=’ (event += …)

class ofxAudioEventArgs: public ofAudioEventArgs{  
	int 	deviceID;  
	string		deviceName;  

Everything else looks good to me (quite similar to ofxMidi). Any help? Do you know what’s going on?


i think you just need to declare the events as:


to be able to call them passing an ofxAudioEventArgs.

Hi Arturo,

actually I am doing it already like this. I am a bit stuck in this problem, would be great if you have an idea about what is happening.

This is how I declare the events:

ofEvent<ofxAudioEventArgs> 	audioReceivedEvent;  
ofEvent<ofxAudioEventArgs> 	audioRequestedEvent;  

This is how the event is invoked:

audioEventArgs.buffer = fPtrIn;  
audioEventArgs.bufferSize = bufferSize;  
audioEventArgs.nChannels = nInputChannels;  
audioEventArgs.deviceID = deviceID;  
audioEventArgs.deviceName = getDeviceName();  
ofNotifyEvent( audioReceivedEvent, audioEventArgs, this);  

getDeviceByName returns the current device name (it works). When I replace ofxAudioEventArgs for ofAudioEventArgs everywhere (removing the deviceID and deviceName of course), everything works fine. As soon as I replace everything for my own ofxAudioEventArgs I get the folloeing error in POCO:

error: no match for ‘operator+=’ in ‘event += Poco::delegate(TObj*, void (TObj::*)(TArgs&)) with-TObj-=-testApp,-TArgs-=-ofAudioEventArgs

Any clues? I have to get back to “regular” work now, but will try to get back to it this evening.

Many thanks,

Hey Arturo,

I found the silly mistake causing the compiler error! So stupid :slight_smile:


hey! could anybody give a simple example about the usage of ofxsoundstream?
say, how can i get the data? where should i call receiveAudioBuffer()?

Hey yaya,

I have the add-on at GitHub including an example of usage (Xcode project).

Best way to use this is with an event listener so you can identify which device the sound is coming from.


[quote author=“jocabola”]Hey yaya,

I have the add-on at GitHub including an example of usage (Xcode project).

Best way to use this is with an event listener so you can identify which device the sound is coming from.

thanks man. it works!

for other people who may need this, just a minor change in testApp’s audioInputListener()

void testApp::audioInputListener(ofxAudioEventArgs &args){	  
	// samples are "interleaved"  
	if(args.deviceID == deviceID2){  
		for (int i = 0; i < args.bufferSize; i++){  
			left2[i] = args.buffer[i*2];  
			right2[i] = args.buffer[i*2+1];  
	if (args.deviceID == deviceID)  
		for (int i = 0; i < args.bufferSize; i++){  
			left[i] = args.buffer[i*2];  
			right[i] = args.buffer[i*2+1];  

and of course, you need to declare deviceID and deviceID2 in testApp.h
a complete one including tespApp.h and testApp.cpp is attached


this is great, extremely useful and a good addition to the addons family, thanks jocabola!

Hi, i’m a begginer at OF. I’m trying to record 2 sources of audio (2 mic’s) with libsndfile and ofxSoundStream posted in this thread.

I can record 1 input of audio with ofSoundStream built in OF but i want 2 inputs. So i tried this code, but when i try to save the content of any buffer of any device it records a noise… and also when i put a counter inside audioInputListener(ofxAudioEventArgs &args) and print it, it ouputs in a speed slower than a counter in the audioReceived function when i used ofSoundStream… why this is happenning?
i’m using the example provided by jacobola, it shows 2 graphics and it can differentiate the 2 inputs but the content of the buffers are wrong or something… i don’t know… help please.


I haven’t tried this actually. When I created the extension I just used for real-time sound spectrum analysis which worked fine.

I’ll give it a look as soon as possible.


thank you jacobola i keep waiting for your response… it seems that the application receive sound in a slow way rather than when i used audioReceived function… i saw the code but i don’t know why…

Btw, do you mind posting your code? I hope I can take a look into this sooner than later, but I am very busy right now :confused:

ok, here it is the sources. I couldn’t upload the libsndfile (to record audio) but it is here[attachment=0:zm6igpsl][/attachment:zm6igpsl]

Hi there,

I have finally a little bit of time to take a look at your code but I am missing “headmanager.h” and not sure where is this coming from. Anyway, I’ll try to see if I can build an example from scratch myself and let you know…


Hi Kazper,

I have built a test myself using the ofxQtAudioSaver and it works perfectly (tested two devices simultaneously).

This is the thread:;-video/4133/0

This is the addon:

Find attached my source with a 10 second recording example (press SPACE bar to begin recording).

The files are recorded into a MOV file (audio only)not at a very good quality though :confused: I found a couple of issues:

* Make sure to close te QT files in the player if you want to overwrite them otherwise you might run into issues

* The sound has a bit of noise sometimes

I will give a try to integrate libsndfile but I was running into issues while compiling and I wouldn’t be able to go anywhere with the time I had today. Will take a look though.

Please, share your progress!!


Hi jacobola,
thank you for your help, but i think that the ofxQtAudioSaver is mac specific code and it gives me errors because i’m on windows. I tried that code already but in windows i can’t get it work so i used libsndfile.

To use libsndfile, you have to install it and then add the libsndfile-1.dll, libsndfile-1.lib and include the sndfile.h in your project. These files are in the libsndfile directory.

I tried to adapt the code to libsndfile, but without success, it’s the same problem, the capture goes very slow… is it necessary to have specific hardware to work?

Hi Kazper,

sorry about that. I will try to build sndfile and make a test later next week and see what happens.

With the QT Audio Saver addon I didn’t experience any slow-downs and could still see the audio waveforms performing good in realtime while recording the audio into a MOV file. The sound quality wasn’t great though.

I’ll post my progress as soon as I have a gap next week.


hi kazper, jacabola, people,

my name is Arne, i am an arts student from Utrecht, the Netherlands, and using oF for a project i am working on. i have been reading up this post and found very useful code for the creation of this application. thanks a lot, super cool!

i thought it might be nice to share how far i got until now, might save people some time compiling the ofxSoundStream + ofxSampleStream + ofxQTAudioSaver in a working project for played over and recording from an external sound card. and maybe someone has some tips or can give an helping hand to get the last bit done.

main objective: output recorded audiobuffer from external soundcard to a .wav file

intro project:

  • i am creating an app with two functions: a sample player and a sample recorder
  • the sample player loops samples continuously and uses the soundcard of my computer
  • the sample recorder is a ‘record booth’ at a distance (5m) and uses an external soundcard with a mic (input) and separate speakerset for instructions (output).
  • the users interact with the system using RFID tags to trigger samples or record samples. to stay on topic of this post i will focus on the sample recording part only.

the features:

  • i am using an the “M-Audio, Inc.: M-Audio Fast Track Pro USB” with left and right channels for input and output, working on a MacBook Snow Leopard and oF0061:
  1. it needs to give auditive instructions and feedback to the user (playback sample stream)
  2. record a sample to a buffer
  3. save the buffer to a .wav file for further use in the application (ofSoundPlayer)
  4. playback the .wav file over the external soundcard for the user to review the recording

current status:

  • currently i have a recording using the ofxQTAudioSaver, saving to .mov. works great! but it seems this filetype can not be played back with ofxSoundStream nor with ofSamplePlayer. for user-review playback i have written a function to playback the buffer directly after the last recording, but this is not enough since the audio recording file needs to be stored in a database (SQLite) to be playback later again with ofSoundPlayer.
  • i have tried to keep using the .mov and playback the audio as an ofVideoPlayer, but this is getting me into other problems when integrating with pre-recorded .wav samples of the sample player part.


  • i am trying to output the recorded buffer to a .wav file so it can be used as sample in the rest of the program using ofSoundPlayer.


  • to get this done i looked at:
    – maximilian: does not seem to support creation of new wave files. there is a save() function but only works for alternations of wav files i guess. i tried to overwrite an empty wave file with the new recording but i couldnt get it done (type errors char * or int)
    – ofxSndObj: made for transforming audio, no such thing as exporting wav files in this fashion
    – ofxSoundEngine: no wave export…-s-with-cc/ (to complex for me and looks like only windows supported)…-xample.htm (visual studio implementation)

a project file (xcode) with sources and addons, audiofiles (bin) and screenshot (png) are included in the zip. might save people some valuable time trying to get the same thing done.

hopefully some can get me going with the .wav stuff. any help is greatly appreciated, thanks in advance.