Replace macros with constexpr inline functions
This commit is contained in:
+5
-3
@@ -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.
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
@@ -447,8 +447,8 @@ inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread,
|
||||
inline float ScaleAzimuthFront(float azimuth, float scale)
|
||||
{
|
||||
ALfloat sign = std::copysign(1.0f, azimuth);
|
||||
if(!(std::fabs(azimuth) > F_PI_2))
|
||||
return minf(std::fabs(azimuth) * scale, F_PI_2) * sign;
|
||||
if(!(std::fabs(azimuth) > al::MathDefs<float>::Pi()*0.5f))
|
||||
return minf(std::fabs(azimuth) * scale, al::MathDefs<float>::Pi()*0.5f) * sign;
|
||||
return azimuth;
|
||||
}
|
||||
|
||||
|
||||
+22
-7
@@ -4,16 +4,31 @@
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI (3.14159265358979323846)
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#define F_PI (3.14159265358979323846f)
|
||||
#define F_PI_2 (1.57079632679489661923f)
|
||||
#define F_TAU (6.28318530717958647692f)
|
||||
|
||||
#define SQRTF_3 1.73205080756887719318f
|
||||
|
||||
constexpr inline float Deg2Rad(float x) noexcept { return x * static_cast<float>(M_PI/180.0); }
|
||||
constexpr inline float Rad2Deg(float x) noexcept { return x * static_cast<float>(180.0/M_PI); }
|
||||
|
||||
namespace al {
|
||||
|
||||
template<typename Real>
|
||||
struct MathDefs { };
|
||||
|
||||
template<>
|
||||
struct MathDefs<float> {
|
||||
static constexpr inline float Pi() noexcept { return 3.14159265358979323846f; }
|
||||
static constexpr inline float Tau() noexcept { return 3.14159265358979323846f * 2.0f; }
|
||||
static constexpr inline float Sqrt3() noexcept { return 1.73205080756887719318f; }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct MathDefs<double> {
|
||||
static constexpr inline double Pi() noexcept { return 3.14159265358979323846; }
|
||||
static constexpr inline double Tau() noexcept { return 3.14159265358979323846 * 2.0; }
|
||||
static constexpr inline double Sqrt3() noexcept { return 1.73205080756887719318; }
|
||||
};
|
||||
|
||||
} // namespace al
|
||||
|
||||
#endif /* AL_MATH_DEFS_H */
|
||||
|
||||
Reference in New Issue
Block a user