### Audio in Torque 3d

Expanding and utilizing the engine via C++.

#### Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am
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.

#### Re: Audio in Torque 3d

Duion
Posts: 1133
Joined: Sun Feb 08, 2015 1:51 am

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.

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am
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.

#### Re: Audio in Torque 3d

Duion
Posts: 1133
Joined: Sun Feb 08, 2015 1:51 am

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.

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am
thats the exponential falloff added anyway, time to add the rest of the features

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am
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

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am
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;

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?

#### Re: Audio in Torque 3d

marauder2k9
Posts: 215
Joined: Wed Feb 18, 2015 7:36 am

but then it cant load all the mOpenAL for the same reason

#### Re: Audio in Torque 3d

OTHGMars
Posts: 27
Joined: Fri Jul 14, 2017 2:19 am
Try voice->LoadEffect(&reverb) before return voice; but after voice = new SFXALVoice...
Load effect should be non-static in that case.

#### Who is online

Users browsing this forum: No registered users and 4 guests