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

Start/End Position to play subclip?

Dec 9, 2011 at 12:50 AM

Hi folks,

I've been asked to allow playback of a sub section of an audio file.  I need to allow a Start/End Position to be set and probably to toggle looped playback.

I'm new to NAudio and have started looking at the source and demos but if anyone can give me a heads up on how I should get started it would be great.

So far the closest I can find to what I want to do is in a tutorial linked from the Documentation for playing multiple samples at once.

It doesn't do exactly what I want but I'm assuming, based on it, that I need to create my own implementation of WaveStream that overrides Read to return bytes between a set Start/End Position.


Any/all feedback would be appreciated.



Dec 12, 2011 at 10:34 AM

yes, creating your own WaveStream / IWaveProvider is the way to go. You would pass in a source stream to the constructor, and then in the Read method just read from the section of the source stream you want to. For looping, you would need to reposition the source stream once you have read up to the ned position. Have a look at LoopStream.cs in NAudioDemo to see looping in action. You would just need to change where it repositions to, and how it decides when it has got to the end.