Implement AL_ROOM_ROLLOFF_FACTOR property
This commit is contained in:
parent
4cc64fa9a8
commit
afd3b71849
15
Alc/ALu.c
15
Alc/ALu.c
@ -192,7 +192,9 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
ALfloat Matrix[3][3];
|
ALfloat Matrix[3][3];
|
||||||
ALint HeadRelative;
|
ALint HeadRelative;
|
||||||
ALfloat flAttenuation;
|
ALfloat flAttenuation;
|
||||||
|
ALfloat RoomAttenuation;
|
||||||
ALfloat MetersPerUnit;
|
ALfloat MetersPerUnit;
|
||||||
|
ALfloat RoomRolloff;
|
||||||
ALfloat DryGainHF = 1.0f;
|
ALfloat DryGainHF = 1.0f;
|
||||||
ALfloat WetGainHF = 1.0f;
|
ALfloat WetGainHF = 1.0f;
|
||||||
|
|
||||||
@ -226,6 +228,7 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
OuterAngle = ALSource->flOuterAngle;
|
OuterAngle = ALSource->flOuterAngle;
|
||||||
HeadRelative = ALSource->bHeadRelative;
|
HeadRelative = ALSource->bHeadRelative;
|
||||||
OuterGainHF = ALSource->OuterGainHF;
|
OuterGainHF = ALSource->OuterGainHF;
|
||||||
|
RoomRolloff = ALSource->RoomRolloffFactor;
|
||||||
|
|
||||||
//Only apply 3D calculations for mono buffers
|
//Only apply 3D calculations for mono buffers
|
||||||
if(isMono != AL_FALSE)
|
if(isMono != AL_FALSE)
|
||||||
@ -242,6 +245,7 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
Distance = aluSqrt(aluDotproduct(Position, Position));
|
Distance = aluSqrt(aluDotproduct(Position, Position));
|
||||||
|
|
||||||
flAttenuation = 1.0f;
|
flAttenuation = 1.0f;
|
||||||
|
RoomAttenuation = 1.0f;
|
||||||
switch (DistanceModel)
|
switch (DistanceModel)
|
||||||
{
|
{
|
||||||
case AL_INVERSE_DISTANCE_CLAMPED:
|
case AL_INVERSE_DISTANCE_CLAMPED:
|
||||||
@ -255,6 +259,8 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
{
|
{
|
||||||
if ((MinDist + (Rolloff * (Distance - MinDist))) > 0.0f)
|
if ((MinDist + (Rolloff * (Distance - MinDist))) > 0.0f)
|
||||||
flAttenuation = MinDist / (MinDist + (Rolloff * (Distance - MinDist)));
|
flAttenuation = MinDist / (MinDist + (Rolloff * (Distance - MinDist)));
|
||||||
|
if ((MinDist + (RoomRolloff * (Distance - MinDist))) > 0.0f)
|
||||||
|
RoomAttenuation = MinDist / (MinDist + (RoomRolloff * (Distance - MinDist)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -267,7 +273,10 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
case AL_LINEAR_DISTANCE:
|
case AL_LINEAR_DISTANCE:
|
||||||
Distance=__min(Distance,MaxDist);
|
Distance=__min(Distance,MaxDist);
|
||||||
if (MaxDist != MinDist)
|
if (MaxDist != MinDist)
|
||||||
|
{
|
||||||
flAttenuation = 1.0f - (Rolloff*(Distance-MinDist)/(MaxDist - MinDist));
|
flAttenuation = 1.0f - (Rolloff*(Distance-MinDist)/(MaxDist - MinDist));
|
||||||
|
RoomAttenuation = 1.0f - (RoomRolloff*(Distance-MinDist)/(MaxDist - MinDist));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_EXPONENT_DISTANCE_CLAMPED:
|
case AL_EXPONENT_DISTANCE_CLAMPED:
|
||||||
@ -278,18 +287,22 @@ static ALvoid CalcSourceParams(ALCcontext *ALContext, ALsource *ALSource,
|
|||||||
//fall-through
|
//fall-through
|
||||||
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 = (ALfloat)pow(Distance/MinDist, -Rolloff);
|
||||||
|
RoomAttenuation = (ALfloat)pow(Distance/MinDist, -RoomRolloff);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_NONE:
|
case AL_NONE:
|
||||||
default:
|
default:
|
||||||
flAttenuation = 1.0f;
|
flAttenuation = 1.0f;
|
||||||
|
RoomAttenuation = 1.0f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source Gain + Attenuation
|
// Source Gain + Attenuation
|
||||||
DryMix = SourceVolume * flAttenuation;
|
DryMix = SourceVolume * flAttenuation;
|
||||||
WetMix = SourceVolume * 0.0f;
|
WetMix = SourceVolume * RoomAttenuation;
|
||||||
|
|
||||||
// Clamp to Min/Max Gain
|
// Clamp to Min/Max Gain
|
||||||
DryMix = __min(DryMix,MaxVolume);
|
DryMix = __min(DryMix,MaxVolume);
|
||||||
|
@ -80,6 +80,8 @@ typedef struct ALsource_struct
|
|||||||
|
|
||||||
ALfloat AirAbsorptionFactor;
|
ALfloat AirAbsorptionFactor;
|
||||||
|
|
||||||
|
ALfloat RoomRolloffFactor;
|
||||||
|
|
||||||
// Index to itself
|
// Index to itself
|
||||||
ALuint source;
|
ALuint source;
|
||||||
|
|
||||||
|
@ -355,6 +355,13 @@ ALAPI ALvoid ALAPIENTRY alSourcef(ALuint source, ALenum eParam, ALfloat flValue)
|
|||||||
alSetError(AL_INVALID_VALUE);
|
alSetError(AL_INVALID_VALUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case AL_ROOM_ROLLOFF_FACTOR:
|
||||||
|
if (flValue >= 0.0f && flValue <= 1.0f)
|
||||||
|
pSource->RoomRolloffFactor = flValue;
|
||||||
|
else
|
||||||
|
alSetError(AL_INVALID_VALUE);
|
||||||
|
break;
|
||||||
|
|
||||||
case AL_SEC_OFFSET:
|
case AL_SEC_OFFSET:
|
||||||
case AL_SAMPLE_OFFSET:
|
case AL_SAMPLE_OFFSET:
|
||||||
case AL_BYTE_OFFSET:
|
case AL_BYTE_OFFSET:
|
||||||
@ -480,6 +487,7 @@ ALAPI ALvoid ALAPIENTRY alSourcefv(ALuint source, ALenum eParam, const ALfloat *
|
|||||||
case AL_SAMPLE_OFFSET:
|
case AL_SAMPLE_OFFSET:
|
||||||
case AL_BYTE_OFFSET:
|
case AL_BYTE_OFFSET:
|
||||||
case AL_AIR_ABSORPTION_FACTOR:
|
case AL_AIR_ABSORPTION_FACTOR:
|
||||||
|
case AL_ROOM_ROLLOFF_FACTOR:
|
||||||
alSourcef(source, eParam, pflValues[0]);
|
alSourcef(source, eParam, pflValues[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -901,6 +909,10 @@ ALAPI ALvoid ALAPIENTRY alGetSourcef(ALuint source, ALenum eParam, ALfloat *pflV
|
|||||||
*pflValue = pSource->AirAbsorptionFactor;
|
*pflValue = pSource->AirAbsorptionFactor;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case AL_ROOM_ROLLOFF_FACTOR:
|
||||||
|
*pflValue = pSource->RoomRolloffFactor;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
alSetError(AL_INVALID_ENUM);
|
alSetError(AL_INVALID_ENUM);
|
||||||
break;
|
break;
|
||||||
@ -1010,6 +1022,7 @@ ALAPI ALvoid ALAPIENTRY alGetSourcefv(ALuint source, ALenum eParam, ALfloat *pfl
|
|||||||
case AL_REFERENCE_DISTANCE:
|
case AL_REFERENCE_DISTANCE:
|
||||||
case AL_CONE_OUTER_GAINHF:
|
case AL_CONE_OUTER_GAINHF:
|
||||||
case AL_AIR_ABSORPTION_FACTOR:
|
case AL_AIR_ABSORPTION_FACTOR:
|
||||||
|
case AL_ROOM_ROLLOFF_FACTOR:
|
||||||
alGetSourcef(source, eParam, pflValues);
|
alGetSourcef(source, eParam, pflValues);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user