aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-22 16:01:14 -0800
committerChris Robinson <[email protected]>2018-12-22 16:01:14 -0800
commit334b3a905a1a387d5fb5f74483a7520bb5d5449a (patch)
tree8f6aa333bb1b4eecbf9bcfe3f3f972c895345480
parentd4d98e2fe9820f390515baf581dea7dc9bec1431 (diff)
Clean up some math stuff
-rw-r--r--Alc/alu.cpp65
-rw-r--r--Alc/filters/splitter.cpp5
-rw-r--r--Alc/mastering.cpp3
-rw-r--r--Alc/mixer/mixer_c.cpp4
-rw-r--r--Alc/mixer/mixer_neon.cpp4
-rw-r--r--Alc/mixer/mixer_sse.cpp4
-rw-r--r--OpenAL32/Include/alu.h35
-rw-r--r--OpenAL32/alSource.cpp4
-rw-r--r--common/math_defs.h23
-rw-r--r--common/vecmat.h3
10 files changed, 70 insertions, 80 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp
index a2c930fc..a6e53f4b 100644
--- a/Alc/alu.cpp
+++ b/Alc/alu.cpp
@@ -27,6 +27,7 @@
#include <assert.h>
#include <cmath>
+#include <limits>
#include <algorithm>
#include "alMain.h"
@@ -437,37 +438,37 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force)
constexpr struct ChanMap MonoMap[1]{
{ FrontCenter, 0.0f, 0.0f }
}, RearMap[2]{
- { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) }
+ { BackLeft, Deg2Rad(-150.0f), Deg2Rad(0.0f) },
+ { BackRight, Deg2Rad( 150.0f), Deg2Rad(0.0f) }
}, QuadMap[4]{
- { FrontLeft, DEG2RAD( -45.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 45.0f), DEG2RAD(0.0f) },
- { BackLeft, DEG2RAD(-135.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 135.0f), DEG2RAD(0.0f) }
+ { FrontLeft, Deg2Rad( -45.0f), Deg2Rad(0.0f) },
+ { FrontRight, Deg2Rad( 45.0f), Deg2Rad(0.0f) },
+ { BackLeft, Deg2Rad(-135.0f), Deg2Rad(0.0f) },
+ { BackRight, Deg2Rad( 135.0f), Deg2Rad(0.0f) }
}, X51Map[6]{
- { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { FrontLeft, Deg2Rad( -30.0f), Deg2Rad(0.0f) },
+ { FrontRight, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
+ { FrontCenter, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
{ LFE, 0.0f, 0.0f },
- { SideLeft, DEG2RAD(-110.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 110.0f), DEG2RAD(0.0f) }
+ { SideLeft, Deg2Rad(-110.0f), Deg2Rad(0.0f) },
+ { SideRight, Deg2Rad( 110.0f), Deg2Rad(0.0f) }
}, X61Map[7]{
- { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { FrontLeft, Deg2Rad(-30.0f), Deg2Rad(0.0f) },
+ { FrontRight, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
+ { FrontCenter, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
{ LFE, 0.0f, 0.0f },
- { BackCenter, DEG2RAD(180.0f), DEG2RAD(0.0f) },
- { SideLeft, DEG2RAD(-90.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
+ { BackCenter, Deg2Rad(180.0f), Deg2Rad(0.0f) },
+ { SideLeft, Deg2Rad(-90.0f), Deg2Rad(0.0f) },
+ { SideRight, Deg2Rad( 90.0f), Deg2Rad(0.0f) }
}, X71Map[8]{
- { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { FrontLeft, Deg2Rad( -30.0f), Deg2Rad(0.0f) },
+ { FrontRight, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
+ { FrontCenter, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
{ LFE, 0.0f, 0.0f },
- { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) },
- { SideLeft, DEG2RAD( -90.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
+ { BackLeft, Deg2Rad(-150.0f), Deg2Rad(0.0f) },
+ { BackRight, Deg2Rad( 150.0f), Deg2Rad(0.0f) },
+ { SideLeft, Deg2Rad( -90.0f), Deg2Rad(0.0f) },
+ { SideRight, Deg2Rad( 90.0f), Deg2Rad(0.0f) }
};
void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev,
@@ -480,8 +481,8 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
const ALCdevice *Device)
{
ChanMap StereoMap[2]{
- { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) }
+ { FrontLeft, Deg2Rad(-30.0f), Deg2Rad(0.0f) },
+ { FrontRight, Deg2Rad( 30.0f), Deg2Rad(0.0f) }
};
bool DirectChannels{props->DirectChannels != AL_FALSE};
@@ -576,7 +577,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
{
/* Special handling for B-Format sources. */
- if(Distance > FLT_EPSILON)
+ if(Distance > std::numeric_limits<float>::epsilon())
{
/* Panning a B-Format sound toward some direction is easy. Just pan
* the first (W) channel as a normal mono sound and silence the
@@ -733,7 +734,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
voice->Direct.Buffer = Device->RealOut.Buffer;
voice->Direct.Channels = Device->RealOut.NumChannels;
- if(Distance > FLT_EPSILON)
+ if(Distance > std::numeric_limits<float>::epsilon())
{
/* Get the HRIR coefficients and delays just once, for the given
* source direction.
@@ -811,7 +812,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
{
/* Non-HRTF rendering. Use normal panning to the output. */
- if(Distance > FLT_EPSILON)
+ if(Distance > std::numeric_limits<float>::epsilon())
{
/* Calculate NFC filter coefficient if needed. */
if(Device->AvgSpeakerDist > 0.0f)
@@ -1206,8 +1207,8 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
/* Calculate directional soundcones */
if(directional && props->InnerAngle < 360.0f)
{
- ALfloat Angle{std::acos(aluDotproduct(Direction, SourceToListener))};
- Angle = RAD2DEG(Angle * ConeScale * 2.0f);
+ const ALfloat Angle{Rad2Deg(std::acos(aluDotproduct(Direction, SourceToListener)) *
+ ConeScale * 2.0f)};
ALfloat ConeVolume, ConeHF;
if(!(Angle > props->InnerAngle))
@@ -1322,7 +1323,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
/* Source moving toward the listener at the speed of sound. Sound
* waves bunch up to extreme frequencies.
*/
- Pitch = HUGE_VALF;
+ Pitch = std::numeric_limits<float>::infinity();
}
else
{
diff --git a/Alc/filters/splitter.cpp b/Alc/filters/splitter.cpp
index 18518dbb..27ea697a 100644
--- a/Alc/filters/splitter.cpp
+++ b/Alc/filters/splitter.cpp
@@ -4,6 +4,7 @@
#include "splitter.h"
#include <cmath>
+#include <limits>
#include <algorithm>
#include "math_defs.h"
@@ -13,7 +14,7 @@ void BandSplitter::init(float f0norm)
{
float w = f0norm * F_TAU;
float cw = std::cos(w);
- if(cw > FLT_EPSILON)
+ if(cw > std::numeric_limits<float>::epsilon())
coeff = (std::sin(w) - 1.0f) / cw;
else
coeff = cw * -0.5f;
@@ -63,7 +64,7 @@ void SplitterAllpass::init(float f0norm)
{
float w = f0norm * F_TAU;
float cw = std::cos(w);
- if(cw > FLT_EPSILON)
+ if(cw > std::numeric_limits<float>::epsilon())
coeff = (std::sin(w) - 1.0f) / cw;
else
coeff = cw * -0.5f;
diff --git a/Alc/mastering.cpp b/Alc/mastering.cpp
index 91ea207b..bdd67aa4 100644
--- a/Alc/mastering.cpp
+++ b/Alc/mastering.cpp
@@ -1,6 +1,7 @@
#include "config.h"
#include <cmath>
+#include <limits>
#include <algorithm>
#include <functional>
@@ -395,7 +396,7 @@ Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
if(hold > 1)
{
Comp->Hold = new ((void*)(Comp + 1)) SlidingHold{};
- Comp->Hold->Values[0] = -HUGE_VALF;
+ Comp->Hold->Values[0] = -std::numeric_limits<float>::infinity();
Comp->Hold->Expiries[0] = hold;
Comp->Hold->Length = hold;
Comp->Delay = (ALfloat(*)[BUFFERSIZE])(Comp->Hold + 1);
diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp
index 99d3e343..7a2a6319 100644
--- a/Alc/mixer/mixer_c.cpp
+++ b/Alc/mixer/mixer_c.cpp
@@ -2,6 +2,8 @@
#include <assert.h>
+#include <limits>
+
#include "alMain.h"
#include "alu.h"
#include "alSource.h"
@@ -137,7 +139,7 @@ void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[
ALfloat gain = CurrentGains[c];
const ALfloat diff = TargetGains[c] - gain;
- if(fabsf(diff) > FLT_EPSILON)
+ if(fabsf(diff) > std::numeric_limits<float>::epsilon())
{
ALsizei minsize = mini(BufferSize, Counter);
const ALfloat step = diff * delta;
diff --git a/Alc/mixer/mixer_neon.cpp b/Alc/mixer/mixer_neon.cpp
index f7fe57d1..fa777eac 100644
--- a/Alc/mixer/mixer_neon.cpp
+++ b/Alc/mixer/mixer_neon.cpp
@@ -2,6 +2,8 @@
#include <arm_neon.h>
+#include <limits>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "alMain.h"
@@ -182,7 +184,7 @@ void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffe
ALfloat gain = CurrentGains[c];
const ALfloat diff = TargetGains[c] - gain;
- if(fabsf(diff) > FLT_EPSILON)
+ if(fabsf(diff) > std::numeric_limits<float>::epsilon())
{
ALsizei minsize = mini(BufferSize, Counter);
const ALfloat step = diff * delta;
diff --git a/Alc/mixer/mixer_sse.cpp b/Alc/mixer/mixer_sse.cpp
index 000196ca..f0620cb5 100644
--- a/Alc/mixer/mixer_sse.cpp
+++ b/Alc/mixer/mixer_sse.cpp
@@ -2,6 +2,8 @@
#include <xmmintrin.h>
+#include <limits>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "alMain.h"
@@ -151,7 +153,7 @@ void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer
ALfloat gain = CurrentGains[c];
const ALfloat diff = TargetGains[c] - gain;
- if(fabsf(diff) > FLT_EPSILON)
+ if(fabsf(diff) > std::numeric_limits<float>::epsilon())
{
ALsizei minsize = mini(BufferSize, Counter);
const ALfloat step = diff * delta;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 1b5c274d..2b7be726 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -10,6 +10,7 @@
#include <ieeefp.h>
#endif
+#include <cmath>
#include <array>
#include "alMain.h"
@@ -106,15 +107,15 @@ enum {
};
-typedef struct MixHrtfParams {
+struct MixHrtfParams {
const ALfloat (*Coeffs)[2];
ALsizei Delay[2];
ALfloat Gain;
ALfloat GainStep;
-} MixHrtfParams;
+};
-typedef struct DirectParams {
+struct DirectParams {
BiquadFilter LowPass;
BiquadFilter HighPass;
@@ -130,9 +131,9 @@ typedef struct DirectParams {
ALfloat Current[MAX_OUTPUT_CHANNELS];
ALfloat Target[MAX_OUTPUT_CHANNELS];
} Gains;
-} DirectParams;
+};
-typedef struct SendParams {
+struct SendParams {
BiquadFilter LowPass;
BiquadFilter HighPass;
@@ -140,7 +141,7 @@ typedef struct SendParams {
ALfloat Current[MAX_OUTPUT_CHANNELS];
ALfloat Target[MAX_OUTPUT_CHANNELS];
} Gains;
-} SendParams;
+};
struct ALvoicePropsBase {
@@ -359,9 +360,7 @@ inline size_t clampz(size_t val, size_t min, size_t max) noexcept
inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu) noexcept
-{
- return val1 + (val2-val1)*mu;
-}
+{ return val1 + (val2-val1)*mu; }
inline ALfloat cubic(ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat mu) noexcept
{
ALfloat mu2 = mu*mu, mu3 = mu2*mu;
@@ -383,16 +382,16 @@ void aluInit(void);
void aluInitMixer(void);
-ResamplerFunc SelectResampler(enum Resampler resampler);
+ResamplerFunc SelectResampler(Resampler resampler);
/* aluInitRenderer
*
* Set up the appropriate panning method and mixing method given the device
* properties.
*/
-void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq);
+void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appreq, HrtfRequestMode hrtf_userreq);
-void aluInitEffectPanning(struct ALeffectslot *slot);
+void aluInitEffectPanning(ALeffectslot *slot);
void aluSelectPostProcess(ALCdevice *device);
@@ -435,9 +434,9 @@ inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat (&
*/
inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat (&coeffs)[MAX_AMBI_COEFFS])
{
- ALfloat x = -sinf(azimuth) * cosf(elevation);
- ALfloat y = sinf(elevation);
- ALfloat z = cosf(azimuth) * cosf(elevation);
+ ALfloat x = -std::sin(azimuth) * std::cos(elevation);
+ ALfloat y = std::sin(elevation);
+ ALfloat z = std::cos(azimuth) * std::cos(elevation);
CalcAmbiCoeffs(x, y, z, spread, coeffs);
}
@@ -450,9 +449,9 @@ inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread,
*/
inline float ScaleAzimuthFront(float azimuth, float scale)
{
- ALfloat sign = copysignf(1.0f, azimuth);
- if(!(fabsf(azimuth) > F_PI_2))
- return minf(fabsf(azimuth) * scale, F_PI_2) * sign;
+ ALfloat sign = std::copysign(1.0f, azimuth);
+ if(!(std::fabs(azimuth) > F_PI_2))
+ return minf(std::fabs(azimuth) * scale, F_PI_2) * sign;
return azimuth;
}
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 3697b232..53aa9389 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -3335,8 +3335,8 @@ ALsource::ALsource(ALsizei num_sends)
DirectChannels = AL_FALSE;
Spatialize = SpatializeAuto;
- StereoPan[0] = DEG2RAD( 30.0f);
- StereoPan[1] = DEG2RAD(-30.0f);
+ StereoPan[0] = Deg2Rad( 30.0f);
+ StereoPan[1] = Deg2Rad(-30.0f);
Radius = 0.0f;
diff --git a/common/math_defs.h b/common/math_defs.h
index 513570f0..4686e96b 100644
--- a/common/math_defs.h
+++ b/common/math_defs.h
@@ -2,9 +2,6 @@
#define AL_MATH_DEFS_H
#include <math.h>
-#ifdef HAVE_FLOAT_H
-#include <float.h>
-#endif
#ifndef M_PI
#define M_PI (3.14159265358979323846)
@@ -14,25 +11,9 @@
#define F_PI_2 (1.57079632679489661923f)
#define F_TAU (6.28318530717958647692f)
-#ifndef FLT_EPSILON
-#define FLT_EPSILON (1.19209290e-07f)
-#endif
-
-#define SQRT_2 1.41421356237309504880
-#define SQRT_3 1.73205080756887719318
-
-#define SQRTF_2 1.41421356237309504880f
#define SQRTF_3 1.73205080756887719318f
-#ifndef HUGE_VALF
-static const union msvc_inf_hack {
- unsigned char b[4];
- float f;
-} msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
-#define HUGE_VALF (msvc_inf_union.f)
-#endif
-
-#define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0))
-#define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI))
+constexpr inline float Deg2Rad(float x) noexcept { return x * float{M_PI/180.0}; }
+constexpr inline float Rad2Deg(float x) noexcept { return x * float{180.0/M_PI}; }
#endif /* AL_MATH_DEFS_H */
diff --git a/common/vecmat.h b/common/vecmat.h
index 1ecc4b7c..ab407b15 100644
--- a/common/vecmat.h
+++ b/common/vecmat.h
@@ -3,6 +3,7 @@
#include <cmath>
#include <array>
+#include <limits>
#include <algorithm>
#include "math_defs.h"
@@ -41,7 +42,7 @@ public:
float normalize()
{
const float length{std::sqrt(mVals[0]*mVals[0] + mVals[1]*mVals[1] + mVals[2]*mVals[2])};
- if(length > FLT_EPSILON)
+ if(length > std::numeric_limits<float>::epsilon())
{
float inv_length = 1.0f/length;
mVals[0] *= inv_length;