Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using large pixmap or redrawing smaller ones?



  • I'm writing an audio app in PyQt, and I have to make a design decision and I need experts' advice. The app will display two waveforms, one over another (different y values, not z-order). For long audio files, the waveforms can contain millions of points. For example, for an hour long audio sampled at 22050 Hz I would have over 79 million data points. I need to figure out how to construct the images/pixmaps to maximize performance over such a large number of points.

    A similar feature is in all video editing programs. For example, if you take a look at Audacity, you can see a waveform, and below you see a scrollbar and above you see a timeline. alt text You can zoom in and out, effectively changing how the waveform appears. It's not just a scaled image of a huge file, but it has to be drawn differently at different zoom levels.

    The scrollbar pans across the image in time, but there's no scaling that happens with it.

    A two hour audio file can easily fit into memory, but since the waveform will need to be redrawn when the user zooms, that makes me think it will be slow to redraw with all the points.

    So, here are my questions.

    1. Should I construct the image all at once in a GraphicsScene and let the built-in scrollbar handle panning across the (potentially) large # of points?
    2. Should I use a QImage or QPixmap to display the waveform and images?
    3. What's the best approach to constructing the timeline bar? It will be rescaled whenever the plot is rescaled. But what if only 10% of the timeline fits onscreen at a time, should I use a QLabel? I was thinking about constructing a very long pixmap, and just copying a portion to the timeline as the scrollbar is moved.

    What do you recommend?

    Thanks!



  • This is a non-trivial problem that is encountered in many mutlimedia editing programs.

    I would pre-generate interpolated waveform graphics for the zoomed out scale factors, and generate graphics for the heavily zoomed scale factors on the fly (by chunks instead of the whole waveform). You will need some strategies for handling this intelligently...strategies that are well beyond my Qt forum pay grade.

    Personally, this is not one I would take on in python. You will want to process samples very quickly.

    Good luck


Log in to reply