AL 3D Audio and Environmental Audio Extension

3D Audio and Environmental Audio Extension: Using AL's Support for 3D Audio and EAX

Introduction

Games and sophisticated applications require the use of a 3D Audio facility to place their gamers or users in a 3D Space. This results in a virtual world in which the user is immersed, resulting in an improved user response. Added to this is a technology by Creative Labs, the EAX or Environmental Audio Extension, which makes the virtual world more rich with respect to 3D sound.

With this simple introduction, you experience the power of 3D sound and EAX and implement these by using the AL SDK.

Requirements

  1. Download the SDK runtime and the SDK from http://streetx.freespaces.com.
  2. Install the SDK runtime on your system.
  3. Install the SDK as directed so that it can run with VC++ (6 or .NET) or BC++ (32 bit).

An Introduction to 3D Audio

Audio in 3D enables a feeling of reality in Sound. To bring about this reality to the sound, you require two attributes:

  1. Attribute of the Listener.
  2. Attribute of the Source.

Attribute of listener means vectors that specify the position of the listener (the gamer or the user) in 3D space along with the relative velocity of motion. Other attributes, such as Doppler shift, Roll off factor, Max and Min hearing distance, FRONT, and UP vector of the listener are also required.

Attribute of the source means the values that determine the characteristics of the sound source. The most important values for these are the vectors for position of source and the relative velocity. Other values can be the cone angle and orientation.

This article will discuss the placement of sound in 3D space with the position and velocity attribute of each. For a full discussion about the attributes, please refer to the help file for the SDK.

Relative Velocity: The Term

The relative velocity of an object may be defined as the (absolute) velocity of the object with respect to the observer, when the observer is stationary. The velocity of the listener and source can be independently specified, yet the term is relative velocity. This is because the effect achieved by setting the velocity of the source and listener independently also can be achieved by setting the velocity of listener to ZERO and the source to the relative velocity of source with respect to listener, and vice-versa. And, because nothing is absolute in space, the term relative provides a better approach.

Steps to Coding

  1. Initialize the AL system.
  2. Create an AL context and set the context for current use.
  3. Open a wave buffer with 3D support and, before using it, set it as the current audio source.
  4. Play the wave.
  5. Perform positioning of listener (it can be done anytime after setting a current context as it has nothing to do with opening of wave or the like).
  6. Position the source in the listener's space.

After youe are done using the program...

  1. Stop the wave.
  2. Close the wave.
  3. Delete the AL context. !!!Use the ALDelete() function!!!
  4. Uninitialize the AL system.

Program Name

The source code of the program and a DEMO EXE are attached.

  • Source Code Archive: CG_Audio3D.zip
  • EXE Demo Archive: CG_Audio3D Demo.zip

Project/EXE Dependence

This project implements functions from AL and a few functions from the GL library. This article will not discuss the functions from GL SDK but only those from AL SDK.

Excerpt from the Code

Because this article deals with 3D location of sound, I will assume that the reader understands the code dealing with initializating the AL system and de-initializating and creating of the AL context by downloading the souce.

The IDs used in the code are defined as follows:

  • ID_WAVE: Points to the Wave buffer to be used.
  • ID_FONT: Points to the Font resource to be used to display result on GLX Window.
  • ID_TEXTURE: The 2D surface that is used to display 2D graphics on GLX Screen.

Opening Audio with 3D Support

if(!ALOpenWave( ID_WAVE,     //Wave resource ID
   // Wave file name (NULL terminated string)
   filename,
   // We need 3D support on the Wave Resource
   TRUE,
   // Wave data will be streamed ino wave buffer
   TRUE,
   // Wave will be audible even if the window loses focus
   TRUE,
   // We are not concerned about EAX now
   FALSE ))
{
   /* TODO : FILE failed to open.
    * Deal with error
    */
}

Setting 3D Audio Attributes (Position and Velocity Vectors)

ALbool ALApply3D();

This function is very important. Whenever 3D parameters of the source and/or listener are changed, this function must be called for the changes in the 3D to take effect. It must be called after the listener and source 3D attributes are all set. It can be called after a batch of changes so that a more efficient program is created.

ALbool ALSet3DPosition( Vector *vec);

This function will take a vector that contains the position vector of the listener. By default, the listener is placed at Vector(0,0,0).

ALbool ALSet3DVelocity( Vector *vec);

This function will take a vector that contains the velocity vector of the listener. By default, the listener is stationary; in other words, Vector(0,0,0).

Now, the wave ID_WAVE is selected as the current wave buffer by calling ALSetWave(ID_WAVE). Then, afterward (because you know that your wave is 3D enabled), you can set the 3D Source attributes.

ALbool ALSetWave3DPosition(Vector *vec);

This function sets the position vector of the source in 3D space. By default, the source is set at the origin, Vector(0,0,0).

ALbool ALSetWave3DVelocity(Vector *vec);

This function sets the velocity vector of the source in 3D space. By default, the source is stationary; in other words, Vector(0,0,0).

Note: This is a general and simple 3D Audio Program; the source and demo can be viewed for results and understanding. Next, I will explain the Creative EAX effect on 3D Audio Resource. You should remember that the next program being discusses is an extension of the 3D Audio program; there is no change to whatever is discussed here, but only an addition of Creative EAX functionality.

AL 3D Audio and Environmental Audio Extension

Creative EAX Support of AL

EAX: An Introduction

A primary goal of computer gaming is to produce a realistic 3D world for the player. Creating the aural component of that world has always lagged behind the visual component. It's not uncommon to find a computer displaying sophisticated 3D graphics with texture mapping, shading, multiple light sources, haze, and one or two tinny speakers spits out monaural sound.

The Audio SDK keeps the nitty gritty of audio hardware at arm's length from the programmer. The programmer uses the relatively simple API to create sound sources, set their 3D positions and velocities (if moving), and take care of other decisions about the quality and placement of sounds in the aural world. The Audio kernel, through the audio driver installed in a computer, does the work of translating sound-source waveforms, positions, velocity, and more into a mix that ultimately comes out in a realistic 3D form through the player's speakers or headphones. Although the basic Audio SDK provides a number of sophisticated 3D aural effects such as Doppler effect, rolloff, and direction, they lack some very important environmental effects: reverberation, reflections, and sound occlusion or obstruction by intervening objects. Without these environmental effects, a listener can tell the direction of each sound source, but has no idea of the environment where the sources are located. The listener also has a more difficult time telling how far away the sources are.

Consider a sword clanked in a small padded cell. It should sound much different than the same sword clanked in a large cathedral, and it's reverberation that tells the story. Or, consider a scream coming from the next room. The occluded (muffled) quality of the scream tells you there's a wall between you and the screamer. Without environmental audio effects, sound sources are naked and lack warmth—the aural equivalent of a visual world without shadows, haze, and independent light sources.

EAX Parameter Path

The EAX parameter keeps two working profiles. The first profile, works on the listener's side, the attributes of which are common to all 3D wave buffers. The second profile is private to the 3D wave buffer that has EAX set on it. Its values affect only the current wave buffer (with EAX) and not all other buffers. For a more detailed discussion about EAX listener and source parameters, refer to the SDK help file. This article discusses the functions used in the EAX sample.

EAX Sample

  • Source Code: CG_EAXAudio
  • EXE/DEMO Application: CG_EAXAudio Demo

EAX Parameters Used in EAX Sample

You have used four functions:

  • EAXIsEnabled()
  • EAXWaveIsEnabled()
  • EAXSetReflections()
  • EAXSetEnvironment()

EAXIsEnabled, EAXSetReflections, and EAXSetEnvironment are listener-side parameters, whereas EAXWaveIsEnabled is a source-side parameter. Now, you can learn about these functions in detail. For the application, please read the source for more detail.

Opening Audio with 3D Support

if(!ALOpenWave( ID_WAVE,    // Wave resource ID
   filename,    // Wave file name (NULL terminated string)
   TRUE,        // We need 3D support on the Wave Resource
   TRUE,        // Wave data will be streamed ino wave buffer
   // Wave will be audible even if the window loses focus
   TRUE,
   // We need EAX support on our Wave resource
   // (It will be disabled automatically if the Sound card does
   // not support Creative EAX 2.0.
   TRUE ))
{
   /* TODO : FILE failed to open.
      Deal with error
    */
}

Checking for EAX Support on the System

ALbool EAXIsEnabled();

This function checks the Creative EAX 2 support on the device. If EAX 2.0 is detected, this function returns TRUE. (Optional, if you do not want to be informed if the host supports EAX or not.)

Checking for EAX Support on the Wave Source

First, set the wave resource as current. For the example, use ALSetWave(ID_WAVE).

ALbool EAXWaveIsEnabled();

This function checks the Creative EAX 2 support on the wave buffer. If EAX 2.0 is enabled on the wave buffer, this function returns TRUE. (Optional, if you do not want to be informed if the buffer had internally disabled support for EAX or not.) When a wave is opened with EAX support, 3D is automatically enabled, if not explicitly enabled when ALOpenWave() is called. But, if 3D support is not explicitly requested during the call to ALOpenWave() and the EAX 2.0 sound card is not detected, the Wave source may not support any 3D call on it.

Set Room Reflection Value

ALbool EAXSetReflections(ALlong v);

Sets the value of the reflection factor. Its value lies in the range -10000 to 1000 and is measured in seconds.

The Reflections property controls the overall amount of initial reflections relative to the Room property. (The Room property sets the overall amount of reflected sound: both initial reflections and later reverberation.) The value of Reflections ranges from a maximum of 10 dB to a minimum of -100 dB (no initial reflections at all), and is corrected by the value of the Room property. The Reflections property does not affect the subsequent reverberation decay. You can increase the amount of initial reflections to simulate a narrower space or closer walls; this is especially effective if you associate the initial reflection's increase with a reduction in reflection delays by lowering the value of the Reflection Delay property. To simulate open or semi-open environments, you can maintain the amount of early reflection while reducing the value of the Reverb property, which controls later reflections.

The Reflections Delay property 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 Reflections Delay to simulate closer or more distant reflective surfaces—and therefore control the perceived size of the room.

Both Reflections and Reflections Delay are low-level properties that may be controlled by the high-level listener property Environment Size. If so, their values are scaled according to the value set there. You can disable Environment Size's control over these properties by setting the appropriate flags in the listener property Flags.

Set the EAX Listener Environment

ALbool EAXSetEnvironment(ALdword v);

Sets the value of environment to use and hence modify the listener Room attributes. Its value lies within the range of 0 to 25, and its default value is 0 or EAX_ENV_GENERIC.

The possible environments are:

  • EAX_ENV_GENERIC
  • EAX_ENV_PADDEDCELL
  • EAX_ENV_ROOM
  • EAX_ENV_BATHROOM
  • EAX_ENV_LIVINGROOM
  • EAX_ENV_STONEROOM
  • EAX_ENV_AUDITORIUM
  • EAX_ENV_CONCERTHALL
  • EAX_ENV_CAVE
  • EAX_ENV_ARENA
  • EAX_ENV_HANGAR
  • EAX_ENV_CARPETEDHALLWAY
  • EAX_ENV_HALLWAY
  • EAX_ENV_STONECORRIDOR
  • EAX_ENV_ALLEY
  • EAX_ENV_FOREST
  • EAX_ENV_CITY
  • EAX_ENV_MOUNTAINS
  • EAX_ENV_QUARRY
  • EAX_ENV_PLAIN
  • EAX_ENV_PARKINGLOT
  • EAX_ENV_SEWERPIPE
  • EAX_ENV_UNDERWATER
  • EAX_ENV_DRUGGED
  • EAX_ENV_DIZZY
  • EAX_ENV_PSYCHOTIC

Value Units Integers that Each Specify a Specific Environment

Environment is the fundamental listener property. You typically set it first and then—if you want—modify it using other listener properties. When you set an environment, you choose the acoustic surroundings of the listener—the size of the virtual room around the listener and the reflective qualities of its walls. When you modify the environment using the other listener properties you can, in particular, modify the room size or adjust lower-level parameters such as the overall level and delay of the first reflections, the overall level of the subsequent reverberation, and the duration and tonal quality of the reverberation decay.

Here, the word Room is specified to emphasize that you are in a virtual 3D Room that you earlier considered as your 3D space. For the application, refer to the source. The detail discussion is here, but see it to believe it!!!



About the Author

Arnav Guddu

A hobby programmer. Do much of programming in graphics, animation, sound and multimedia. But a lot crazy about C++ related development. I may be reached at http://pendorasoft.byethost15.com/

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds