Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals

are going to have more compression applied to the audio data, which will result in lower quality. These will
stream (play back) more smoothly across a greater number of devices because fewer bits can be quickly
transferred, as well as processed, more easily.


Digital Audio Assets in JavaFX: Digital Audio Codec and Data Format


Support


There are considerably more digital audio codecs in JavaFX than there are digital video codecs, as there
are only two video codecs, which are MPEG-4 H.264 AVC or ON2 VP6. JavaFX audio support includes MP3
(MPEG3) files, Windows Wav e (Pulse Code Modulated [PCM] audio) WAV files, MP4 (or M4A) MPEG-4
AAC audio, and Apple’s AIFF (PCM) file format. The most common audio format supported by JavaFX is the
MP3 digital audio file format. The reason the MP3 digital audio file format is popular is because it has a good
compression to quality ratio and is widely supported.
MP3 would be an acceptable digital audio format to use in a Java game or IoT application, as long as you
get the highest quality level possible out of it, using an optimal encoding work process. It’s important to note
that MP3 is a lossy audio file format, like JPEG uses for digital images, where some of the audio data, and
therefore some of your original audio sample quality, is thrown away during your compression process and
cannot later be recovered.
JavaFX does have two lossless audio compression codecs, called AIFF and WAVE. You are probably
familiar with these digital audio formats, as they are the original audio formats used for the Apple and
Microsoft Windows operating systems, respectively. These files use PCM audio, which is lossless, in this
case, because there is no compression applied whatsoever! Pulse Code Modulated refers to the data format it
holds.
PCM audio is commonly used for CD-ROM content, as well as telephony applications. This is because
PCM Wave audio is an uncompressed digital audio format, and it has no CPU-intensive compression
algorithms applied to the data stream; thus, decoding (CPU data processing) is not an issue for telephony
equipment or for CD players.
For this reason, when we start compressing digital audio assets into these various file formats, we will
use PCM as our baseline file format. Not only can we look at the difference between the PCM (Wave) and
MP3 or MP4 audio compression results to get an idea of how much data footprint optimization we are
getting for our JAR file, but more importantly, we can see how our sample resolution and sample frequency
optimization are going to affect system memory used for our game audio effects. Even if we used MP3 or
MP4 format, it would still have to be decompressed into memory before the audio asset can be used with the
AudioClip class, and used as a sound effect, in a Java game.
Since a Wave or AIFF file will not have any quality loss because there is also no decompression
needed, this Pulse Code Modulated data can be placed straight from the JAR file into system memory!
This makes PCM audio great for game sound effects that are short in duration (0.1 to 1 second) and can be
highly optimized, using 8-bit and 12-bit sample resolution and 8kHz, 22kHz, or 32kHz sample frequency.
Ultimately, the only real way to find out which audio format supported by JavaFX has the best digital audio
compression result for any given digital audio data is to actually encode your digital audio in the primary
codecs that we know are supported and efficient. We will be going through this work process in Chapter 21
when we add audio to the game and will observe the relative data footprint results between the different
formats using the same source audio sample. Then we will listen to the audio playback quality so that we
can make our final quality to file size decision. This is the work process that you will need to go through to
develop your JavaFX digital audio assets, for use in your pro Java game development work process.
JavaFX also supports the popular MPEG-4 Advanced Audio Coding (AAC) codec. This digital audio
data can be contained in MPEG4 containers (.mp4, .m4a, .m4v) or file extensions and can all be played back
using all operating systems. It’s important to note that JavaFX does not contain an MPEG-4 decoder but
instead supports what is called a “Multimedia Container.” What this means is that it uses the host operating
system’s MPEG-4 decoder for decoding.

Free download pdf