chapter 5.5 audio programming lacey montgomery. 2 audio programming audio in games is more important...

42
Chapter 5.5 Audio Programming Lacey Montgomery

Upload: harvey-kelly

Post on 26-Dec-2015

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

Chapter 5.5 Audio Programming

Lacey Montgomery

Page 2: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

2

Audio Programming

Audio in games is more important than ever before

- less repetitive

- More complex sound and musical components

Page 3: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

3

Programming Basic Audio

• Most gaming hardware has similar capabilities (on similar platforms) Mostly programming interfaces differ

• Learning fundamental concepts of audio programming is important

Page 4: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

4

API Choices

• DirectSound (part of DirectX API) Only available on Windows platforms Free Most popular Antiquated, faults, problems Support and Example Code

Page 5: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

5

More API Choices

•OpenAL (like OpenGL, but for sound)Newer APIAvailable on multiple platformsLack of support for basic 2D sound rendering

Proprietary APIsTypically available on consoles

3rd Party Licensable APIsCan offer broad cross-platform solutions

Page 6: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

6

Analog Sound Wave

Page 7: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

7

Basic Audio Terminology and Physics

• Amplitude Measurement of a sound wave’s pressure (positive or negative direction)

• Frequency Measurement of the interval between wave cycles, typically measured in

Hertz (cycles/second)

• Pitch The perception of frequency (perceive high notes at a slightly higher

frequency and lower notes at a slightly higher frequency), usually used interchangeably with Frequency

• Tuning Musical distribution of frequencies over keys

• Decibel Measures sound amplitude, measures perceived difference in loudness

between two sounds

Page 8: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

8

Digital Representation of a Sound Wave

Page 9: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

9

Digital Representationof a Sound Wave

• Most common technique known as sampling Sampling involves measuring the amplitude of the

analog wave file at discrete intervals Sampling Rate = frequency of sampling Each sample is typically stored in a value ranging

from 4 to 24 bits in size The size of the sample value in bits is known as

the ‘bit depth’ Music CDs have a sample rate and bit depth of

44.1 kHz (samples/sec) and 16 bits (sample size)

Page 10: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

10

Quantization Error in Sampling

Amplitude cannot be perfectly represented due to low bit depth

Lower the bit depth, the more noise that will be introduced into the signal

Page 11: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

11

Bit Depth and Signal Noise

• Bit depth of sample data affects signal noise Signal to noise ratio = number of available bits / 1 For example, 8-bit samples have a 256:1 SNR (~48

dB), and 16-bit samples have a 65,536:1 SNR (~96 dB)

Decibel ratio is calculated using 10 x log10 (ratio) or 8.685890 x log e (ratio)

Page 12: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

12

Sampling Frequency and Frequency Reproduction

• Sampling frequency affects range and quality of high-frequency reproduction

• Nyquist Limit Frequencies up to one-half the sampling rate

can be reproduced Audio quality degrades as frequency

approaches this limit

Page 13: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

13

Modern Audio Hardware

• Samples are piped into sound “channels” Often a hardware pipeline from this point

• Various operations, such as volume, pan, and pitch may be applied

• 3D sounds may apply HRTF algorithms and/or mix the sound into final output buffers.

Page 14: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

14

Sound Playback Techniques

• Two basic playback methods:1. Play sample entirely from memory buffer

2. Stream data in real-time from storage medium• Streaming is more memory efficient for very large

audio files, such as music tracks, dialogue, etc• Streaming systems use either a circular buffer with

read-write pointers, or a double-buffering algorithm

Page 15: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

15

Sample Playback and Manipulation

• Three basic operations Panning is the attenuation of left and right

channels of a mixed sound• Results in spatial positioning within the aural stereo

field

Pitch allows the adjustment of a sample’s playback frequency in real-time

Volume control typically attenuates the volume of a sound

• Amplification is generally never supported

Page 16: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

16

Compressed Audio Format

• Compressed audio formats allow sound and music to be stored more compactly Bit reduction codecs generally are lightweight

• ADPCM compression is implemented in hardware on all the major current video game console systems

Psycho-acoustic codecs often have better compression

• Require substantially more computational horsepower to decode

Page 17: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

17

MP3, Ogg Vorbis,Licensing & Patent Issues

• The MP3 format is patented Any commercial game is subject to licensing terms

as determined by Fraunhofer & Thompson Multimedia, the holders of the patents

• Ogg Vorbis is similar to MP3 in many ways Open source and patent-free (royalty-free)

• Be aware of patent and license restrictions when using 3rd party software

Page 18: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

18

ADSR Envelope(Attack, Decay, Sustain, Release)

Page 19: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

19

3D Audio

• Two sets of data required when working in world coordinates: Listener Data

• Composed of world position and orientation (virtual microphone in the world)

Source Data• Composed of sound position, orientation, velocity, etc

(virtual sound source in the world)

Page 20: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

20

Environmental Effects

• Environmental effects nearly always implemented in hardware

• Sound transmission is categorized in three ways Direct transmission Early reflections (echo) Late reflections (reverberation)

Page 21: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

21

Sound Transmission Categories

Page 22: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

22

Programming Music Systems

• Two common music systems MIDI-based systems

• (Musical Instrument Digital Interface)

Digital audio streaming systems• (CD audio, MP3 playback, etc)

Page 23: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

23

Advantages and Disadvantages of MIDI

• Actual music data size is negligible

• Easy to control, alter, and even generate in real-time

• High quality music is more difficult to compose and program

• Only effective if you can guarantee playback of a common instrument set

Page 24: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

24

Other MIDI-based technologies to be aware of

• DLS (DownLoadable Sound) Format A standardized format for instrument definition

files

• iXMF (Interactive eXtensible Music Format) New proposed standard for a container format

for interactive music

Page 25: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

25

Advantages / Disadvantages of Digital Audio Streams

• Superb musical reproduction is guaranteed

• Allows composers to work with any compositional techniques

• Some potential interactivity is sacrificed for expediency and musical quality

• Generally high storage requirements

Page 26: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

26

A Conceptual Interactive Music Playback System

• Divide music into small two to eight-bar chunks that we’ll call segments.

• A network of transitions from segment to segment (including loops and branches) is called a theme.

• Playing music is now as simple as choosing a theme to play. The transition map tracks the details.

Page 27: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

27

Advanced Audio Programming

• 3D Audio Environmental Effects Integration

• Audio Scripting and Engine Integration

• Lip-sync Technology

• Advanced Voice Playback

• Voice Recognition

Page 28: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

28

3D Audio Environmental Effects Integration

• Environmental effects should be driven by a room’s shape and material composition. Can determining the optimal effect settings be

done automatically? This may be important as game worlds

become larger and more complex

Page 29: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

29

3D Audio Environmental Effects Integration (cont)

• Sound occlusion and damping is a particularly difficult problem to solve This is essentially a pathfinding problem for

audio. Doors can dynamically affect a sound’s

properties Very few titles have even attempted a robust,

general-purpose, and automated solution to these problems.

Page 30: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

30

Dynamic Occlusion

Page 31: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

31

Audio Scripting and Engine Integration

• Very little audio programming should be done by general game programmers

• Game Engine should offer robust support for audio triggers and scripts

• Engine should deal with audio scripts, not “sound files”

Page 32: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

32

Audio Scripting

• Many situations require much more information than can be embedded in a linear audio file Sound Variation Sound Repetition Complex Sound Looping Background Ambience

Page 33: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

33

Lip-sync Technology

• Lip-sync technology is a blending of audio and visual techniques to create realistic-looking speech by in-game actors. Simple techniques such as waveform

amplitude measurement has worked previously, but…

In future titles, it will be considered inadequate.

Much work can still be done in this field.

Page 34: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

34

Advanced Voice Playback

• Real-time spoken feedback is especially important in sports titles (simulated announcers)

• Game are reaching the limits of what current techniques (canned, prerecorded phrases combined in series) can provide.

• Again, this is an opportunity for future groundbreaking audio work.

Page 35: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

35

Voice Recognition

• Spoken commands are much easier to deliver in certain situations. Squad-based tactical shooters.

• Current generation systems are still very error prone. Research Area

Page 36: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

36

Music for Games

• Remember copyright laws• If you use someone else’s work for a game

you plan to sell, GET PERMISSION.• Writing your own music may be the better

option.• Fruity-Loops/FL Studios (Windows)• Garage Band (Mac)

Page 37: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

37

Writing Music for Games

• Start with a theme.• Steal ideas, not whole songs.• Use variations of a theme and build on it until you have a

complete song.• It doesn’t need to be very long… its going to be playing

over and over anyway! The longest song on the Half-Life 2 soundtrack is less than 3 minutes long!

Page 38: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

38

Screenshots of Fruity Loops

Page 39: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

39

More Fruity Loops

Page 40: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

40

Garage Band

Page 41: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

41

More Garage Band

Page 42: Chapter 5.5 Audio Programming Lacey Montgomery. 2 Audio Programming Audio in games is more important than ever before - less repetitive - More complex

The End

Any Questions?