aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALu.c31
-rw-r--r--Alc/alcReverb.c13
-rw-r--r--Alc/hrtf.c14
-rw-r--r--OpenAL32/Include/alu.h8
-rw-r--r--OpenAL32/alFilter.c4
5 files changed, 32 insertions, 38 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index f8c8060d..aaf79fe3 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -180,9 +180,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
}
/* Calculate gains */
- DryGain = SourceVolume;
- DryGain = __min(DryGain,MaxVolume);
- DryGain = __max(DryGain,MinVolume);
+ DryGain = clampF(SourceVolume, MinVolume, MaxVolume);
DryGainHF = 1.0f;
switch(ALSource->DirectFilter.type)
{
@@ -193,9 +191,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
}
for(i = 0;i < NumSends;i++)
{
- WetGain[i] = SourceVolume;
- WetGain[i] = __min(WetGain[i],MaxVolume);
- WetGain[i] = __max(WetGain[i],MinVolume);
+ WetGain[i] = clampF(SourceVolume, MinVolume, MaxVolume);
WetGainHF[i] = 1.0f;
switch(ALSource->Send[i].WetFilter.type)
{
@@ -501,8 +497,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALContext->DistanceModel)
{
case InverseDistanceClamped:
- ClampedDist=__max(ClampedDist,MinDist);
- ClampedDist=__min(ClampedDist,MaxDist);
+ ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
if(MaxDist < MinDist)
break;
//fall-through
@@ -520,8 +515,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
break;
case LinearDistanceClamped:
- ClampedDist=__max(ClampedDist,MinDist);
- ClampedDist=__min(ClampedDist,MaxDist);
+ ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
if(MaxDist < MinDist)
break;
//fall-through
@@ -529,18 +523,17 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
if(MaxDist != MinDist)
{
Attenuation = 1.0f - (Rolloff*(ClampedDist-MinDist)/(MaxDist - MinDist));
- Attenuation = __max(Attenuation, 0.0f);
+ Attenuation = maxF(Attenuation, 0.0f);
for(i = 0;i < NumSends;i++)
{
RoomAttenuation[i] = 1.0f - (RoomRolloff[i]*(ClampedDist-MinDist)/(MaxDist - MinDist));
- RoomAttenuation[i] = __max(RoomAttenuation[i], 0.0f);
+ RoomAttenuation[i] = maxF(RoomAttenuation[i], 0.0f);
}
}
break;
case ExponentDistanceClamped:
- ClampedDist=__max(ClampedDist,MinDist);
- ClampedDist=__min(ClampedDist,MaxDist);
+ ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
if(MaxDist < MinDist)
break;
//fall-through
@@ -608,13 +601,9 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
}
// Clamp to Min/Max Gain
- DryGain = __min(DryGain,MaxVolume);
- DryGain = __max(DryGain,MinVolume);
+ DryGain = clampF(DryGain, MinVolume, MaxVolume);
for(i = 0;i < NumSends;i++)
- {
- WetGain[i] = __min(WetGain[i],MaxVolume);
- WetGain[i] = __max(WetGain[i],MinVolume);
- }
+ WetGain[i] = clampF(WetGain[i], MinVolume, MaxVolume);
// Apply filter gains and filters
switch(ALSource->DirectFilter.type)
@@ -772,7 +761,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALfloat length;
ALint pos;
- length = __max(Distance, MinDist);
+ length = maxF(Distance, MinDist);
if(length > 0.0f)
{
ALfloat invlen = 1.0f/length;
diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c
index 4f9360b8..e4fb4ebf 100644
--- a/Alc/alcReverb.c
+++ b/Alc/alcReverb.c
@@ -388,13 +388,10 @@ static ALfloat CalcLimitedHfRatio(ALfloat hfRatio, ALfloat airAbsorptionGainHF,
*/
limitRatio = 1.0f / (CalcDecayLength(airAbsorptionGainHF, decayTime) *
SPEEDOFSOUNDMETRESPERSEC);
- // Need to limit the result to a minimum of 0.1, just like the HF ratio
- // parameter.
- limitRatio = __max(limitRatio, 0.1f);
-
- // Using the limit calculated above, apply the upper bound to the HF
- // ratio.
- return __min(hfRatio, limitRatio);
+ /* Using the limit calculated above, apply the upper bound to the HF
+ * ratio. Also need to limit the result to a minimum of 0.1, just like the
+ * HF ratio parameter. */
+ return clampF(limitRatio, 0.1f, hfRatio);
}
// Calculate the coefficient for a HF (and eventually LF) decay damping
@@ -418,7 +415,7 @@ static __inline ALfloat CalcDampingCoeff(ALfloat hfRatio, ALfloat length, ALfloa
// Very low decay times will produce minimal output, so apply an
// upper bound to the coefficient.
- coeff = __min(coeff, 0.98f);
+ coeff = minF(coeff, 0.98f);
}
return coeff;
}
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index c90a45dc..4b3b2160 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -65,7 +65,7 @@ static void CalcEvIndices(ALfloat ev, ALuint *evidx, ALfloat *evmu)
{
ev = (M_PI/2.0f + ev) * (ELEV_COUNT-1) / M_PI;
evidx[0] = (ALuint)ev;
- evidx[1] = __min(evidx[0] + 1, ELEV_COUNT-1);
+ evidx[1] = minF(evidx[0] + 1, ELEV_COUNT-1);
*evmu = ev - evidx[0];
}
@@ -86,11 +86,11 @@ static void CalcAzIndices(ALuint evidx, ALfloat az, ALuint *azidx, ALfloat *azmu
// values.
ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3])
{
- ALfloat gainChange, angleChange, delta;
+ ALfloat gainChange, angleChange;
// Calculate the normalized dB gain change.
- newGain = __max(newGain, 0.0001f);
- oldGain = __max(oldGain, 0.0001f);
+ newGain = maxF(newGain, 0.0001f);
+ oldGain = maxF(oldGain, 0.0001f);
gainChange = aluFabs(log10(newGain / oldGain) / log10(0.0001f));
// Calculate the normalized listener to source angle change when there is
@@ -109,8 +109,7 @@ ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3],
// Use the largest of the two changes for the delta factor, and apply a
// significance shaping function to it.
- delta = __max(gainChange, angleChange) * 2.0f;
- return __min(delta, 1.0f);
+ return clampF(angleChange*2.0f, gainChange*2.0f, 1.0f);
}
// Calculates static HRIR coefficients and delays for the given polar
@@ -224,8 +223,7 @@ ALuint GetMovingHrtfCoeffs(ALfloat elevation, ALfloat azimuth, ALfloat gain, ALf
ridx[3] = evOffset[evidx[1]] + ((azCount[evidx[1]]-azidx[1]) % azCount[evidx[1]]);
// Calculate the stepping parameters.
- delta = floor(delta*(Hrtf.sampleRate*0.015f) + 0.5);
- delta = __max(delta, 1.0f);
+ delta = maxF(floor(delta*(Hrtf.sampleRate*0.015f) + 0.5), 1.0f);
step = 1.0f / delta;
// Calculate the normalized and attenuated target HRIR coefficients using
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 609978f5..65d8d3a7 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -127,6 +127,14 @@ enum DistanceModel {
#endif
+static __inline ALfloat minF(ALfloat a, ALfloat b)
+{ return ((a > b) ? b : a); }
+static __inline ALfloat maxF(ALfloat a, ALfloat b)
+{ return ((a > b) ? a : b); }
+static __inline ALfloat clampF(ALfloat val, ALfloat mn, ALfloat mx)
+{ return minF(mx, maxF(mn, val)); }
+
+
static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu)
{
return val1 + (val2-val1)*mu;
diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c
index 063c26c9..13391ab0 100644
--- a/OpenAL32/alFilter.c
+++ b/OpenAL32/alFilter.c
@@ -385,10 +385,12 @@ ALfloat lpCoeffCalc(ALfloat g, ALfloat cw)
/* Be careful with gains < 0.01, as that causes the coefficient
* head towards 1, which will flatten the signal */
- g = __max(g, 0.01f);
if(g < 0.9999f) /* 1-epsilon */
+ {
+ g = maxF(g, 0.01f);
a = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) /
(1 - g);
+ }
return a;
}