Drawing Wave File waveforms/peaks

BlitzPlus Forums/BlitzPlus Programming/Drawing Wave File waveforms/peaks

Timjo(Posted 2009) [#1]
I'm trying to make a simple waveform viewer for .wav files - that will display the waveforms from the files, like the ones you see in most waveform editors (Audacity etc).

I have stripped out the format details from the format chunk ('fmt ') - 44100 samples per second - 16 bits per sample etc .

I also have all the sample data stored in banks - (2 banks for stereo - left & right).

Does anyone have any experience of using this kind of data to draw a graphic of the waveform? If I have a canvas of, say 500*200 - I will need a way to reduce the sample data to fit the waveform in the space provided.

Any help welcome - or any links to non Blitz specific sites that may be informative. Thanks - Timjo.


Mahan(Posted 2009) [#2]
Example strategy: Let's assume you got 5000 samples (values). Divide the # of samples with your amount of X-pixels (500 like you wrote above). So you know that each x-pixel on your canvas amounts to 10 samples. Take out the average of 10 samples per pixel (in this example). Likewise in the Y direction you got to divide 65536 (for each 16-bit sound sample) with 200 (the Y-width of the canvas). Then simply draw lines (or plot) the approximated sound wave.

I've done this on C64 in my youth =)