1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: Sound Drivers</TITLE>
<META NAME="description" CONTENT="Crystal Space: Sound Drivers">
<META NAME="keywords" CONTENT="Crystal Space: Sound Drivers">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC350"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_165.html#SEC344"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_167.html#SEC358"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_164.html#SEC343"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_159.html#SEC338"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_246.html#SEC610"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H2> 7.4 Sound Drivers </H2>
<!--docid::SEC350::-->
<P>
The sound system consists of three components.
</P><P>
<DL COMPACT>
<DT><EM>Sound Driver</EM>
<DD>System dependent sound drivers. This driver is used to pass one audio stream
to the sound hardware (it does not mix several streams), and is only used by
the software sound renderer. The other renderers do not need this driver.
There are currently drivers for MacOS/9, OSS (Linux) and WaveOut
(Windows).
<P>
<EM>Note</EM>: You need not load the sound driver yourself. It is loaded
automatically by the software sound renderer. In fact, you normally don't
have to deal with the sound driver in any way.
</P><P>
<DT><EM>Sound Renderer</EM>
<DD>System dependent sound renderers. This driver can be used to play sound.
There are currently renderers for DirectSound3D and software.
<P>
<DT><EM>Sound Loader</EM>
<DD>This module is used to load sound files. There is only one implementation for
this module. It supports the following sound formats:
<P>
<UL>
<LI>
Sun standard `<TT>.au</TT>' (or `<TT>.snd</TT>'), 8- and 16-bit PCM and 8-bit
G.711 u-Law (no-compression).
<LI>
Microsoft `<TT>.wav</TT>', 8- and 16-bit PCM.
<LI>
Amiga `<TT>.8svx</TT>' and `<TT>.iff</TT>', 8-bit PCM.
<LI>
MacOS/9 `<TT>.aiff</TT>', 8- and 16-bit PCM.
</UL>
</DL>
<P>
The options for all sound modules must be set in the (virtual) file
`<TT>/config/sound.cfg</TT>'.
</P><P>
<A NAME="SEC351"></A>
<H3> Sound Loader </H3>
<!--docid::SEC351::-->
<P>
The sound loader plug-in is used to load sound files and create sound data
objects (<CODE>iSoundData</CODE>) from it. A sound data object represents the sound
in its raw form. It is the same as the <CODE>iImage</CODE> is for graphics.
</P><P>
Looking at the sound loader's methods, you have probably noticed that it
takes an object of `<SAMP>csSoundFormat</SAMP>' type. This object tells the sound
loader in what format (frequency, 8- or 16-bits, stereo or mono) the samples
should be supplied. You can get this from the sound renderer.
</P><P>
<A NAME="SEC352"></A>
<H3> Sound Data </H3>
<!--docid::SEC352::-->
<P>
A sound data object can be either <EM>static</EM> or <EM>streamed</EM>. These are
fundamentally different. The only reason why they use the same interface is
that this makes it easier for the user. A static sound is mainly a buffer of
samples. A streamed sound is mainly a callback function to read samples. At
this point we can already say that one main difference is that you can play
many instances of a static sound at the same time (each with its own position
counter), but only one instance of a streamed sound. However, this does not
mean that you can't create more than one sound source from a streamed sound.
Read on!
</P><P>
<A NAME="SEC353"></A>
<H3> Sound Handle </H3>
<!--docid::SEC353::-->
<P>
The next step towards playing the sound is to hand over the sound data to the
sound renderer. After doing this you may not use the sound data itself
anymore. The renderer will now possibly convert the sound data to an internal
format, load it into the soundcard memory, etc. In return you get a
<EM>sound handle</EM>, which you should use from now.
</P><P>
For static sounds, the sound handle is just that: A wrapper around the sound
data. But for streamed sounds it is more: We said before that there can be
only one instance of a streamed sound. This is not really correct. There may
be several instances, as long as they play the same sequence of samples all
the time (like several speakers that are connected to the same recorder).
</P><P>
So here's a big difference between static and streamed sound. For static
sounds, every instance has its own idea of which part of the sound to play,
and you can control this on a per-instance basis. For streamed sounds, all
instances of the same sound handle play the same stuff, and this is
controlled on a per-handle basis. So the sound handle interface also contains
methods to control playback, but only for streamed sounds.
</P><P>
In short, the sound handle can do the following:
</P><P>
<UL>
<LI>
Create and play an instance of the sound. This is a convenience function. It
does not allow 3d effects or stopping the sound later (you must wait until
it is finished). IT can be used for example for GUI sounds.
<P>
<LI>
Create a sound source. A <EM>sound source</EM> is an instance of the sound.
<P>
<LI>
Control playback for streamed sounds.
</UL>
<P>
<A NAME="SEC354"></A>
<H3> Sound Source </H3>
<!--docid::SEC354::-->
<P>
The sound source is one instance of a sound. It controls position and velocity
for 3d sounds. For static sounds it also controls playback position and
activeness, while for streamed sounds it controls only activeness.
</P><P>
<A NAME="SEC355"></A>
<H3> The Sound Listener </H3>
<!--docid::SEC355::-->
<P>
The sound renderer uses one global listener object. It controls how you hear
sounds. This includes your own position and velocity (only for 3D sounds),
and environmental effects. @@@FIXME do env effects affect non-3D sounds?
</P><P>
<A NAME="SEC356"></A>
<H3> Sound System Example </H3>
<!--docid::SEC356::-->
<P>
Here's an example on how to set up the sound system:
</P><P>
Assume you have five players running around in a FPS game. Three of them
have a pistol, two have a shotgun. You want to play sounds when they fire
their weapons, and you also have a sound file for footsteps. Finally, you
want to play some music from thee big speakers that are placed in the level.
</P><P>
First you load the sounds and register them. After that, you have three static
sound handles for pistol, shotgun and footsteps, and one streamed sound handle
for the music (note that there is currently no loader that creates streamed
sound data, but let's assume there is).
</P><P>
Now you create the sound sources. As said before, a sound source is one
instance of a sound. Thus, if you want to hear the same sound from two
directions, it must come from two sources. We actually have some freedom on
how we create the sound sources. One thing is sure: We need one source for
each of the three speakers for the music. We create the sources, set them to
active, set the position to the position of the speakers and start stream
playback at the sound handle for the music.
</P><P>
For the footsteps we have several options. As one player cannot produce two
footstep sounds at the same time, we can create one sound source for every
player, then start playing on every step without looping. Or we could start
looped playing when the player starts walking and stop playing when the player
stops walking.
</P><P>
Instead of starting and stopping playback all the time, we could also create
a new sound source on every step, and destroy at afterwards. Currently this
should be considered slow, but this may change. On the other hand, every
sound source takes its part of memory, possibly soundcard memory. This may
also change.
</P><P>
What about the guns? It's similar to the footsteps. A player can only fire
one shot at a time, so you can create one source per player for the shooting
sound.
</P><P>
<A NAME="SEC357"></A>
<H3> Advanced Sound Effects </H3>
<!--docid::SEC357::-->
<P>
The environmental effects of the listener are not enough for you? You want to
dynamically generate the sound? This is possible. You have to create your own
implementation of <CODE>iSoundData</CODE>, usually as a streamed sound.
</P><P>
To create special effects, you may for example load a sound as a streamed
sound. Instead of passing it to the sound renderer, you create an object of
your special effects class that takes the original stream and is itself a
sound stream. You then pass this object to the sound renderer. When it is
asked for sample data by the sound renderer, it could for example read data
from the original stream, apply an echoing effect and return the modified
data to the sound renderer. Note that it has to copy the data before modifying
it! Otherwise you may seriously damage the original stream.
<A NAME="Network Drivers"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_165.html#SEC344"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_167.html#SEC358"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_164.html#SEC343"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_159.html#SEC338"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_246.html#SEC610"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
This document was generated
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>
|