Use inline minF/maxF/clampF functions instead of the __min/__max macros
This commit is contained in:
parent
b3cb511c06
commit
8a51a7ea2d
31
Alc/ALu.c
31
Alc/ALu.c
@ -180,9 +180,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate gains */
|
/* Calculate gains */
|
||||||
DryGain = SourceVolume;
|
DryGain = clampF(SourceVolume, MinVolume, MaxVolume);
|
||||||
DryGain = __min(DryGain,MaxVolume);
|
|
||||||
DryGain = __max(DryGain,MinVolume);
|
|
||||||
DryGainHF = 1.0f;
|
DryGainHF = 1.0f;
|
||||||
switch(ALSource->DirectFilter.type)
|
switch(ALSource->DirectFilter.type)
|
||||||
{
|
{
|
||||||
@ -193,9 +191,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
}
|
}
|
||||||
for(i = 0;i < NumSends;i++)
|
for(i = 0;i < NumSends;i++)
|
||||||
{
|
{
|
||||||
WetGain[i] = SourceVolume;
|
WetGain[i] = clampF(SourceVolume, MinVolume, MaxVolume);
|
||||||
WetGain[i] = __min(WetGain[i],MaxVolume);
|
|
||||||
WetGain[i] = __max(WetGain[i],MinVolume);
|
|
||||||
WetGainHF[i] = 1.0f;
|
WetGainHF[i] = 1.0f;
|
||||||
switch(ALSource->Send[i].WetFilter.type)
|
switch(ALSource->Send[i].WetFilter.type)
|
||||||
{
|
{
|
||||||
@ -501,8 +497,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
ALContext->DistanceModel)
|
ALContext->DistanceModel)
|
||||||
{
|
{
|
||||||
case InverseDistanceClamped:
|
case InverseDistanceClamped:
|
||||||
ClampedDist=__max(ClampedDist,MinDist);
|
ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
|
||||||
ClampedDist=__min(ClampedDist,MaxDist);
|
|
||||||
if(MaxDist < MinDist)
|
if(MaxDist < MinDist)
|
||||||
break;
|
break;
|
||||||
//fall-through
|
//fall-through
|
||||||
@ -520,8 +515,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LinearDistanceClamped:
|
case LinearDistanceClamped:
|
||||||
ClampedDist=__max(ClampedDist,MinDist);
|
ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
|
||||||
ClampedDist=__min(ClampedDist,MaxDist);
|
|
||||||
if(MaxDist < MinDist)
|
if(MaxDist < MinDist)
|
||||||
break;
|
break;
|
||||||
//fall-through
|
//fall-through
|
||||||
@ -529,18 +523,17 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
if(MaxDist != MinDist)
|
if(MaxDist != MinDist)
|
||||||
{
|
{
|
||||||
Attenuation = 1.0f - (Rolloff*(ClampedDist-MinDist)/(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++)
|
for(i = 0;i < NumSends;i++)
|
||||||
{
|
{
|
||||||
RoomAttenuation[i] = 1.0f - (RoomRolloff[i]*(ClampedDist-MinDist)/(MaxDist - MinDist));
|
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;
|
break;
|
||||||
|
|
||||||
case ExponentDistanceClamped:
|
case ExponentDistanceClamped:
|
||||||
ClampedDist=__max(ClampedDist,MinDist);
|
ClampedDist = clampF(ClampedDist, MinDist, MaxDist);
|
||||||
ClampedDist=__min(ClampedDist,MaxDist);
|
|
||||||
if(MaxDist < MinDist)
|
if(MaxDist < MinDist)
|
||||||
break;
|
break;
|
||||||
//fall-through
|
//fall-through
|
||||||
@ -608,13 +601,9 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clamp to Min/Max Gain
|
// Clamp to Min/Max Gain
|
||||||
DryGain = __min(DryGain,MaxVolume);
|
DryGain = clampF(DryGain, MinVolume, MaxVolume);
|
||||||
DryGain = __max(DryGain,MinVolume);
|
|
||||||
for(i = 0;i < NumSends;i++)
|
for(i = 0;i < NumSends;i++)
|
||||||
{
|
WetGain[i] = clampF(WetGain[i], MinVolume, MaxVolume);
|
||||||
WetGain[i] = __min(WetGain[i],MaxVolume);
|
|
||||||
WetGain[i] = __max(WetGain[i],MinVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply filter gains and filters
|
// Apply filter gains and filters
|
||||||
switch(ALSource->DirectFilter.type)
|
switch(ALSource->DirectFilter.type)
|
||||||
@ -772,7 +761,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
|||||||
ALfloat length;
|
ALfloat length;
|
||||||
ALint pos;
|
ALint pos;
|
||||||
|
|
||||||
length = __max(Distance, MinDist);
|
length = maxF(Distance, MinDist);
|
||||||
if(length > 0.0f)
|
if(length > 0.0f)
|
||||||
{
|
{
|
||||||
ALfloat invlen = 1.0f/length;
|
ALfloat invlen = 1.0f/length;
|
||||||
|
@ -388,13 +388,10 @@ static ALfloat CalcLimitedHfRatio(ALfloat hfRatio, ALfloat airAbsorptionGainHF,
|
|||||||
*/
|
*/
|
||||||
limitRatio = 1.0f / (CalcDecayLength(airAbsorptionGainHF, decayTime) *
|
limitRatio = 1.0f / (CalcDecayLength(airAbsorptionGainHF, decayTime) *
|
||||||
SPEEDOFSOUNDMETRESPERSEC);
|
SPEEDOFSOUNDMETRESPERSEC);
|
||||||
// Need to limit the result to a minimum of 0.1, just like the HF ratio
|
/* Using the limit calculated above, apply the upper bound to the HF
|
||||||
// parameter.
|
* ratio. Also need to limit the result to a minimum of 0.1, just like the
|
||||||
limitRatio = __max(limitRatio, 0.1f);
|
* HF ratio parameter. */
|
||||||
|
return clampF(limitRatio, 0.1f, hfRatio);
|
||||||
// Using the limit calculated above, apply the upper bound to the HF
|
|
||||||
// ratio.
|
|
||||||
return __min(hfRatio, limitRatio);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the coefficient for a HF (and eventually LF) decay damping
|
// 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
|
// Very low decay times will produce minimal output, so apply an
|
||||||
// upper bound to the coefficient.
|
// upper bound to the coefficient.
|
||||||
coeff = __min(coeff, 0.98f);
|
coeff = minF(coeff, 0.98f);
|
||||||
}
|
}
|
||||||
return coeff;
|
return coeff;
|
||||||
}
|
}
|
||||||
|
14
Alc/hrtf.c
14
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;
|
ev = (M_PI/2.0f + ev) * (ELEV_COUNT-1) / M_PI;
|
||||||
evidx[0] = (ALuint)ev;
|
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];
|
*evmu = ev - evidx[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,11 +86,11 @@ static void CalcAzIndices(ALuint evidx, ALfloat az, ALuint *azidx, ALfloat *azmu
|
|||||||
// values.
|
// values.
|
||||||
ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3])
|
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.
|
// Calculate the normalized dB gain change.
|
||||||
newGain = __max(newGain, 0.0001f);
|
newGain = maxF(newGain, 0.0001f);
|
||||||
oldGain = __max(oldGain, 0.0001f);
|
oldGain = maxF(oldGain, 0.0001f);
|
||||||
gainChange = aluFabs(log10(newGain / oldGain) / log10(0.0001f));
|
gainChange = aluFabs(log10(newGain / oldGain) / log10(0.0001f));
|
||||||
|
|
||||||
// Calculate the normalized listener to source angle change when there is
|
// 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
|
// Use the largest of the two changes for the delta factor, and apply a
|
||||||
// significance shaping function to it.
|
// significance shaping function to it.
|
||||||
delta = __max(gainChange, angleChange) * 2.0f;
|
return clampF(angleChange*2.0f, gainChange*2.0f, 1.0f);
|
||||||
return __min(delta, 1.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculates static HRIR coefficients and delays for the given polar
|
// 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]]);
|
ridx[3] = evOffset[evidx[1]] + ((azCount[evidx[1]]-azidx[1]) % azCount[evidx[1]]);
|
||||||
|
|
||||||
// Calculate the stepping parameters.
|
// Calculate the stepping parameters.
|
||||||
delta = floor(delta*(Hrtf.sampleRate*0.015f) + 0.5);
|
delta = maxF(floor(delta*(Hrtf.sampleRate*0.015f) + 0.5), 1.0f);
|
||||||
delta = __max(delta, 1.0f);
|
|
||||||
step = 1.0f / delta;
|
step = 1.0f / delta;
|
||||||
|
|
||||||
// Calculate the normalized and attenuated target HRIR coefficients using
|
// Calculate the normalized and attenuated target HRIR coefficients using
|
||||||
|
@ -127,6 +127,14 @@ enum DistanceModel {
|
|||||||
#endif
|
#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)
|
static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu)
|
||||||
{
|
{
|
||||||
return val1 + (val2-val1)*mu;
|
return val1 + (val2-val1)*mu;
|
||||||
|
@ -385,10 +385,12 @@ ALfloat lpCoeffCalc(ALfloat g, ALfloat cw)
|
|||||||
|
|
||||||
/* Be careful with gains < 0.01, as that causes the coefficient
|
/* Be careful with gains < 0.01, as that causes the coefficient
|
||||||
* head towards 1, which will flatten the signal */
|
* head towards 1, which will flatten the signal */
|
||||||
g = __max(g, 0.01f);
|
|
||||||
if(g < 0.9999f) /* 1-epsilon */
|
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))) /
|
a = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) /
|
||||||
(1 - g);
|
(1 - g);
|
||||||
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user