Environmental sound effects      P  A8.22

The Effects Extension (EAX) provides environmental sound effects for OpenAL sounds. Environmental effects greatly contribute to the realism and immersion in a game or simulation. For instance, a sword clanked in a small wooden cell sounds very different to the same sword clanked in a large cathedral. A scream coming from the next room sounds muffled when there’s a wall between the listener and the screamer. Without this aural context, the listener cannot pinpoint how far away the sound sources are and where they are located. Reverb and reflections combine to add a visceral realism to the 3D environment, an often subliminal context that gives an emotional depth to the 3D world. This works even when the visual component of the 3D world is out of sight.

For playing sounds in an aural context, create a reverb effect with the characteristics of the sound environment, such as a room, a hallway, or a courtyard. When playing sounds in that environment, attach the reverb effect to them. There are 13 reverb parameters that can model the aural characteristics of any imaginable environment:

Parameter Range Description
density float, 0.0..1.0 (default 1.0) The Modal Density controls the coloration of the late reverb. Lowering the value adds more coloration.
diffusion float, 0.0..1.0 (default 1.0) The Reverb Diffusion controls the echo density in the reverb decay. It’s set by default to 1.0, which provides the highest density. Reducing diffusion gives the reverb a more “grainy” character that is especially noticeable with percussive sound sources. If you set a diffusion value of 0.0, the late reverb sounds like a succession of distinct echoes.
gain float, 0.0..1.0 (default 0.32) The Reverb Gain controls the volume for the reflected sound (both early reflections and reverberation) that the reverb effect adds to all sound sources. It sets the maximum amount of reflections and reverberation added to the final sound mix. The value of the Reverb Gain ranges from 1.0 (0db, maximum amount) to 0.0 (-100db, no reflected sound at all).
gainHf float, 0.0..1.0 (default 0.89) High frequency part of the Reverb Gain; further tweaks reflected sound by attenuating it at high frequencies. It controls a low-pass filter that applies globally to the reflected sound of all sound sources feeding the particular instance of the reverb effect. The value of the Reverb Gain HF ranges from 1.0 (0db, no HF filter) to 0.0 (-100db, virtually no reflected sound).
decayTime float, 0.0..20.0 (default 1.49) The Decay Time sets the reverberation decay time. It ranges from 0.1 (typically a small room with very dead surfaces) to 20.0 (typically a large room with very live surfaces).
decayHfRatio float, 0.0..2.0 (default 0.83) The Decay HF Ratio sets the spectral quality of the Decay Time. It is the ratio of high-frequency decay time relative to the time set by Decay Time. The Decay HF Ratio value 1.0 is neutral: the decay time is equal for all frequencies. As Decay HF Ratio increases
above 1.0, the high-frequency decay time increases so it’s longer than the decay time at low frequencies. You hear a more brilliant reverberation with a longer decay at high frequencies. As the Decay HF Ratio value decreases below 1.0, the high-frequency decay time decreases so it’s shorter than the decay time of the low frequencies. You hear a more natural reverberation.
reflectionsGain float, 0.0..3.16 (default 0.05) The Reflections Gain controls the overall amount of initial reflections relative to the Gain. The value of Reflections Gain ranges from a maximum of 3.16 (+10 dB) to a minimum of 0.0 (-100 dB, no initial reflections at all), and is corrected by the value of the Gain. The Reflections Gain does not affect the subsequent reverberation decay. You can increase the amount of initial reflections to simulate a more narrow space or closer walls, especially effective if you associate the initial reflections increase with a reduction in reflections delays by lowering the value of the Reflection Delay. To simulate open or semi-open environments, you can maintain the amount of early reflections while reducing the value of the Late Reverb Gain, which controls later reflections.
reflectionsDelay float, 0.0..0.3 (default 0.007) The Reflections Delay is the amount of delay between the arrival time of the direct path from the source to the first reflection from the source. It ranges from 0 to 300 milliseconds. You can reduce or increase the Reflections Delay to simulate closer or more distant reflective surfaces, and this way control the perceived size of the room.
lateReverbGain float, 0.0..10.0 (default 1.26) The Late Reverb Gain controls the overall amount of later reverberation relative to the Gain. The value of Late Reverb Gain ranges from a maximum of 10.0 (+20 dB) to a minimum of 0.0 (-100 dB, no late reverberation at all). Note that Late Reverb Gain and Decay Time are independent properties: If you adjust the Decay Time without changing the Late Reverb Gain, the total intensity (the averaged square of the amplitude) of the late reverberation remains constant.
lateReverbDelay float, 0.0..0.1 (default 0.011) The Late Reverb Delay defines the begin time of the late reverberation relative to the time of the initial reflection (the first of the early reflections). It ranges from 0 to 100 milliseconds. Reducing or increasing Late Reverb Delay is useful for simulating a smaller or larger room.
airAbsorptionGainHf float, 0.892..1.0 (default 0.994) The Air Absorption Gain HF controls the distance-dependent attenuation at high frequencies caused by the propagation medium. It applies to reflected sound only. You can use Air Absorption Gain HF to simulate sound transmission through foggy air, dry air, smoky atmosphere, and so on. The default value is 0.994 (-0.05 dB) per meter, which roughly corresponds to typical condition of atmospheric humidity, temperature, and so on. Lowering the value simulates a more absorbent medium (more humidity in the air, for example); raising the value simulates a less absorbent medium (dry desert air, for example).
roomRolloffFactor float, 0.0..10.0 (default 0.0) The Room Rolloff Factor is one of two methods available to attenuate the reflected sound (containing both reflections and reverberation) according to source-listener distance. Setting the Room Rolloff Factor value to 1.0 specifies that the reflected sound will decay by 6 dB every time the distance doubles. Any value other than 1.0 is equivalent to a scaling factor applied to the quantity specified by the listener distance. The default value of Room Rolloff Factor is 0.0 because the default reverb effect naturally manages the reflected sound level automatically for each sound source to simulate the natural rolloff of reflected sound vs. distance in typical rooms. You can use the Room Rolloff Factor as an option to automatic control so you can exaggerate or replace the default automatically-controlled rolloff.
decayHfLimit int, 0 or 1 (default 1) When at 1, the high-frequency decay time automatically stays below a limit value that’s derived from the setting of the property Air Absorption HF. This limit applies regardless of the setting of the Decay HF Ratio, and the limit doesn’t affect the value of Decay HF Ratio. This limit, when on, maintains a natural sounding reverberation decay by allowing you to increase the value of Decay Time without the risk of getting an unnaturally long decay time at high frequencies. If parameter is 0, high-frequency decay time isn’t automatically limited.

One can imagine that fine-tuning all those parameters for every different location of a game is a quite cumbersome task. Therefore, predefined sets of reverb parameters for all sorts of locations are available:

Generic FX_GENERIC, FX_PADDEDCELL, FX_ROOM, FX_BATHROOM, FX_LIVINGROOM, FX_STONEROOM, FX_AUDITORIUM, FX_CONCERTHALL, FX_CAVE, FX_ARENA, FX_HANGAR, FX_HALLWAY, FX_CARPETTEDHALLWAY, FX_STONECORRIDOR, FX_ALLEY, FX_DUSTYROOM, FX_CHAPEL, FX_SMALLWATERROOM, FX_UNDERWATER
Castle FX_CASTLE_SMALLROOM, FX_CASTLE_SHORTPASSAGE, FX_CASTLE_MEDIUMROOM, FX_CASTLE_LONGPASSAGE, FX_CASTLE_LARGEROOM, FX_CASTLE_HALL, FX_CASTLE_CUPBOARD, FX_CASTLE_COURTYARD, FX_CASTLE_ALCOVE
Factory FX_FACTORY_ALCOVE, FX_FACTORY_SHORTPASSAGE, FX_FACTORY_MEDIUMROOM, FX_FACTORY_LONGPASSAGE, FX_FACTORY_LARGEROOM, FX_FACTORY_HALL, FX_FACTORY_CUPBOARD, FX_FACTORY_COURTYARD, FX_FACTORY_SMALLROOM
Ice Palace FX_ICEPALACE_ALCOVE, FX_ICEPALACE_SHORTPASSAGE, FX_ICEPALACE_MEDIUMROOM, FX_ICEPALACE_LONGPASSAGE, FX_ICEPALACE_LARGEROOM, FX_ICEPALACE_HALL, FX_ICEPALACE_CUPBOARD, FX_ICEPALACE_COURTYARD, FX_ICEPALACE_SMALLROOM
Space Station

FX_SPACESTATION_ALCOVE, FX_SPACESTATION_MEDIUMROOM, FX_SPACESTATION_SHORTPASSAGE, FX_SPACESTATION_LONGPASSAGE, FX_SPACESTATION_LARGEROOM, FX_SPACESTATION_HAL, FX_SPACESTATION_CUPBOARD, FX_SPACESTATION_SMALLROOM

Wooden Galleon

FX_WOODEN_ALCOVE, FX_WOODEN_SHORTPASSAGE, FX_WOODEN_MEDIUMROOM, FX_WOODEN_LONGPASSAGE, FX_WOODEN_LARGEROOM, FX_WOODEN_HALL, FX_WOODEN_CUPBOARD, FX_WOODEN_SMALLROOM, FX_WOODEN_COURTYARD

Sports

FX_SPORT_EMPTYSTADIUM, FX_SPORT_SQUASHCOURT, FX_SPORT_SMALLSWIMMINGPOOL, FX_SPORT_LARGESWIMMINGPOOL, FX_SPORT_GYMNASIUM, FX_SPORT_FULLSTADIUM, FX_SPORT_STADIUMTANNOY

Prefab

FX_PREFAB_WORKSHOP, FX_PREFAB_SCHOOLROOM, FX_PREFAB_PRACTISEROOM, FX_PREFAB_OUTHOUSE, FX_PREFAB_CARAVAN

Dome, Pipe

FX_DOME_TOMB, FX_DOME_SAINTPAULS, FX_SEWERPIPE, FX_PIPE_SMALL, FX_PIPE_LONGTHIN, FX_PIPE_RESONANT

Outdoors

FX_FOREST, FX_MOUNTAINS, FX_QUARRY, FX_PLAIN, FX_OUTDOORS_BACKYARD, FX_OUTDOORS_ROLLINGPLAINS, FX_OUTDOORS_DEEPCANYON, FX_OUTDOORS_CREEK, FX_OUTDOORS_VALLEY

Mood

FX_MOOD_HEAVEN, FX_MOOD_HELL, FX_MOOD_MEMORY, FX_DRUGGED, FX_DIZZY, FX_PSYCHOTIC

Driving

FX_DRIVING_COMMENTATOR, FX_DRIVING_PITGARAGE, FX_DRIVING_INCAR_RACER, FX_DRIVING_INCAR_SPORTS, FX_DRIVING_INCAR_LUXURY, FX_DRIVING_FULLGRANDSTAND, FX_DRIVING_EMPTYGRANDSTAND, FX_DRIVING_TUNNEL

City

FX_CITY, FX_PARKINGLOT, FX_CITY_STREETS, FX_CITY_SUBWAY, FX_CITY_MUSEUM, FX_CITY_LIBRARY, FX_CITY_UNDERPASS, FX_CITY_ABANDONED



Reverb effect functions

eax_create (): var

Creates a reverb effect, and returns the reverb handle.

eax_remove (var reverb)

Removes a reverb effect. The reverb handle becomes invalid.

eax_attach (var reverb, var handle)

Attaches a reverb effect to a handle of an OpenAL 3D sound. The sound is then played with the reverb parameters. The same reverb can be attached to many sounds. If a reverb was already attached to the sound, the old reverb is detached and the new reverb is attached.

eax_detach (var reverb, var handle)

Detaches a reverb effect from a sound handle. The sound then continues playing normally without reverb.

eax_set (var reverb, REVERB*)

Configures the reverb parameters from a REVERB struct or a predefined parameter set. The REVERB struct is defined in the ackoal.h header.

 

Parameters:

handle Handle of an OpenAL 3D sound, returned by ent_playsound.
reverb Handle of a reverb effect.
REVERB* Either one of the predefined reverb parameter sets, or the pointer to a self-defined parameter set. The REVERB struct is defined in include\ackoal.h

Speed:

Fast

Example:

#include <default.c>
#include <ackoal.h>
function main()
{
level_load("");
ENTITY *actor = ent_create(CUBE_MDL,NULL,NULL);
SOUND *sound = snd_createoal("tock.wav");
var h = ent_playloop(actor,sound,200);
var env = eax_create(); // create a reverb effect
eax_set(env,FX_PIPE_RESONANT); // set up reverb parameters
eax_attach(env,h); // attach reverb to the sound
vec_set(camera.x,vector(-420,30,70));
vec_set(camera.pan,vector(20,-10,0)); while(1)
{
actor.pan += 3*time_step;
vec_set(actor.x,vector(300,0,20));
vec_rotate(actor.x,vector(actor.pan-90,0,0)); wait(1); }
}

See also:

snd_create, snd_play, ent_playsound

► latest version online