Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize sample waveform rendering time #7210

Closed
wants to merge 6 commits into from

Conversation

khoidauminh
Copy link
Contributor

@khoidauminh khoidauminh commented Apr 17, 2024

I've been noticing that LMMS was lagging under a big project with long samples. Zooming in and out causes notable frame rate drop.

This pull request makes the following changes to SampleWaveform::visualize (in order of performance improvement):

  1. Change maxFramesPerPixel from 512 to 24. Often, processing this many frames are redundant and can cause lag when working on a sample heavy project.

  2. Remove 3 vector allocation by nesting the loops. The min, max and squared values are computed on the spot for each new pixelIndex, which means they no longer need to be stored in vectors.

  3. Calculate halfHeight, parameters.amplification and frame.size() outside of the loops into scalingFactor.

The refactoring tries to minimize the performance cost while retaining the look of the waveform. Compared to the original code, when zoomed all the way out, some sample tracks may appear to be quieter. However they look almost identical when zoomed in.

comparison:

Master branch:

lmms-sample-original-code.mp4

Pull request:

lmms-sample-new-code.mp4

Eliminates vector allocation.

Reduces the number of frames to process per pixel index from 512 down to 16.

Restructure the 2 loops and move some math out of the loops.
@khoidauminh khoidauminh changed the title Reorganize SampleWaveform::visualize Minimize sample waveform rendering time Apr 20, 2024
@khoidauminh khoidauminh marked this pull request as draft April 21, 2024 02:26
@khoidauminh khoidauminh marked this pull request as ready for review April 21, 2024 03:28
src/gui/SampleWaveform.cpp Show resolved Hide resolved
src/gui/SampleWaveform.cpp Show resolved Hide resolved
@khoidauminh
Copy link
Contributor Author

Sacrifices too much quality in exchange for performance.

@khoidauminh khoidauminh closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants