How to get Preferred Format List for any audio capture device?

Dec 20, 2012 at 9:59 AM
Edited Dec 20, 2012 at 10:03 AM

Hello everyone,

I am not able to find the preferred/default audio format for the selected audio capture device. Actually I am using IWaveIn.WaveFormat property to get the audio format but I am not sure if its a default format. How NAudio retrieves this WaveFormat? (I am facing problem if I try to use this format for recording, audio codec is not supporting this format!).

I was comparing the default format retrieved using NAudio and DirectShow and I found that both are different! DirectShow provides a way to get the preferred format list for the audio capture device (using IPin::EnumMediaTypes), is there any way in NAudio to get the same list?

Coordinator
Dec 20, 2012 at 10:47 AM

As far as I know, WaveIn doesn't offer this capability. Wasapi in does though if you are using Windows Vista or above. There is some enum wrappers for DirectSound in NAudio, but it doesn't cover the whole API, and I suspect EnumMediaTypes is not included,

Dec 20, 2012 at 12:33 PM

The WaveFormat that I am getting using IWaveIn.WaveFormat for my capture device has values as follows - BitsPerSample = 32, SampleRate = 48000 and Channels = 1. I want to record using Windows Media Audio 9.2 codec but this codec does not support a stream with such format. I tried other formats (available in this codec) which has same Sample Rate and Channel values but my output recording is not proper (audio is like blablakchilblachilbal...)!!!

Dec 21, 2012 at 5:24 AM

I want to capture audio with stereo CBR so I tried configuring my wavIn instance with a WaveFormat (stereo) which is supported by the codec but it is not working and throws "Unsupported wave format" exception!  I tried almost all stereo formats that are available in the codec but same exception is coming for all.

What should I do? Any suggestion?

Thanks.

Coordinator
Dec 21, 2012 at 7:23 AM

you can't capture audio directly in a compressed audio format. You must capture it in PCM and then encode it afterwards. Read this article on CodeProject to get a better understanding of working with compressed audio formats.

Mark

Dec 21, 2012 at 9:16 AM

Thank you for your reply. I am going through the article that you have suggested.

But actually I was creating WasapiCapture instance for my audio capture device and I faced above issues. But I tried creating WaveIn instance, configuring it with the required WaveFormat (16 kbps, 44 kHz, 2 channels), capturing with this instance and is working fine. I am also able to record received audio samples using above mentioned codec.

Thank you so much for your help.

Coordinator
Dec 21, 2012 at 9:18 AM

yes, but you will still be recording in PCM. For WMA you'd need to encode afterwards