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

WaveCallbackInfo/BufferedWaveProvider fixes?

Aug 22, 2011 at 2:41 AM

I fixed a crash problem i was having when disposing of an object. In the Disconnect() function of WaveCallbackInfo I added a InvokeRequired check to fix my issue.

In "WaveCallbackInfo.cs"

delegate void FuncCallbackDelegate();

        internal void Disconnect()
            if (waveOutWindow != null)
                if (!waveOutWindow.InvokeRequired)
                    waveOutWindow.Invoke(new FuncCallbackDelegate(waveOutWindow.Close));

                waveOutWindow = null;
            if (waveOutWindowNative != null)
                waveOutWindowNative = null;


In BufferedWaveProvider i seemd to have a problem settings the BufferDuration below 1 second.
_provider.BufferDuration = TimeSpan.FromMilliseconds(500d);

I'm not sure exactly what was happening but I modified the set parameter to cast the (int) WaveFormat.AverageBytesPerSecond to a (double) and it seem to fix the math problems...

In "BufferedWaveProvider.cs"

public TimeSpan BufferDuration
                return TimeSpan.FromSeconds((double)BufferLength / WaveFormat.AverageBytesPerSecond);
                BufferLength = (int)(value.TotalSeconds * (double)WaveFormat.AverageBytesPerSecond);

Are these real fixes? Or was i doing something wrong to begin with? haha; enlighten me

Aug 25, 2011 at 10:30 AM

ideally you shouldn't be using an instance of WaveOut from multiple threads at the same time, which is what you seem to be doing.

As for the BufferDuration fix, you now run the risk of creating a BufferLength that is not block aligned with the setter. Might not be an issue, but it would mean that the bufferduration getter wouldn't be accurate.