RtAudio multiple audio input

Hi,

I’m trying to use 2 audio input sources as independent controls for a project. I created a class based on ofSoundStream, adding the ability to choose a device.

The problem is: when I connect 2 webcams, only one of them works. The same code works with 1 webcam and 1 microphone (connected to the PC’s mic input), but not with 2 webcams. I thought the problem could be related with the callback mechanism and changed it to tickStream, but it gives me same results.

  
  
#include "SoundStream.h"  
  
SoundStream::SoundStream( int deviceID, int numInputChannels )  
{  
    this->deviceID = deviceID;  
    this->numInputChannels = numInputChannels;  
  
    try  
    {  
        int bufferSize = 256;  
        audio = new RtAudio;  
        audio->openStream( 0, 0, deviceID, numInputChannels, RTAUDIO_FLOAT32, 44100, &bufferSize, 4 );  
        buffer = (float *) audio->getStreamBuffer();  
        audio->startStream();  
    }  
    catch (RtError &error)  
    {  
        error.printMessage();  
    }  
}  
  
SoundStream::~SoundStream()  
{  
}  
  
void SoundStream::start()  
{  
    try  
    {  
        audio->startStream();  
    }  
    catch (RtError &error)  
    {  
        error.printMessage();  
    }  
}  
  
void SoundStream::stop()  
{  
    try  
    {  
        audio->stopStream();  
    }  
    catch (RtError &error)  
    {  
        error.printMessage();  
    }  
}  
  
void SoundStream::close()  
{  
    try  
    {  
        audio->stopStream();  
        audio->closeStream();  
    }  
    catch (RtError &error)  
    {  
        error.printMessage();  
    }  
  
    delete audio;  
}  
  
void SoundStream::tick()  
{  
    audio->tickStream();  
}  
  

I tested both webcams with Audacity and they work fine for sound recording.
What am I missing?

Thanks in advance.

Hey!

I had this bug too.
Are you using windows?

If so I have a fix. It is a bug with rtAudio and the DirectSound code where device enumeration is based on name alone. This means if you have two identical devices rtAudio first tries to open the first device and then when you try and open the second device it tries again to open the first device causing a crash or an error.

give me a sec to find the code.
will post it soon!

Theo

Here it is - let me know if you have any problems!

Theo

FixedRtAudioWin.zip

Yes, I’m on Windows and both webcams have the same name.
Thanks a lot Theo for the fix!

:slight_smile: