This project has moved. For the latest updates, please go here.

WaveIn Valid Sample Rates

Mar 4, 2013 at 4:04 PM
Edited Mar 4, 2013 at 4:05 PM
Hi Mark,
I'm working on converting a microphone app from DirectX to NAudio.
I notice from the Windows Control Panel, microphone sample rates can range across 8000, 11025, 22050, 44100, 48000, 96000, 192000 Hz.

Can waveIn handle all these possible values? Or is there a max value that it will process?
waveIn = new WaveIn();
int sampleRate = 192000;
waveIn.WaveFormat = new WaveFormat(sampleRate,bitDepth, channels);

Question 2: Is there a way to get these input device capabilities for a microphone -- Sample Rate,Bit Depth.

Using this
WaveInCapabilities capabilities = WaveIn.GetCapabilities(waveInDevice);
WaveInCapabilities only exposes ProductName and Channels.

Thanks for any advice you can provide.
Mar 4, 2013 at 5:24 PM
1) it will depend on your soundcard. Note that WaveOut can resample for you, and it may be that WaveIn will simply record at the native sample rate of the sound card and resample to your requested rate. I would expect that only top end audio cards would do frequencies above 96kHz.

2) Probably I should update WaveInCapabilities to allow querying the supported formats enum like WaveOutCapabilities does. You'd have to use reflection to get at that at the moment.
Mar 4, 2013 at 7:08 PM
Ok thanks Mark.

It's not a big deal. Low values (like 8-bits / 8K sample) make the output hiss a little and lowers quality (as expected), but that's the worst that happens. My USB headset microphone (rated at 16-Bit 44100/48000 Hz) produces very good quality output when I use the rated values. There is no perceivable difference when I use a sample rate higher than 48000 Hz with that mic. So I think I'm in good shape even without being able to query the device Sample Rate and Bit Depth.

I'm getting just a bit of delay between speaking and hearing the output. Just a tad of delay, but still noticeable. I set Latency at 51. If I drop it one to 50, it produces crackling static.
waveOut.DesiredLatency = 51;
Is there any other settings that might help reduce the output delay?
Mar 5, 2013 at 5:00 PM
You better don't use that extremly low latency values. I guess you can't really do anything against that little delay. You really would have to play it in the exactly same millisecond as you say it.
Mar 5, 2013 at 5:54 PM
Thanks filoe. I know .Net isn't the best at timing. The Forms Timer is only accurate to 55 milliseconds which seems like a life-time in CPU instructions. But it is what it is.
Mar 5, 2013 at 7:15 PM
it's not .NET, its the waveIn and waveOut APIs. They are not particularly low latency. You need to work with WASAPI or ASIO to go to lower latencies.
Mar 5, 2013 at 7:22 PM
Ok, thanks Mark, good to know. I'll keep that in mind. I want to stick with WaveIn/Out for now because I have XP users. And XP is still 40% of the OS marketshare -- too big to ignore.