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

Using NAudio in a game

Oct 20, 2014 at 12:01 AM
I have a few questions about using NAudio.

Basically I was using to play Sounds and BGM's and I'm wondering how that would transfer over to NAudio. I got most of it working but I'm having a few issues.

I noticed the Sample (Fire & forget) on the Wiki with CachedSound and for the most part that was fine except how do I know when a SoundEffect or BGM has finished playing because for some SoundEffects/Songs I need to manage when they end as they are supposed to loop until a event triggers them not to.

Also I have a collection of 3,864 songs and sounds and they all have different sample rates and MixingSampleProvider does not like that. Will I have to manually convert each mp3 to match?

Other then that implementing NAudio has been pretty easy and pain free.
Oct 23, 2014 at 10:00 AM
A sound has reached its end when the Read method returns 0. I usually implement a simple wrapper (decorator pattern) around my SampleProviders if I need to raise an event or do something special when the end is reached. A WaveStream based example of this is available on my blog here.

NAudio has a few resamplers that you can make use of. Read my blog post here for details.