aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/alnumbers.h4
-rw-r--r--common/math_defs.h23
-rw-r--r--common/polyphase_resampler.cpp8
3 files changed, 10 insertions, 25 deletions
diff --git a/common/alnumbers.h b/common/alnumbers.h
index 98994b44..37a55410 100644
--- a/common/alnumbers.h
+++ b/common/alnumbers.h
@@ -19,10 +19,14 @@ template<typename T>
static constexpr auto inv_pi_v = detail_::as_fp<T>(0.318309886183790671537767526745028724L);
template<typename T>
+static constexpr auto sqrt2_v = detail_::as_fp<T>(1.414213562373095048801688724209698079L);
+
+template<typename T>
static constexpr auto sqrt3_v = detail_::as_fp<T>(1.732050807568877293527446341505872367L);
static constexpr auto pi = pi_v<double>;
static constexpr auto inv_pi = inv_pi_v<double>;
+static constexpr auto sqrt2 = sqrt2_v<double>;
static constexpr auto sqrt3 = sqrt3_v<double>;
} // namespace numbers
diff --git a/common/math_defs.h b/common/math_defs.h
index ba007115..d66923ea 100644
--- a/common/math_defs.h
+++ b/common/math_defs.h
@@ -1,26 +1,7 @@
#ifndef AL_MATH_DEFS_H
#define AL_MATH_DEFS_H
-constexpr float Deg2Rad(float x) noexcept { return x * 1.74532925199432955e-02f/*pi/180*/; }
-constexpr float Rad2Deg(float x) noexcept { return x * 5.72957795130823229e+01f/*180/pi*/; }
-
-namespace al {
-
-template<typename Real>
-struct MathDefs { };
-
-template<>
-struct MathDefs<float> {
- static constexpr float Pi() noexcept { return 3.14159265358979323846e+00f; }
- static constexpr float Tau() noexcept { return 6.28318530717958647692e+00f; }
-};
-
-template<>
-struct MathDefs<double> {
- static constexpr double Pi() noexcept { return 3.14159265358979323846e+00; }
- static constexpr double Tau() noexcept { return 6.28318530717958647692e+00; }
-};
-
-} // namespace al
+constexpr float Deg2Rad(float x) noexcept
+{ return static_cast<float>(x * 1.74532925199432955e-02/*pi/180*/); }
#endif /* AL_MATH_DEFS_H */
diff --git a/common/polyphase_resampler.cpp b/common/polyphase_resampler.cpp
index 88c4bc4b..bb8f69a4 100644
--- a/common/polyphase_resampler.cpp
+++ b/common/polyphase_resampler.cpp
@@ -4,7 +4,7 @@
#include <algorithm>
#include <cmath>
-#include "math_defs.h"
+#include "alnumbers.h"
#include "opthelpers.h"
@@ -21,9 +21,9 @@ 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);
+ return std::sin(al::numbers::pi*x) / (al::numbers::pi*x);
}
/* The zero-order modified Bessel function of the first kind, used for the
@@ -95,7 +95,7 @@ constexpr uint Gcd(uint x, uint y)
*/
constexpr uint CalcKaiserOrder(const double rejection, const double transition)
{
- const double w_t{2.0 * al::MathDefs<double>::Pi() * transition};
+ const double w_t{2.0 * al::numbers::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));