breakfastquay / rubberband

Official mirror of Rubber Band Library, an audio time-stretching and pitch-shifting library.
http://breakfastquay.com/rubberband/
GNU General Public License v2.0
561 stars 89 forks source link

Optimized MovingMean #100

Closed JoergAtGithub closed 2 months ago

JoergAtGithub commented 3 months ago

I noticed that significiant CPU time is burned for calculating the MovingMean. This PR is contains an alternative implementation based on std functions. In my setup the profiler results were sometimes better and sometimes worse.

JoergAtGithub commented 2 months ago

As alternative the rolling mean implementation of the boost library could be used: https://www.boost.org/doc/libs/1_85_0/boost/accumulators/statistics/rolling_mean.hpp

cannam commented 2 months ago

Thank you for the proposal - you're right that quite a lot of time is spent here. However I don't think a change like this would be a good idea unless profiling showed it to be consistently faster. I appreciate that it makes the code shorter as well, but it replaces a fairly well optimised path that has predictable performance with a standard library container whose performance is a relative unknown and that may involve heap allocation.

I may revisit the question of median filters at some point, but it's very sensitive to code generation and details of measurement.

(We don't use Boost in this library - only for the unit tests. But in any case that is a moving mean, not the moving median we need.)