Using NAudio playback as time source

Nov 4, 2010 at 5:06 PM

I am converting a c++ pyrotechnic firing system to C# / .NET and also adding in a shoot to music feature set. Does the NAudio async playback provide information on the current audio position by time in the audio file?  I need around 100 millisec timing accuracy. Using the playback position as the timing source is the desired solution because of operator pauses, where the music and the pyro should both stop and then continue to be in sync after continuing the show. I do have the option of limiting the sound files to non compressed codecs and doing time calcs based on sample rate and position in playback. I would like to allow for MP3 and other compressed formats if possible.

Thanks for any help,

Neil

 

Coordinator
Nov 4, 2010 at 7:20 PM

wow, sounds amazing! The latency of NAudio is not particularly low, but you can adjust it for WaveOut or WasapiOut. Wasapi will give you lower latency. The other issue that you might run into is that the MP3 file reader is not always reliable in its position reporting. I have been working on fixing that in the latest code, but not sure if it is quite there yet.

Mark

 

May 4, 2012 at 5:15 AM

I'm there, its all working and the timing is close enough. I used the WPFSoundVisualizationLib to show progress along the soundtrack. The only thing to solve is a problem with the sound after a pause. Seems like its playing 2 versions simultaneously. I'm using the NAudio sample from the visualization lib. After the restart of the audio, its garbled like its being played twice slightly out of phase. Any advice on pausing and resuming audio play?

 

Thanks,

 

Neil

Coordinator
May 8, 2012 at 9:10 AM

I haven't examined the WPF Sound Visualization Library's example, so it is hard to say what the problem is. You should have an IWavePlayer implementation that you just call Pause and Play on. Whave version of NAudio are you working with?