diff options
author | Chris Robinson <[email protected]> | 2019-01-06 04:16:51 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-06 04:16:51 -0800 |
commit | da3a916042a7ba9426af1d6f03e689dbd7760191 (patch) | |
tree | ab6cfc0d2fd26504a013989af7ecd399a4034914 /Alc | |
parent | 98f3e6a16295029129193a073680a70c034703dd (diff) |
Replace macros with constexpr inline functions
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alu.cpp | 8 | ||||
-rw-r--r-- | Alc/bs2b.cpp | 4 | ||||
-rw-r--r-- | Alc/effects/autowah.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/chorus.cpp | 6 | ||||
-rw-r--r-- | Alc/effects/distortion.cpp | 3 | ||||
-rw-r--r-- | Alc/effects/echo.cpp | 4 | ||||
-rw-r--r-- | Alc/effects/fshifter.cpp | 8 | ||||
-rw-r--r-- | Alc/effects/modulator.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/pshifter.cpp | 8 | ||||
-rw-r--r-- | Alc/effects/reverb.cpp | 12 | ||||
-rw-r--r-- | Alc/filters/biquad.cpp | 2 | ||||
-rw-r--r-- | Alc/filters/biquad.h | 4 | ||||
-rw-r--r-- | Alc/filters/splitter.cpp | 4 | ||||
-rw-r--r-- | Alc/hrtf.cpp | 6 | ||||
-rw-r--r-- | Alc/panning.cpp | 8 |
15 files changed, 42 insertions, 39 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 58247631..e5fa0c89 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -1390,7 +1390,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A ALfloat spread{0.0f}; if(props->Radius > Distance) - spread = F_TAU - Distance/props->Radius*F_PI; + spread = al::MathDefs<float>::Tau() - Distance/props->Radius*al::MathDefs<float>::Pi(); else if(Distance > 0.0f) spread = std::asin(props->Radius/Distance) * 2.0f; @@ -1571,8 +1571,10 @@ void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*RESTRICT Buffer)[BUFFER * frequency sum is 1/4th toward center (3/4ths on left/right). These * values can be tweaked. */ - ALfloat m{lfsum*std::cos(1.0f/3.0f * F_PI_2) + hfsum*std::cos(1.0f/4.0f * F_PI_2)}; - ALfloat c{lfsum*std::sin(1.0f/3.0f * F_PI_2) + hfsum*std::sin(1.0f/4.0f * F_PI_2)}; + ALfloat m{lfsum*std::cos(1.0f/3.0f * (al::MathDefs<float>::Pi()*0.5f)) + + hfsum*std::cos(1.0f/4.0f * (al::MathDefs<float>::Pi()*0.5f))}; + ALfloat c{lfsum*std::sin(1.0f/3.0f * (al::MathDefs<float>::Pi()*0.5f)) + + hfsum*std::sin(1.0f/4.0f * (al::MathDefs<float>::Pi()*0.5f))}; /* The generated center channel signal adds to the existing signal, * while the modified left and right channels replace. diff --git a/Alc/bs2b.cpp b/Alc/bs2b.cpp index b1833b8c..2d1b96aa 100644 --- a/Alc/bs2b.cpp +++ b/Alc/bs2b.cpp @@ -91,11 +91,11 @@ static void init(struct bs2b *bs2b) * $d = 1 / 2 / pi / $fc; * $x = exp(-1 / $d); */ - x = std::exp(-2.0f * F_PI * Fc_lo / bs2b->srate); + x = std::exp(-al::MathDefs<float>::Tau() * Fc_lo / bs2b->srate); bs2b->b1_lo = x; bs2b->a0_lo = G_lo * (1.0f - x) * g; - x = std::exp(-2.0f * F_PI * Fc_hi / bs2b->srate); + x = std::exp(-al::MathDefs<float>::Tau() * Fc_hi / 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/Alc/effects/autowah.cpp b/Alc/effects/autowah.cpp index b116cc0f..7df5d49e 100644 --- a/Alc/effects/autowah.cpp +++ b/Alc/effects/autowah.cpp @@ -150,7 +150,7 @@ void ALautowahState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT Sampl 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) * F_TAU; + w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * al::MathDefs<float>::Tau(); mEnv[i].cos_w0 = cosf(w0); mEnv[i].alpha = sinf(w0)/(2.0f * Q_FACTOR); } diff --git a/Alc/effects/chorus.cpp b/Alc/effects/chorus.cpp index 1a89a015..1132a33a 100644 --- a/Alc/effects/chorus.cpp +++ b/Alc/effects/chorus.cpp @@ -147,8 +147,8 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co /* Gains for left and right sides */ ALfloat coeffs[2][MAX_AMBI_COEFFS]; - CalcAngleCoeffs(-F_PI_2, 0.0f, 0.0f, coeffs[0]); - CalcAngleCoeffs( F_PI_2, 0.0f, 0.0f, coeffs[1]); + CalcAngleCoeffs(al::MathDefs<float>::Pi()*-0.5f, 0.0f, 0.0f, coeffs[0]); + CalcAngleCoeffs(al::MathDefs<float>::Pi()* 0.5f, 0.0f, 0.0f, coeffs[1]); mOutBuffer = target.Main->Buffer; mOutChannels = target.Main->NumChannels; @@ -178,7 +178,7 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co mLfoScale = 4.0f / mLfoRange; break; case WaveForm::Sinusoid: - mLfoScale = F_TAU / mLfoRange; + mLfoScale = al::MathDefs<float>::Tau() / mLfoRange; break; } diff --git a/Alc/effects/distortion.cpp b/Alc/effects/distortion.cpp index e54ae455..1b9c66fa 100644 --- a/Alc/effects/distortion.cpp +++ b/Alc/effects/distortion.cpp @@ -65,7 +65,8 @@ void ALdistortionState::update(const ALCcontext *context, const ALeffectslot *sl const ALCdevice *device{context->Device}; /* Store waveshaper edge settings. */ - const ALfloat edge{minf(std::sin(props->Distortion.Edge * F_PI_2), 0.99f)}; + const ALfloat edge{ + minf(std::sin(al::MathDefs<float>::Pi()*0.5f * props->Distortion.Edge), 0.99f)}; mEdgeCoeff = 2.0f * edge / (1.0f-edge); ALfloat cutoff{props->Distortion.LowpassCutoff}; diff --git a/Alc/effects/echo.cpp b/Alc/effects/echo.cpp index b774052a..697d2e88 100644 --- a/Alc/effects/echo.cpp +++ b/Alc/effects/echo.cpp @@ -116,8 +116,8 @@ void ALechoState::update(const ALCcontext *context, const ALeffectslot *slot, co ); ALfloat coeffs[2][MAX_AMBI_COEFFS]; - CalcAngleCoeffs(-F_PI_2*lrpan, 0.0f, spread, coeffs[0]); - CalcAngleCoeffs( F_PI_2*lrpan, 0.0f, spread, coeffs[1]); + CalcAngleCoeffs(al::MathDefs<float>::Pi()*-0.5f*lrpan, 0.0f, spread, coeffs[0]); + CalcAngleCoeffs(al::MathDefs<float>::Pi()* 0.5f*lrpan, 0.0f, spread, coeffs[1]); mOutBuffer = target.Main->Buffer; mOutChannels = target.Main->NumChannels; diff --git a/Alc/effects/fshifter.cpp b/Alc/effects/fshifter.cpp index 9b8499cf..c444872c 100644 --- a/Alc/effects/fshifter.cpp +++ b/Alc/effects/fshifter.cpp @@ -52,7 +52,7 @@ std::array<ALdouble,HIL_SIZE> InitHannWindow(void) /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(ALsizei i{0};i < HIL_SIZE>>1;i++) { - ALdouble val = std::sin(M_PI * (ALdouble)i / (ALdouble)(HIL_SIZE-1)); + ALdouble val = std::sin(al::MathDefs<double>::Pi() * i / ALdouble{HIL_SIZE-1}); ret[i] = ret[HIL_SIZE-1-i] = val * val; } return ret; @@ -140,13 +140,13 @@ void ALfshifterState::update(const ALCcontext *context, const ALeffectslot *slot void ALfshifterState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { - static const complex_d complex_zero{0.0, 0.0}; + static constexpr complex_d complex_zero{0.0, 0.0}; ALfloat *RESTRICT BufferOut = mBufferOut; ALsizei j, k, base; for(base = 0;base < SamplesToDo;) { - ALsizei todo = mini(HIL_SIZE-mCount, SamplesToDo-base); + const ALsizei todo{mini(HIL_SIZE-mCount, SamplesToDo-base)}; ASSUME(todo > 0); @@ -189,7 +189,7 @@ void ALfshifterState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT Samp /* Process frequency shifter using the analytic signal obtained. */ for(k = 0;k < SamplesToDo;k++) { - double phase = mPhase * ((1.0/FRACTIONONE) * 2.0*M_PI); + double phase = mPhase * ((1.0/FRACTIONONE) * al::MathDefs<double>::Tau()); BufferOut[k] = (float)(mOutdata[k].real()*std::cos(phase) + mOutdata[k].imag()*std::sin(phase)*mLdSign); diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp index 889d6a86..3544188b 100644 --- a/Alc/effects/modulator.cpp +++ b/Alc/effects/modulator.cpp @@ -43,7 +43,7 @@ static inline ALfloat Sin(ALsizei index) { - return std::sin((ALfloat)index * (F_TAU / (ALfloat)WAVEFORM_FRACONE)); + return std::sin((ALfloat)index * (al::MathDefs<float>::Tau() / (ALfloat)WAVEFORM_FRACONE)); } static inline ALfloat Saw(ALsizei index) diff --git a/Alc/effects/pshifter.cpp b/Alc/effects/pshifter.cpp index a70fae52..8d82b07e 100644 --- a/Alc/effects/pshifter.cpp +++ b/Alc/effects/pshifter.cpp @@ -84,7 +84,7 @@ std::array<ALdouble,STFT_SIZE> InitHannWindow(void) /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(ALsizei i{0};i < STFT_SIZE>>1;i++) { - ALdouble val = std::sin(M_PI * (ALdouble)i / (ALdouble)(STFT_SIZE-1)); + ALdouble val = std::sin(al::MathDefs<double>::Pi() * i / ALdouble{STFT_SIZE-1}); ret[i] = ret[STFT_SIZE-1-i] = val * val; } return ret; @@ -195,7 +195,7 @@ void ALpshifterState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT Samp * http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ */ - static constexpr ALdouble expected{M_PI*2.0 / OVERSAMP}; + static constexpr ALdouble expected{al::MathDefs<double>::Tau() / OVERSAMP}; const ALdouble freq_per_bin{mFreqPerBin}; ALfloat *RESTRICT bufferOut{mBufferOut}; ALsizei count{mCount}; @@ -237,8 +237,8 @@ void ALpshifterState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT Samp double tmp{(component.Phase - mLastPhase[k]) - k*expected}; /* Map delta phase into +/- Pi interval */ - int qpd{double2int(tmp / M_PI)}; - tmp -= M_PI * (qpd + (qpd%2)); + int qpd{double2int(tmp / al::MathDefs<double>::Pi())}; + tmp -= al::MathDefs<double>::Pi() * (qpd + (qpd%2)); /* Get deviation from bin frequency from the +/- Pi interval */ tmp /= expected; diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp index 9bc4f8f2..6f1b1bb1 100644 --- a/Alc/effects/reverb.cpp +++ b/Alc/effects/reverb.cpp @@ -738,9 +738,9 @@ alu::Matrix GetTransformFromVector(const ALfloat *vec) ALfloat mag{std::sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2])}; if(mag > 1.0f) { - norm[0] = vec[0] / mag * -SQRTF_3; - norm[1] = vec[1] / mag * SQRTF_3; - norm[2] = vec[2] / mag * SQRTF_3; + norm[0] = vec[0] / mag * -al::MathDefs<float>::Sqrt3(); + norm[1] = vec[1] / mag * al::MathDefs<float>::Sqrt3(); + norm[2] = vec[2] / mag * al::MathDefs<float>::Sqrt3(); mag = 1.0f; } else @@ -749,9 +749,9 @@ alu::Matrix GetTransformFromVector(const ALfloat *vec) * term. There's no need to renormalize the magnitude since it would * just be reapplied in the matrix. */ - norm[0] = vec[0] * -SQRTF_3; - norm[1] = vec[1] * SQRTF_3; - norm[2] = vec[2] * SQRTF_3; + norm[0] = vec[0] * -al::MathDefs<float>::Sqrt3(); + norm[1] = vec[1] * al::MathDefs<float>::Sqrt3(); + norm[2] = vec[2] * al::MathDefs<float>::Sqrt3(); } return alu::Matrix{ diff --git a/Alc/filters/biquad.cpp b/Alc/filters/biquad.cpp index b010ebed..e4b7bec0 100644 --- a/Alc/filters/biquad.cpp +++ b/Alc/filters/biquad.cpp @@ -16,7 +16,7 @@ void BiquadFilterR<Real>::setParams(BiquadType type, Real gain, Real f0norm, Rea // Limit gain to -100dB assert(gain > 0.00001f); - const Real w0{F_TAU * f0norm}; + const Real w0{al::MathDefs<Real>::Tau() * 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/Alc/filters/biquad.h b/Alc/filters/biquad.h index a7d830a2..57edd782 100644 --- a/Alc/filters/biquad.h +++ b/Alc/filters/biquad.h @@ -124,13 +124,13 @@ inline double calc_rcpQ_from_slope(double gain, double slope) */ inline float calc_rcpQ_from_bandwidth(float f0norm, float bandwidth) { - const float w0{F_TAU * f0norm}; + const float w0{al::MathDefs<float>::Tau() * f0norm}; return 2.0f*std::sinh(std::log(2.0f)/2.0f*bandwidth*w0/std::sin(w0)); } inline double calc_rcpQ_from_bandwidth(double f0norm, double bandwidth) { - const double w0{F_TAU * f0norm}; + const double w0{al::MathDefs<double>::Tau() * f0norm}; return 2.0*std::sinh(std::log(2.0)/2.0*bandwidth*w0/std::sin(w0)); } diff --git a/Alc/filters/splitter.cpp b/Alc/filters/splitter.cpp index 27ea697a..0f099661 100644 --- a/Alc/filters/splitter.cpp +++ b/Alc/filters/splitter.cpp @@ -12,7 +12,7 @@ void BandSplitter::init(float f0norm) { - float w = f0norm * F_TAU; + float w = f0norm * al::MathDefs<float>::Tau(); float cw = std::cos(w); if(cw > std::numeric_limits<float>::epsilon()) coeff = (std::sin(w) - 1.0f) / cw; @@ -62,7 +62,7 @@ void BandSplitter::process(float *RESTRICT hpout, float *RESTRICT lpout, const f void SplitterAllpass::init(float f0norm) { - float w = f0norm * F_TAU; + float w = f0norm * al::MathDefs<float>::Tau(); float cw = std::cos(w); if(cw > std::numeric_limits<float>::epsilon()) coeff = (std::sin(w) - 1.0f) / cw; diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 8b32989d..7f4668de 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -160,7 +160,7 @@ public: */ ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu) { - ev = (F_PI_2+ev) * (evcount-1) / F_PI; + ev = (al::MathDefs<float>::Pi()*0.5f + ev) * (evcount-1) / al::MathDefs<float>::Pi(); ALsizei idx{float2int(ev)}; *mu = ev - idx; @@ -172,7 +172,7 @@ ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu) */ ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) { - az = (F_TAU+az) * azcount / F_TAU; + az = (al::MathDefs<float>::Tau()+az) * azcount / al::MathDefs<float>::Tau(); ALsizei idx{float2int(az)}; *mu = az - idx; @@ -188,7 +188,7 @@ ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays) { - const ALfloat dirfact{1.0f - (spread / F_TAU)}; + const ALfloat dirfact{1.0f - (spread / al::MathDefs<float>::Tau())}; /* Claculate the lower elevation index. */ ALfloat emu; diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 8de52308..f934aabd 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -752,9 +752,9 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf /* Zeroth-order */ coeffs[0] = 1.0f; /* ACN 0 = 1 */ /* First-order */ - coeffs[1] = SQRTF_3 * y; /* ACN 1 = sqrt(3) * Y */ - coeffs[2] = SQRTF_3 * z; /* ACN 2 = sqrt(3) * Z */ - coeffs[3] = SQRTF_3 * x; /* ACN 3 = sqrt(3) * X */ + coeffs[1] = 1.732050808f * y; /* ACN 1 = sqrt(3) * Y */ + coeffs[2] = 1.732050808f * z; /* ACN 2 = sqrt(3) * Z */ + coeffs[3] = 1.732050808f * x; /* ACN 3 = sqrt(3) * X */ /* Second-order */ coeffs[4] = 3.872983346f * x * y; /* ACN 4 = sqrt(15) * X * Y */ coeffs[5] = 3.872983346f * y * z; /* ACN 5 = sqrt(15) * Y * Z */ @@ -808,7 +808,7 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf */ ALfloat ca = std::cos(spread * 0.5f); /* Increase the source volume by up to +3dB for a full spread. */ - ALfloat scale = std::sqrt(1.0f + spread/F_TAU); + ALfloat scale = std::sqrt(1.0f + spread/al::MathDefs<float>::Tau()); ALfloat ZH0_norm = scale; ALfloat ZH1_norm = 0.5f * (ca+1.f) * scale; |