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

📄 ch11.htm

📁 对于程序员来说可以利用JAVA来开发网络游戏!
💻 HTM
📖 第 1 页 / 共 3 页
字号:
If you need mechanical sounds, look no farther than your kitchen
appliances. You probably don't want to drag your whole computer
into the kitchen, which means you'll be limited to portable appliances.
However, that still leaves a lot of opportunities. My juicer makes
sounds that easily could pass for some interesting futuristic
weapons. How about opening a bottle of soda? Sounds an awful lot
like hydraulic brakes, doesn't it? Or maybe the huff or puff of
a big alien?
<P>
What if you need some background sounds? I know I could open my
window on many nights and record the sound of crickets chirping
all night long. Although less dramatic, cricket sounds can add
a lot to the realism of a night scene in a game. That is, until
dogs start barking!
<P>
The goal here isn't to go through an exhaustive description of
every possible thing you can use to create sounds. I mainly just
want to spark your imagination so that you can start thinking
about what you can do with things that are readily available.
That's the beauty of creating games. You can turn otherwise ordinary
things into interesting elements of a game. Think about all the
things you hear on a daily basis. Then go through your house and
make notes of what sounds you could create with different items.
You'll find that this process can be a lot of fun. It's even better
after you've incorporated the sounds into a game and people ask
where the sounds came from.
<H3><A NAME="SamplingfromExternalSoundSources"><B>Sampling from
External Sound Sources</B></A></H3>
<P>
Another very useful method for finding sound effects for games
is to sample sounds from external sound sources such as VCRs and
CD players. Before I say any more, let me reiterate that it is
illegal to distribute sounds sampled from movies or copyrighted
CDs or cassettes without getting permission.
<P>
Sampling sounds from external sound sources requires a little
more work than recording them with a microphone, but not much.
Basically, the extra work is in connecting the external sound
source to your computer. You connect external sound sources via
a line input on your computer; most multimedia computer systems
these days have a line input for receiving analog audio. For example,
Soundblaster sound cards on pcs have a line input jack that can
be used to connect a stereo cassette deck or VCR. To see whether
your computer has a line input jack, look at the back of your
computer. If you have speakers hooked up, they are probably plugged
in very close to the line input jack. Look for one or more jacks
labeled <I>input</I>. On pcs equipped with Soundblaster family
sound cards, the word <I>input</I> usually accompanies the input
jack. Input jacks are usually the same type of mini connectors
used for headphones on a portable Walkman.
<P>
After you determine where the line input jack is located, plug
in the line out cable from the sound device from which you want
to sample sounds. The only problem is that the connectors are
usually of differing types. The type of connector used by most
audio equipment-including cassette decks, CD players, and VCRs-is
called an RCA connector. You need to go to an electronics store
and buy a cable that allows you to connect the RCA sound device
to the mini input jack on your computer. You might also want to
pick up an RCA extension cable so that you don't have to stack
the sound device on top of your monitor!
<P>
When you get the cables squared away, plug the RCA end into the
line output of the sound device, and the mini end into the input
jack on the back of your computer. Then fire up the sound utility
and get ready for some fun. From this point on, it's pretty much
the same as recording sounds using a microphone, except that the
sound device is generating the sound rather than you. The sound
utility doesn't really care where the sound is coming from; it
knows only to look at the input jack and grab whatever sound information
is there.
<P>
If a sound doesn't sound right after you sample it, it's probably
because you have the cable plugged into the microphone input rather
than the line input. Try switching inputs (if you have another
one) and trying again. If it sounds okay this time, you're set.
If not, don't worry because there are work-arounds.
<P>
If you only have a microphone input, you need to make an adjustment
to record sounds from other input devices because microphone inputs
are designed to deal only with low-amplitude signals. The signals
from other sound devices can easily overwhelm a microphone input
jack. The solution is to somehow alter the incoming signal so
that it comes in at around a microphone level. The easiest fix
is to lower the input level of the sound source in software. An
example of this is using the Volume Control application in Windows
95.
<P>
If you aren't so lucky to be able to fix things in software, you
can adjust the output level of the sound device by passing it
through an audio mixer. If you don't have an audio mixer handy,
your best bet is to buy an attenuator connector. Attenuator connectors
adjust the signal level down to a level that will work for a microphone
input. You can find attenuator connectors at most electronics
stores.
<P>
An <I>attenuator</I> is an electronic device or circuit that lowers
the magnitude of an electric signal. In the case of audio signals,
an attenuator results in a decrease in volume.
<P>
After you have the technical difficulties out of the way, you
can focus on the creative end of sampling sounds. When it comes
to movies, I tend to favor war movies for finding gunshots and
explosions, for obvious reasons. Science fiction movies are great
for space sounds and other weird effects. The range of sounds
that can be found in movies is practically unlimited.
<P>
One advantage of sampling sounds from movies is that they typically
are of very high quality. Companies exist that do nothing more
than create sounds for movies. For this reason, movies provide
probably the richest variety of sounds available. Typically, every
sound you hear in a movie has been carefully placed there. The
problem, of course, is that they are protected by copyright law,
which means that you can't just run around ripping sounds out
of movies and putting them into your games.
<H2><A NAME="FindingSounds"><B><FONT SIZE=5 COLOR=#FF0000>Finding
Sounds</FONT></B></A></H2>
<P>
If you've decided that you don't have what it takes to create
your own sounds, you still have options. In this case, you need
to seek an outside source for your sounds. The best source for
finding prerecorded sounds is in sound archives on the Web. Many
different sound archives are out there with a vast amount of sounds
to choose from. Many are even available already in the AU sound
format. Even if you get sounds from a sound archive, be very careful
about the copyright issues surrounding using them.
<P>
A good starting point for finding sounds is the World Wide Web
Virtual Library, which maintains an Audio page with links to sound
archives. This Audio Web site is located at
<BLOCKQUOTE>
<TT><A HREF="http://www.comlab.ox.ac.uk/archive/audio.html">http://www.comlab.ox.ac.uk/archive/audio.html</A></TT>
</BLOCKQUOTE>
<P>
Figure 11.8 shows what the WWW Virtual Library Audio Web site
looks like.
<P>
<A HREF="f11-8.gif" ><B>Figure 11.8 : </B><I>The World Wide Web Virtual Library Audio Web site.</I></A>
<H2><A NAME="Summary"><B><FONT SIZE=5 COLOR=#FF0000>Summary</FONT></B></A>
</H2>
<P>
Today you took a step away from the details of Java coding to
learn about sound and how it can be created for games. You began
with the physics of sound and followed it up with the basics of
digital sound representation and the AU sound format supported
by Java. You then saw where you could get some shareware sound
utilities that enable you to record and edit your own sounds.
You finished up by learning about creative outlets for creating
your own sounds, both from scratch and also from existing sources.
<P>
I hope today's lesson gave you a break from technical programming
details, along with providing a creative surge for you to go out
and create some interesting sounds. My main goal was to remind
you that games are all about fun-and not just from a player's
perspective. The more you enjoy the process of creating games,
the more fun they will probably end up being. Sound creation is
only one of the aspects of game development that can be both challenging
and fun.
<P>
Just in case you forgot that this book is about Java, tomorrow's
lesson turns your attention toward the specifics of playing sound
in Java. Don't worry; it's a lot easier than you might suspect!
<H2><A NAME="QA"><B><FONT SIZE=5 COLOR=#FF0000>Q&amp;A</FONT></B></A>
<BR>
</H2>

<TABLE>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>What's the difference between sampled sound and sampled music?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>Technically, there is no difference; they are both sampled as digital audio and stored in the AU sound format. However, sampled music is usually designed to be relatively short in length and sampled so that it 
can be looped repeatedly to sound like a longer piece of music. The trick then is to sample music sounds so that they end similarly to how they begin, thereby smoothing out the looping effect.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>Can I record sounds from an audio CD in an internal CD-ROM drive?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>Certainly! As a matter of fact, this is an ideal scenario because you bypass the whole issue of connecting an external sound device through an input jack. Typically, this simply involves adjusting the volume of 
the CD-ROM appropriately and sampling just as if you were using the microphone.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>What if I find a bunch of neat sounds but they are stored in a different sound format, such as WAV?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>You need to convert them to the AU sound format to be able to use them with Java. This is usually as easy as loading them into a sound utility and saving them as an AU file type.
</TD></TR>
</TABLE>
<P>
<H2><A NAME="Workshop"><B><FONT SIZE=5 COLOR=#FF0000>Workshop</FONT></B></A>
</H2>
<P>
The Workshop section provides questions and exercises to help
strengthen your grasp of the material you learned today. Try to
answer the questions and at least go over the exercises before
moving on to tomorrow's lesson. You'll find the answers to the
questions in appendix A, &quot;Quiz Answers.&quot;
<H3><A NAME="Quiz"><B>Quiz</B></A></H3>
<OL>
<LI>What is a sound wave?
<LI>What is an analog to digital converter used for in regard
to sampling sounds?
<LI>What is the sampling frequency for the AU sound format?
<LI>What is latency?
</OL>
<H3><A NAME="Exercises"><B>Exercises</B></A></H3>
<OL>
<LI>Find a sound utility capable of recording and editing sounds.
You'll need it!
<LI>Try your hand at creating some sounds of your own with a microphone.
<LI>Sample some sounds from an external sound device, making sure
to get the volume level settings correct.
<LI>Try applying some special effects in the sound utility to
your newly sampled sounds.
</OL>
<P>
<HR WIDTH="100%"></P>

<CENTER><P><A HREF="ch10.htm"><IMG SRC="pc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="index.htm"><IMG SRC="hb.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="#CONTENTS"><IMG SRC="cc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="ch12.htm"><IMG 
SRC="nc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A></P></CENTER>

<P>
<HR WIDTH="100%"></P>

</BODY>
</HTML>

⌨️ 快捷键说明

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