diff options
Diffstat (limited to 'docs/doxygen/nel/ambiant__source_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/ambiant__source_8cpp-source.html | 488 |
1 files changed, 488 insertions, 0 deletions
diff --git a/docs/doxygen/nel/ambiant__source_8cpp-source.html b/docs/doxygen/nel/ambiant__source_8cpp-source.html new file mode 100644 index 00000000..cf461d56 --- /dev/null +++ b/docs/doxygen/nel/ambiant__source_8cpp-source.html @@ -0,0 +1,488 @@ +<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<HTML> +<HEAD> + <TITLE>nevrax.org : docs</TITLE> + <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css"> + <link href="doxygen.css" rel="stylesheet" type="text/css"> +</HEAD> +<BODY MARGINHEIGHT="0" MARGINWIDTH="0"> + +<!-- uplinks --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD> + </TR> +</TABLE> + +<!-- banner Nevrax --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%> + <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR> +</TABLE> + +<!-- main table --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + + <!------ Begin Box ------> + <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black> + <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF> + <TABLE cellspacing=0 cellpadding=1 border=0> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr> + </TABLE> + </TD></TR></TABLE></TD></TR></TABLE> + <!------ End Box ------> + + </TD> + <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + +<!-- title --> +<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td> +<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A> +</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT=""> +</td></tr></table> + + +<!-- block --> +<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD> + <TD><B>Documentation</B></TD> + <TD ALIGN=RIGHT> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center> +<hr><h1>ambiant_source.cpp</h1><a href="ambiant__source_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000, 2001 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 <font class="preprocessor">#error "Deprecated"</font> +00027 <font class="preprocessor"></font> +00028 <font class="preprocessor">#include "<a class="code" href="stdsound_8h.html">stdsound.h</a>"</font> +00029 +00030 <font class="preprocessor">#include "<a class="code" href="ambiant__source_8h.html">ambiant_source.h</a>"</font> +00031 <font class="preprocessor">#include "<a class="code" href="sound_8h.html">sound.h</a>"</font> +00032 +00033 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00034 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00035 +00036 +00037 <font class="keyword">namespace </font>NLSOUND { +00038 +00039 +00040 <font class="comment">// If this flag is defined, one ambiant sound cannot be the next one to itself</font> +<a name="l00041"></a><a class="code" href="ambiant__source_8cpp.html#a0">00041</a> <font class="preprocessor">#define ENVSOUND_DONT_DUPLICATE_AMBIANT</font> +00042 <font class="preprocessor"></font> +00043 +00044 <font class="comment">/*</font> +00045 <font class="comment"> * Constructor</font> +00046 <font class="comment"> */</font> +<a name="l00047"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#a0">00047</a> CAmbiantSource::CAmbiantSource() : _Play(false), +00048 _StereoGain(0.0f), +00049 _Sustain(false), +00050 _RandomSoundChosen(false), +00051 _NextSparseSoundTime(0), +00052 _CrossfadeTime(4000), +00053 _SustainTime(8000), +00054 _SparseAvgPeriod(20000) +00055 { +00056 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>].setLooping( <font class="keyword">true</font> ); +00057 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>].setLooping( <font class="keyword">true</font> ); +00058 <font class="comment">//_StereoChannels[SPARSE_CH].setLooping( false );</font> +00059 +00060 srand( (uint32)CTime::getLocalTime() ); +00061 } +00062 +00063 +00064 <font class="comment">/*</font> +00065 <font class="comment"> * Destructor</font> +00066 <font class="comment"> */</font> +<a name="l00067"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#a1">00067</a> CAmbiantSource::~CAmbiantSource() +00068 { +00069 CAudioMixerUser::instance()->removeMySource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>] ); +00070 CAudioMixerUser::instance()->removeMySource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>] ); +00071 CAudioMixerUser::instance()->removeMySource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>] ); +00072 +00073 <font class="comment">// Delete sounds: now done in CAudioMixerUser::~CAudioMixerUser()</font> +00074 <font class="comment">/*vector<CSound*>::iterator ipsnds;</font> +00075 <font class="comment"> for ( ipsnds=_AmbiantSounds.begin(); ipsnds!=_AmbiantSounds.end(); ++ipsnds )</font> +00076 <font class="comment"> {</font> +00077 <font class="comment"> nldebug( "Deleting ambiant sound" );</font> +00078 <font class="comment"> delete (*ipsnds);</font> +00079 <font class="comment"> }</font> +00080 <font class="comment"> for ( ipsnds=_SparseSounds.begin(); ipsnds!=_SparseSounds.end(); ++ipsnds )</font> +00081 <font class="comment"> {</font> +00082 <font class="comment"> nldebug( "Deleting sparse sound" );</font> +00083 <font class="comment"> delete (*ipsnds);</font> +00084 <font class="comment"> }</font> +00085 <font class="comment"> */</font> +00086 } +00087 +00088 +00089 <font class="comment">/* Init. You can pass a position vector to link to (if the playable has stereo source(s))</font> +00090 <font class="comment"> * When reading from a stream, call init() *after* serial().</font> +00091 <font class="comment"> */</font> +00092 <font class="keywordtype">void</font> CAmbiantSource::initPos( <font class="keyword">const</font> CVector *posvector ) +00093 { +00094 <font class="comment">// Initialize ambiant sound channels</font> +00095 <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a>.empty() ) +00096 { +00097 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>].set3DPositionVector( posvector ); +00098 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>].setSound( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a> ) ); +00099 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>].setGain( 0.0f ); +00100 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a>); +00101 CAudioMixerUser::instance()->addSource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>] ); +00102 CAudioMixerUser::instance()->giveTrack( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>] ); +00103 +00104 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a>.size() > 1 ) +00105 { +00106 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>].set3DPositionVector( posvector ); +00107 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>].setSound( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a> ) ); +00108 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>].setGain( 0.0f ); +00109 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a>); +00110 CAudioMixerUser::instance()->addSource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>] ); +00111 CAudioMixerUser::instance()->giveTrack( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a2">AMBIANT_CH2</a>] ); +00112 } +00113 } +00114 +00115 <font class="comment">// Initialize sparse sounds channel</font> +00116 <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o4">_SparseSounds</a>.empty() ) +00117 { +00118 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].set3DPositionVector( posvector ); +00119 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a> ); +00120 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setSound( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o4">_SparseSounds</a> ) ); +00121 CAudioMixerUser::instance()->addSource( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>] ); +00122 CAudioMixerUser::instance()->giveTrack( &<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>] ); +00123 } +00124 } +00125 +00126 +00127 <font class="comment">/*</font> +00128 <font class="comment"> * Enable (play with high priority) and set general gain, or disable (stop and set low priority).</font> +00129 <font class="comment"> */</font> +<a name="l00130"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#a4">00130</a> <font class="keywordtype">void</font> CAmbiantSource::enable( <font class="keywordtype">bool</font> toplay, <font class="keywordtype">float</font> gain ) +00131 { +00132 <font class="comment">// Calc position in cycle</font> +00133 <font class="keywordtype">bool</font> crossfade; +00134 uint32 leadchannel; +00135 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a>.size() > 1 ) +00136 { +00137 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b0">calcPosInCycle</a>( crossfade, leadchannel ); +00138 } +00139 <font class="keywordflow">else</font> +00140 { +00141 crossfade = <font class="keyword">false</font>; +00142 leadchannel = <a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>; +00143 } +00144 +00145 <font class="comment">// Enable/disable</font> +00146 <font class="keywordflow">if</font> ( toplay ) +00147 { +00148 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a> = gain; +00149 +00150 <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o0">_Play</a> ) +00151 { +00152 <font class="comment">// Start lead channel</font> +00153 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].getSound() != NULL ) +00154 { +00155 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Envsound: Switch on channel %u"</font>, leadchannel ); +00156 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a11">HighPri</a> ) ; +00157 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].play(); +00158 } +00159 +00160 <font class="comment">// If crossfading, start back channel</font> +00161 <font class="keywordflow">if</font> ( crossfade && (<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].getSound() != NULL) ) +00162 { +00163 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Envsound: Switch on channel %u"</font>, 1-leadchannel ); +00164 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a11">HighPri</a> ) ; +00165 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].play(); +00166 } +00167 +00168 <font class="comment">// Calc when the next spare sound will play</font> +00169 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b2">calcRandomSparseSoundTime</a>( NULL ); +00170 +00171 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o0">_Play</a> = <font class="keyword">true</font>; +00172 } +00173 <font class="comment">// The SPARSE_CH is added only when needed</font> +00174 } +00175 <font class="keywordflow">else</font> +00176 { +00177 <font class="keywordflow">if</font> ( _Play ) +00178 { +00179 <font class="comment">// Stop lead channel</font> +00180 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].getSound() != NULL ) +00181 { +00182 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Envsound: Switch off channel %u"</font>, leadchannel ); +00183 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].stop(); +00184 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a> ); +00185 } +00186 +00187 <font class="comment">// If crossfading, stop back channel</font> +00188 <font class="keywordflow">if</font> ( crossfade && (<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].getSound() != NULL) ) +00189 { +00190 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Envsound: Switch off channel %u"</font>, 1-leadchannel ); +00191 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].stop(); +00192 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[1-leadchannel].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a> ); +00193 } +00194 +00195 <font class="comment">// Stop spare channel, anyway</font> +00196 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].getSound() != NULL ) +00197 { +00198 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Envsound: Switch off sparse channel"</font> ); +00199 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].stop(); +00200 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a13">LowPri</a> ); +00201 } +00202 +00203 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o0">_Play</a> = <font class="keyword">false</font>; +00204 } +00205 } +00206 } +00207 +00208 +00209 <font class="comment">/*</font> +00210 <font class="comment"> * Calc pos in cycle</font> +00211 <font class="comment"> */</font> +<a name="l00212"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b0">00212</a> <a class="code" href="namespaceNLMISC.html#a183">TTime</a> CAmbiantSource::calcPosInCycle( <font class="keywordtype">bool</font>& crossfade, uint32& leadchannel ) +00213 { +00214 <a class="code" href="namespaceNLMISC.html#a183">TTime</a> pos = CTime::getLocalTime(); +00215 uint32 cycletime = <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o9">_CrossfadeTime</a> + <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o10">_SustainTime</a>; +00216 pos = pos % (cycletime*2); +00217 +00218 <font class="comment">// Calc which channel will be the lead one</font> +00219 <font class="keywordflow">if</font> ( pos < cycletime ) +00220 { +00221 leadchannel = 0; +00222 } +00223 <font class="keywordflow">else</font> +00224 { +00225 leadchannel = 1; +00226 pos = pos - (cycletime); +00227 } +00228 +00229 <font class="comment">// Calc if the pos is in the first part (crossfade) or in the other part (sustain)</font> +00230 crossfade = ( pos < <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o9">_CrossfadeTime</a> ); +00231 +00232 <font class="keywordflow">return</font> pos; +00233 } +00234 +00235 +00236 <font class="comment">/*</font> +00237 <font class="comment"> * Update the stereo mix (call evenly)</font> +00238 <font class="comment"> */</font> +<a name="l00239"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#a3">00239</a> <font class="keywordtype">void</font> CAmbiantSource::update() +00240 { +00241 <font class="keywordflow">if</font> ( (!<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o0">_Play</a>) || (<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a>==0.0f) ) +00242 { +00243 <font class="keywordflow">return</font>; +00244 } +00245 +00246 <font class="comment">// Calc pos in cycle</font> +00247 <font class="keywordtype">bool</font> crossfade; +00248 uint32 leadchannel, backchannel=0; +00249 <a class="code" href="namespaceNLMISC.html#a183">TTime</a> posInCycle=0; +00250 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a>.size() > 1 ) +00251 { +00252 posInCycle = <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b0">calcPosInCycle</a>( crossfade, leadchannel ); +00253 backchannel = 1 - leadchannel; +00254 } +00255 <font class="keywordflow">else</font> +00256 { +00257 <font class="comment">// If there is less than 2 sounds, no crossfade, always sustain (a single sound must be looping)</font> +00258 crossfade = <font class="keyword">false</font>; +00259 leadchannel = <a class="code" href="env__sound__user_8h.html#a1">AMBIANT_CH1</a>; +00260 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o6">_Sustain</a> = <font class="keyword">true</font>; +00261 } +00262 +00263 <font class="comment">// Crossfade the first two sources</font> +00264 <font class="keywordflow">if</font> ( crossfade ) +00265 { +00266 <font class="comment">// Attack</font> +00267 <font class="keywordtype">float</font> ratio = (float)posInCycle / (float)<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o9">_CrossfadeTime</a>; +00268 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].setRelativeGain( ratio*<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a> ); +00269 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[backchannel].setRelativeGain( (1.0f - ratio)*<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a> ); +00270 +00271 <font class="comment">// Start next sound</font> +00272 <font class="keywordflow">if</font> ( _Sustain ) +00273 { +00274 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Beginning crossfade: channel #%u rising"</font>, leadchannel ); +00275 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a11">HighPri</a> ) ; +00276 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].play(); +00277 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o6">_Sustain</a> = <font class="keyword">false</font>; +00278 } +00279 } +00280 <font class="keywordflow">else</font> +00281 { +00282 <font class="comment">// Set sustain gain (takes into account the possible changes to _StereoGain)</font> +00283 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].setRelativeGain( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a> ); +00284 +00285 <font class="comment">// Prepare next ambiant sound</font> +00286 <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o6">_Sustain</a> ) +00287 { +00288 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o6">_Sustain</a> = <font class="keyword">true</font>; +00289 <a class="code" href="namespaceNLSOUND.html#a8">TSoundId</a> nextsound = <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a> ); +00290 <font class="preprocessor">#ifdef ENVSOUND_DONT_DUPLICATE_AMBIANT</font> +00291 <font class="preprocessor"></font> <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a>.size() > 1 ); <font class="comment">// or infinite loop</font> +00292 <font class="keywordflow">while</font> ( nextsound == <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[leadchannel].getSound() ) +00293 { +00294 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Avoiding ambiant sound duplication..."</font> ); +00295 nextsound = <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a> ); +00296 } +00297 <font class="preprocessor">#endif</font> +00298 <font class="preprocessor"></font> <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Sustain: channel #1"</font> ); +00299 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[backchannel].setRelativeGain( 0.0f ); +00300 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[backchannel].stop(); <font class="comment">// we don't set the priority to LowPri</font> +00301 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[backchannel].setSound( nextsound ); +00302 } +00303 } +00304 +00305 <font class="comment">// Add a short random sound into the third source</font> +00306 <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o4">_SparseSounds</a>.empty() ) +00307 { +00308 <font class="comment">// Set sustain gain (takes into account the possible changes to _StereoGain)</font> +00309 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setRelativeGain( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o2">_StereoGain</a> ); +00310 +00311 <font class="comment">// Start next sparse sound</font> +00312 <a class="code" href="namespaceNLMISC.html#a183">TTime</a> now = CTime::getLocalTime(); +00313 <font class="keywordflow">if</font> ( now > <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o8">_NextSparseSoundTime</a> ) +00314 { +00315 <a class="code" href="namespaceNLSOUND.html#a8">TSoundId</a> nextsound = <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">getRandomSound</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o4">_SparseSounds</a> ); +00316 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].stop(); +00317 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setSound( nextsound ); +00318 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].setPriority( <a class="code" href="namespaceNLSOUND.html#a82a12">MidPri</a> ); +00319 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].play(); +00320 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Playing sparse sound"</font> ); +00321 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].getTrack() == NULL ) +00322 { +00323 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: Ensound: Switch on sparse channel"</font> ); +00324 <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o1">_StereoChannels</a>[<a class="code" href="env__sound__user_8h.html#a3">SPARSE_CH</a>].getSound() != NULL ); +00325 } +00326 <font class="comment">// Does not leave the track</font> +00327 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b2">calcRandomSparseSoundTime</a>( nextsound ); +00328 } +00329 } +00330 } +00331 +00332 +00333 <font class="comment">/*</font> +00334 <font class="comment"> * Select a random sound in a bank</font> +00335 <font class="comment"> */</font> +<a name="l00336"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b1">00336</a> <a class="code" href="namespaceNLSOUND.html#a8">TSoundId</a> CAmbiantSource::getRandomSound( <font class="keyword">const</font> std::vector<CSound*>& bank )<font class="keyword"> const</font> +00337 <font class="keyword"></font>{ +00338 <a class="code" href="debug_8h.html#a6">nlassert</a>( ! bank.empty() ); +00339 <font class="comment">// Note: does not work with a very big size (rand()*bank.size() would overflow)</font> +00340 uint32 <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a> = rand()*bank.size()/(RAND_MAX+1); +00341 <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a> < bank.size() ); +00342 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Prepared random sound number %u of %u"</font>, <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>, bank.size()-1 ); +00343 +00344 <font class="keywordflow">return</font> bank[<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>]; +00345 } +00346 +00347 +00348 +00349 +00350 <font class="comment">/*</font> +00351 <font class="comment"> * Calculate the next time a sparse sound plays</font> +00352 <font class="comment"> */</font> +<a name="l00353"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#b2">00353</a> <font class="keywordtype">void</font> CAmbiantSource::calcRandomSparseSoundTime( <a class="code" href="namespaceNLSOUND.html#a8">TSoundId</a> currentsparesound ) +00354 { +00355 uint32 delay = (uint)((float)rand() * (float)(<a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o11">_SparseAvgPeriod</a>*2) / (float)RAND_MAX); +00356 +00357 <font class="comment">// Check the next sound will play after the current one</font> +00358 <font class="keywordflow">if</font> ( currentsparesound != NULL ) +00359 { +00360 uint32 soundlength = currentsparesound->getDuration(); +00361 <font class="keywordflow">if</font> ( delay <= soundlength ) +00362 { +00363 delay = soundlength+1; +00364 } +00365 } +00366 +00367 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"AM: EnvSound: Next sparse sound will play in %u ms"</font>, delay ); +00368 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o8">_NextSparseSoundTime</a> = CTime::getLocalTime() + delay; +00369 } +00370 +00371 +00372 <font class="comment">/*</font> +00373 <font class="comment"> * Serialize</font> +00374 <font class="comment"> */</font> +00375 <font class="comment">/*</font> +00376 <font class="comment">void CAmbiantSource::serial( NLMISC::IStream& s )</font> +00377 <font class="comment">{</font> +00378 <font class="comment"> // If you change this, increment the version number in CEnvSoundUser::load() !</font> +00379 <font class="comment"></font> +00380 <font class="comment"> // Constants</font> +00381 <font class="comment"> s.serial( _CrossfadeTime );</font> +00382 <font class="comment"> s.serial( _SustainTime );</font> +00383 <font class="comment"> s.serial( _SparseAvgPeriod );</font> +00384 <font class="comment"></font> +00385 <font class="comment"> // Stereo sound banks (sounds allocated here once per pointer, deleted by CAudioMixerUser::~CAudioMixerUser())</font> +00386 <font class="comment"> s.serialContPtr( _AmbiantSounds );</font> +00387 <font class="comment"> s.serialContPtr( _SparseSounds );</font> +00388 <font class="comment"></font> +00389 <font class="comment"> // Register within the audio mixer for deletion at the end</font> +00390 <font class="comment"> vector<CSound*>::iterator ips;</font> +00391 <font class="comment"> for ( ips=_AmbiantSounds.begin(); ips!=_AmbiantSounds.end(); ++ips )</font> +00392 <font class="comment"> {</font> +00393 <font class="comment"> CAudioMixerUser::instance()->addAmbiantSound( (*ips) );</font> +00394 <font class="comment"> }</font> +00395 <font class="comment"> for ( ips=_SparseSounds.begin(); ips!=_SparseSounds.end(); ++ips )</font> +00396 <font class="comment"> {</font> +00397 <font class="comment"> CAudioMixerUser::instance()->addAmbiantSound( (*ips) );</font> +00398 <font class="comment"> }</font> +00399 <font class="comment">}</font> +00400 <font class="comment"></font> +00401 <font class="comment">*/</font> +00402 +00403 <font class="comment">/*</font> +00404 <font class="comment"> * Set properties (EDIT)</font> +00405 <font class="comment"> */</font> +<a name="l00406"></a><a class="code" href="classNLSOUND_1_1CAmbiantSource.html#a6">00406</a> <font class="keywordtype">void</font> CAmbiantSource::setProperties( std::vector<TSoundId>& ambiantsounds, +00407 std::vector<TSoundId>& sparsesounds, +00408 uint32 crossfadeTimeMs, uint32 sustainTimeMs, +00409 uint32 sparseAvgPeriodMs ) +00410 { +00411 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o3">_AmbiantSounds</a> = ambiantsounds; +00412 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o4">_SparseSounds</a> = sparsesounds; +00413 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o9">_CrossfadeTime</a> = crossfadeTimeMs; +00414 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o10">_SustainTime</a> = sustainTimeMs; +00415 <a class="code" href="classNLSOUND_1_1CAmbiantSource.html#o11">_SparseAvgPeriod</a> = sparseAvgPeriodMs; +00416 } +00417 +00418 +00419 } <font class="comment">// NLSOUND</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |