AudioThumbnail UI Overlay



I am building a plugin which has a component that overlays an audio thumbnail (granular playback reader visualization). There is an AudioThumbnail component to which the parent component is added as a listener. In the AudioThumbnail documentation the following is mentioned.

The class will asynchronously scan the wavefile to create its scaled-down view, so you should make your UI repaint itself as this data comes in. To do this, the AudioThumbnail is a ChangeBroadcaster, and will broadcast a message when its listeners should repaint themselves.

The thumbnail stores an internal low-res version of the wave data, and this can be loaded and saved to avoid having to scan the file again.

Now since I need to update the UI overlay at a decent frame rate, how do I repaint the AudioThumbnail component in the most efficient way (or is there another way)? Does the thumbnail component automatically use the Cache that is passed in the constructor?


Sorry, really can’t understand what you’re asking there?


When I repaint the playback visualization, I have to repaint the underlaying AudioThumbnail right? If I use the drawChannels method in from the AudioThumbnail class, does it automatically use the stored low-res version (when using the Cache)?


Yeah, it’ll draw itself with the low-res data. That’s what the low-res data is for. Not sure I understand fully what you’re asking!


I’m just checking whether it actually used the cache, because its eating up a huge amount of CPU just to redraw the thumbnail at that rate.


If you zoom in far enough that each low-res data point covers more than 1 pixel, then it will switch to reading the actual samples from the file. Presumably that’s what you’re seeing?


I’m using a block size of 512, but maybe my samples are just too big, if I dynamically change the block size based on the size of the sample, does it recalculate the low-res file for the cache all the time?


It’s not a setting that would be expected to change dynamically. If it’s worth generating thumbnails at all then you generally don’t want to keep regenerating the data. But I don’t know, maybe it’d work OK in your use-case.


Ok I think I should probably figure out some way to generate a bunch of thumbnails beforehand at different blocksizes, because samples can differ from one shots to loops to field recordings of about half a minute. Thank you for the help.