
3D Game Programming All In One (2004)
.pdf
538 Chapter 18 ■ Making the Game World Environment
Moving Right Along
So, you've now seen how you can create and modify your game environment. The three main environmental elements are Sky, Clouds, and Water. We looked at the different ways each of those three elements can be created using tools and techniques available in Torque.
In most cases, you will probably use some form of all of those techniques when you create your game. For example, you would judiciously mix overhead cloud layers with skybox renderings of distant clouds on the horizon.
We've also looked at the combined weather effects involved in storms, and how you can initiate an automated process to start and end storms over time using Torque Script.
In this chapter, we were introduced to sounds in the form of thunder for the lightning strikes. In the next chapter we will more thoroughly explore how to incorporate sounds in our game.
Team LRN

chapter 19
Creating and
Programming Sound
As I mentioned in Chapter 1, audio artists compose the music and sound in a game. Good designers work with creative and inspired audio artists to create musical compositions that intensify the game experience.
It also bears repeating that audio artists work closely with the game designers determining where the sound effects are needed and what the character of the sounds should be. They often spend quite a bit of time experimenting with sound-effect sources, looking for different ways to generate the precise sound needed. Visit an audio artist at work and you might catch him slapping rulers and dropping boxes in front of a microphone. After capturing the basic sound, an audio artist will then massage the sound with sound-editing tools, varying the pitch, speeding up the sound or slowing it down, removing unwanted noise, and so on. It's often a tightrope walk balancing realistic sounds with the need sometimes to exaggerate certain characteristics in order to make the right point in the game context.
When creating your game, you have a choice between two basic approaches: obtain a good source of sound effects and music (like an audio library) or create your own sounds. Of course, you also have the option to combine the two approaches. Audio libraries are available from a wide variety of sources, and the commercial ones are quite thorough and professionally made. There are audio libraries available via the Internet for free, but the quality of these sources varies widely in breadth, depth, and recording fidelity.
In this book we are going to take the do-it-yourself approach. The main advantage of going this way is the price; a secondary advantage is that you have total control over the contents of your sound files.
539
Team LRN

540 Chapter 19 ■ Creating and Programming Sound
Audacity
There are several tools available to use for recording and editing sound effects and music. A very good open source program—it doesn't cost you anything to use and is made available under the GNU General Public License—is Audacity.
This chapter will show you how to use Audacity (see Figure 19.1) to make sounds for use in your game.
Installing Audacity
To install Audacity, do the following:
1.Browse to your CD in the \Audacity directory.
2.Locate the audacity-win-1_0_0.exe file and double-click it to run it.
3.Click the Next button for the Welcome screen.
4.Follow the various screens, and take the default options for each one, unless you know you have a specific reason to do otherwise.
Using Audacity
You need to ensure that you've got your microphone set up properly—connected to the MIC or microphone input jack on your sound card. Of course, you don't need to obtain your sounds directly from a microphone; you can record from a CD or another audio source. In any event, you need to have that source connected to the correct input and ensure that your audio mixer is set up to record from that source. You should refer to your sound card documentation if you don't know how to do this.
The basic operation of Audacity is quite straightforward for recording, simple editing, playback, and saving your data.
Recording
Let's record some sound:
|
1. |
Launch Audacity by choos- |
|
|
|
ing Start, Programs, Audac- |
|
|
|
ity, Audacity. You will get |
|
|
|
the main window, as you |
|
|
|
saw earlier in Figure 19.1. |
|
Figure 19.1 Audacity main window. |
|
||
2. |
Click the Record button, as |
||
|
shown in Figure 19.2.
Team LRN

Audacity 541
The program is now recording from the microphone. You can see the progress of the recording and the waveforms of the sounds in the window as the recording proceeds, as shown in Figure 19.3.
3. Speak into the microphone, or if you
Figure 19.2 The Record button.
don't want to hear your own voice, make a noise, like slapping a book down on the desk or something. You will see the sound you made appear in the waveform. Figure 19.4 shows the waveform created when I tapped a pen on the desk next to the microphone.
4.When you have your sound recorded, click the
Stop button, as shown in |
Figure 19.3 Recording in progress. |
|
Figure 19.5. |
||
|
5.Now you can play back your recording, by clicking the Play button, as shown in Figure 19.6.
We'll continue working with Audacity in a moment, but first I want to point out that if you have a waveform but don't hear any sound, make sure that you have the volume turned up high enough in your speakers.
Also be sure that it is turned up high Figure 19.4 Waveform in Audacity. enough—and is not muted—in your
Windows Volume Control applet (in the Control Panel, and usually on the Windows System Tray on the right side of the taskbar).
Simple Editing
Now if you're like me you probably have a long period Figure 19.5 Stop recording. of dead air before the sound effect you made and
another chunk afterward. That's fine, because it's easy to fix. So, picking up where we left off in the previous section:
Team LRN

542 Chapter 19 ■ Creating and Programming Sound
Figure 19.6 Playback.
Figure 19.7 Selecting a portion of the waveform.
6.Place your cursor to one side of the portion of the waveform you want to eliminate, and drag it across to the other side. This selects an area to be worked on. See Figure 19.7.
7.Choose Edit, Delete. The selected portion will be excised from the waveform.
8.Repeat the preceding two steps for the unwanted portions of the waveform on the other side of your sound effect. Eventually you will end up with something like Figure 19.8.
We're not finished with our procedure yet; there's still some exporting to do. But before we cover that, I want to mention that above the waveform panel is a series of numbers on a scale. This is the elapsed time scale. The example in Figure 19.8 shows that my final waveform is just a little more than three-quarters of a second in duration.
Figure 19.8 The final waveform of the sound effect.
Exporting
Now, once again picking up where we left off, you need to save the sound effect as a file before you can use it:
9.Choose File, Export as WAV. Name your file and save it somewhere convenient for the moment, such as on your desktop.
10.Browse to your desktop (or wherever you saved your file) and double-click your newly created file. Whichever program is set up to play sounds in Windows on your computer will be launched and play your sound.
There are other export options available, but we'll stick with the WAV format for its simplicity and wide availability on Windows platforms. For other platforms, Ogg Vorbis is probably the format of choice on Linux, and AIFF for Macintosh.
Audacity Reference
This section contains some useful reference details to help you use Audacity.
The Main Screen
Figure 19.9 shows the Audacity main screen, with the major components labeled. This section will provide some detail on those components.
Team LRN

The toolbar is where you will find the tools that you will probably use more than any other tools available with Audacity. Use Figure 19.9 to locate the tools in the toolbar, and Table 19.1 to review their functions.
The Track Panel contains tools for managing specific tracks and groups of tracks. See Table 19.2 for details.
|
|
Audacity |
543 |
|
|
|
|
Envelope |
Play |
Stop Record Master Gain |
|
|
|
|
|
Selection |
|
|
|
Time |
|
Toolbar |
|
Shift |
|
Time Scale |
|
Zoom |
|
|
|
|
|
|
|
Track Delete |
|
|
|
Track Menu |
|
|
|
Track Mute |
|
|
|
Track Solo |
Track |
Waveform |
|
|
Panel |
Panel |
|
Sample Rate
Figure 19.9 The Audacity main screen.
|
Table 19.1 |
Toolbar Tools |
|
|
Tool |
Description |
|
|
Selection |
Selects a portion of the audio track. You can set the position of the track cursor simply by |
|
|
|
clicking at the right place in the track. Select a range of audio by clicking and dragging |
|
|
|
over the desired portion. Select multiple tracks by dragging across the tracks. Playback |
|
|
|
begins at the position of the track cursor and will play to the end of the track. If you |
|
|
|
have selected a range of audio, only the selected range will be played. |
|
|
Time Shift |
Changes the positioning of tracks relative to one another in time. Select this tool, |
|
|
|
then click in a track and drag it to the left or right. |
|
|
Envelope |
A handy audio processing tool. Its presence directly in the main window of the |
|
|
|
program is an innovative move. You get detailed control over how tracks fade in and |
|
|
|
out, right in the main track window with this tool. When you select the Envelope tool, |
|
|
|
the amplitude envelope of each track is highlighted in a green line; there are control |
|
|
|
points at the beginning and end of each track. To move a control point, click it and |
|
|
|
drag it to its new position. To add a new point, click anywhere in the track where a |
|
|
|
control point doesn't already exist. To remove a point, drag it outside of the track. |
|
|
Zoom |
Zooms in or out of a specific part of the audio. Clicking anywhere in the audio will |
|
|
|
zoom you in. Right-click or shift-click to zoom out. You can also zoom into a region by |
|
|
|
dragging the mouse to highlight the region while you have the Zoom tool selected. |
|
|
Play |
Enables you to listen to the audio file currently loaded or to a recording you have just |
|
|
|
created. The spacebar can be used as a stop and start toggle. Playback always begins |
|
|
|
at the current cursor position. If a region of audio is selected, only the selected region |
|
|
|
will play. To play the entire project, choose Edit, Select All and then click the Play |
|
|
|
button. All tracks on a given channel will be mixed automatically for playback. |
|
|
Stop |
Halts playback. |
|
|
Record |
Records a new track from your microphone or another input device. You can |
|
|
|
configure recording options by choosing Edit, Preferences. Recording always happens |
|
|
|
at the project's sample rate. |
|
|
Master Gain |
Controls the volume of the audio output by Audacity to your hardware. Volume |
|
|
|
increases as you move the slider from left to right. |
|
|
|
|
|
Team LRN

544 Chapter 19 ■ Creating and Programming Sound
Table 19.2 Track Panel Tools
Tool |
Description |
Track Menu |
Allows the user to display a track in different formats. This menu also provides the |
|
Set Name option that allows the user to create a name for a given track. |
Track Delete |
Immediately deletes a track, without the option to undo. Use this button carefully. |
Solo |
Switches the current track to solo mode. You can change a track out of solo mode |
|
by clicking it again. When in solo mode, the button for that track turns red. Only |
|
tracks that have the Solo button enabled will be played when in solo mode. |
Mute |
Switches off a track without deleting it. You can unmute a track just by clicking the |
|
Mute button again. When muted, a track's Mute button will be green. |
Table 19.3 Track Types
Tool |
Description |
Audio |
Audio tracks contain digitally sampled sounds. Two stereo channels are |
|
represented by two stereo tracks. Each audio track has a sample rate that is the |
|
same as the project sample rate. |
Note |
Note tracks display data loaded from a MIDI file. They cannot be changed or |
|
played, only viewed. |
Label |
Label tracks can be used to mark a document with annotations. Annotations can |
|
be saved to a text file. |
Audacity supports three different track types that can be viewed simultaneously when they exist in a single channel. These three track types let you view waveform, MIDI information, and label information for a given audio file. Table 19.3 describes each of the three types.
n o t e
Common values for audio sample rates are shown in Table 19.4.
Table 19.4 Common Sample Rates
|
Frequency |
Usage |
|
|
8000 Hertz |
Typical telephone |
|
|
11025 Hertz |
Minimum "voice quality" |
|
|
16000 Hertz |
Typical "voice quality" |
|
|
22050 Hertz |
Common digital interactive media |
|
|
44100 Hertz |
CD audio, DAT (digital audiotape) |
|
|
48000 Hertz |
Digital studio quality |
|
|
96000 Hertz |
Digital studio quality (newer) |
|
|
|
|
|
Team LRN

Audacity 545
Menus
The Audacity menus provide access to functions for managing files, editing, adjusting views, managing Audacity projects, and finally, creating special effects. There is also a standard Help menu.
The File Menu
Figure 19.10 shows the File menu, and Table 19.5 contains an itemized description of the menu. Note that menu items that have names ending with three ellipsis points (three dots) will bring up a dialog box where you can fill in some parameters.
The Edit Menu
Figure 19.11 shows the Edit menu, and Table 19.6 contains an itemized description of the menu. Parts of this menu contain the standard Cut, Copy, and Paste functions; the rest are related functions that are specific to Audacity's capabilities.
The View Menu
The View menu provides functions that you can use to control what you see in the Audacity window and how you see it. Figure 19.12 shows the View menu, and Table 19.7 contains an itemized description of the menu.
The Project Menu
Audacity uses the concept of projects that you've encountered elsewhere, such as with UltraEdit earlier in this book. By using projects, you can organize data files as well as configuration and operational parameters in one collection that can be recalled at any time. This really helps when dealing with complex tasks. Figure 19.13 shows the Project menu, and Table 19.8 contains an itemized description of the menu.
The Effect Menu
Audacity includes many built-in effects and also lets you use plug-in effects. To apply an effect, simply select part or all of the tracks you want to modify, and select the effect from the menu. Figure 19.14 shows the Effect menu, and Table 19.9 contains an itemized description of the menu.
Figure 19.10 File menu.
Figure 19.11 |
Figure 19.12 View |
Edit menu. |
menu. |
|
Figure 19.14 |
Figure 19.13 Project |
Effect menu. |
|
|
menu. |
|
Team LRN

546 Chapter 19 ■ Creating and Programming Sound
|
Table 19.5 |
File Menu |
||
|
Menu Item |
|
Description |
|
|
New |
|
Creates a new empty project window. |
|
|
Open |
|
Presents you with a dialog box to choose a file to open. If a project window |
|
|
|
|
is open and empty, the new file will appear in that window; otherwise a |
|
|
|
|
new project window will open. |
|
|
Close |
|
Closes the current project window. |
|
|
Save Project |
|
Saves the current Audacity project file in AUP format. Audacity projects are |
|
|
|
|
not usable by other programs. Audio data for an Audacity project is not |
|
|
|
|
stored in the AUP file—instead, it is stored in a directory with the same |
|
|
|
|
name as the project. |
|
|
Save Project As |
|
Saves the current Audacity project file, with a different name or directory path. |
|
|
Export as WAV |
|
Exports the current Audacity project as a standard audio file format, such as |
|
|
|
|
WAV or AIFF. Change the format of the exported file in the Preferences |
|
|
|
|
dialog box. |
|
|
Export Selection as WAV |
The same as Export as WAV, but only exports the selected portion of the |
||
|
|
|
project. |
|
|
Export as MP3 |
|
Exports the current Audacity project as an MP3 file. Exporting MP3 files |
|
|
|
|
requires that you install a separate MP3 encoder, not included with Audacity. |
|
|
Export selection as MP3 |
The same as Export as MP3, but only exports the selected portion of the |
||
|
|
|
project. |
|
|
Export as OGG |
|
Exports the current Audacity project as an Ogg Vorbis file. |
|
|
Export selection as OGG |
The same as Export as OGG, but only exports the selected portion of the |
||
|
|
|
project. |
|
|
Export Labels |
|
Exports label tracks to a text file. |
|
|
Preferences |
|
Place where you configure Audacity. |
|
|
Exit |
|
Closes all project windows and exits Audacity. It will ask if you want to save |
|
|
|
|
changes to your project. |
|
|
|
|
|
|
Team LRN

Audacity |
547 |
|
Table 19.6 |
Edit Menu |
|
|
Menu Item |
Description |
|
|
Undo |
Undoes the last edits performed. Allows you to undo every operation going back to |
|
|
|
the last time the document was saved. |
|
|
Redo |
Redoes edits that were just undone. The redo history remains available until you do a |
|
|
|
fresh edit. |
|
|
Cut |
Removes the selected audio data and moves it to the Clipboard. |
|
|
Copy |
Copies the selected audio data to the Clipboard. |
|
|
Paste |
Inserts the Clipboard contents at the position of the selection cursor in the project, |
|
|
|
replacing any selected data. |
|
|
Delete |
Removes selected data without copying it to the Clipboard. |
|
|
Silence |
Replaces selected audio data with silence. |
|
|
Insert Silence |
Inserts the prompted amount of silence entered at the current track cursor position in |
|
|
|
the project. Overwrites selections. |
|
|
Split |
Moves the selected region into its own track or tracks, replacing the affected portion |
|
|
|
of the original track with silence. |
|
|
Duplicate |
Makes a copy of all or part of a track or set of tracks into new tracks. |
|
|
Select All |
Selects all of the audio in all of the tracks. |
|
|
|
|
|
Table 19.7 View Menu
Menu Item |
Description |
Zoom In |
Zooms in on a portion of the audio data. Doing this allows you to view |
|
more data detail for a smaller time period. |
Zoom Normal |
Changes the zoom factor to one inch of data for one second of time; this is |
|
the default zoom factor. |
Zoom Out |
Zooms out so you can see a larger time base, at the cost of less detail. |
Fit in Window |
Adjusts the zoom factor so that the entire project fits exactly in the window. |
Plot Spectrum |
Plots a spectrum for a selected portion of a single track. First select a |
|
portion of audio data from a single track, then select this menu item. A |
|
window will open that will display the Power Spectrum of the audio for the |
|
selected data. The Power Spectrum computation uses the Fast Fourier |
|
Transform (FFT) algorithm to graph the proportional energy level for each |
|
frequency. |
Float or Unfloat Palette |
Allows you to switch between docking the Tool palette at the top of each |
|
project window or in a separate floating window. |
Team LRN