Best method for sonogram display?

i am still rather new to JUCE, and hope this question isn't too elementary. i would like to build a scrolling sonogram display where the new spectra info gets drawn on the bottom of the component, and rest of the image gets moved up a pixel every n times a second.

i am drawing a single line now, using drawRect for every band in the FFT... with a argb lookup table now that translates amplitude values into colours.

this works fine out of the paint method in the component, but i can't find an easy method to move previously drawn graphics up one pixel...

any advice?

Drowaudio has a sonogram component.

i know, but it doesn't scroll the sonogram... it moves the new line, which isn't the look i want.

my question is really if there is an efficient way to scroll an existing graphics context without having to redraw every pixel.

Why don't you simply repaint everything again in each paint() call? (this should not be inefficient if you save the previously calculated lookup tables somewhere).

If you use a FIFO structure with x elements (where x is the width of the component), you can simply iterate over it and paint the whole area.


One easy way to do this is with Juce::Image


Create a history image, and then draw the new sonogram data across the bottom row.

Maybe repaint on a timer, and each time repaint() is called, move the image up a bit ...

history->moveImageSection(0, 0, 1, 0, history->getWidth(), history->getHeight());

Draw the new data (across the now clear bottom row of the image).

Then paint the image on the component with drawImage().

Yes, that’s the best method to use… But I believe the OP wanted to be able to blit the image to update it.


i'll give the history image method another try (i tried this before my OP, but couldn't get my code to work).


i did try chrisboy's idea of just saving pixel color data, and redrawing everything on paint(). it works, but really eats up processor.


and finally, now that i've gotten this far, i'm not so sure i like sonogram displays as much as i do spectral curves. unless i have a huge window for the sonogram, i can see more info in the spectra.

If I was doing this again I would probably just keep all the FFT buffers in a FIFO and simply redraw the whole thing in the paint method. This would avoid all the rescaling issues you get when resizing etc. and give you far greater flexibility over the actual drawing routine.

In all my profiling I've never actually found it quicker to draw an image than to re-render the source contents. If you can create things like rectangle lists and paths these draw really quickly. My advice would be to draw it without the image caching first and profile, if you see a bottle neck that could be improved with image caching it should be relatively simple to add from there.