28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />

Converting Analog Audio to Digital Audio Data: Sampling, Accuracy, HD Audio<br />

The process of turning analog audio (sound waves) into digital audio data is called sampling. If you work in the<br />

music industry, you have probably heard about a type of keyboard (or even rack-mounted equipment) called a<br />

sampler. Sampling is the process of slicing an analog audio wave into segments so that you can store the shape of<br />

the wave as digital audio data, using a digital audio format. This turns an infinitely accurate analog sound wave into<br />

a discrete amount of digital data, that is, into zeroes and ones. The more zeroes and ones used, the more accurate the<br />

reproduction of the infinitely accurate (original) analog sound wave.<br />

Each digital segment of a sampled audio sound wave is called a sample, because it samples that sound wave at an<br />

exact point in time. The sample accuracy (resolution) you want will determine how many zeroes and ones are used<br />

to reproduce analog sound waves, so the precision of a sample is determined by the amount of data used to define<br />

each wave slice’s height. As with digital imaging, this precision is termed the resolution, or, more accurately (no pun<br />

intended), the sample resolution. Sample resolution is usually defined using 8-bit, 12-bit, 16-bit, 24-bit, or 32-bit<br />

resolution. <strong>Games</strong> mostly leverage 8-bit resolution for effects such as explosions, in which clarity is not as important;<br />

12-bit resolution for crystal-clear spoken dialogue and more important audio elements; and, possibly,<br />

16-bit resolution for background music.<br />

In digital imaging and digital video this resolution is quantified by the number of pixels, and in digital audio,<br />

by how many bits of data are used to define each of the analog audio samples taken. Again, as with digital imaging,<br />

in which more pixels yields better quality, with digital audio a higher sample resolution yields better sound<br />

reproduction. Thus, higher sampling resolutions, using more data to reproduce a given sound wave sample, will<br />

produce higher-quality audio playback, at the expense of a larger data footprint. This is the reason that 16-bit audio<br />

(commonly referred to as CD quality audio) sounds better than 8-bit audio. Depending on the audio involved, 12-bit<br />

audio can be a great compromise.<br />

In digital audio there is a new type of audio sample, known as HD audio in the consumer electronics industry.<br />

HD digital audio broadcast radio uses a 24-bit sample resolution, so each audio sample, or slice of the sound wave,<br />

contains 16,777,216 bits of sample resolution. Some of the newer hardware devices now support HD audio, such as<br />

the smartphones you see advertised featuring “HD-quality audio,” meaning that they have 24-bit audio hardware.<br />

These days, laptops (including PCs), as well as game consoles and iTVs, also come standard with 24-bit audio<br />

playback hardware.<br />

It is important to note that HD audio is probably not necessary for <strong>Java</strong> 8 games, unless your game is music<br />

oriented and makes use of high-quality music, in which case you can use HD audio samples via a WAVE file format.<br />

Another consideration is digital audio sampling frequency (also called the sampling rate), This is a measure<br />

of how many samples at a particular sample resolution are taken during 1 second of sampling time frame. In terms<br />

of digital image editing, sampling frequency is analogous to the number of colors contained in a digital image. You<br />

are probably familiar with the term “CD-quality audio,” which is defined as using a 16-bit sample resolution and a<br />

44.1kHz sampling rate (taking 44,100 samples, each of which has 16 bits of sample resolution, or 65,536 bits of audio<br />

data). You can determine the amount of raw data in an audio file by multiplying the sampling bit rate by the sampling<br />

frequency by the number of seconds in the audio snippet. Obviously, this can potentially be a huge number! Audio<br />

codecs are really great at optimizing data down to an amazingly small data footprint with very little audible loss<br />

in quality.<br />

Thus, the exact same trade-off that exists in digital imaging and digital video occurs with digital audio as well:<br />

the more data you include, the higher quality the result, but always at the cost of a much larger data footprint. In the<br />

visual mediums the size of the data footprint is defined using color depth, pixels, and, in the case of digital video and<br />

animation, frames. In the aural medium it is defined via the sample resolution, in combination with the sampling<br />

rate. The most common sampling rates in the digital audio industry currently include 8kHz, 22kHz, 32kHz, 44.1kHz,<br />

48kHz, 96KHz, 192kHz, and even 384kHz.<br />

Lower sampling rates, such as 8kHz, 11kHz, and 22kHz, are the ones that you are going to use in your games, as,<br />

with careful optimization, these can yield high-quality sound effects and arcade music. These rates would be optimal<br />

for sampling any voice-based digital audio as well, such as movie dialogue or an e-book narration track. Higher audio<br />

sample rates, such as 44.1kHz, would be more appropriate for music, and sound effects that need a high dynamic<br />

range (high fidelity), such as rumbling thunder, could use 48kHz. Higher sample rates will allow audio reproduction<br />

that exhibits movie theater (THX) sound quality, but this is not required for most games.<br />

www.it-ebooks.info<br />

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!