Understanding Digital Sound


Although you could probably get away with playing sounds in games without understanding how digital sound works, I'm not going to let you off the hook that easy. It's important to at least have a basic understanding of digital sound, and how it relates to physical sound that we hear in the real world. A physical sound is a wave that moves through the air, kind of like an air equivalent of an ocean wave. A sound wave is actually a result of the pressure of air expanding and contracting. In other words, a sound wave is a series of traveling pressure changes in the air. You hear sound because the traveling sound wave eventually gets to your ears, where the pressure changes are processed and interpreted by your eardrums. If your eardrums are rocky outcroppings on a beach , you hear sound when an ocean wave crashes against the rocks. The softness or loudness of a sound is determined by the amount of energy in the wave, which corresponds to the height and force of an ocean wave. Because sound waves lose energy as they travel, you hear sounds louder up close and softer from a distance. Eventually, sound waves travel far enough to be completely absorbed by the air or some other object such as a wall in your house.

When I refer to the energy of a sound wave, I'm really talking about the amplitude of the wave. Amplitudes of sound waves are usually measured in decibels (dB). Decibels are logarithmic units of measurement, meaning that 80dB is 10 times louder than 79dB. This type of measurement is used because it reflects the hearing characteristics of the human ear. The threshold of human hearing is 0dB, which means that anything less is too soft to be heard by humans. Likewise, the threshold of pain is 120dB, which is the amplitude level at which humans experience physical pain. Prolonged exposure to sound this loud can cause permanent hearing damage.

graphics/book.gif

Many rock concerts over the years have hit the 120dB sound level. In 1976, The Who made it into the Guinness Book of World Records with a 125dB concert that is now considered the loudest concert of all time.


When a microphone converts sound waves to voltage signals, the resulting signal is an analog (or continuous) signal. Because computers are digital machines, it is necessary to convert this analog signal to a digital signal for a computer to process. Analog to digital (A/D) converters handle the task of converting analog signals to digital signals, which is also referred to as sampling . The process of converting an analog signal to a digital signal doesn't always yield exact results. How closely a digital wave matches its analog counterpart is determined by the frequency at which it is sampled, as well as the amount of information stored at each sample.

To sample a sound, you just store the amplitude of the sound wave at regular intervals. Taking samples at more frequent intervals causes the digital signal to more closely approximate the analog signal and, therefore, sound more like the analog wave when played . So, when sampling sounds the rate ( frequency ) at which the sound is sampled is very important, as well as how much data is stored for each sample. The unit of measurement for frequency is Hertz (Hz), which specifies how many samples are taken per second. As an example, CD-quality audio is sampled at 44,000Hz (44kHz), which means that when you're listening to a music CD you're actually hearing 44,000 digital sound samples every second.

In addition to the frequency of a sampled sound, the number of bits used to represent the amplitude of the sound impacts the sound quality, as well as whether the sound is a stereo or mono sound. Knowing this, it's possible to categorize the quality of a digital sound according to the following properties:

  • Frequency

  • Bits-per-sample

  • Mono/stereo

The frequency of a sampled sound typically falls somewhere in the range of 8kHz to 44kHz, with 44kHz representing CD-quality sound. The bits-per-sample of a sound is usually either 8bps (bits per sample) or 16bps, with 16bps representing CD-quality audio; this is also known as 16-bit audio. A sampled sound is then classified as being either mono or stereo, with mono meaning that there is only one channel of sound, whereas stereo has two channels. As you might expect, a stereo sound contains twice as much information as a mono sound. Not surprisingly, CD-quality audio is always stereo. Therefore, you now understand that a CD-quality sound is a 44kHz 16-bit stereo sound.

Although it would be great to incorporate sounds that are CD-quality into all of your games, the reality is that high-quality sounds take up a lot of memory and can therefore be burdensome to play if your game already relies on a lot of images and other memory-intensive resources. Granted, most computers these days are capable of ripping through memory- intensive multimedia objects such as MP3 songs like they are nothing, but games must be designed for extreme efficiency. Therefore, it's important to consider ways to minimize the memory and processing burden on games every chance you get. One way to minimize this burden is to carefully choose a sound quality that sounds good without hogging too much memory.

Another issue you should consider in regard to using sound in games is that of copyrighted sounds ”you can't use copyrighted sounds without written permission from the owner of the copyright. For example, sounds sampled from copyrighted movies or audio recordings can't be used without permission. It is technically no different than using copyrighted software without permission or a licensing agreement. So be careful when sampling sounds from copyrighted sources.

graphics/clock.gif

Some seemingly public domain sound collections are actually copyrighted and can get you into trouble. Most of these types of collections come in the form of an audio CD containing a variety of sound effects. Be sure to read the fine print on these CDs, and make sure that you can legally reuse the sounds or get explicit permission from the publisher.




Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net