0
0

Hi

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.

thanks

  • You must to post comments
0
0

Good point, how? I did not find a good way…

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

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 :)

thanks again

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.