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

How to play multiple sounds in quick succession?

Mar 27 at 3:47 PM

I’m completely new to naudio so please bear with me…

I trying to play many short (about 500 milliseconds) sounds (wav files) in quick succession with little to no time between them and no overlap.

Let us say, for example, I have 5 different sounds, each exactly 400 ms long. Ideally I would like to play them all in a row, getting a 2000 ms long output.

I accomplished that using the OffsetSampleProvider-class, where I simply give each sound a fitting DelayBy-value and then call the play-functions of all corresponding IWavePlayer simultaneously. This way, I get very good results (only a little time gap between sounds, about 5 ms).

So far so good.

However, the situation becomes slightly more complicated:

What if I want to change a sound while the one before is already playing?

Let us say, I play a row of 5 Sounds like in the previous example. But while the one is playing I want to change the one.

I tried to accomplish that again by using the OffsetSampleProvider-class, initializing each sound individually while the previous one is playing and giving an offset (DelayBy-value) based on the CurrentTime-value of the AudioFileReader of the currently playing sound.
This works in principle, but I get huge (about 30 ms) time gaps and overlaps between the sounds.

Anny Ideas?

Thank you.