mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
162 lines
18 KiB
HTML
162 lines
18 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>The Synthesis ToolKit in C++ (STK)</TITLE>
|
|
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF">
|
|
<CENTER>
|
|
<img src="princeton.gif"> <img src="ccrma.gif"> <img src="mcgill.gif"><P>
|
|
<a class="qindex" href="index.html">Home</a> <a class="qindex" href="information.html">Information</a> <a class="qindex" href="classes.html">Classes</a> <a class="qindex" href="download.html">Download</a> <a class="qindex" href="usage.html">Usage</a> <a class="qindex" href="maillist.html">Mail List</a> <a class="qindex" href="system.html">Requirements</a> <a class="qindex" href="links.html">Links</a> <a class="qindex" href="faq.html">FAQ</a> <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
|
|
<HR>
|
|
<!-- Generated by Doxygen 1.5.8 -->
|
|
<div class="navpath"><a class="el" href="dir_d499f4756a454d8a02faa5ebe57d576f.html">include</a>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>Voicer.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef STK_VOICER_H</span>
|
|
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define STK_VOICER_H</span>
|
|
<a name="l00003"></a>00003 <span class="preprocessor"></span>
|
|
<a name="l00004"></a>00004 <span class="preprocessor">#include "Instrmnt.h"</span>
|
|
<a name="l00005"></a>00005 <span class="preprocessor">#include <vector></span>
|
|
<a name="l00006"></a>00006
|
|
<a name="l00007"></a>00007 <span class="keyword">namespace </span>stk {
|
|
<a name="l00008"></a>00008
|
|
<a name="l00009"></a>00009 <span class="comment">/***************************************************/</span>
|
|
<a name="l00032"></a>00032 <span class="comment">/***************************************************/</span>
|
|
<a name="l00033"></a>00033
|
|
<a name="l00034"></a><a class="code" href="classstk_1_1Voicer.html">00034</a> <span class="keyword">class </span><a class="code" href="classstk_1_1Voicer.html" title="STK voice manager class.">Voicer</a> : <span class="keyword">public</span> <a class="code" href="classstk_1_1Stk.html" title="STK base class.">Stk</a>
|
|
<a name="l00035"></a>00035 {
|
|
<a name="l00036"></a>00036 <span class="keyword">public</span>:
|
|
<a name="l00038"></a>00038 <a class="code" href="classstk_1_1Voicer.html#4b2eb777e91f0dd33403ec23c68bb43f" title="Class constructor taking an optional note decay time (in seconds).">Voicer</a>( StkFloat decayTime = 0.2 );
|
|
<a name="l00039"></a>00039
|
|
<a name="l00041"></a>00041
|
|
<a name="l00045"></a>00045 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#ff9fc9304ef6ae9f7aa1e15611728b8c" title="Add an instrument with an optional group number to the voice manager.">addInstrument</a>( <a class="code" href="classstk_1_1Instrmnt.html" title="STK instrument abstract base class.">Instrmnt</a> *instrument, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00046"></a>00046
|
|
<a name="l00048"></a>00048
|
|
<a name="l00053"></a>00053 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#c5190f84fb8507cac2a18dece242d4d8" title="Remove the given instrument pointer from the voice manager&#39;s control.">removeInstrument</a>( <a class="code" href="classstk_1_1Instrmnt.html" title="STK instrument abstract base class.">Instrmnt</a> *instrument );
|
|
<a name="l00054"></a>00054
|
|
<a name="l00056"></a>00056
|
|
<a name="l00064"></a>00064 <span class="keywordtype">long</span> <a class="code" href="classstk_1_1Voicer.html#bd09d3a8e935fe36776f165038e33176" title="Initiate a noteOn event with the given note number and amplitude and return a unique...">noteOn</a>( StkFloat noteNumber, StkFloat amplitude, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00065"></a>00065
|
|
<a name="l00067"></a>00067
|
|
<a name="l00070"></a>00070 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#4843895d8e4c0fffdd165aa480e2dcde" title="Send a noteOff to all voices having the given noteNumber and optional group (default...">noteOff</a>( StkFloat noteNumber, StkFloat amplitude, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00071"></a>00071
|
|
<a name="l00073"></a>00073
|
|
<a name="l00076"></a>00076 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#4843895d8e4c0fffdd165aa480e2dcde" title="Send a noteOff to all voices having the given noteNumber and optional group (default...">noteOff</a>( <span class="keywordtype">long</span> tag, StkFloat amplitude );
|
|
<a name="l00077"></a>00077
|
|
<a name="l00079"></a>00079
|
|
<a name="l00082"></a>00082 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#5ee3f8a17e031430486e030520709acf" title="Send a frequency update message to all voices assigned to the optional group argument...">setFrequency</a>( StkFloat noteNumber, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00083"></a>00083
|
|
<a name="l00085"></a>00085
|
|
<a name="l00088"></a>00088 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#5ee3f8a17e031430486e030520709acf" title="Send a frequency update message to all voices assigned to the optional group argument...">setFrequency</a>( <span class="keywordtype">long</span> tag, StkFloat noteNumber );
|
|
<a name="l00089"></a>00089
|
|
<a name="l00091"></a>00091 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#e2ab6a6804960c686509d7f919829ad4" title="Send a pitchBend message to all voices assigned to the optional group argument (default...">pitchBend</a>( StkFloat value, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00092"></a>00092
|
|
<a name="l00094"></a>00094 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#e2ab6a6804960c686509d7f919829ad4" title="Send a pitchBend message to all voices assigned to the optional group argument (default...">pitchBend</a>( <span class="keywordtype">long</span> tag, StkFloat value );
|
|
<a name="l00095"></a>00095
|
|
<a name="l00097"></a>00097 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#b5fe99a639a872c90aed2541417cc896" title="Send a controlChange to all instruments assigned to the optional group argument (default...">controlChange</a>( <span class="keywordtype">int</span> number, StkFloat value, <span class="keywordtype">int</span> group=0 );
|
|
<a name="l00098"></a>00098
|
|
<a name="l00100"></a>00100 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#b5fe99a639a872c90aed2541417cc896" title="Send a controlChange to all instruments assigned to the optional group argument (default...">controlChange</a>( <span class="keywordtype">long</span> tag, <span class="keywordtype">int</span> number, StkFloat value );
|
|
<a name="l00101"></a>00101
|
|
<a name="l00103"></a>00103 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1Voicer.html#238f0936f6c0b54c7eb756ad3ac1f019" title="Send a noteOff message to all existing voices.">silence</a>( <span class="keywordtype">void</span> );
|
|
<a name="l00104"></a>00104
|
|
<a name="l00106"></a><a class="code" href="classstk_1_1Voicer.html#35230ae97772ae581fb9658a5f4d57b6">00106</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classstk_1_1Voicer.html#35230ae97772ae581fb9658a5f4d57b6" title="Return the current number of output channels.">channelsOut</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> lastFrame_.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>(); };
|
|
<a name="l00107"></a>00107
|
|
<a name="l00109"></a><a class="code" href="classstk_1_1Voicer.html#50caec57c6a566e4836181774adf5e7b">00109</a> <span class="keyword">const</span> <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& <a class="code" href="classstk_1_1Voicer.html#50caec57c6a566e4836181774adf5e7b" title="Return an StkFrames reference to the last output sample frame.">lastFrame</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> lastFrame_; };
|
|
<a name="l00110"></a>00110
|
|
<a name="l00112"></a>00112
|
|
<a name="l00120"></a>00120 StkFloat <a class="code" href="classstk_1_1Voicer.html#98d843fa1f9fd2ad9a9fb03538dba03a" title="Return the specified channel value of the last computed frame.">lastOut</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel = 0 );
|
|
<a name="l00121"></a>00121
|
|
<a name="l00123"></a>00123
|
|
<a name="l00131"></a>00131 StkFloat <a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70" title="Mix one sample frame of all sounding voices and return the specified channel value...">tick</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel = 0 );
|
|
<a name="l00132"></a>00132
|
|
<a name="l00134"></a>00134
|
|
<a name="l00142"></a>00142 <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& <a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70" title="Mix one sample frame of all sounding voices and return the specified channel value...">tick</a>( <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& frames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel = 0 );
|
|
<a name="l00143"></a>00143
|
|
<a name="l00144"></a>00144 <span class="keyword">protected</span>:
|
|
<a name="l00145"></a>00145
|
|
<a name="l00146"></a>00146 <span class="keyword">struct </span>Voice {
|
|
<a name="l00147"></a>00147 <a class="code" href="classstk_1_1Instrmnt.html" title="STK instrument abstract base class.">Instrmnt</a> *instrument;
|
|
<a name="l00148"></a>00148 <span class="keywordtype">long</span> tag;
|
|
<a name="l00149"></a>00149 StkFloat noteNumber;
|
|
<a name="l00150"></a>00150 StkFloat frequency;
|
|
<a name="l00151"></a>00151 <span class="keywordtype">int</span> sounding;
|
|
<a name="l00152"></a>00152 <span class="keywordtype">int</span> group;
|
|
<a name="l00153"></a>00153
|
|
<a name="l00154"></a>00154 <span class="comment">// Default constructor.</span>
|
|
<a name="l00155"></a>00155 Voice()
|
|
<a name="l00156"></a>00156 :instrument(0), tag(0), noteNumber(-1.0), frequency(0.0), sounding(0), group(0) {}
|
|
<a name="l00157"></a>00157 };
|
|
<a name="l00158"></a>00158
|
|
<a name="l00159"></a>00159 std::vector<Voice> voices_;
|
|
<a name="l00160"></a>00160 <span class="keywordtype">long</span> tags_;
|
|
<a name="l00161"></a>00161 <span class="keywordtype">int</span> muteTime_;
|
|
<a name="l00162"></a>00162 StkFrames lastFrame_;
|
|
<a name="l00163"></a>00163 };
|
|
<a name="l00164"></a>00164
|
|
<a name="l00165"></a><a class="code" href="classstk_1_1Voicer.html#98d843fa1f9fd2ad9a9fb03538dba03a">00165</a> <span class="keyword">inline</span> StkFloat <a class="code" href="classstk_1_1Voicer.html#98d843fa1f9fd2ad9a9fb03538dba03a" title="Return the specified channel value of the last computed frame.">Voicer :: lastOut</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel )
|
|
<a name="l00166"></a>00166 {
|
|
<a name="l00167"></a>00167 <span class="preprocessor">#if defined(_STK_DEBUG_)</span>
|
|
<a name="l00168"></a>00168 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( channel >= lastFrame_.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>() ) {
|
|
<a name="l00169"></a>00169 errorString_ << <span class="stringliteral">"Voicer::lastOut(): channel argument is invalid!"</span>;
|
|
<a name="l00170"></a>00170 <a class="code" href="classstk_1_1Stk.html#48ac73a0d8ca28445ba1a054e1f061ff" title="Static function for error reporting and handling using c-strings.">handleError</a>( StkError::FUNCTION_ARGUMENT );
|
|
<a name="l00171"></a>00171 }
|
|
<a name="l00172"></a>00172 <span class="preprocessor">#endif</span>
|
|
<a name="l00173"></a>00173 <span class="preprocessor"></span>
|
|
<a name="l00174"></a>00174 <span class="keywordflow">return</span> lastFrame_[channel];
|
|
<a name="l00175"></a>00175 }
|
|
<a name="l00176"></a>00176
|
|
<a name="l00177"></a>00177
|
|
<a name="l00178"></a><a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70">00178</a> <span class="keyword">inline</span> StkFloat <a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70" title="Mix one sample frame of all sounding voices and return the specified channel value...">Voicer :: tick</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel )
|
|
<a name="l00179"></a>00179 {
|
|
<a name="l00180"></a>00180 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j;
|
|
<a name="l00181"></a>00181 <span class="keywordflow">for</span> ( j=0; j<lastFrame_.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>(); j++ ) lastFrame_[j] = 0.0;
|
|
<a name="l00182"></a>00182 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<voices_.size(); i++ ) {
|
|
<a name="l00183"></a>00183 <span class="keywordflow">if</span> ( voices_[i].sounding != 0 ) {
|
|
<a name="l00184"></a>00184 voices_[i].instrument->tick();
|
|
<a name="l00185"></a>00185 <span class="keywordflow">for</span> ( j=0; j<voices_[i].instrument->channelsOut(); j++ ) lastFrame_[j] += voices_[i].instrument->lastOut( j );
|
|
<a name="l00186"></a>00186 }
|
|
<a name="l00187"></a>00187 <span class="keywordflow">if</span> ( voices_[i].sounding < 0 ) {
|
|
<a name="l00188"></a>00188 voices_[i].sounding++;
|
|
<a name="l00189"></a>00189 <span class="keywordflow">if</span> ( voices_[i].sounding == 0 )
|
|
<a name="l00190"></a>00190 voices_[i].noteNumber = -1;
|
|
<a name="l00191"></a>00191 }
|
|
<a name="l00192"></a>00192 }
|
|
<a name="l00193"></a>00193
|
|
<a name="l00194"></a>00194 <span class="keywordflow">return</span> lastFrame_[channel];
|
|
<a name="l00195"></a>00195 }
|
|
<a name="l00196"></a>00196
|
|
<a name="l00197"></a><a class="code" href="classstk_1_1Voicer.html#3fd795b0fce684c470484936ef39aa16">00197</a> <span class="keyword">inline</span> <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& <a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70" title="Mix one sample frame of all sounding voices and return the specified channel value...">Voicer :: tick</a>( <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& frames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel )
|
|
<a name="l00198"></a>00198 {
|
|
<a name="l00199"></a>00199 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nChannels = lastFrame_.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>();
|
|
<a name="l00200"></a>00200 <span class="preprocessor">#if defined(_STK_DEBUG_)</span>
|
|
<a name="l00201"></a>00201 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( channel > frames.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>() - nChannels ) {
|
|
<a name="l00202"></a>00202 errorString_ << <span class="stringliteral">"Voicer::tick(): channel and StkFrames arguments are incompatible!"</span>;
|
|
<a name="l00203"></a>00203 <a class="code" href="classstk_1_1Stk.html#48ac73a0d8ca28445ba1a054e1f061ff" title="Static function for error reporting and handling using c-strings.">handleError</a>( StkError::FUNCTION_ARGUMENT );
|
|
<a name="l00204"></a>00204 }
|
|
<a name="l00205"></a>00205 <span class="preprocessor">#endif</span>
|
|
<a name="l00206"></a>00206 <span class="preprocessor"></span>
|
|
<a name="l00207"></a>00207 StkFloat *samples = &frames[channel];
|
|
<a name="l00208"></a>00208 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j, hop = frames.<a class="code" href="classstk_1_1StkFrames.html#ec7ef9c46675a24111aa6e2fda3ba870" title="Return the number of channels represented by the data.">channels</a>() - nChannels;
|
|
<a name="l00209"></a>00209 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<frames.<a class="code" href="classstk_1_1StkFrames.html#05b1ab6fa750a8221a7d65c30e0cdab9" title="Return the number of sample frames represented by the data.">frames</a>(); i++, samples += hop ) {
|
|
<a name="l00210"></a>00210 <a class="code" href="classstk_1_1Voicer.html#3e504b3a6b896772b0f94a12faf0ee70" title="Mix one sample frame of all sounding voices and return the specified channel value...">tick</a>();
|
|
<a name="l00211"></a>00211 <span class="keywordflow">for</span> ( j=0; j<nChannels; j++ )
|
|
<a name="l00212"></a>00212 *samples++ = lastFrame_[j];
|
|
<a name="l00213"></a>00213 }
|
|
<a name="l00214"></a>00214
|
|
<a name="l00215"></a>00215 <span class="keywordflow">return</span> frames;
|
|
<a name="l00216"></a>00216 }
|
|
<a name="l00217"></a>00217
|
|
<a name="l00218"></a>00218 } <span class="comment">// stk namespace</span>
|
|
<a name="l00219"></a>00219
|
|
<a name="l00220"></a>00220 <span class="preprocessor">#endif</span>
|
|
</pre></div></div>
|
|
<HR>
|
|
|
|
<table>
|
|
<tr><td><A HREF="http://ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
|
|
<tr><td>©1995-2009 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|