Value does not fall within the expected range (NSpeexTest)

Jul 26, 2010 at 3:26 AM
Hey, Have any of you had issues running the NSpeex test code (WPF) on certain client machines? Apparently NAudio emits the following error message when the waveOut is initialized. Any help would be more than appreciated! I have no idea what causes this issue, and I thought it was just perhaps sound being disabled on a client's machine, but that's not the case. Sound is enabled and unmuted, so I have no idea what generates this message in the test code. The issue is at line 265 of MainViewModel.cs waveOut = new WasapiOut(AudioClientShareMode.Shared, 20); waveOut.Init(waveProvider); Thanks in advance! ************** Exception Text ************** System.ArgumentException: Value does not fall within the expected range. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at NAudio.CoreAudioApi.AudioClient.Initialize(AudioClientShareMode shareMode, AudioClientStreamFlags streamFlags, Int64 bufferDuration, Int64 periodicity, WaveFormat waveFormat, Guid audioSessionGuid) at NAudio.Wave.WasapiOut.Init(IWaveProvider waveStream)
Jul 26, 2010 at 7:11 AM


NAudio is basically a COM wrapper around the WASAPI interface and the exception comes from an COM call. So it sound like the API cannot be initialized. I have never come accross this particular error but maybe you can have a look at the NAudio forum.

Hm, what happens if you double the buffer size (20ms) and make it 40ms it could be that the buffer is too small for the hardware of the soundcard but this is just a quick guess as I am not the pro on NAudio and WASPI.


Jul 26, 2010 at 6:16 PM
Yeah, no luck with changing it. Is there any other way we can use a library besides NAudio? I have also asked about the issue in their forum section and I'm awaiting a reply. However, if we could just get it running on our end using another library like DirectSound, that would be nice, however I am unsure since the jitterbuffer provider extends WaveStream, so I am at a loss.
Jul 26, 2010 at 9:35 PM
Edited Jul 26, 2010 at 9:42 PM


you could try to switch to Directsound instead of Wasapi by changing the MainViewModel.cs where the error occurs to:

waveOut = new DirectSoundOut(40);
//waveOut = new WaveOut();
//waveOut = new WasapiOut(AudioClientShareMode.Shared, 20);

this should do the trick. So if that doesn't work either then there seems to be a problem either with NAudio itself or your hardware.
btw: are you using win7 or Win Vista? If that's not the case then this explains the problem with WASAPI since this API is available from Vista onwards.