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

Fire-and-forget game audio.

May 4, 2015 at 7:20 PM
I'm trying to use NAudio to play sound in a game context, using as my guide. I've run into a bit of a snag, though. Playing a sound seems to set a playback position in the provider object, and I'm unclear on how to reset that or make a copy decoupled from the cached sound. This means that trying to play two instances of the same sound overlapping doesn't start a new sound but rather doubles the existing one, and once a sound has played once it effectively can't be played again.

Is this indicative of me having done something wrong, or intended behavior? My implementation passes sound around as sample providers, and I've gotten a sense from looking around that handling wave providers instead would maybe avoid this. Is that a red herring, or a good lead?

I'd post sample code, but I'm not sure quite what part would be useful to excerpt, and the current state is a bit messy with attempted fixes and work-arounds, so I thought it'd be better to ask those prelim questions first.
Oct 20, 2015 at 6:32 PM
Sorry for long delay replying.

Yes, to play two versions of the sound, create a new ISampleProvider (with a RawSourceWaveStream reading from memory). It's because Read will be called independently on each one