This project has moved and is read-only. For the latest updates, please go here.

WaveInStream callback problem (and possible solution)

Jan 6, 2009 at 10:23 PM
I've was having some trouble using WaveInStream to record wav files.  If I ran everything in a single WinForms thread (as the Demo project does), it worked fine.  Anything else, and it barfed on me.

Based on some of Mark's blog posts and the behavior I saw, I'm guessing that the native WaveIn was calling the callback function a few more times after I had stopped recording.  Since I had disposed of the target window, I got a null reference exception.

Anyway, I think I may have fixed it by adding a simple check to WaveInStream.Callback():
// Make sure that our target window isn't disposed.
if (hBuffer.Target != null)

Any thoughts?  This doesn't seem like the most elegant fix to me, but I'm not sure how else to fix it (short of keeping a form open so that the target always exists).

(I also tidied up WaveInStream a bit so that it works more like WaveOut...  I'd be happy to share if anyone is interested.)
Jan 7, 2009 at 4:03 PM
hi, WaveInStream is still a bit raw. I really want to rethink the way it works, but it does a job for now. Do feel free to send me your updated version, and I'll have a look at getting it included in the main source.