I know that fmod does not handle downsampling of raw data but i thought i would ask on here as someone may have aready come accross this sort of thing.
I am trying to display a waveform from a 16bit 44k wav in C#. I can show part of the wave using 1 pixel per sample but obviously it would be nice to zoom in and out.
Zooming in should be easier than zooming out so i am trying to acomplish the latter first.
My question is, could anybody point me in the direction of a simple downsampling algorithm?
it doesnt really need to be totally accurate as ill only be displaying the waveform, not playing it.
- e_mpika asked 10 years ago
This should just be a matter of calculating the ratio of raw data versus display data based on your "window" size into the waveform. Let’s say you want to display a section of the waveform 1000 samples long, but you want to display it in a 250 pixel window. This gives you a 4/1 ratio of data traversed to display info.
Probably the simplest approach is a point sampling algorithm. This would mean you just read the wafeform data and display every fourth sample. Or you could add the samples in each gap and divide by your step value. In this case, that means adding up four samples and then dividing by four* to get an average value. An alternative method might be to track the largest and smallest values within the step size, and then draw a vertical line between these two values to simulate the waveform volume. Which method you use is ultimately dependent on what you want the waveform to look like.
*If you constrain zoom to powers of two, you can replace divides with shifts to optimize the code a bit.
- JamesB answered 10 years ago
Hi thanks for the reply, i figured out that a good way would be to take the lowest and highest values in a ‘step’ and then draw a line between them… im having issues creating an array with all the data in though (i think this is just my dodgy maths though).
I may well try adding the values in a step and then averaging them. i hadnt thought of that
- e_mpika answered 10 years ago
Please login first to submit.