Export (0) Print
Expand All

Audio Attenuation and Doppler Pitch Shifting Overview (XACT)

This section provides an overview of attenuation and Doppler pitch shifting. Procedures for using each are provided .

Attenuation

In 3D audio, attenuation refers to volume attenuation—the effect of having volume fade with distance between emitter and listener. By default, the Microsoft Cross-Platform Audio Creation Tool (XACT) does not automatically apply volume attenuation as a result of calculating distance, or Doppler effect as a result of relative emitter and listener velocity.

The programmer controls the position and velocity of game objects, and the sound designer determines how that affects sound. XACT is designed to partition and simplify the work of the programmer and sound designer. It determines emitted sound by combining effects specified by the sound designer with positional information supplied by the game.

XACT exposes variables as placeholders for run-time game information such as position and velocity. The sound designer uses XACT runtime parameter controls (RPCs) to define the relationships between those variables and sound effects. The variables are then set at run time, either by the game or by XACT itself, and produce the desired sounds.

The project tree region of the XACT tool shows the available variables.

Figure 1.  XACT variables

Dd231913.advanced_audio_project_tree(en-us,XNAGameStudio.41).png

Global variables are shared by all active sound cues. Only one of each global variable exists and persists the entire time the game is running. In contrast, a separate copy of each cue instance variable exists for every active cue. Cue instance variables persist only for the lifetime of an individual cue instance.

Global variables allow multiple audio elements to be controlled together. Cue instance variables provide individual control or information for each instance of a cue, and for each copy of the same cue.

Figure 2.  Cue instance variables

Dd231913.advanced_audio_variables(en-us,XNAGameStudio.41).png

The variables used for 3D audio effects are the cue instance variables Distance, DopplerPitchScalar, and OrientationAngle. XACT automatically updates these variables for the cue when the game calls Apply3D.

VariableDescription
Distance The distance between the emitter and listener.
DopplerPitchScalar A value calculated by comparing the relative velocities of the emitter and listener; used for Doppler pitch shifting.
OrientationAngle The angle difference between the emitter and listener.

XACT updates the cue's Distance variable. By default, the variable does not adjust the volume for that cue. It is not the developer's job to try to determine and set the appropriate volume. Instead, the sound designer defines the attenuation, which is the relationship between distance and volume. To do so, the designer uses the XACT tool to create an RPC. An RPC defines the mapping between an input variable such as Distance and an output parameter such as sound volume.

The programmer might be tempted to query distance with Cue.GetVariable("Distance"), and then, based on distance, try to set the volume of the cue. Normally, volume can be set only for categories of cues defined by the sound designer (see Adjusting Volume (XACT) for more information). The game code would also have to calculate the proper volume change based on distance. To avoid these issues, use an RPC as described in this topic and let XACT, as designed, perform attenuation automatically.

Defining the Distance Scale

To define the Distance scale

  1. Click the Distance variable in the tree.

    The properties pane, below the project tree, displays properties for the Distance variable. Look for the section named General.

    Figure 3.  The variable range

    Dd231913.advanced_audio_distance(en-us,XNAGameStudio.41).png
  2. Under General, find the Variable Range boxes.

    The left box is the minimum value and the right box is the maximum value.

  3. Enter values into these boxes that are appropriate to the game's world scale (or whatever scale is used when calling Apply3D).

    Distances outside the specified range are clamped to the range. The designer need not worry about extreme values when determining the curve. For example, a game uses a 1 m (one meter) game scale, and sounds trail off completely near 1000 m. The minimum value would be 0, and the maximum value would be 1000.

Creating a Distance::Volume RPC

To create a Distance::Volume RPC

  1. Right-click the RPC Presets node in the project tree, and then select New RPC Preset.

    XACT creates and displays a new RPC, and then opens it for editing.

  2. In the Variable box, select Distance (the default is OrientationAngle).

  3. In the Object box, select Sound.

  4. In the Parameter box, select Volume.

    The RPC now adjusts volume based on distance. However, the curve is created flat, which means that volume remains constant over distance. To change that and to define the attenuation, you must adjust the curve. In the curve plot window, distance is on the x-axis and volume, in decibels (dB), is on the y-axis. To attenuate over distance, Y (volume) should decrease as X (distance) increases.

  5. Double-click anywhere on the plot line to create a new control point.

    The curve is split and a new adjustable control point is added.

  6. Add and adjust as many curve points as needed to define the attenuation.

    Dd231913.note(en-us,XNAGameStudio.41).gifNote

    Different sounds may have different attenuation characteristics. These two example curves produce significantly different attenuation. The first creates a simple constant ramp from full volume (+0 decibel (dB)) to silence (−96 dB) over the full distance range. The second has a fast rolloff after a short distance, then a fade out to full distance.

    Figure 4.  Attenuation RPC (constant rolloff)

    Dd231913.advanced_audio_RPC_attenuation1(en-us,XNAGameStudio.41).jpg

     

    Figure 5.  Attenuation RPC (quick rolloff)

    Dd231913.advanced_audio_RPC_attenuation2(en-us,XNAGameStudio.41).jpg
  7. When finished, close the RPC window.

    The new RPC is called "RPC Preset," but it can be renamed (to "Attenuation," for example) to make it easier to find in the RPC list. The name given does not affect the RPC or the game code.

  8. Right-click the RPC to rename it, and then click Rename.

Applying the RPC to Sounds

To apply the RPC to sounds

The RPC is now defined, but no sounds are configured yet to use it. By default, sounds do not use any of the defined RPCs. Some sounds will not need attenuation (for example, narration or tutorial instructions), while others may need several different RPC effects.

  1. Double-click a sound bank listed in Sound Banks in the project tree.

    The sound bank opens, showing the sounds and cues defined in that bank.

  2. From RPC Presets in the project tree, drag the desired RPC onto the sound that will use that RPC.

Do this for as many sounds as will be used for the attenuation effect. You can apply more than one RPC to a sound. RPC curves that modify elements such as pitch and volume are additive, so if multiple parameters influence the sound, their results are combined.

Removing an RPC from a Sound

To remove an RPC from a sound

  1. Right-click the sound, and then click Attach/Detach RPC(s).

    -or-

    Right-click the RPC in the project tree, and then click Attach/Detach Sounds.

  2. Right-click the sound, and then click Attach/Detach RPC(s).

At this point, the attenuation RPC is defined and applied to the appropriate sounds. XACT will now use the curve to adjust emitter volume based on the distance between emitter and listener. Game code sets the AudioEmitter.Position and AudioListener.Position properties to specify the 3D location of the game objects. When the code then calls Apply3D, XACT adjusts the volume appropriately. See Applying a 3D Positional Effect to a Cue (XACT) for a description of the steps needed to use 3D positioning in a game.

Doppler Pitch Shifting

Doppler pitch shifting is the pitch shifting effect when a listener and an emitter are moving toward or away from each other. The relative velocities of the emitter and listener are compared and the result is used raise or lower the pitch of the emitter's sound.

Doppler pitch shifting is applied to sounds in the same way that attenuation is, except that the RPC adjusts pitch based on relative velocity rather than adjusting volume based on distance. The Doppler RPC ties the DopplerPitchScalar input variable to the Sound::Pitch output parameter.

Adding Doppler Pitch Shifting

To add Doppler pitch shifting

  1. Set the scale of the DopplerPitchScalar variable.

    Dd231913.note(en-us,XNAGameStudio.41).gifTip

    The default scale of 0–4 is appropriate, so leave MinimumValue at 0 and MaximumValue at 4.

    The scale of DopplerPitchScalar is not based on the velocity scale used by the game. Instead, this value is the result of an XACT calculation to determine the pitch adjustment that should be applied due to Doppler effect. Zero indicates down one octave, 1 indicates unity pitch, and 4 indicates up two octaves.

  2. Right-click RPC Presets to create a new RPC, and then click New RPC Preset.

  3. In the Variable box, select DopplerPitchScalar.

  4. In the Object box, select Sound.

  5. In the Parameter box, select Pitch.

  6. Define the Doppler curve effect.

    Dd231913.note(en-us,XNAGameStudio.41).gifNote

    The y-axis is the pitch, in semitones, and ranges from down one octave (−12 semitones) to up one octave (+12 semitones).

    For normal Doppler effect, the beginning of the curve would look like the following.

    Figure 6.  Doppler RPC

    Dd231913.advanced_audio_RPC_doppler(en-us,XNAGameStudio.41).jpg

    However, this curve limits the effect to +12 semitones. To enable a wider range effect, make the curve half as steep (+12 semitones at 4.0 rather than 2.0) and set the emitter's Doppler scale (AudioEmitter.DopplerScale) to 2.0f.

  7. Close the RPC window and, if desired, rename the RPC.

  8. Open the sound bank to associate the RPC with sounds, and then drag the RPC from the project tree onto the desired sound or sounds.

Code Changes to Support Doppler Pitch Shifting

XACT derives DopplerPitchScalar based on the relative velocities of the emitter and listener. The game informs XACT of these velocities by setting the AudioListener.Velocity and AudioEmitter.Velocity properties before calling Apply3D.

The AudioEmitter.DopplerScale property can be used to exaggerate (values > 1.0) or diminish (values < 1.0) of the Doppler effect.

For sample code that demonstrates the steps needed to enable attenuation and Doppler effects, see Applying 3D Audio Effects (XACT).

Concepts

Sounds Overview
Provides a high-level overview about the capabilities of the Audio API in XNA Game Studio in addition to general audio terminology.
Applying a 3D Positional Effect to a Cue (XACT)
Demonstrates how to apply a 3D positioning effect to a cue.
Applying 3D Audio Effects (XACT)
Demonstrates how to apply attenuation and Doppler 3D audio effects in code.
XACT Runtime Parameter Controls [DirectX]
XACT Audio Authoring [DirectX]

Reference

Cue.Apply3D Method
Calculates the 3D audio values between an AudioEmitter and an AudioListener object, and applies the resulting values to this Cue.
AudioEmitter.Position Property
Gets or sets the position of this emitter.
AudioListener.Position Property
Gets or sets the position of this listener.
AudioEmitter.Velocity Property
Gets or sets the velocity vector of this emitter.
AudioListener.Velocity Property
Gets or sets the velocity vector of this listener.
AudioEmitter.DopplerScale Property
Gets or sets a scalar applied to the level of Doppler effect calculated between this and any AudioListener.

Community Additions

ADD
Show:
© 2014 Microsoft