aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-01-27 02:59:07 -0800
committerChris Robinson <[email protected]>2022-01-27 02:59:07 -0800
commitf8ac1ffe805b13c8b1cd2bc4d4a8362cbe1c2cbe (patch)
treea8a24a3e85f7a8f00cf3947da37e97ab0f42d3f6
parent1bbea9cd3060ef65a2623f156b4f12ebf62c52fe (diff)
Get rid of MathDefs
-rw-r--r--al/source.cpp1
-rw-r--r--alc/alu.cpp21
-rw-r--r--alc/effects/autowah.cpp4
-rw-r--r--alc/effects/chorus.cpp4
-rw-r--r--alc/effects/distortion.cpp4
-rw-r--r--alc/effects/fshifter.cpp6
-rw-r--r--alc/effects/modulator.cpp4
-rw-r--r--alc/effects/pshifter.cpp10
-rw-r--r--alc/effects/reverb.cpp14
-rw-r--r--alc/effects/vmorpher.cpp6
-rw-r--r--alc/panning.cpp4
-rw-r--r--common/alnumbers.h4
-rw-r--r--common/math_defs.h23
-rw-r--r--common/polyphase_resampler.cpp8
-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
-rw-r--r--utils/uhjdecoder.cpp3
22 files changed, 81 insertions, 96 deletions
diff --git a/al/source.cpp b/al/source.cpp
index 5e34e1df..f7b07338 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -68,7 +68,6 @@
#include "core/voice_change.h"
#include "event.h"
#include "filter.h"
-#include "math_defs.h"
#include "opthelpers.h"
#include "ringbuffer.h"
#include "threads.h"
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 37d5a1ed..dbf4dedf 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -40,6 +40,7 @@
#include <utility>
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "alstring.h"
@@ -505,16 +506,16 @@ bool CalcEffectSlotParams(EffectSlot *slot, EffectSlot **sorted_slots, ContextBa
inline float ScaleAzimuthFront(float azimuth, float scale)
{
const float abs_azi{std::fabs(azimuth)};
- if(!(abs_azi >= al::MathDefs<float>::Pi()*0.5f))
- return std::copysign(minf(abs_azi*scale, al::MathDefs<float>::Pi()*0.5f), azimuth);
+ if(!(abs_azi >= al::numbers::pi_v<float>*0.5f))
+ return std::copysign(minf(abs_azi*scale, al::numbers::pi_v<float>*0.5f), azimuth);
return azimuth;
}
/* Wraps the given value in radians to stay between [-pi,+pi] */
inline float WrapRadians(float r)
{
- constexpr float Pi{al::MathDefs<float>::Pi()};
- constexpr float Pi2{al::MathDefs<float>::Tau()};
+ constexpr float Pi{al::numbers::pi_v<float>};
+ constexpr float Pi2{Pi*2.0f};
if(r > Pi) return std::fmod(Pi+r, Pi2) - Pi;
if(r < -Pi) return Pi - std::fmod(Pi-r, Pi2);
return r;
@@ -617,17 +618,18 @@ void AmbiRotator(std::array<std::array<float,MaxAmbiChannels>,MaxAmbiChannels> &
auto V = [P](const int l, const int m, const int n, const size_t last_band,
const std::array<std::array<float,MaxAmbiChannels>,MaxAmbiChannels> &R)
{
+ using namespace al::numbers;
if(m > 0)
{
const bool d{m == 1};
const float p0{P( 1, l, m-1, n, last_band, R)};
const float p1{P(-1, l, -m+1, n, last_band, R)};
- return d ? p0*std::sqrt(2.0f) : (p0 - p1);
+ return d ? p0*sqrt2_v<float> : (p0 - p1);
}
const bool d{m == -1};
const float p0{P( 1, l, m+1, n, last_band, R)};
const float p1{P(-1, l, -m-1, n, last_band, R)};
- return d ? p1*std::sqrt(2.0f) : (p0 + p1);
+ return d ? p1*sqrt2_v<float> : (p0 + p1);
};
auto W = [P](const int l, const int m, const int n, const size_t last_band,
const std::array<std::array<float,MaxAmbiChannels>,MaxAmbiChannels> &R)
@@ -816,7 +818,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
* panning.
*/
const float coverage{!(Distance > std::numeric_limits<float>::epsilon()) ? 1.0f :
- (Spread * (1.0f/al::MathDefs<float>::Tau()))};
+ (al::numbers::inv_pi_v<float>/2.0f * Spread)};
auto calc_coeffs = [xpos,ypos,zpos](RenderMode mode)
{
@@ -1388,7 +1390,8 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa
/* Calculate directional soundcones */
if(directional && props->InnerAngle < 360.0f)
{
- const float Angle{Rad2Deg(std::acos(-Direction.dot_product(ToSource)) * ConeScale * 2.0f)};
+ constexpr float Rad2Deg{5.72957795130823229e+01f/*180/pi*/};
+ const float Angle{Rad2Deg*2.0f * std::acos(-Direction.dot_product(ToSource)) * ConeScale};
float ConeGain, ConeHF;
if(!(Angle > props->InnerAngle))
@@ -1520,7 +1523,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa
float spread{0.0f};
if(props->Radius > Distance)
- spread = al::MathDefs<float>::Tau() - Distance/props->Radius*al::MathDefs<float>::Pi();
+ spread = al::numbers::pi_v<float>*2.0f - Distance/props->Radius*al::numbers::pi_v<float>;
else if(Distance > 0.0f)
spread = std::asin(props->Radius/Distance) * 2.0f;
diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp
index f496eb51..46cc8fb0 100644
--- a/alc/effects/autowah.cpp
+++ b/alc/effects/autowah.cpp
@@ -28,6 +28,7 @@
#include "alc/effects/base.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/ambidefs.h"
@@ -38,7 +39,6 @@
#include "core/effectslot.h"
#include "core/mixer.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
namespace {
@@ -159,7 +159,7 @@ void AutowahState::process(const size_t samplesToDo,
env_delay = lerp(sample, env_delay, a);
/* Calculate the cos and alpha components for this sample's filter. */
- w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * al::MathDefs<float>::Tau();
+ w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * (al::numbers::pi_v<float>*2.0f);
mEnv[i].cos_w0 = std::cos(w0);
mEnv[i].alpha = std::sin(w0)/(2.0f * QFactor);
}
diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp
index 7d32f8ff..99a2a68a 100644
--- a/alc/effects/chorus.cpp
+++ b/alc/effects/chorus.cpp
@@ -28,6 +28,7 @@
#include "alc/effects/base.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/bufferline.h"
@@ -39,7 +40,6 @@
#include "core/mixer/defs.h"
#include "core/resampler_limits.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
#include "opthelpers.h"
#include "vector.h"
@@ -150,7 +150,7 @@ void ChorusState::update(const ContextBase *Context, const EffectSlot *Slot,
mLfoScale = 4.0f / static_cast<float>(mLfoRange);
break;
case ChorusWaveform::Sinusoid:
- mLfoScale = al::MathDefs<float>::Tau() / static_cast<float>(mLfoRange);
+ mLfoScale = al::numbers::pi_v<float>*2.0f / static_cast<float>(mLfoRange);
break;
}
diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp
index c9366791..74cffd4a 100644
--- a/alc/effects/distortion.cpp
+++ b/alc/effects/distortion.cpp
@@ -27,6 +27,7 @@
#include "alc/effects/base.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/bufferline.h"
@@ -38,7 +39,6 @@
#include "core/mixer.h"
#include "core/mixer/defs.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
namespace {
@@ -77,7 +77,7 @@ void DistortionState::update(const ContextBase *context, const EffectSlot *slot,
const DeviceBase *device{context->mDevice};
/* Store waveshaper edge settings. */
- const float edge{minf(std::sin(al::MathDefs<float>::Pi()*0.5f * props->Distortion.Edge),
+ const float edge{minf(std::sin(al::numbers::pi_v<float>*0.5f * props->Distortion.Edge),
0.99f)};
mEdgeCoeff = 2.0f * edge / (1.0f-edge);
diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp
index b143db0c..def745c4 100644
--- a/alc/effects/fshifter.cpp
+++ b/alc/effects/fshifter.cpp
@@ -30,6 +30,7 @@
#include "alc/effects/base.h"
#include "alcomplex.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/bufferline.h"
@@ -40,7 +41,6 @@
#include "core/mixer.h"
#include "core/mixer/defs.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
namespace {
@@ -61,7 +61,7 @@ std::array<double,HIL_SIZE> InitHannWindow()
/* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */
for(size_t i{0};i < HIL_SIZE>>1;i++)
{
- constexpr double scale{al::MathDefs<double>::Pi() / double{HIL_SIZE}};
+ constexpr double scale{al::numbers::pi / double{HIL_SIZE}};
const double val{std::sin(static_cast<double>(i+1) * scale)};
ret[i] = ret[HIL_SIZE-1-i] = val * val;
}
@@ -217,7 +217,7 @@ void FshifterState::process(const size_t samplesToDo, const al::span<const Float
uint phase_idx{mPhase[c]};
for(size_t k{0};k < samplesToDo;++k)
{
- const double phase{phase_idx * ((1.0/MixerFracOne) * al::MathDefs<double>::Tau())};
+ const double phase{phase_idx * (al::numbers::pi*2.0 / MixerFracOne)};
BufferOut[k] = static_cast<float>(mOutdata[k].real()*std::cos(phase) +
mOutdata[k].imag()*std::sin(phase)*mSign[c]);
diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp
index 4a086b11..84561f5c 100644
--- a/alc/effects/modulator.cpp
+++ b/alc/effects/modulator.cpp
@@ -27,6 +27,7 @@
#include "alc/effects/base.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/ambidefs.h"
@@ -38,7 +39,6 @@
#include "core/filters/biquad.h"
#include "core/mixer.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
namespace {
@@ -53,7 +53,7 @@ using uint = unsigned int;
inline float Sin(uint index)
{
- constexpr float scale{al::MathDefs<float>::Tau() / WAVEFORM_FRACONE};
+ constexpr float scale{al::numbers::pi_v<float>*2.0f / WAVEFORM_FRACONE};
return std::sin(static_cast<float>(index) * scale);
}
diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp
index dae0a267..aa20c660 100644
--- a/alc/effects/pshifter.cpp
+++ b/alc/effects/pshifter.cpp
@@ -30,6 +30,7 @@
#include "alc/effects/base.h"
#include "alcomplex.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/bufferline.h"
@@ -39,7 +40,6 @@
#include "core/mixer.h"
#include "core/mixer/defs.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
struct ContextBase;
@@ -63,7 +63,7 @@ std::array<double,STFT_SIZE> InitHannWindow()
/* Create lookup table of the Hann window for the desired size, i.e. STFT_SIZE */
for(size_t i{0};i < STFT_SIZE>>1;i++)
{
- constexpr double scale{al::MathDefs<double>::Pi() / double{STFT_SIZE}};
+ constexpr double scale{al::numbers::pi / double{STFT_SIZE}};
const double val{std::sin(static_cast<double>(i+1) * scale)};
ret[i] = ret[STFT_SIZE-1-i] = val * val;
}
@@ -155,7 +155,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span<const Float
/* Cycle offset per update expected of each frequency bin (bin 0 is none,
* bin 1 is x1, bin 2 is x2, etc).
*/
- constexpr double expected_cycles{al::MathDefs<double>::Tau() / OVERSAMP};
+ constexpr double expected_cycles{al::numbers::pi*2.0 / OVERSAMP};
for(size_t base{0u};base < samplesToDo;)
{
@@ -198,8 +198,8 @@ void PshifterState::process(const size_t samplesToDo, const al::span<const Float
double tmp{(phase - mLastPhase[k]) - static_cast<double>(k)*expected_cycles};
/* Map delta phase into +/- Pi interval */
- int qpd{double2int(tmp / al::MathDefs<double>::Pi())};
- tmp -= al::MathDefs<double>::Pi() * (qpd + (qpd%2));
+ int qpd{double2int(tmp / al::numbers::pi)};
+ tmp -= al::numbers::pi * (qpd + (qpd%2));
/* Get deviation from bin frequency from the +/- Pi interval */
tmp /= expected_cycles;
diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp
index 379cc1fb..0b5e4edb 100644
--- a/alc/effects/reverb.cpp
+++ b/alc/effects/reverb.cpp
@@ -44,7 +44,6 @@
#include "core/mixer.h"
#include "core/mixer/defs.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
#include "opthelpers.h"
#include "vecmat.h"
#include "vector.h"
@@ -113,7 +112,7 @@ alignas(16) constexpr float EarlyA2B[NUM_LINES][NUM_LINES]{
};
/* Converts A-Format to B-Format for late reverb. */
-constexpr float Sqrt1_2{7.07106781e-01f/*1.0f/std::sqrt(2.0f)*/};
+constexpr auto Sqrt1_2 = static_cast<float>(1.0/al::numbers::sqrt2);
alignas(16) constexpr float LateA2B[NUM_LINES][NUM_LINES]{
{ 0.5f, 0.5f, 0.5f, 0.5f },
{ Sqrt1_2, -Sqrt1_2, 0.0f, 0.0f },
@@ -795,10 +794,8 @@ void T60Filter::calcCoeffs(const float length, const float lfDecayTime,
void EarlyReflections::updateLines(const float density_mult, const float diffusion,
const float decayTime, const float frequency)
{
- constexpr float sqrt1_2{0.70710678118654752440f/*1.0f/std::sqrt(2.0f)*/};
-
/* Calculate the all-pass feed-back/forward coefficient. */
- VecAp.Coeff = diffusion*diffusion * sqrt1_2;
+ VecAp.Coeff = diffusion*diffusion * Sqrt1_2;
for(size_t i{0u};i < NUM_LINES;i++)
{
@@ -888,8 +885,7 @@ void LateReverb::updateLines(const float density_mult, const float diffusion,
DensityGain[1] = CalcDensityGain(CalcDecayCoeff(length, decayTimeWeighted));
/* Calculate the all-pass feed-back/forward coefficient. */
- constexpr float sqrt1_2{0.70710678118654752440f/*1.0f/std::sqrt(2.0f)*/};
- VecAp.Coeff = diffusion*diffusion * sqrt1_2;
+ VecAp.Coeff = diffusion*diffusion * Sqrt1_2;
for(size_t i{0u};i < NUM_LINES;i++)
{
@@ -1431,7 +1427,7 @@ void ReverbState::earlyFaded(const size_t offset, const size_t todo, const float
void Modulation::calcDelays(size_t todo)
{
- constexpr float inv_scale{MOD_FRACONE / al::MathDefs<float>::Tau()};
+ constexpr float inv_scale{MOD_FRACONE / al::numbers::pi_v<float> / 2.0f};
uint idx{Index};
const uint step{Step};
const float depth{Depth[0]};
@@ -1446,7 +1442,7 @@ void Modulation::calcDelays(size_t todo)
void Modulation::calcFadedDelays(size_t todo, float fadeCount, float fadeStep)
{
- constexpr float inv_scale{MOD_FRACONE / al::MathDefs<float>::Tau()};
+ constexpr float inv_scale{MOD_FRACONE / al::numbers::pi_v<float> / 2.0f};
uint idx{Index};
const uint step{Step};
const float depth{Depth[0]};
diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp
index e3eed179..48cbb15e 100644
--- a/alc/effects/vmorpher.cpp
+++ b/alc/effects/vmorpher.cpp
@@ -40,6 +40,7 @@
#include "alc/effects/base.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/ambidefs.h"
@@ -50,7 +51,6 @@
#include "core/effectslot.h"
#include "core/mixer.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
namespace {
@@ -71,7 +71,7 @@ using uint = unsigned int;
inline float Sin(uint index)
{
- constexpr float scale{al::MathDefs<float>::Tau() / WAVEFORM_FRACONE};
+ constexpr float scale{al::numbers::pi_v<float>*2.0f / WAVEFORM_FRACONE};
return std::sin(static_cast<float>(index) * scale)*0.5f + 0.5f;
}
@@ -103,7 +103,7 @@ struct FormantFilter
FormantFilter() = default;
FormantFilter(float f0norm, float gain)
- : mCoeff{std::tan(al::MathDefs<float>::Pi() * f0norm)}, mGain{gain}
+ : mCoeff{std::tan(al::numbers::pi_v<float> * f0norm)}, mGain{gain}
{ }
inline void process(const float *samplesIn, float *samplesOut, const size_t numInput)
diff --git a/alc/panning.cpp b/alc/panning.cpp
index 90fbc9d4..3431a3f9 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -42,6 +42,7 @@
#include "alconfig.h"
#include "alc/context.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alnumeric.h"
#include "aloptional.h"
#include "alspan.h"
@@ -57,7 +58,6 @@
#include "core/logging.h"
#include "core/uhjfilter.h"
#include "device.h"
-#include "math_defs.h"
#include "opthelpers.h"
@@ -658,7 +658,7 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=
void InitHrtfPanning(ALCdevice *device)
{
- constexpr float Deg180{al::MathDefs<float>::Pi()};
+ constexpr float Deg180{al::numbers::pi_v<float>};
constexpr float Deg_90{Deg180 / 2.0f /* 90 degrees*/};
constexpr float Deg_45{Deg_90 / 2.0f /* 45 degrees*/};
constexpr float Deg135{Deg_45 * 3.0f /*135 degrees*/};
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));
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;
diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp
index 7bb1a51a..cd385e2b 100644
--- a/utils/uhjdecoder.cpp
+++ b/utils/uhjdecoder.cpp
@@ -37,6 +37,7 @@
#include "albyte.h"
#include "alcomplex.h"
#include "almalloc.h"
+#include "alnumbers.h"
#include "alspan.h"
#include "vector.h"
#include "opthelpers.h"
@@ -501,7 +502,7 @@ int main(int argc, char **argv)
for(size_t i{0};i < got;++i)
{
/* Attenuate by -3dB for FuMa output levels. */
- constexpr float sqrt1_2{0.707106781187f};
+ constexpr auto sqrt1_2 = static_cast<float>(1.0/al::numbers::sqrt2);
for(size_t j{0};j < outchans;++j)
outmem[i*outchans + j] = f32AsLEBytes(decmem[j][LeadIn+i] * sqrt1_2);
}