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

Audio Samplerate

Nov 1, 2012 at 4:33 PM


I'm using some very simple code to open and play a wave file, using a DirectSoundOut object.  If I open a 44.1kHz wave file to start, then the output on WinXP is 44.1kHz to my USB sound card.  If I open a 48kHz wave file to start, then the output on WinXP is 48kHz.  However, once I've opened one file, the sample rate is stuck at that value until I close and re-open the application.

I've tried disposing the DirectSoundOut object between wave files, and have run a full GC.Collect() to try to call the finalizers/etc on the objects.  I then re-create everything from scratch, but it looks like Windows is somehow caching the previous samplerate.  This causes samplerate conversion artifacts in my sound.  Is there any way around this using NAudio?

With the new Windows Core Audio functionality (Win8/7/Vista) I can create an IAudioClient and using the IAudioClockAdjustment interface to set the samplerate of the audio device, but this is a pain and most likely will not work in WinXP.  I'd like to solve this with NAudio if possible.



Nov 3, 2012 at 2:48 PM

The actual sample rate that the sound card runs at is determined by the operating system, and NAudio is not able to control it with the waveOut or DirectSound out APIs.

Nov 22, 2012 at 10:06 PM

Hi Mark - thanks for the reply.  In Windows Vista and later, you can use the core audio library to control the sample rate from the application.  It's a big pain though, so I've abandoned this effort for now.