⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch11.htm

📁 对于程序员来说可以利用JAVA来开发网络游戏!
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML>

<HEAD>
   <TITLE>Chapter 11 -- The Basics of Sound</TITLE>
   <META>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<H1><FONT COLOR=#FF0000>Chapter 11</FONT></H1>
<H1><B><FONT SIZE=5 COLOR=#FF0000>The Basics of Sound</FONT></B>
</H1>
<P>
<HR WIDTH="100%"></P>
<P>
<H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A>
</FONT></FONT></H3>

<UL>
<LI><A HREF="#ThePhysicsofSound" >The Physics of Sound</A>
<LI><A HREF="#DigitalSoundFundamentals" >Digital Sound Fundamentals</A>
<LI><A HREF="#TheAUSoundFormat" >The AU Sound Format</A>
<LI><A HREF="#UsingSoundinGames" >Using Sound in Games</A>
<LI><A HREF="#SoundUtilities" >Sound Utilities</A>
<UL>
<LI><A HREF="#CoolEdit" >Cool Edit</A>
<LI><A HREF="#SoundExchangeSoX" >Sound Exchange (SoX)</A>
<LI><A HREF="#SoundMachine" >Sound Machine</A>
<LI><A HREF="#SoundHack" >Sound Hack</A>
</UL>
<LI><A HREF="#CreatingandEditingSounds" >Creating and Editing Sounds</A>
<UL>
<LI><A HREF="#RecordingwithaMicrophone" >Recording with a Microphone</A>
<LI><A HREF="#SamplingfromExternalSoundSources" >Sampling from External Sound Sources</A>
</UL>
<LI><A HREF="#FindingSounds" >Finding Sounds</A>
<LI><A HREF="#Summary" >Summary</A>
<LI><A HREF="#QA" >Q&amp;A</A>
<LI><A HREF="#Workshop" >Workshop</A>
<UL>
<LI><A HREF="#Quiz" >Quiz</A>
<LI><A HREF="#Exercises" >Exercises</A>
</UL>
</UL>
<HR>
<P>
On <A HREF="ch10.htm" >Day 10</A>, you created your first complete
game, Traveling Gecko, which contained most of the core components
found in commercial games. However, it was missing one particularly
important component-sound. In today's lesson, you remedy this
problem by learning about sound and how to create it for your
games. You don't get into too many of the technical details surrounding
sound in Java; you'll learn all about that in tomorrow's lesson.
The focus of today's lesson is on the overall usage of sound and
how to create your own sound effects.
<P>
There was a time when a game without sound might have been acceptable.
I'm here to tell you that you're now living in a different time!
Although Traveling Gecko is a neat game, it seems somewhat lacking
without any sound effects or music. Game players have come to
expect realistic sound that works hand in hand with the graphics
to convey a greater sense of realism. Sound is such an integral
part of computer games that you should consider it a necessary
part of your design-as necessary as graphics. Understanding that,
let's get started on today's lesson!
<P>
The following topics are covered in today's lesson:
<UL>
<LI>The physics of sound
<LI>Digital sound fundamentals
<LI>The AU sound format
<LI>Using sound in games
<LI>Sound utilities
<LI>Creating and editing sounds
<LI>Finding sounds
</UL>
<H2><A NAME="ThePhysicsofSound"><B><FONT SIZE=5 COLOR=#FF0000>The
Physics of Sound</FONT></B></A></H2>
<P>
Before getting into the specifics of sound and how to create your
own, a little background on digital sound is in order. By understanding
how sounds are modeled in Java, and in software in general, you
gain more insight into what functionality is provided in the standard
Java audio implementation. You learn all about Java audio support
in tomorrow's lesson.
<P>
The first issue to tackle is understanding the physics behind
sound waves. A sound wave is a mechanical wave moving through
a compressible medium such as air. 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. The softness or loudness of a sound
is determined by the amount of energy in the 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 less
compressible medium such as a wall in your house.
<P>
A <I>sound wave</I> is a mechanical wave moving through a compressible
medium such as air.
<P>
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 a logarithmic
unit 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, not to mention an annoying ringing sensation.
This typically isn't a problem in computer games!
<P>
When a sound wave is converted to an electrical signal (by a microphone,
for example), the amplitude is represented by a voltage. The amplitude
of the voltage directly corresponds to the amplitude of the physical
sound wave. As the amplitude of the wave varies, so does the corresponding
voltage. In fact, the varying amplitude of a sound wave over time
is all that is needed to reproduce a sound. Figure 11.1 shows
a sound wave plotted as a voltage (amplitude) varying over time.
<P>
<A HREF="f11-1.gif" ><B>Figure 11.1 : </B><I>A sound wave plotted as voltage versus time.</I></A>
<H2><A NAME="DigitalSoundFundamentals"><B><FONT SIZE=5 COLOR=#FF0000>Digital
Sound Fundamentals</FONT></B></A></H2>
<P>
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 <I>sampling</I>.
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.
<P>
<I>Sampling</I> is the process of converting an analog audio signal
to a digital audio signal.
<P>
To sample a sound, you just store the amplitude of the sound wave
at regular intervals. Figure 11.2 shows how an analog sound wave
is converted to a digital wave by sampling the sound at regular
intervals. Notice in Figure 11.2 that the digital representation
of the analog sound wave is not a very good one. 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.
<P>
<A HREF="f11-2.gif" ><B>Figure 11.2 : </B><I>An analog sound wave and its digital representation.</I></A>
<P>
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. In
Java 1.0, the only supported sound frequency is 8,000 Hz, which
means that there are 8,000 samples per second. Although it sounds
like a lot, this frequency actually results in a fairly low-quality
sound. To understand why, consider the fact that the frequency
for CD-quality audio is 44,000 Hz.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
The limitations on sound quality imposed by Java are really a reflection of the underlying AU sound format, which is discussed in the next section. When Java widens its support for other sound formats in a future release, these limitations will likely 
disappear.</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>
The amount of data stored per sample determines the number of
discrete amplitudes that a digital signal can represent. The wider
the range is of amplitudes represented by the digital signal,
the closer the original wave is approximated. In Java 1.0, the
sample data width is limited to 8 bits. A wave sampled at 8 bits
has 256 different discrete amplitude levels (2<FONT SIZE=1>8</FONT>).
Again, compare this to CD-quality sound, which uses 16 bits per
sample and therefore has 65,536 different discrete amplitude levels
(2<FONT SIZE=1>16</FONT>).
<H2><A NAME="TheAUSoundFormat"><B><FONT SIZE=5 COLOR=#FF0000>The
AU Sound Format</FONT></B></A></H2>
<P>
The AU sound format is currently the only sound format supported
by Java. The <I>AU</I> name stands for ULAW, which specifies the
type of encoding used to store each sample. The format is specific
to Sun and NeXT computer systems, and it specifies that sounds
be 8,000 Hz mono 8-bit ULAW encoded. This is a pretty low-quality
sound format, especially when compared to what other formats provide.
<P>
However, within the context of the Web, the AU format is acceptable
for now. This is mainly because of the ever-present bandwidth
problem associated with the transfer of data over the Internet.
Restricting sounds to a compact format such as AU guarantees that
all sounds incur relatively low transmission times.
<P>
However, don't expect this situation to last long. Sun is already
promising more complete multimedia support in a future release
of Java, which will no doubt include support for more sound formats.
At that point, it will be up to Web developers to balance the
scale between sound quality and bandwidth delays.
<H2><A NAME="UsingSoundinGames"><B><FONT SIZE=5 COLOR=#FF0000>Using
Sound in Games</FONT></B></A></H2>
<P>
Aside from the programming issues surrounding sound in Java, which
you learn about tomorrow, integrating sound into Java games consists
primarily of creating or finding the right sound effects and music
to fit your needs. You'll be happy to know that creating sound
effects for games is often one of the most creative and fun aspects
of game development, because there are very few rules. Which aspects
of a game you want to associate sounds with are totally up to
you. Along with that, you have complete freedom over the sounds
you create and use.
<P>
Well, almost complete freedom. Actually, two limitations are imposed
on sounds in games. The first limitation is communication bandwidth,
which keeps you from being able to use lots of long sounds. This
limitation exists because it takes time to transmit resources
used by a Java game, such as graphics and sounds, over the Internet.
To keep game players from having to wait an inordinate amount

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -