NAudio is a great library! Thanks for sharing it.
A bug fix for your review.
See \naudio_38dadb417edc\NAudio\Wave\MmeInterop\WaveCallbackInfo.cs line 75
My fix is to pin the delegate used by the WinMM callback...
private static WaveInterop.WaveCallback reference; // pin the reference to the callback delegate.
// the CG may choose to clean up the "pointer to the function" as no one is using it!
// except that WinMM is!
internal MmResult WaveOutOpen(out IntPtr waveOutHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
reference = callback;
if (reference == null)
throw new ApplicationException("callback is null");
MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveOutOpen(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
I'm using your library in a "busy" .NET C# SDR application.
Comments: thanks for reporting this. any reason you made it static? that would break if more than one output device was in use at once
A bug fix for your review.
See \naudio_38dadb417edc\NAudio\Wave\MmeInterop\WaveCallbackInfo.cs line 75
My fix is to pin the delegate used by the WinMM callback...
private static WaveInterop.WaveCallback reference; // pin the reference to the callback delegate.
// the CG may choose to clean up the "pointer to the function" as no one is using it!
// except that WinMM is!
internal MmResult WaveOutOpen(out IntPtr waveOutHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
reference = callback;
if (reference == null)
throw new ApplicationException("callback is null");
MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveOutOpen(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
I'm using your library in a "busy" .NET C# SDR application.
Comments: thanks for reporting this. any reason you made it static? that would break if more than one output device was in use at once