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 />

Digital Audio Streaming: Captive Audio vs. Streaming Audio<br />

As with digital video data, digital audio data can be either captive within the application distribution file (in the case<br />

of <strong>Java</strong>, a .JAR file) or streamed, using remote data servers. Similar to digital video, the upside to streaming digital<br />

audio data is that it can reduce the data footprint of the application file. The downside is reliability. Many of the same<br />

concepts apply equally well to audio and video. Streaming audio will save the data footprint, because you do not have<br />

to include all that heavy new media digital audio data in your .JAR files. So, if you are planning on coding a Jukebox<br />

application, you may want to consider streaming your digital audio data; otherwise, try to optimize your digital audio<br />

data so that you can include them (captive) inside the .JAR file. This way, the data will always be available to the<br />

application’s users when they need it!<br />

The downside to streaming digital audio is that if a user’s connection (or the audio data server) goes down, your<br />

digital audio file may not always be present for your end users to play and listen to, using your game application! The<br />

reliability and availability of digital audio data are a key factor to be considered on the other side of this streamingversus-captive<br />

trade-off. The same would apply to digital video assets as well.<br />

Again, as with digital video, one of the primary concepts in regard to streaming your digital audio is the bit rate of<br />

the digital audio data. As you learned in the previous section, the bit rate is defined during the compression process.<br />

Digital audio files that need to support lower bit-rate bandwidth are going to have more compression applied to the<br />

audio data, which will result in lower quality. These will stream (play back) more smoothly across a greater number of<br />

devices, because fewer bits can be quickly transferred as well as processed more easily.<br />

Digital Audio in <strong>Java</strong>FX: Supported Digital Audio Codecs and Data Formats<br />

There are considerably more digital audio codecs in <strong>Java</strong>FX than digital video codecs, as there is only one video<br />

codec, MPEG-4 H.264 AVC. Android audio support includes .MP3 (MPEG-3) files, Windows WAVE (Pulse Code<br />

Modulation [PCM] audio) .WAV files, .MP4 (or .M4A) MPEG-4 AAC (Advanced Audio Coding) audio, and Apple’s<br />

AIFF (PCM) file format. The most common format supported by <strong>Java</strong>FX (and thus <strong>Java</strong> 8) is the popular .MP3 digital<br />

audio file format. Most of you are familiar with MP3 digital audio files, owing to music download web sites, such as<br />

Napster or Soundcloud, and most of us collect songs in this format to use on MP3 players and in CD-ROM- or DVD-<br />

ROM-based music collections. The MP3 digital audio file format is popular because it has a fairly good compressionto-quality<br />

ratio and is widely supported.<br />

MP3 is an acceptable format to use in a <strong>Java</strong> 8 application, so long as you get the highest quality level possible<br />

out of it, using an optimal encoding work process. It is important to note that, like JPEG (used for images), MP3 is a<br />

lossy audio file format, in which some of the audio data (and thus quality) are thrown away during your compression<br />

process and cannot be recovered.<br />

<strong>Java</strong>FX does have two lossless audio compression codecs, AIFF and WAVE. Many of you are familiar with these,<br />

as they were the original audio formats used with the Apple Macintosh and Microsoft Windows OSs, respectively.<br />

These files use PCM audio, which is lossless (in this case, because there is no compression applied whatsoever!).<br />

“PCM,” which, as stated, stands for “pulse code modulation,” refers to the data format it holds.<br />

PCM audio is commonly used for CD-ROM content as well as telephony applications. This is because PCM WAVE<br />

audio is an uncompressed digital audio format, with no CPU-intensive compression algorithms applied to the data<br />

stream. Thus, decoding (CPU data processing) is not an issue for telephony equipment or for CD players.<br />

For this reason, when you start compressing digital audio assets into the various file formats, you can use PCM<br />

as your baseline file format. It allows you to look at the difference between PCM (WAVE) and MP3 and MP4 audio<br />

compression results to get an idea of how much data footprint optimization you are getting for your JAR file; more<br />

important, you can also see how your sample resolution and sample frequency optimization are going to affect the<br />

system memory used for your game’s audio effects. Even if you used an MP3 or MP4 format, it would still have to be<br />

decompressed into memory before the audio asset could be used with the AudioClip class and employed as a sound<br />

effect in a <strong>Java</strong> 8 game.<br />

118

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

Saved successfully!

Ooh no, something went wrong!