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

Drawing Waveform of Wavestream subsection

Sep 5, 2013 at 1:51 PM
Edited Sep 5, 2013 at 1:52 PM

I am drawing the waveform of a wav file on a mediaobject representation.
The user can make the duration of this media object smaller. The wav is then played only the duration and the rest is cut off.
I can draw the waveform of the entire wav no problem, and for the smaller duration I thought I could just change the length of the wavestream like so:
WaveDrawer wd = new WaveDrawer();
wd.WaveStream = new NAudio.Wave.WaveFileReader(lr.URL);
TimeSpan ts = (_representedObject as MediaObject).Duration;
wd.WaveStream.SetLength((long)(wd.WaveStream.WaveFormat.AverageBytesPerSecond * ts.TotalSeconds));
But this results in the exception "Can't set length of WaveFormatString".
What am I doing wrong? Or is there another way to go about this?

Thank you!
Sep 6, 2013 at 10:02 AM
You can't change the length of a WaveStream. I'd probably create a wrapper WaveStream with a shorter duration, whose Read method passes into the full WaveFileReader, but doesn't read more than the specified length. Have a look at OffsetSampleProvider for an idea of how this would be implemented.