Jump to content

OpenAL Exponential Falloff


Recommended Posts

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:



then at line 189 after break; ad


case SFXDistanceModelExponent:
distance = getMax(distance, minDistance);
distance = getMin(distance, maxDistance);
gain = pow((distance / minDistance), (-rolloffFactor));


Then in sfxDSDevice.cpp at line 203 you will see SFXDevice::setDistanceModel

in the switch below break at case SFXDistanceModelLogarithmic:



 case SFXDistanceModelExponent:
	   Con::errorf("SFXDSDevice::setDistanceModel - 'exponential' distance attenuation not supported by DirectSound");


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;



case SFXDistanceModelExponent:
		  if (mUserRolloffFactor != mRolloffFactor)


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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...