How to uniquely identify audio capture device?

Dec 15, 2012 at 12:20 PM

Hello everyone,

I observed that using NAudio.CoreAudioApi.MMDevice.ID property we can uniquely identify the audio capture device. But I cannot create an instance of WaveIn using MMDevice. The only way to associate WaveIn object with the audio capture device is its device index. But device index may change if we plug/unplug audio capture device.

Using MMDevice we can create an instance of WasapiCapture and capture audio from it but is not supported on XP.

I want to preserve the selected audio device ID somewhere (like database) so that my application can capture audio from that device when it launches for the next time. Is there any solution?

Thanks.

Dec 16, 2012 at 6:43 AM
Edited Dec 16, 2012 at 6:45 AM

hello,

Saving the driver name.Recall of the application or driver do a search type:


// Save CurrentDriverName
string CurrentDriverName = WaveIn.GetCapabilities(Convert.ToInt16(idCurrent)).ProductName

private int SearchByName(string drivername)
{
	for (int id = 0; id < WaveIn.DeviceCount; id++)
	{
		if (drivername == WaveIn.GetCapabilities(Convert.ToInt16(id)).ProductName)
	        return id;
	}

	return -1; // erreur 
}
Dec 16, 2012 at 6:49 AM

May be that Mark can add this type of feature in WaveIn, WaveOut, ...

Dec 17, 2012 at 4:01 AM

Hi Manu,

Thanks for your reply. I thought of using ProductName but I doubt that it may give incorrect result if two or more devices have same name. Is it possible that two devices can have same name? I am going to try plugging two web cams (of exactly same model) if those become available for me. I'll post my observation later...

Coordinator
Dec 17, 2012 at 5:49 AM

The WaveIn/WaveOut APIs are particularly poor for this and may not be able to tell the difference between two instances of the same soundcard. I'd remember the name and the device id, and so if the device with the same id still has the same name, you can assume that things haven't changed since the last run of the program.

Dec 17, 2012 at 6:28 AM

I found one more problem for me! Actually I am going to record the captured video and audio in a WMV file. For which I need to know few properties of the audio format like bits per sample, sample rate, etc.. I am getting these properties using MMDevice.AudioClient.MixFormat but again this will not work on XP! What could be the solution?

Thanks.

Dec 17, 2012 at 6:36 AM
Edited Dec 17, 2012 at 6:37 AM

Normally, "productName" is increment of "(1) .. (2)." but this is not guaranteed.

It's like MIDI interfaces.

I had a computer with twice the same "ProductName" (microphone) of two different manufacturers, so I added the property ManufacturerID for ProductId and distinguished.

Dec 17, 2012 at 6:40 AM
Edited Dec 17, 2012 at 6:42 AM
PPavan wrote:

I found one more problem for me! Actually I am going to record the captured video and audio in a WMV file. For which I need to know few properties of the audio format like bits per sample, sample rate, etc.. I am getting these properties using MMDevice.AudioClient.MixFormat but again this will not work on XP! What could be the solution?

Thanks.

 

Complement the properties in "WaveInCapabilities.cs", and make public the SupportedFormats.
You have all the opportunities Audio card after you Choose your currency format.

Must remain cautious about this option because some drivers do not respect this option.