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: case AL_EXPONENT_DISTANCE:
if(Distance > 0.0f && MinDist > 0.0f) if(Distance > 0.0f && MinDist > 0.0f)
{ {
flAttenuation = (ALfloat)pow(Distance/MinDist, -Rolloff); flAttenuation = aluPow(Distance/MinDist, -Rolloff);
for(i = 0;i < NumSends;i++) for(i = 0;i < NumSends;i++)
RoomAttenuation[i] = (ALfloat)pow(Distance/MinDist, -RoomRolloff[i]); RoomAttenuation[i] = aluPow(Distance/MinDist, -RoomRolloff[i]);
} }
break; break;
@ -672,7 +672,7 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
absorb = (ALSource->AirAbsorptionFactor*AIRABSORBGAINDBHF) * absorb = (ALSource->AirAbsorptionFactor*AIRABSORBGAINDBHF) *
effectiveDist; effectiveDist;
// Convert dB to linear gain before applying // Convert dB to linear gain before applying
absorb = pow(10.0, absorb/20.0); absorb = aluPow(10.0f, absorb/20.0f);
DryGainHF *= absorb; DryGainHF *= absorb;
} }
@ -722,62 +722,60 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
{ {
ALeffectslot *Slot = ALSource->Send[i].Slot; 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) /* Apply a decay-time transformation to the wet path, based on
WetGain[i] *= ConeVolume; * the attenuation of the dry path.
if(ALSource->WetGainHFAuto) *
WetGainHF[i] *= ConeHF; * Using the approximate (effective) source to listener
* distance, the initial decay of the reverb effect is
// Clamp to Min/Max Gain * calculated and applied to the wet path.
WetGain[i] = __min(WetGain[i],MaxVolume); */
WetGain[i] = __max(WetGain[i],MinVolume); WetGain[i] *= aluPow(10.0f, effectiveDist /
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 /
(SPEEDOFSOUNDMETRESPERSEC * (SPEEDOFSOUNDMETRESPERSEC *
Slot->effect.Reverb.DecayTime) * Slot->effect.Reverb.DecayTime) *
-60.0 / 20.0); -60.0 / 20.0);
WetGainHF[i] *= pow(10.0, WetGainHF[i] *= aluPow(10.0f,
log10(Slot->effect.Reverb.AirAbsorptionGainHF) * log10(Slot->effect.Reverb.AirAbsorptionGainHF) *
ALSource->AirAbsorptionFactor * effectiveDist); 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 else
{ {
ALSource->Params.WetGains[i] = 0.0f; /* If the slot's auxiliary send auto is off, the data sent to the
WetGainHF[i] = 1.0f; * 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++) 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. // until the decay reaches -60 dB.
static __inline ALfloat CalcDecayCoeff(ALfloat length, ALfloat decayTime) 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 // 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++) 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)); LATE_LINE_LENGTH[0] * (1.0f + (density * LATE_LINE_MULTIPLIER));
State->DecoTap[index] = (ALuint)(length * frequency); State->DecoTap[index] = (ALuint)(length * frequency);
} }
@ -522,7 +522,7 @@ static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix
decayTime)); decayTime));
// Calculate the all-pass feed-back and feed-forward coefficient. // 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++) 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); State->Echo.DensityGain = CalcDensityGain(State->Echo.Coeff);
// Calculate the echo all-pass feed coefficient. // 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. // Calculate the echo all-pass attenuation coefficient.
State->Echo.ApCoeff = CalcDecayCoeff(ECHO_ALLPASS_LENGTH, decayTime); 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 // is calculated given the current sample rate. This ensures that the
// resulting filter response over time is consistent across all sample // resulting filter response over time is consistent across all sample
// rates. // rates.
State->Mod.Coeff = pow(MODULATION_FILTER_COEFF, MODULATION_FILTER_CONST / State->Mod.Coeff = aluPow(MODULATION_FILTER_COEFF,
frequency); MODULATION_FILTER_CONST / frequency);
// The early reflection and late all-pass filter line lengths are static, // The early reflection and late all-pass filter line lengths are static,
// so their offsets only need to be calculated once. // 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(fenv.h HAVE_FENV_H)
CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_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 sqrtf "" HAVE_SQRTF)
CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF) CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF) CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)

View File

@ -15,6 +15,12 @@
#define M_PI_2 1.57079632679489661923 /* pi/2 */ #define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif #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 #ifdef HAVE_SQRTF
#define aluSqrt(x) ((ALfloat)sqrtf((float)(x))) #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
#else #else

View File

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