This project has moved and is read-only. For the latest updates, please go here.

C# save waveform data?

Apr 23, 2014 at 9:20 PM

Because MP3's must be converted to wav before NAudio (or any other app) can calculate a waveform I would like to save the waveform data. You could call it a cache if you want.

Because everytime converting a mp3 to wav file takes too much time and unnecessary disk read/writes (on an ssd).

Can anybody tell me how I can do this the best way? It must stay resizable. I've already got a function for resizing that's working properly in my app
public void fitToScreen()
            if( waveStream == null )

            int samples = (int)(waveStream.Length / bytesPerSample);

            startPosition = 0;
            SamplesPerPixel = samples / this.Width; 
I was thinking about just saving the wav file, but if you got a library of 1000 mp3 files that would be like 50gb just so i can draw a waveform for every mp3..

Thanks in advance!
Apr 24, 2014 at 10:18 AM
Mark, any idea?
Apr 29, 2014 at 8:06 PM
I'd probably calculate the peaks at various intervals and save the array of peak values to a file. Should be quite easy to do. Resizable is a bigger challenge though, as you'd need to support peaks at different numbers of samples per pixel. I've used a MipMap approach for this in the past.
May 4, 2014 at 2:51 PM
Thanks I'll be looking in to that