Audacity 3.2.0
|
#include <cstdint>
Go to the source code of this file.
Functions | |
constexpr float | FastLog2 (float x) |
Approximates the base-2 logarithm of a float to two decimal places, adapted from https://stackoverflow.com/a/28730362. More... | |
Variables | |
static constexpr float | log2ToDb = 20 / 3.321928094887362f |
|
constexpr |
Approximates the base-2 logarithm of a float to two decimal places, adapted from https://stackoverflow.com/a/28730362.
Audacity: A Digital Audio Editor
Matthieu Hodgkinson
Accuracy claim is demonstated in MathApproxTest.cpp, and coincides with @Paul-Licameli's analysis (copied from conversation): "If x == 1.0f, then log2 before the += correction actually becomes -1 – because a zero exponent of two is represented by 127 in the eight exponent bits, but one more was subtracted. > u.x by that point has been normalized to the range [1.0f, 2.0f), by changing the exponent, multiplying it by an integer power of 2. > So the correction must add 1 – so that log2(1) comes out (approximately) zero – but then, add a quadratic polynomial in u.x, a*x*x + b*x + c, where a is -0.3358287811f, b is 2, c is -1.65871759316667f (the magic number as written, minus 1) > Evaluate that at x = 1, and you don't get exactly 0 ! You get a little off. It's correct to only two decimal places. Curious why they chose it that way."
Definition at line 32 of file MathApprox.h.
Referenced by DanielRudrich::GainReductionComputer::computeGainInDecibelsFromSidechainSignal(), anonymous_namespace{CompressorInstance.cpp}::GetMaxDbIncrease(), CompressorProcessor::Process(), FormantShifter::Process(), and TEST_CASE().
|
staticconstexpr |
Definition at line 46 of file MathApprox.h.
Referenced by DanielRudrich::GainReductionComputer::computeGainInDecibelsFromSidechainSignal(), anonymous_namespace{CompressorInstance.cpp}::GetMaxDbIncrease(), and CompressorProcessor::Process().