diff options
author | Chris Robinson <[email protected]> | 2020-08-10 15:11:52 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-08-10 15:11:52 -0700 |
commit | c549797af0420942ab460cc3ca1ded1b55956681 (patch) | |
tree | ebedf10d25dd7815a76ade8c5477b6cb1e027217 | |
parent | e8b3e82f96d28d725bc44f5a99d0b2646394019e (diff) |
Make osme things constexpr
-rw-r--r-- | common/polyphase_resampler.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/common/polyphase_resampler.cpp b/common/polyphase_resampler.cpp index d572ddcc..88c4bc4b 100644 --- a/common/polyphase_resampler.cpp +++ b/common/polyphase_resampler.cpp @@ -10,7 +10,7 @@ namespace { -#define EPSILON 1e-9 +constexpr double Epsilon{1e-9}; using uint = unsigned int; @@ -21,7 +21,7 @@ using uint = unsigned int; */ double Sinc(const double x) { - if UNLIKELY(std::abs(x) < EPSILON) + if UNLIKELY(std::abs(x) < Epsilon) return 1.0; return std::sin(al::MathDefs<double>::Pi()*x) / (al::MathDefs<double>::Pi()*x); } @@ -32,22 +32,20 @@ double Sinc(const double x) * I_0(x) = sum_{k=0}^inf (1 / k!)^2 (x / 2)^(2 k) * = sum_{k=0}^inf ((x / 2)^k / k!)^2 */ -double BesselI_0(const double x) +constexpr double BesselI_0(const double x) { - double term, sum, x2, y, last_sum; - int k; - // Start at k=1 since k=0 is trivial. - term = 1.0; - sum = 1.0; - x2 = x/2.0; - k = 1; + const double x2{x/2.0}; + double term{1.0}; + double sum{1.0}; + int k{1}; // Let the integration converge until the term of the sum is no longer // significant. + double last_sum{}; do { - y = x2 / k; - k++; + const double y{x2 / k}; + ++k; last_sum = sum; term *= y * y; sum += term; @@ -77,11 +75,11 @@ double Kaiser(const double b, const double k) } // Calculates the greatest common divisor of a and b. -uint Gcd(uint x, uint y) +constexpr uint Gcd(uint x, uint y) { while(y > 0) { - uint z{y}; + const uint z{y}; y = x % y; x = z; } @@ -95,16 +93,16 @@ uint Gcd(uint x, uint y) * { ceil(5.79 / 2 pi f_t), r <= 21. * */ -uint CalcKaiserOrder(const double rejection, const double transition) +constexpr uint CalcKaiserOrder(const double rejection, const double transition) { - double w_t = 2.0 * al::MathDefs<double>::Pi() * transition; + const double w_t{2.0 * al::MathDefs<double>::Pi() * transition}; if LIKELY(rejection > 21.0) return static_cast<uint>(std::ceil((rejection - 7.95) / (2.285 * w_t))); return static_cast<uint>(std::ceil(5.79 / w_t)); } // Calculates the beta value of the Kaiser window. Rejection is in dB. -double CalcKaiserBeta(const double rejection) +constexpr double CalcKaiserBeta(const double rejection) { if LIKELY(rejection > 50.0) return 0.1102 * (rejection - 8.7); |