-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize dBFS/amplitude conversion functions #7535
Optimize dBFS/amplitude conversion functions #7535
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thoughts regarding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested it, but I verified that the math is correct [Desmos link], and the changes are minimal, so I think it's safe to merge.
@messmerd I get compilation errors when compiling those changes on my PC, The best workaround seems to be simply using |
Alternatively, it looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
* Optimize dBFS <-> amplitude functions
std::pow(10.f, x)
andlog10f
are painfully slow functions when run per-sample, as is commonly required viadbfsToAmp
andampToDbfs
. This PR sacrifices a completely negligible amount of precision for a significant performance boost for several LMMS plugins:Notice that these are mathematically equivalent operations, not approximations. The lost precision, which is very nearly 0, is solely due to the limited precision of floats.
Compiled via GCC with -O2:
fastLog10f is 1.993x as fast on this hardware.
fastPow10f is 1.662x as fast on this hardware.
(This might even provide a larger benefit on older hardware, I've seen performance benefits of up to 3x reported by others.)
It might be worth exploring some faster and less-precise alternatives in the future, but what this PR provides is a significant improvement for no actual downsides whatsoever.