aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bformatdec.cpp10
-rw-r--r--core/bs2b.cpp6
-rw-r--r--core/bsinc_tables.cpp8
-rw-r--r--core/filters/biquad.cpp3
-rw-r--r--core/filters/biquad.h16
-rw-r--r--core/filters/splitter.cpp4
-rw-r--r--core/hrtf.cpp14
7 files changed, 31 insertions, 30 deletions
diff --git a/core/bformatdec.cpp b/core/bformatdec.cpp
index ed00566e..1ad46f95 100644
--- a/core/bformatdec.cpp
+++ b/core/bformatdec.cpp
@@ -9,9 +9,9 @@
#include <utility>
#include "almalloc.h"
+#include "alnumbers.h"
#include "filters/splitter.h"
#include "front_stablizer.h"
-#include "math_defs.h"
#include "mixer.h"
#include "opthelpers.h"
@@ -164,10 +164,10 @@ void BFormatDec::processStablize(const al::span<FloatBufferLine> OutBuffer,
* is panned 1/3rd toward center and the high-frequency signal is panned
* 1/4th toward center. These values can be tweaked.
*/
- const float cos_lf{std::cos(1.0f/3.0f * (al::MathDefs<float>::Pi()*0.5f))};
- const float cos_hf{std::cos(1.0f/4.0f * (al::MathDefs<float>::Pi()*0.5f))};
- const float sin_lf{std::sin(1.0f/3.0f * (al::MathDefs<float>::Pi()*0.5f))};
- const float sin_hf{std::sin(1.0f/4.0f * (al::MathDefs<float>::Pi()*0.5f))};
+ const float cos_lf{std::cos(1.0f/3.0f * (al::numbers::pi_v<float>*0.5f))};
+ const float cos_hf{std::cos(1.0f/4.0f * (al::numbers::pi_v<float>*0.5f))};
+ const float sin_lf{std::sin(1.0f/3.0f * (al::numbers::pi_v<float>*0.5f))};
+ const float sin_hf{std::sin(1.0f/4.0f * (al::numbers::pi_v<float>*0.5f))};
for(size_t i{0};i < SamplesToDo;i++)
{
const float m{mStablizer->MidLF[i]*cos_lf + mStablizer->MidHF[i]*cos_hf + mid[i]};
diff --git a/core/bs2b.cpp b/core/bs2b.cpp
index 00207bc0..303bf9bd 100644
--- a/core/bs2b.cpp
+++ b/core/bs2b.cpp
@@ -27,8 +27,8 @@
#include <cmath>
#include <iterator>
+#include "alnumbers.h"
#include "bs2b.h"
-#include "math_defs.h"
/* Set up all data. */
@@ -91,11 +91,11 @@ static void init(struct bs2b *bs2b)
* $d = 1 / 2 / pi / $fc;
* $x = exp(-1 / $d);
*/
- x = std::exp(-al::MathDefs<float>::Tau() * Fc_lo / static_cast<float>(bs2b->srate));
+ x = std::exp(-al::numbers::pi_v<float>*2.0f*Fc_lo/static_cast<float>(bs2b->srate));
bs2b->b1_lo = x;
bs2b->a0_lo = G_lo * (1.0f - x) * g;
- x = std::exp(-al::MathDefs<float>::Tau() * Fc_hi / static_cast<float>(bs2b->srate));
+ x = std::exp(-al::numbers::pi_v<float>*2.0f*Fc_hi/static_cast<float>(bs2b->srate));
bs2b->b1_hi = x;
bs2b->a0_hi = (1.0f - G_hi * (1.0f - x)) * g;
bs2b->a1_hi = -x * g;
diff --git a/core/bsinc_tables.cpp b/core/bsinc_tables.cpp
index ff73c301..a81167d2 100644
--- a/core/bsinc_tables.cpp
+++ b/core/bsinc_tables.cpp
@@ -9,8 +9,8 @@
#include <memory>
#include <stdexcept>
+#include "alnumbers.h"
#include "core/mixer/defs.h"
-#include "math_defs.h"
namespace {
@@ -28,7 +28,7 @@ constexpr double Sinc(const double x)
constexpr double epsilon{std::numeric_limits<double>::epsilon()};
if(!(x > epsilon || 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
@@ -87,9 +87,9 @@ constexpr double Kaiser(const double beta, const double k, const double besseli_
constexpr double CalcKaiserWidth(const double rejection, const uint order) noexcept
{
if(rejection > 21.19)
- return (rejection - 7.95) / (order * 2.285 * al::MathDefs<double>::Tau());
+ return (rejection - 7.95) / (2.285 * al::numbers::pi*2.0 * order);
/* This enforces a minimum rejection of just above 21.18dB */
- return 5.79 / (order * al::MathDefs<double>::Tau());
+ return 5.79 / (al::numbers::pi*2.0 * order);
}
/* Calculates the beta value of the Kaiser window. Rejection is in dB. */
diff --git a/core/filters/biquad.cpp b/core/filters/biquad.cpp
index fefdc8e1..470b1cd3 100644
--- a/core/filters/biquad.cpp
+++ b/core/filters/biquad.cpp
@@ -7,6 +7,7 @@
#include <cassert>
#include <cmath>
+#include "alnumbers.h"
#include "opthelpers.h"
@@ -16,7 +17,7 @@ void BiquadFilterR<Real>::setParams(BiquadType type, Real f0norm, Real gain, Rea
// Limit gain to -100dB
assert(gain > 0.00001f);
- const Real w0{al::MathDefs<Real>::Tau() * f0norm};
+ const Real w0{al::numbers::pi_v<Real>*2.0f * f0norm};
const Real sin_w0{std::sin(w0)};
const Real cos_w0{std::cos(w0)};
const Real alpha{sin_w0/2.0f * rcpQ};
diff --git a/core/filters/biquad.h b/core/filters/biquad.h
index b2e2cfdb..75a4009b 100644
--- a/core/filters/biquad.h
+++ b/core/filters/biquad.h
@@ -6,8 +6,8 @@
#include <cstddef>
#include <utility>
+#include "alnumbers.h"
#include "alspan.h"
-#include "math_defs.h"
/* Filters implementation is based on the "Cookbook formulae for audio
@@ -40,11 +40,11 @@ enum class BiquadType {
template<typename Real>
class BiquadFilterR {
/* Last two delayed components for direct form II. */
- Real mZ1{0.0f}, mZ2{0.0f};
+ Real mZ1{0}, mZ2{0};
/* Transfer function coefficients "b" (numerator) */
- Real mB0{1.0f}, mB1{0.0f}, mB2{0.0f};
+ Real mB0{1}, mB1{0}, mB2{0};
/* Transfer function coefficients "a" (denominator; a0 is pre-applied). */
- Real mA1{0.0f}, mA2{0.0f};
+ Real mA1{0}, mA2{0};
void setParams(BiquadType type, Real f0norm, Real gain, Real rcpQ);
@@ -55,7 +55,7 @@ class BiquadFilterR {
* \param slope 0 < slope <= 1
*/
static Real rcpQFromSlope(Real gain, Real slope)
- { return std::sqrt((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f); }
+ { return std::sqrt((gain + Real{1}/gain)*(Real{1}/slope - Real{1}) + Real{2}); }
/**
* Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the
@@ -65,12 +65,12 @@ class BiquadFilterR {
*/
static Real rcpQFromBandwidth(Real f0norm, Real bandwidth)
{
- const Real w0{al::MathDefs<Real>::Tau() * f0norm};
- return 2.0f*std::sinh(std::log(Real{2.0f})/2.0f*bandwidth*w0/std::sin(w0));
+ const Real w0{al::numbers::pi_v<Real>*Real{2} * f0norm};
+ return 2.0f*std::sinh(std::log(Real{2})/Real{2}*bandwidth*w0/std::sin(w0));
}
public:
- void clear() noexcept { mZ1 = mZ2 = 0.0f; }
+ void clear() noexcept { mZ1 = mZ2 = Real{0}; }
/**
* Sets the filter state for the specified filter type and its parameters.
diff --git a/core/filters/splitter.cpp b/core/filters/splitter.cpp
index 8ebc482f..5ffe51e1 100644
--- a/core/filters/splitter.cpp
+++ b/core/filters/splitter.cpp
@@ -7,14 +7,14 @@
#include <cmath>
#include <limits>
-#include "math_defs.h"
+#include "alnumbers.h"
#include "opthelpers.h"
template<typename Real>
void BandSplitterR<Real>::init(Real f0norm)
{
- const Real w{f0norm * al::MathDefs<Real>::Tau()};
+ const Real w{f0norm * (al::numbers::pi_v<Real>*2)};
const Real cw{std::cos(w)};
if(cw > std::numeric_limits<float>::epsilon())
mCoeff = (std::sin(w) - 1.0f) / cw;
diff --git a/core/hrtf.cpp b/core/hrtf.cpp
index 74483c26..e8d3310a 100644
--- a/core/hrtf.cpp
+++ b/core/hrtf.cpp
@@ -23,6 +23,7 @@
#include "albyte.h"
#include "alfstream.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "aloptional.h"
#include "alspan.h"
@@ -30,7 +31,6 @@
#include "filters/splitter.h"
#include "helpers.h"
#include "logging.h"
-#include "math_defs.h"
#include "mixer/hrtfdefs.h"
#include "opthelpers.h"
#include "polyphase_resampler.h"
@@ -79,7 +79,7 @@ constexpr char magicMarker03[8]{'M','i','n','P','H','R','0','3'};
/* First value for pass-through coefficients (remaining are 0), used for omni-
* directional sounds. */
-constexpr float PassthruCoeff{0.707106781187f/*sqrt(0.5)*/};
+constexpr auto PassthruCoeff = static_cast<float>(1.0/al::numbers::sqrt2);
std::mutex LoadedHrtfLock;
al::vector<LoadedHrtf> LoadedHrtfs;
@@ -164,8 +164,8 @@ struct IdxBlend { uint idx; float blend; };
*/
IdxBlend CalcEvIndex(uint evcount, float ev)
{
- ev = (al::MathDefs<float>::Pi()*0.5f + ev) * static_cast<float>(evcount-1) /
- al::MathDefs<float>::Pi();
+ ev = (al::numbers::pi_v<float>*0.5f + ev) * static_cast<float>(evcount-1) /
+ al::numbers::pi_v<float>;
uint idx{float2uint(ev)};
return IdxBlend{minu(idx, evcount-1), ev-static_cast<float>(idx)};
@@ -176,8 +176,8 @@ IdxBlend CalcEvIndex(uint evcount, float ev)
*/
IdxBlend CalcAzIndex(uint azcount, float az)
{
- az = (al::MathDefs<float>::Tau()+az) * static_cast<float>(azcount) /
- al::MathDefs<float>::Tau();
+ az = (al::numbers::pi_v<float>*2.0f + az) * static_cast<float>(azcount) /
+ (al::numbers::pi_v<float>*2.0f);
uint idx{float2uint(az)};
return IdxBlend{idx%azcount, az-static_cast<float>(idx)};
@@ -192,7 +192,7 @@ IdxBlend CalcAzIndex(uint azcount, float az)
void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
float spread, HrirArray &coeffs, const al::span<uint,2> delays)
{
- const float dirfact{1.0f - (spread / al::MathDefs<float>::Tau())};
+ const float dirfact{1.0f - (al::numbers::inv_pi_v<float>/2.0f * spread)};
const auto *field = Hrtf->field;
const auto *field_end = field + Hrtf->fdCount-1;