106 lines
12 KiB
HTML
106 lines
12 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Game Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
|
||
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
|
||
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheGameKit_Overview.html" title="The Game Kit" /><link rel="prev" href="BFileGameSound_Overview.html" title="BFileGameSound" /><link rel="next" href="BPushGameSound_Overview.html" title="BPushGameSound" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BFileGameSound_Overview.html" title="BFileGameSound"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheGameKit_Overview.html" title="The Game Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BPushGameSound_Overview.html" title="BPushGameSound"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Game Kit</div></div><div id="headerB">Prev: <a href="BFileGameSound_Overview.html">BFileGameSound</a> Up: <a href="TheGameKit_Overview.html">The Game Kit</a> Next: <a href="BPushGameSound_Overview.html">BPushGameSound</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BGameSound_Overview"></a>BGameSound</h2></div></div></div><a id="id529500" class="indexterm"></a><p>
|
||
The <a class="link" href="BGameSound.html" title="BGameSound"><code class="classname">BGameSound</code></a>
|
||
class is the base class for other game sound classes. You
|
||
never use this class directly; instead, you should use the derived
|
||
classes.
|
||
</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BGameSound_Overview_Explosions"></a>The Sound of Explosions in the Morning</h3></div></div></div><p>
|
||
Nothing makes the player happy like the sound of lots of explosions,
|
||
weird alien things, and other thrilling audio pleasures. The various
|
||
<a class="link" href="BGameSound.html" title="BGameSound"><code class="classname">BGameSound</code></a>-derived classes make this a snap.
|
||
</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BGameSound_Overview_Choosing_A_Player"></a>Choosing a Player Class</h4></div></div></div><p>
|
||
Playing a sound is as simple as instantiating an object derived from the
|
||
most appropriate class and calling
|
||
<a class="link" href="BGameSound.html#BGameSound_StartPlaying" title="StartPlaying(), StopPlaying()"><code class="methodname">StartPlaying()</code></a>
|
||
on it. How do you determine the most appropriate class? Here are some hints:
|
||
</p><ul class="itemizedlist"><li><p>
|
||
If you have a sound effect that's short and is likely to be played
|
||
often, or needs to be played with minimal latency, use the
|
||
<a class="link" href="BSimpleGameSound.html" title="BSimpleGameSound"><code class="classname">BSimpleGameSound</code></a> class.
|
||
An arcade game's explosions definitely fit into this class.
|
||
</p></li><li><p>
|
||
If you have a sound effect that's very long, or doesn't need to be
|
||
played very often, or whose latency doesn't matter much, use the
|
||
<a class="link" href="BFileGameSound.html" title="BFileGameSound"><code class="classname">BFileGameSound</code></a> class.
|
||
Music loops can take advantage of this class.
|
||
</p></li><li><p>
|
||
If you want to be able to push audio buffers at the system, instead
|
||
of having a callback that fills buffers, use the
|
||
<a class="link" href="BPushGameSound.html" title="BPushGameSound"><code class="classname">BPushGameSound</code></a> class.
|
||
</p></li></ul><p>
|
||
Most games' needs will be filled by the
|
||
<a class="link" href="BSimpleGameSound.html" title="BSimpleGameSound"><code class="classname">BSimpleGameSound</code></a> and
|
||
<a class="link" href="BFileGameSound.html" title="BFileGameSound"><code class="classname">BFileGameSound</code></a>
|
||
classes. And, of course, you can write your own derived
|
||
classes if none of these classes meet your requirements.
|
||
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BGameSound_Overview_Polyphony"></a>Polyphony</h4></div></div></div><p>
|
||
Sometimes the player needs to hear multiple copies of the same sound at
|
||
the same time; for instance, if they shoot a three-way splitting weapon
|
||
and hit two targets, they need to hear two explosions at once. Each
|
||
<a class="link" href="BGameSound.html" title="BGameSound"><code class="classname">BGameSound</code></a> (or
|
||
<a class="link" href="BGameSound.html" title="BGameSound"><code class="classname">BGameSound</code></a>-derived)
|
||
object can play only once at a time,
|
||
so you'll need to use cloned copies of the sound, one for each channel of
|
||
polyphony you allow.
|
||
</p><p>
|
||
This can be done with ease using a simple class like this:
|
||
</p><pre class="programlisting example cpp">class <code class="classname">MultipleEffect</code> {
|
||
public:
|
||
<code class="methodname">MultipleEffect</code>(<span class="type">BGameSound*</span> <code class="parameter">sound</code>, <span class="type">int</span> <code class="parameter">polyphony</code>) {
|
||
<code class="varname">m_fx</code> = new <code class="classname">BGameSound</code> *[<code class="varname">polyphony</code>];
|
||
<code class="varname">m_fx</code>[0] = <code class="parameter">sound</code>;
|
||
for (<span class="type">int</span> <code class="varname">ix</code>=1; <code class="varname">ix</code><<code class="varname">polyphony</code>; <code class="varname">ix</code>++) {
|
||
<code class="varname">m_fx</code>[<code class="varname">ix</code>] = <code class="parameter">sound</code>-><code class="methodname">Clone</code>();
|
||
}
|
||
<code class="varname">m_current</code> = 0;
|
||
<code class="varname">m_polyphony</code> = <code class="varname">polyphony</code>;
|
||
}
|
||
<span class="type">void</span> StartPlaying() {
|
||
<span class="type">int</span> <code class="varname">id</code> = <code class="function">atomic_add</code>(&<code class="varname">m_current</code>, 1) % <code class="varname">m_polyphony</code>;
|
||
<code class="varname">m_fx</code>[<code class="varname">id</code>]-><code class="methodname">StartPlaying</code>();
|
||
}
|
||
|
||
private:
|
||
<span class="type">int32</span> <code class="varname">m_current</code>;
|
||
<span class="type">int32</span> <code class="varname">m_polyphony</code>;
|
||
<span class="type">BGameSound*</span> <code class="varname">m_fx</code>;
|
||
};</pre><p>
|
||
This class' constructor lets you specify a
|
||
<a class="link" href="BGameSound.html" title="BGameSound"><code class="classname">BGameSound</code></a>-derived sound and
|
||
the maximum number of times it can be playing at once. It creates the
|
||
appropriate number of clones, and its
|
||
<a class="link" href="BGameSound.html#BGameSound_StartPlaying" title="StartPlaying(), StopPlaying()"><code class="methodname">StartPlaying()</code></a> implementation
|
||
automatically selects the oldest one and reuses it. Since
|
||
<a class="link" href="BGameSound.html#BGameSound_StartPlaying" title="StartPlaying(), StopPlaying()"><code class="methodname">StartPlaying()</code></a>
|
||
restarts a sound from the beginning if it's called on a playing sound,
|
||
this works out well—if polyphony is 3, and there are already three
|
||
sounds playing, the oldest one will be reset and played from the
|
||
beginning.
|
||
</p><div class="admonition note"><div class="title">Note</div><div class="graphic"><img class="icon" alt="Note" width="32" src="./images/admonitions/Info_32.png" /><div class="text"><p>In the current version of the BeOS, when you clone a
|
||
<a class="link" href="BSimpleGameSound.html" title="BSimpleGameSound"><code class="classname">BSimpleGameSound</code></a>,
|
||
the sound data buffer is also cloned, so you'll have multiple copies of
|
||
the sound effect in memory. Keep this in mind as you write your code, as
|
||
you can rapidly use a lot of memory this way.</p></div></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BGameSound_Overview_Performance_Verification"></a>Performance Verification</h4></div></div></div><p>
|
||
There are a wide variety of performance concerns, and of course you want
|
||
your game to work on as many systems as possible. Be recommends that you
|
||
test your application in at least these three situations:
|
||
</p><ul class="itemizedlist"><li><p>
|
||
Real-time audio disabled, using an ISA sound card (such as an AWE64
|
||
or equivalent card).
|
||
</p></li><li><p>
|
||
Real-time audio enabled, using a PCI sound card (SoundBlaster PCI 64
|
||
or equivalent).
|
||
</p></li><li><p>
|
||
Real-time audio enabled, using an E-mu 10k sound card. This sound
|
||
card has its own node, so its behavior is a little different, and is
|
||
therefore worth special testing attention.
|
||
</p></li></ul><p>
|
||
This isn't intended to be an exhaustive list; you should always test your
|
||
software in as many configurations as possible.
|
||
</p></div></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BFileGameSound_Overview.html">BFileGameSound</a> Up: <a href="TheGameKit_Overview.html">The Game Kit</a> Next: <a href="BPushGameSound_Overview.html">BPushGameSound</a> </div><div id="footerB"><div id="footerBL"><a href="BFileGameSound_Overview.html" title="BFileGameSound"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheGameKit_Overview.html" title="The Game Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BPushGameSound_Overview.html" title="BPushGameSound"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
|
||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
|
||
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>
|