I’m implementing a waveform from an audio file that can be zoomed up to a sample level. Performance wise the path rendering isn’t a problem, but the data processing might be: the bigger the file, the more samples must be evaluated. Downsampling (discarding samples to make it faster) creates aliasing when zooming, so I was thinking about lower resolution representation of the min/max samples (i.e for each 32 samples find the min/max and use that to draw), but for big files like 15-30 minutes this seems like a lot of samples to make it work smoothly on each zoom iteration. Doing it with preacalculated mipmaps would take a good amount of memory aswell and zoom wouldn’t be that smooth. Maybe an hybrid method between those two?
I wonder how DAWs like Ableton are doing this smoothly and in a responsive way without sweating, even with huge files.
i recently wrote something like that too and my approach rn is to only read as many samples as there are pixels on the x-achsis, no matter the zoom level or position. it still needs some improvements, like what you said about finding the max of each sample index. maybe it would be sufficient to just read a few sorrounding samples to approx max instead of finding the actual max
IIRC, Ableton produces .asd files which contain amongst other stuff peak data specifically for speeding up rendering. Reaper does a similar thing. Not sure about the format so you’ll have to do a bit of research.
that’s intelligent. since all maxima are known at sample import already why not make a lookuptable of their positions, sure
I actually tried to look into the .asd files to get a grasp on how many samples per file they take but it’s all on binary data.
Maybe an hybrid between what you both said? Having kind of an .asd file or aux buffer with the analyzed waveform storing all its peaks (min and max values) and if that’s still bigger than X samples per zoom, use a downsampled version of that reading every 8-16-32 peaks.
As a curiosity, I loaded a 37 min 410mb file in Ableton and it generated a 2mb .asd file, the memory usage only increased 20mb aprox (playback may be streaming from disk using a background thread instead of storing all file in a buffer) and the CPU usage didn’t change compared to zooming in/out the Ableton UI (in arrangement view). So it barely uses the CPU to process the waveform data when zooming.
Here’s Reapers .reapeaks file format:
I think it pretty much does the same thing.
Thanks! There’s a lot of good info in it (number of peaks per second, amount of mipmaps…) even the type of variables used to store data