LMMS / lmms

Cross-platform music production software
https://lmms.io
GNU General Public License v2.0
8.18k stars 1.01k forks source link

Cache and interpolate resolutions when drawing sample waveforms #7574

Closed sakertooth closed 1 week ago

sakertooth commented 1 week ago

This PR is meant to improve performance when drawing sample waveforms by:

  1. Caching multiple waveform resolutions that are decimated in logarithms (currently by powers of 2)
  2. Interpolating between the cached waveform resolutions to get the resolution necessary for the current zoom level (currently done using linear interpolation)

That's about it. I do want to note that when stretching sample clips vertically and using continuous scrolling, there is still a major drop in performance due to the drawing that's being done on the CPU. In the future, we should migrate such drawing to be done by the GPU using something like OpenGL.

Below is an attachment for the results of perf when sampling cycles in the scenario stated above: as shown, most of the overhead in this case lies within the Qt library itself, more specifically its software rasterization that is done on the CPU. image

I have also omitted RMS calculations from the waveform visualization since most DAWs (and now even Audacity when using default settings) don't consider this, and I wanted to prioritize more performance.

khoidauminh commented 1 week ago

Pretty decent performance! Though I'm seeing some bugs

The sample zoom jitter is still there:

https://github.com/user-attachments/assets/0fc81c40-4b5d-460e-8d6e-c5b629395b8e

Some sample shape artifacts when zooming:

https://github.com/user-attachments/assets/21f8825c-9fe2-4ffb-869e-d556860b3ab5

Waveform not being drawn in SlicerT (or you haven't drawn it yet):

ảnh

Incorrect rendering in AFP:

https://github.com/user-attachments/assets/f8a4765f-dd0e-415a-b0fb-7a976df7b30d

Also iirc, this one also uses more ram, but it's not a big problem.

Have you tested how this compares to my implementation?

khoidauminh commented 1 week ago

If you don't mind, I'll push some fixes

sakertooth commented 1 week ago

If you don't mind, I'll push some fixes

Yeah, that's fine with me.

sakertooth commented 1 week ago

@khoidauminh, I tested your PR. I don't remember the implementation being that good, wow. I think I might close this PR actually and continue contributing to what you have over there. And the ideas we did here are the same, at least in terms of caching, but I'm shocked at how the continuous scrolling is that fast with your PR.

khoidauminh commented 1 week ago

@sakertooth Damn thank you

Though I think my PR is only faster because I clipped rendering to the visible region

This PR did make me realize how messy my code still is lol. I'll see what I can clean up