Jump to content

Audio in Torque 3d


Recommended Posts

I was checking around the source files on how torque3d handles audio. Am i right in saying that torque3d uses the linear falloff model from openal?


If so has anyone toyed around with both adding the reverb openal uses and an exponential falloff? i was thinking of implementing it instead of using the linear falloff model. This would bring in a more realistic falloff over distances for audio but also would give built in reverb functions to torque3d, there are more effects in openal as well that i may implement as well.


There are a few effects that could come in handy for people that either dont have or dont want to use fmod for example the equalizer.

Link to post
Share on other sites

In the code there are also alternatives for audio, like logarithmic distance falloff and many other advanced effects, but those are limited to the proprietary FMOD sound engine, that is obviously not in the open source version of Torque3D.


This is probably where we do not have a complex open source version of this, since it was just ported quickly and then left that way, so yes we could need alternatives for that. I would also like to have the environment sound effects back, like when you are in a big hall all sounds will echo more etc which was also a part of FMOD probably.

Link to post
Share on other sites

thats reverb basically, with openal you can do that, i think there is a basic implementation of reverb in openal in torque but not a full one? like certain features are initialised but not used, most probably to have one single layer between openal and fmod, but openal can do nearly the same as fmod only fmod can use soundbanks and has that fancy interface whereas with a more fleshed out implementation of openal it would all be done in torques gui without the need of a separate app and with mostly text inputs.

Link to post
Share on other sites

I would be totally satisfied with a better distance falloff model, that linear one is horrible, if you have a lot of sounds with high range, such as gunshots obviously, with a lot of players it will be a constant loud noise that gets very annoying and if you make the distance smaller, you obviously hardly ever hear anyone.


So yes that would be cool if you could implement that.

Link to post
Share on other sites

little snag: This reports an error in that it cant return effect; due to function type, i have to be able to call effect in other parts of this file anyone any ideas?

 

void SFXALVoice::setReverb(const SFXReverbProperties& reverb)
{
	ALuint effect;
	ALenum err;
	mOpenAL.alGenEffects(1, &effect);
	mOpenAL.alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
	mOpenAL.alEffectf(effect, AL_REVERB_DENSITY, reverb.mDensity);
	mOpenAL.alEffectf(effect, AL_REVERB_DIFFUSION, reverb.mDiffusion);
	mOpenAL.alEffectf(effect, AL_REVERB_MIN_GAIN, reverb.mReverb);
	mOpenAL.alEffectf(effect, AL_REVERB_GAINHF, reverb.mRoomHF);
	mOpenAL.alEffectf(effect, AL_REVERB_DECAY_TIME, reverb.mDecayTime);
	mOpenAL.alEffectf(effect, AL_REVERB_DECAY_HFRATIO, reverb.mDecayHFRatio);
	mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_GAIN, reverb.mReflections);
	mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_DELAY, reverb.mReflectionsDelay);
	mOpenAL.alEffectf(effect, AL_REVERB_LATE_REVERB_DELAY, reverb.mReverbDelay);
	mOpenAL.alEffectf(effect, AL_REVERB_AIR_ABSORPTION_GAINHF, reverb.mAirAbsorptionHF);
	mOpenAL.alEffectf(effect, AL_REVERB_ROOM_ROLLOFF_FACTOR, reverb.mRoomRolloffFactor);
	mOpenAL.alEffecti(effect, AL_REVERB_DECAY_HFLIMIT, reverb.mDecayHFRatio);
 
	err = alGetError();
	if (err != AL_NO_ERROR)
	{
		fprintf(stderr, "OpenAL error: %s\n", alGetString(err));
		if (mOpenAL.alIsEffect(effect))
			mOpenAL.alDeleteEffects(1, &effect);
		return;
	}
 
	return effect;
}

 

I will probably need to create a different function SFXALVoice::setEffect or something like that but this was just to test that the values in torque can be passed to the reverb in openal and produce expected changes to the sound

Link to post
Share on other sites

Fixed previous error, now hit another snag

 

ALuint SFXALVoice::LoadEffect(EFXEAXREVERBPROPERTIES *reverb)
{
 
	effect = 0;
 
	/* Create the effect object and check if we can do EAX reverb. */
	mOpenAL.alGenEffects(1, &effect);
	mOpenAL.alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
 
	mOpenAL.alEffectf(effect, AL_REVERB_DENSITY, reverb->flDensity);
	mOpenAL.alEffectf(effect, AL_REVERB_DIFFUSION, reverb->flDiffusion);
	mOpenAL.alEffectf(effect, AL_REVERB_GAIN, reverb->flGain);
	mOpenAL.alEffectf(effect, AL_REVERB_GAINHF, reverb->flGainHF);
	mOpenAL.alEffectf(effect, AL_REVERB_DECAY_TIME, reverb->flDecayTime);
	mOpenAL.alEffectf(effect, AL_REVERB_DECAY_HFRATIO, reverb->flDecayHFRatio);
	mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_GAIN, reverb->flReflectionsGain);
	mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_DELAY, reverb->flReflectionsDelay);
	mOpenAL.alEffectf(effect, AL_REVERB_LATE_REVERB_GAIN, reverb->flLateReverbGain);
	mOpenAL.alEffectf(effect, AL_REVERB_LATE_REVERB_DELAY, reverb->flLateReverbDelay);
	mOpenAL.alEffectf(effect, AL_REVERB_AIR_ABSORPTION_GAINHF, reverb->flAirAbsorptionGainHF);
	mOpenAL.alEffectf(effect, AL_REVERB_ROOM_ROLLOFF_FACTOR, reverb->flRoomRolloffFactor);
	mOpenAL.alEffecti(effect, AL_REVERB_DECAY_HFLIMIT, reverb->iDecayHFLimit);
 
	return effect;
}
 
SFXALVoice* SFXALVoice::create( SFXALDevice* device, SFXALBuffer *buffer )
{
   AssertFatal( buffer, "SFXALVoice::create() - Got null buffer!" );
 
   ALuint sourceName;
   EFXEAXREVERBPROPERTIES reverb = EFX_REVERB_PRESET_CASTLE_LARGEROOM;
   ALuint slot, effect;
   effect = LoadEffect(&reverb);
 
   device->mOpenAL.alGenSources( 1, &sourceName );
   AssertFatal( device->mOpenAL.alIsSource( sourceName ), "AL Source Sanity Check Failed!" );
 
   // Is this 3d?
   // Okay, this looks odd, but bear with me for a moment.  AL_SOURCE_RELATIVE does NOT indicate
   // whether or not the volume of the sound should change depending on the position of the listener.
   // OpenAL assumes that the volume will ALWAYS depend on the position of the listener.  What AL_SOURCE_RELATIVE
   // does do is dictate if the position of THIS SOURCE is relative to the listener.  If AL_SOURCE_RELATIVE is AL_TRUE
   // and the source's position is 0, 0, 0, then the source is directly on top of the listener at all times, which is what
   // we want for non-3d sounds.
   device->mOpenAL.alSourcei( sourceName, AL_SOURCE_RELATIVE, ( buffer->mIs3d ? AL_FALSE : AL_TRUE ) );
   device->mOpenAL.alSource3i(sourceName,AL_AUXILIARY_SEND_FILTER, slot, 0 , AL_FILTER_NULL);

 

In this block of code

effect = LoadEffect(&reverb); is throwing up an error "a nonstatic member reference must be relative to a specific object"


Any ideas?

Link to post
Share on other sites

Okay i have it stable now but no reverb effect is being made. I think the function to create the reverb isnt being called:


in sfxALDevice.cpp i have

 

ALuint SFXALDevice::setReverb(EFXEAXREVERBPROPERTIES *reverb)
{
	ALuint effect = 0;
 
		mOpenAL.alGenEffects(1, &effect);
 
		mOpenAL.alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
 
		mOpenAL.alEffectf(effect, AL_REVERB_DENSITY, reverb->flDensity);
		mOpenAL.alEffectf(effect, AL_REVERB_DIFFUSION, reverb->flDiffusion);
		mOpenAL.alEffectf(effect, AL_REVERB_GAIN, reverb->flGain);
		mOpenAL.alEffectf(effect, AL_REVERB_GAINHF, reverb->flGainHF);
		mOpenAL.alEffectf(effect, AL_REVERB_DECAY_TIME, reverb->flDecayTime);
		mOpenAL.alEffectf(effect, AL_REVERB_DECAY_HFRATIO, reverb->flDecayHFRatio);
		mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_GAIN, reverb->flReflectionsGain);
		mOpenAL.alEffectf(effect, AL_REVERB_REFLECTIONS_DELAY, reverb->flReflectionsDelay);
		mOpenAL.alEffectf(effect, AL_REVERB_LATE_REVERB_GAIN, reverb->flLateReverbGain);
		mOpenAL.alEffectf(effect, AL_REVERB_LATE_REVERB_DELAY, reverb->flLateReverbDelay);
		mOpenAL.alEffectf(effect, AL_REVERB_AIR_ABSORPTION_GAINHF, reverb->flAirAbsorptionGainHF);
		mOpenAL.alEffectf(effect, AL_REVERB_ROOM_ROLLOFF_FACTOR, reverb->flRoomRolloffFactor);
		mOpenAL.alEffecti(effect, AL_REVERB_DECAY_HFLIMIT, reverb->iDecayHFLimit);
 
	/* Check if an error occured, and clean up if so. */
 
 
	return effect;
}

 


This defines the effect and brings in all the details available to openal to create a reverb effect


In sfxALVoice.cpp i have

 

void SFXALVoice::setReverb(SFXALDevice* device)
{
	EFXEAXREVERBPROPERTIES reverb = EFX_REVERB_PRESET_ARENA;
	AL_SANITY_CHECK();
	ALuint effect, slot;
	effect = device->setReverb(&reverb);
	slot = 0;
 
	mOpenAL.alGenAuxiliaryEffectSlots(1, &slot);
	mOpenAL.alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, effect);
 
	mOpenAL.alSource3i(mSourceName, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL);
}

 

EFXEAXREVERBPROPERTIES reverb = EFX_REVERB_PRESET_ARENA this loads a preset in openal and adds the values into sfxALDevice setReverb then creates the required effect slots for openal to create the effect with the source, this is stable and doesnt crash everytime a sound is played but i think that is becuase the function isnt being called =/

Link to post
Share on other sites

finished an implementation of an effects layer that takes info from sfxdescription and sfxenvironment to decide whether an sfxalvoice should have a certain effect. also created parameters in both sfxdescription and sfxenvironment for other effects available in openal:


EAX Reverb

Reverb

Echo

Distortion

Flanger

Chorus

Pitch Shifter

Vocal Morpher

Auto-Wah

Ring Modulator

Compressor

Equalizer


Although u can only use 4 of these at any given time as i understand it openal advises a max of 4 auxiliary sends and each effect has to have its own send. i think......


the 4 filters available are:

Null (yes it is a filter type lol)

lowpass

bandpass

highpass


Only one filter can be applied to each send as i understand it.


This will all create static environments for audio effects, im afraid my coding knowledge cant create the dynamic environment processing available in openal to automatically adjust reverb effects due to the size of a zone. As i understand it open al eax reverb effects can take into account the distance from the source to the listener and attenuate the reverb properties to be a lot more realistic for example if ur in a large room the reverberation of the sound would get less and less the closer the source of the sound gets to the listener. i know this may sound easy to implement but once an effect changes its parameters it needs to be deleted then recreated each time.


NOTE: i would of had a video up tonight showcasing these changes but youtube is down so probably wont get a chance to upload a video until the weekend

Link to post
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.

Guest
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...