I have two USB web cams - a Logitech (Logicool) C920 and a C922 - and want to use both of their mics simultaneously.
I’m not able to get both of them working at the same time in ASIO4All using either pure data, touchDesigner or openFrameworks. I am able to get ASIO4All to work with certain combinations of other devices, eg. BOSS GP-10 & Presonus AudioBox iTwo, but not with the Logitech cameras. (Also, if anyone knows of an ASIO4All community, please let me know)
The only way I’ve been able to use both cam mics at all is in touchDesigner: by having two audioDeviceIns set to DirectSound driver and the respective camera device. But I don’t want to have to use TD for audio input unless absolutely needed, so I’ve been looking up how to do this in oF…
I’ve found this topic, though it’s very large, old, and the bulk of it seems to be about how to use two different sound cards simultaneously…
I’ve also found this topic where it’s implied that you can use two input devices on the same soundcard without any addons. @nylki was seemingly able to do it, but it’s also kind of old I’m not able to replicate it. (I also have only ever had success setting up audio using ofSoundStreamSettings objects, which @nylki doesn’t do)
Here’s my current code. The audioIn code I think I got from an oF audio example for getting the rms from a stereo mic and I’d like to implement it for two mics instead of one:
void ofApp::setup(){
ofSoundStreamListDevices();
ofSoundStreamSettings s1 = audioInPreSetup(m_audioIn1, m_sound1L, m_sound1R, "マイク (HD Pro Webcam C920)");
//ofSoundStreamSettings s2 = audioInPreSetup(m_audioIn2, m_sound2L, m_sound2R, "マイク (C922 Pro Stream Webcam)");
m_audioIn1.setup(s1);
//m_audioIn2.setup(s2);
}
ofSoundStreamSettings ofApp::audioInPreSetup(ofSoundStream& stream, std::vector<float>& l, std::vector<float>& r, std::string dev)
{
int bufferSize = 512;
ofSoundStreamSettings settings;
l.assign(bufferSize, 0.0f);
r.assign(bufferSize, 0.0f);
auto devices = stream.getDeviceList(ofSoundDevice::Api::MS_DS);
int devInd = 0;
for (int i = 0; i < devices.size(); ++i)
{
std::cout << "device " << i << " : " << devices[i].name << endl;
if (devices[i].name == dev)
{
devInd = i;
std::cout << "setting audio device " << i << ": " << devices[i].name << endl;
break;
}
}
auto inDevice = devices[devInd];
settings.setInDevice(inDevice);
settings.setInListener(this);
settings.numBuffers = 4;
settings.sampleRate = 44100;
settings.numOutputChannels = 0;
settings.numInputChannels = 2;
settings.bufferSize = bufferSize;
return settings;
}
void ofApp::audioIn(ofSoundBuffer& input)
{
float curVol1 = 0.0f;
//float curVol2 = 0.0f;
int numCounted = 0;
for (size_t i = 0; i < input.getNumFrames(); i++) {
m_sound1L[i] = input[i * 2] * 0.5; //would it be i*4 if using two stereo mics, ie. would all four channels come into the same buffer?
m_sound1R[i] = input[i * 2 + 1] * 0.5;
//m_sound2L[i] = input[i * 4 + 2] * 0.5;
//m_sound2R[i] = input[i * 4 + 3] * 0.5;
curVol1 += m_sound1L[i] * m_sound1L[i];
curVol1 += m_sound1R[i] * m_sound1R[i];
//curVol2 += m_sound2L[i] * m_sound2L[i];
//curVol2 += m_sound2R[i] * m_sound2R[i];
numCounted += 2; // 4 if two mics?
}
curVol1 /= (float)numCounted;
curVol1 = sqrt(curVol1);
//curVol2 /= (float)numCounted;
//curVol2 = sqrt(curVol2);
}
EDIT: Using both cameras doesn’t consistently work in TD either. The C922 seems to be the problem- it doesn’t even work as as an MME input in PD.