While these formats aren't universal standards, they are widely supported and well-documented. Many multimedia authoring tools will produce files in these formats, and a large number of public domain files are available for all of the formats. In addition, together, these formats address most of the needs that game authors are likely to have when designing games. WAV provides high-quality digitized recordings that can reproduce essentially any sound, while MIDI provides a versatile and compact format for storing music. MPEG and Ogg Vorbis are compressed digital audio formats that offer excellent fidelity but vastly smaller file sizes than uncompressed WAV files; MPEG and Ogg Vorbis work well for both sound effects and music.
Ogg Vorbis is a compressed digital audio format that can be used for digitized sound effects and music. This format is similar to MPEG, but was created as an open-source project and designed to become an internet standard. Ogg Vorbis is said to have compression and audio fidelity characteristics superior to MP3, and has the advantage of being a completely open standard.
Freeware tools for encoding and playing Ogg Vorbis files are available on the Web. You can find information and links to Ogg Vorbis software and sample music files at Vorbis.com. Reference information about the Ogg Vorbis format is available at Xiph.org.
In HTML TADS, Ogg Vorbis resources must be named with the suffix ".OGG".
Ogg Vorbis audio is suitable for both music and sound effects, so the HTML TADS sound system allows this format to be used in any layer. HTML TADS makes no assumptions about which layer is appropriate for a particular Ogg Vorbis sound; therefore, all <SOUND> tags specifying Ogg Vorbis resources must specify a layer.
The MPEG 2.0 audio format provides variable compression for digitized sound effects and music. This format allows you to substantially reduce the size of your sound files.
The MPEG 2.0 standard defines three different compression formats, referred to as layers I, II, and III. These layers are essentially independent formats; for most purposes, layer III delivers the highest quality and best compression of the three layers.
Note that some encoders provide another layer, usually called "2.5"; this uses a proprietary format. and HTML TADS does not support this format. When encoding a sound, please be sure not to use layer 2.5, or the sound will not play.
The MPEG format is "lossy," which means that it achieves better compression than might otherwise be possible by discarding some of the information in the original sound recording. The amount of loss is parameterized: when you're encoding a recording, you can select a compression rate that will provide the best compromise between sound quality and encoded data size. The more data loss you're willing to accept, the smaller the encoded file will be.
MPEG is supported by numerous tools, including freeware, shareware, and commercial products; most platforms have at least one or two good MPEG encoders and players. You should have no problem finding MPEG software resources on the web; a good starting point is www.mpeg3.org.
In HTML TADS, MPEG resources must be named with one of the following suffixes:
.MPG .MP2 .MP3
Conventionally, MPG is used for layer I files; MP2 for layer II files; and MP3 for layer III files. However, the MPEG standard defines a common header format for all three layers, so HTML TADS can automatically sense which type of decoding to use, as long as it can see that the file is an MPEG resource of some kind.
Because MPEG audio is suitable for both music and sound effects, the HTML TADS sound system allows MPEG audio to be used in any layer, and makes no assumptions about which layer is appropriate for a particular sound; therefore, all <SOUND> tags with MPEG resources must specify a layer.
The background layer is used for music. Background music can repeat to provide a continuous soundtrack, and you can program multiple selections that play one after another. You can change the background music whenever you want; for example, each room can have its own background music.
The bgambient (background ambient) layer is used for continuous digitized sound effects. The purpose of this layer is essentially the same as that of the background layer, but the bgambient layer is used for digitized sound effects instead of music.
The ambient layer is used for sound effects that occur in the background, but not continuously like the background music. You can set up a group of ambient sounds that will play randomly to enhance the atmosphere. As with background music, you can change the ambient sounds whenever you want; you can, for example, provide an appropriate set of ambient sound effects for each location.
The foreground layer is used for sound effects that play immediately in response to an event in the game. For example, you could play a sound effect in the foreground when the player opens a door in the game.
Sound is an inherently time-based medium. Text adventures, in contrast, are essentially static, except to the extent that the game state evolves in bursts in response to commands from the player. To bridge this gap, HTML TADS provides automatic management of the time domain. You simply specify which sounds are to be played and in what order, and HTML TADS takes care of the timing details.
At any given time, HTML TADS allows one active sound in each layer. The background sound must be MIDI, MPEG, or Ogg Vorbis and the bgambient, ambient, and foreground sounds must be WAV, MPEG, or Ogg Vorbis. The layers are treated independently; a sound in one layer doesn't normally affect sounds in the other layers. However, the hardware or the operating system may limit the number of sounds that can be played simultaneously; in these cases, a bgambient sound will temporarily suspend a background sound, an ambient sound will temporarily suspend a bgambient or background sound, and a foreground sound will temporarily suspend an ambient, bgambient, or background sound. Except for this type of temporary preemption, though, the layers do not interact. On systems that are capable of mixing multiple sounds at once, this type of preemption will not occur, and all of the layers will play simultaneously.
Within a layer, sounds are queued. This means that sounds play sequentially, in the order that you specify the sounds. When you start a sound, you specify how it interacts with other queued sounds and how it plays:
This layered approach follows the sound hardware architecture common in Windows PC's. Most PC sound cards have a synthesizer, which the system uses to play back a MIDI sequence, and a separate digital-to-analog converter, which the system uses to play back digitized audio. Both of these subsystems can be used simultaneously, which allows MIDI music and digitized sound effects to be played back together. Windows can further mix multiple digitized sound effects together for simultaneous playback (via the DirectSound system).
Despite the PC-centric design of the layer system, it should be possible to adapt the model to other hardware. On some systems, the hardware may not allow playing digitized and synthesized audio simultaneously. In these cases, the background music can be temporarily suspended whenever a digitized sound is played, then resumed after the digitized sound ends. While this will slightly degrade audio quality, the overall sequence of sounds will be essentially the same as the overlapped version.
Attributes of the SOUND tag specify the action that the SOUND tag should perform.
The SRC attribute specifies the name of the resource containing the sound data. The resource name must end in .WAV for a wave file; .MID or .MIDI for a MIDI file; .MPG, .MP2, or .MP3 for an MPEG audio file; and .OGG for an Ogg Vorbis file. Refer to Using Resources in HTML TADS for information on how to include resource files in your game.
The LAYER attribute specifies the layer containing the sound. The value of the LAYER attribute must be FOREGROUND, BGAMBIENT, AMBIENT, or BACKGROUND. Although you should always specify a layer for each sound, HTML TADS can sometimes infer the correct LAYER attribute for a sound based on its other attributes:
The RANDOM attribute lets you specify the probability of playing a sound in the ambient layer. Usually, you will want a sound in the ambient layer to be played randomly from time to time; this attribute specifies the probability that the sound will be played at any given time. This attribute takes a value from 1 to 100. A low value makes the sound play infrequently; a value of 100 causes the sound to play at every opportunity (i.e., whenever another sound in the same layer isn't playing).
The REPEAT attribute lets you specify how many times a sound should play. This can be used for all layers. This attribute takes a numeric value specifying the number of times to play the sound, or a value of LOOP to indicate that the sound plays repeatedly until cancelled.
If you don't specify a REPEAT attribute for an ambient sound, and the sound has a RANDOM setting, the default REPEAT=LOOP will be used. If you do specify a REPEAT parameter for an ambient sound, the sound will be played a maximum of the given number of times; the sound will still play only when the system randomly chooses the play it, the probability of which is controlled through the RANDOM attribute.
If you specify a REPEAT attribute for a foreground sound, the sound will be played the given number of times in sequence.
If you specify a REPEAT attribute for a sound in the background or bgambient layers, the sound will be played the given number of times. The actual sequence in which the sound is played depends on the SEQUENCE attribute used in the sound and other background sounds.
The SEQUENCE attribute is used to control the order of repetition for a group of background sounds; it's meant primarily for use with the background and bgambient layers. The SEQUENCE value can be REPLACE, RANDOM, or CYCLE. REPLACE causes the sound to remove any previous background sounds from the queue when the new sound starts. RANDOM leaves any previous sounds in the queue, assuming they have enough REPEAT cycles remaining; when the new sound is finished, if no other background sounds are waiting to be played, the system randomly picks one of the sounds remaining in the queue and plays it again. CYCLE is similar to random, but goes back to the first sound in the queue when the new sound is done.
You can use SEQUENCE to provide transitions with the music. For example, you could specify REPEAT=1 for introductory music, then specify REPEAT=LOOP and SEQUENCE=RANDOM for a set of ongoing background music. By using SEQUENCE=RANDOM, you can prevent the music from becoming too repetitive by randomly varying the order of the tracks.
The INTERRUPT attribute (which takes no value) specifies that the sound is to abort any currently playing sound in the layer and start the new sound immediately. You should usually only use INTERRUPT with foreground sounds.
The CANCEL attribute turns off all currently queued sounds. With no value, a <SOUND CANCEL> tag cancels all queued sounds in all layers. You could use this, for example, when switching to a new room, to turn off all sounds. You can also specify a layer with CANCEL to specify that sounds in that particular layer are to be cancelled; the layer values FOREGROUND, AMBIENT, and BACKGROUND are allowed. For example: <SOUND CANCEL=AMBIENT> cancels only the sounds in the ambient layer.
The ALT attribute lets you specify a textual description of the sound. This could be used by a version of the interpreter that doesn't support sound to display a description of the sound (the Windows version of the interpreter currently ignores this attribute).
FADEIN and FADEOUT specify the number of seconds over which to fade the music or sound effect in and out. These are currently ignored, but may be used in the future.
Because the <SOUND> tag is part of the formatting information that makes up the display window, sounds are conceptually part of the page on which they appear. This means that all sounds are cancelled as soon as you clear the screen using the clearscreen() function.
If you want to perform full-screen animation or other effects that require erasing the display, but you want your sounds to continue playing, you must use a banner. A banner lets you replace the information displayed on part of the screen without clearing the entire window. Note that you can use a banner that covers the entire display window (by using the HEIGHT=100% attribute) if you want to use the entire window for your animated effects.
At the time of this writing, the MIDI, WAV, and MPEG audio formats are supported on both the 32-bit Windows and the Macintosh versions of HTML TADS. Ogg Vorbis is currently supported only on Windows, although Macintosh support is expected soon.
If and when other HTML TADS ports appear, it is likely that some of the audio features will be supported, but it is possible that not all of the formats will be available. Sound requires specialized hardware; not all computers have any sound capabilities, although most reasonably modern machines do. The sound resource formats that HTML TADS supports are not universal standards, but they are very widely used de facto standards and hence are widely supported. It is possible, though, that some future ports will not have access to support libraries for all of the audio formats.
As a game author, you should consider the trade-offs in using sound in your game. If you want to use sound, you should keep in mind that some players will be using systems that don't provide sound support, and some will choose to play with sounds turned off.
Fortunately, in an adventure game, it's relatively easy to use sound as an enhancement rather than as a crucial feature of the game. One of the primary benefits of using sound in a game is that it can add to the atmosphere and mood of the game; even though this type of sound can add a lot to the game, it can be be omitted without ruining the game, since the game will still be fully playable.
Unless you don't mind limiting your audience, you should be careful to avoid using sound effects that provide crucial information. Whenever you use a sound effect as a clue, you should add some textual description of the sound as well, so that the game is still playable without sound.