Use powf when available

This commit is contained in:
Chris Robinson 2010-03-07 22:12:33 -08:00
parent dc40702b53
commit 1f10195c47
5 changed files with 62 additions and 54 deletions

View File

@ -644,9 +644,9 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
case AL_EXPONENT_DISTANCE:
if(Distance > 0.0f && MinDist > 0.0f)
{
flAttenuation = (ALfloat)pow(Distance/MinDist, -Rolloff);
flAttenuation = aluPow(Distance/MinDist, -Rolloff);
for(i = 0;i < NumSends;i++)
RoomAttenuation[i] = (ALfloat)pow(Distance/MinDist, -RoomRolloff[i]);
RoomAttenuation[i] = aluPow(Distance/MinDist, -RoomRolloff[i]);
}
break;
@ -672,7 +672,7 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
absorb = (ALSource->AirAbsorptionFactor*AIRABSORBGAINDBHF) *
effectiveDist;
// Convert dB to linear gain before applying
absorb = pow(10.0, absorb/20.0);
absorb = aluPow(10.0f, absorb/20.0f);
DryGainHF *= absorb;
}
@ -722,62 +722,60 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
{
ALeffectslot *Slot = ALSource->Send[i].Slot;
if(Slot && Slot->effect.type != AL_EFFECT_NULL)
if(!Slot || Slot->effect.type == AL_EFFECT_NULL)
{
if(Slot->AuxSendAuto)
ALSource->Params.WetGains[i] = 0.0f;
WetGainHF[i] = 1.0f;
continue;
}
if(Slot->AuxSendAuto)
{
if(ALSource->WetGainAuto)
WetGain[i] *= ConeVolume;
if(ALSource->WetGainHFAuto)
WetGainHF[i] *= ConeHF;
// Clamp to Min/Max Gain
WetGain[i] = __min(WetGain[i],MaxVolume);
WetGain[i] = __max(WetGain[i],MinVolume);
if(Slot->effect.type == AL_EFFECT_REVERB ||
Slot->effect.type == AL_EFFECT_EAXREVERB)
{
if(ALSource->WetGainAuto)
WetGain[i] *= ConeVolume;
if(ALSource->WetGainHFAuto)
WetGainHF[i] *= ConeHF;
// Clamp to Min/Max Gain
WetGain[i] = __min(WetGain[i],MaxVolume);
WetGain[i] = __max(WetGain[i],MinVolume);
if(Slot->effect.type == AL_EFFECT_REVERB ||
Slot->effect.type == AL_EFFECT_EAXREVERB)
{
/* Apply a decay-time transformation to the wet path,
* based on the attenuation of the dry path.
*
* Using the approximate (effective) source to listener
* distance, the initial decay of the reverb effect is
* calculated and applied to the wet path.
*/
WetGain[i] *= pow(10.0, effectiveDist /
/* Apply a decay-time transformation to the wet path, based on
* the attenuation of the dry path.
*
* Using the approximate (effective) source to listener
* distance, the initial decay of the reverb effect is
* calculated and applied to the wet path.
*/
WetGain[i] *= aluPow(10.0f, effectiveDist /
(SPEEDOFSOUNDMETRESPERSEC *
Slot->effect.Reverb.DecayTime) *
-60.0 / 20.0);
WetGainHF[i] *= pow(10.0,
log10(Slot->effect.Reverb.AirAbsorptionGainHF) *
ALSource->AirAbsorptionFactor * effectiveDist);
}
WetGainHF[i] *= aluPow(10.0f,
log10(Slot->effect.Reverb.AirAbsorptionGainHF) *
ALSource->AirAbsorptionFactor * effectiveDist);
}
else
{
// If the slot's auxiliary send auto is off, the data sent to
// the effect slot is the same as the dry path, sans filter
// effects
WetGain[i] = DryMix;
WetGainHF[i] = DryGainHF;
}
switch(ALSource->Send[i].WetFilter.type)
{
case AL_FILTER_LOWPASS:
WetGain[i] *= ALSource->Send[i].WetFilter.Gain;
WetGainHF[i] *= ALSource->Send[i].WetFilter.GainHF;
break;
}
ALSource->Params.WetGains[i] = WetGain[i] * ListenerGain;
}
else
{
ALSource->Params.WetGains[i] = 0.0f;
WetGainHF[i] = 1.0f;
/* If the slot's auxiliary send auto is off, the data sent to the
* effect slot is the same as the dry path, sans filter effects */
WetGain[i] = DryMix;
WetGainHF[i] = DryGainHF;
}
switch(ALSource->Send[i].WetFilter.type)
{
case AL_FILTER_LOWPASS:
WetGain[i] *= ALSource->Send[i].WetFilter.Gain;
WetGainHF[i] *= ALSource->Send[i].WetFilter.GainHF;
break;
}
ALSource->Params.WetGains[i] = WetGain[i] * ListenerGain;
}
for(i = NumSends;i < MAX_SENDS;i++)
{

View File

@ -311,7 +311,7 @@ static ALboolean AllocLines(ALboolean eaxFlag, ALuint frequency, ALverbState *St
// until the decay reaches -60 dB.
static __inline ALfloat CalcDecayCoeff(ALfloat length, ALfloat decayTime)
{
return pow(10.0f, length / decayTime * -60.0f / 20.0f);
return aluPow(10.0f, length / decayTime * -60.0f / 20.0f);
}
// Calculate a decay length from a coefficient and the time until the decay
@ -488,7 +488,7 @@ static ALvoid UpdateDecorrelator(ALfloat density, ALuint frequency, ALverbState
*/
for(index = 0;index < 3;index++)
{
length = (DECO_FRACTION * pow(DECO_MULTIPLIER, (ALfloat)index)) *
length = (DECO_FRACTION * aluPow(DECO_MULTIPLIER, (ALfloat)index)) *
LATE_LINE_LENGTH[0] * (1.0f + (density * LATE_LINE_MULTIPLIER));
State->DecoTap[index] = (ALuint)(length * frequency);
}
@ -522,7 +522,7 @@ static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix
decayTime));
// Calculate the all-pass feed-back and feed-forward coefficient.
State->Late.ApFeedCoeff = 0.5f * pow(diffusion, 2.0f);
State->Late.ApFeedCoeff = 0.5f * aluPow(diffusion, 2.0f);
for(index = 0;index < 4;index++)
{
@ -566,7 +566,7 @@ static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoT
State->Echo.DensityGain = CalcDensityGain(State->Echo.Coeff);
// Calculate the echo all-pass feed coefficient.
State->Echo.ApFeedCoeff = 0.5f * pow(diffusion, 2.0f);
State->Echo.ApFeedCoeff = 0.5f * aluPow(diffusion, 2.0f);
// Calculate the echo all-pass attenuation coefficient.
State->Echo.ApCoeff = CalcDecayCoeff(ECHO_ALLPASS_LENGTH, decayTime);
@ -1022,8 +1022,8 @@ static ALboolean EAXVerbDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
// is calculated given the current sample rate. This ensures that the
// resulting filter response over time is consistent across all sample
// rates.
State->Mod.Coeff = pow(MODULATION_FILTER_COEFF, MODULATION_FILTER_CONST /
frequency);
State->Mod.Coeff = aluPow(MODULATION_FILTER_COEFF,
MODULATION_FILTER_CONST / frequency);
// The early reflection and late all-pass filter line lengths are static,
// so their offsets only need to be calculated once.

View File

@ -143,6 +143,7 @@ CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(pri
CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
CHECK_LIBRARY_EXISTS(m powf "" HAVE_POWF)
CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)

View File

@ -15,6 +15,12 @@
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#ifdef HAVE_POWF
#define aluPow(x,y) ((ALfloat)powf((float)(x),(float)(y)))
#else
#define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))
#endif
#ifdef HAVE_SQRTF
#define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
#else

View File

@ -31,6 +31,9 @@
/* Define if we have the stat function */
#cmakedefine HAVE_STAT
/* Define if we have the powf function */
#cmakedefine HAVE_POWF
/* Define if we have the sqrtf function */
#cmakedefine HAVE_SQRTF