| Steven Yi wrote:
> It should certainly be possible and I've seen some code here and there
> and have investigated some but I haven't had a chance to implement. A
> while back I had wanted to implement the same method as Ardour (which
> I think uses a cache file for faster rendering) but I couldn't find
> it's waveform rendering code the last time I looked. If I remember it
> correctly, to show a waveform well it has to do some averaging or
> peaks for all the sample values that the pixel holds, otherwise you
> could get really different waveforms if you happen to hit the wrong
> sample. I'm not sure what's involved, but if someone knows what is
> involved and tells me I'm sure it wouldn't be too bad to figure out an
> implementation.
I did it a couple of times by figuring out how many samples fit into a pixel width, then scanning that many samples for maximum and minimum, then drawing a vertical line between the maximum and minimum points, and repeat for each pixel column. It's also useful to cache either the bitmap image or the list of min/max pairs as long as the scale and data stay unchanged. Some audio apps seem to be doing that in the background whenever they have idle time.
Martin
|