Game Programming Algorithms and Techniques Chapter 6 Sound




















- Slides: 20

Game Programming Algorithms and Techniques Chapter 6 Sound

Chapter 6 Objectives § § Basic Sound – Learn the difference between source data and sound cues – Creating switches to select from different sets of sounds 3 D Sounds – Placing the listener in the world – Surround sound principles Digital Signal Processing – Basic DSP effects – How to mark regions Other Topics – What's the Doppler effect, and how is it used in games? – Difference between sound occlusion and obstruction

Source Data § § § Original audio files created by sound designer. File formats: – Sound effects generally use uncompressed formats such as WAV. – Music/dialogue is usually compressed with MP 3 or OGG. Two ways sounds can be played: – Loaded fully into memory (usually for small files). – Streamed off of the disk (for larger files).

Sound Cue § Maps to one or more source data files § Says how or when particular source data should play § What's triggered by gameplay code

Sound Cue Example: Explosion sound cue

Storing Sound Cue Data § One possibility is JSON. Here’s an example: { "name": "explosion", "falloff": 150, "priority": 10, "sources": [ "explosion 1. wav", "explosion 2. wav", "explosion 3. wav" ] }

Basic Sound Cue Class § Would correspond to the type of data in a basic cue class Sound. Cue string name int falloff int priority // List of strings of all the sources List sources; function Play() // Randomly select from sources and play. . . end

Sound Switch § Suppose we have different footstep sounds depending on the surface the character walks on. § We want to be able to switch between different sets of sounds, depending on surface. § To do this, we need a switch.

Sound Cue Data w/ Switch { "name": "footstep", "falloff": 25, "priority": "low", "switch_name": "foot_surface", "sources": [ { "switch": "sand", "sources": [ "fs_sand 1. wav", "fs_sand 2. wav", "fs_sand 3. wav" ] }, { "switch": "grass", "sources": [ "fs_grass 1. wav", "fs_grass 2. wav", "fs_grass 3. wav" ] }

Sound Cue Class w/ Switch interface ISound. Cue function Play() end class Switchable. Sound. Cue implements ISound. Cue string name int falloff int priority string switch_name // Hash Map that stores (string, List) pairs // For example ("sand", ["fs_sand 1. wav", "fs_sand 2. wav", // "fs_sand 3. wav"]) Hash. Map sources function Play() // Grab the current value for switch_name // Lookup list in the hash map and randomly play a sound. . . end

3 D Sounds § A listener is what hears a sound: – Think of it as a virtual microphone in the world. § An emitter is what emits a sound: – For instance, a fireplace would have an emitter that emits the sound of crackling fire.

Listener/Emitter Diagram Sound listener and emitter; in this case, the sound effect should be heard on the right.

Listener Position § FPS – At the camera § Cutscene – At the camera § Third person – Not always at the camera!

Listener Position Listener position in a third-person game.

Falloff § § § How volume of a sound decreases as it gets further from the listener. Decibel – Unit of sound measurement – Logarithmic scale The falloff will depend on the sound—an explosion would have less of a falloff than a footstep.

Surround Sound § A "5. 1" system may be configured like so: A standard 5. 1 surround speaker configuration

Digital Signal Processing § § Takes sound data and transforms it at runtime Common effects: – Reverb (echo) – Pitch shift (increase/decrease frequency) – Compressor (reduce dynamic range of sound volume levels) – Low-pass filter (reduce volume of high-pitch sounds)

Doppler Effect § § As a sound emitter approaches towards the listener, the pitch increases. As it goes away, the pitch decreases.

Sound Occlusion/Obstruction § § § Occlusion – Sound has to travel through wall (or other material) to reach listener. – Reduction of high-frequency volumes. Obstruction – Sound travels around an object to reach a listener. – Causes interaural time difference (sound arrives in each ear at a different time). Fresnel Acoustic Diffraction – Used to determine whether a sound is occluded or obstructed.

Sound Occlusion/Obstruction, Cont'd Sound occlusion (a), sound obstruction (b), and Fresnel acoustic diffraction (c)