### OpenAL Exponential Falloff

Scripts and code that enhance the gameplay functionality of the engine.

#### OpenAL Exponential Falloff

marauder2k9
Posts: 315
Joined: Wed Feb 18, 2015 7:36 am
This resource will add the exponential falloff to torque3ds sound distance attenuation instead of the linear falloff that it uses as stock... ALOT OF CODE CHANGES INCOMING BACK UP YOUR SOURCE!!! These changes were tested on stock Torque3d 3.10.1 release.

Our first change of many:
in sfxCommon.h around line 152 you should see enum SFXDistanceModel

after SFXDistanceModelLogarithmic add:
SFXDistanceModelExponent,
then at line 189 after break; ad
case SFXDistanceModelExponent:
distance = getMax(distance, minDistance);
distance = getMin(distance, maxDistance);

gain = pow((distance / minDistance), (-rolloffFactor));
break;
Then in sfxDSDevice.cpp at line 203 you will see SFXDevice::setDistanceModel

in the switch below break at case SFXDistanceModelLogarithmic:

add
 case SFXDistanceModelExponent:
Con::errorf("SFXDSDevice::setDistanceModel - 'exponential' distance attenuation not supported by DirectSound");
break;
I'm not sure whether directsound has an exponential attenuation feature but just in case it doesnt i thought it best to sort it out with an error here.

Next in sfxALDevice.cpp find SFXALDevice::setDistanceModel under the case SFXDistanceModelLogarithmic break;

add:
case SFXDistanceModelExponent:
mOpenAL.alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
if (mUserRolloffFactor != mRolloffFactor)
_setRolloffFactor(mUserRolloffFactor);
break;
You could just copy and paste the logarithmic case here and change the values to be exponent but that would just be lazy...........

Next in sfxSystem.cpp

Find around line 94
{ SFXDistanceModelLogarithmic, "Logarithmic",
"Volume attenuates logarithmically starting from the reference distance and halving every reference distance step from there on. "
"Attenuation stops at max distance but volume won't reach zero." },

Below this add
 { SFXDistanceModelExponent, "Exponential",
"Volume attenuates exponentially starting from the reference distance and attenuating every reference distance step by the rolloff factor. "
"Attenuation stops at max distance but volume won't reach zero." },
Because we are using AL_EXPONENT_DISTANCE_CLAMPED the volume attenuation stops when the source reaches max distance.

Then load up your level in the world editor choose thelevelinfo from the mission group and scroll down to sound, under that change soundDistanceModel to Exponential. Done now any sound profiles that you have you can create an exponential rolloff attenuation rather than a linear rolloff.

#### Who is online

Users browsing this forum: No registered users and 4 guests