librosa icon indicating copy to clipboard operation
librosa copied to clipboard

Improvements to adaptive waveplot

Open bmcfee opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. Documenting this conversation with @achabotl -

The AdaptiveWaveplot class is used by waveshow to dynamically switch between a step plot of the raw samples and an fill_between plot of the amplitude envelope based on the size of the viewport. If the viewport is smaller than max_points / sr, then the step plot is shown; otherwise, the envelope is shown.

To balance memory usage between the two views, the envelope plot is constructed so that it has about max_points horizontal steps. This works well enough for most cases, but if the signal is very long, and the user zooms in to just above the threshold for switching to step plots, it will result in a very blocky display.

Describe the solution you'd like Instead of having only two modes (step and envelope), it might be worth maintaining a downsampling pyramid of envelopes at different resolutions. This way, we'd never be off by more than a factor of two from a reasonably high-resolution display.

While this sounds expensive up front, I think it could end up being cheaper overall if we use more aggressive decimation in constructing the envelopes. Rather than pinning the number of horizontal steps to the sample threshold, we could instead derive a meaningful limit by querying the figure for its DPI.

The only change to the logic here would be that instead of one threshold, we have multiple, and switch to the lowest resolution that still provides reasonable resolution. (Some details to be fleshed out here.)

bmcfee avatar Jul 20 '22 17:07 bmcfee