Game Development Reference
In-Depth Information
trol the volume (or amplitude) of the sound, and control the number of times the
sound is played, from once to forever, using the AudioClip INDEFINITE constant.
Besides the getter and setter methods for these AudioClip properties, there are
.play() and .stop() methods as well as three (overloaded) .play() methods: one for
simple (default) playback; one where you can specify volume; and one where you can
specify volume, balance, frequency rate (pitch shifting factor), panning, and sample
priority.
The key to controlling the AudioClip object is to call one of the three .play() meth-
ods based upon how you want to control the sample playback. Use .play() for straight-
forward playback, as we will be doing during this chapter; or use .play(double
volume) to play your AudioClip object at a relative volume level from 0.0 (off) to 1.0
(full); or use the .play(double volume, double balance, double rate, double pan,
double priority) to play your AudioClip object at a relative volume (0.0 to 1.0), a rel-
ative balance (-1.0 left, 0.0 center, 1.0 right), pitch shift rate (0.125 to 8.0), relative
pan (-1.0 left, 0.0 center, 1.0 right); and priority integer, which specifies which
samples get played over others, which, due to low resources and low priority, may not
get played. Let's get into using Audacity to optimize our samples next!
Creating and Optimizing Digital Audio:
Audacity 2.0.6
Launch the latest version of Audacity—at the time of this writing that would be 2.0.6,
and use your microphone to record your voice saying the word “left.” Fortunately my
NetBeans 8 and Java 8 development workstation is also my Skype workstation, and I
have a basic Logitech adjustable microphone on a stand that I can use to make the ba-
sic audio files that we will need to put audio files into place for each of our different
sprite movements that we put into place in Chapter 13 . I will go through the digital au-
dio file “scratch creation” and optimization work process in this section of the chapter,
and you can do this yourself, for each of the six digital audio files we will need to use
in the coding sections of this chapter. You can also use the six audio files included with
this topic's software repository if you want to simply get onto the Java 8 coding part of
digital audio asset implementation using the JavaFX AudioClip class. I would recom-
mend going over how to optimize uncompressed audio for use in system memory, as
we're about to take 113KB of raw source audio data, and knock 99KB of data off of it,
and reduce it another 88% to be only 14KB.
Search WWH ::




Custom Search