mirror of
https://github.com/thestk/stk
synced 2026-01-13 04:51:53 +00:00
228 lines
18 KiB
HTML
228 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="tutorial.html">Tutorial</a></CENTER>
|
|
<HR>
|
|
<!-- Generated by Doxygen 1.3.4 -->
|
|
<h1>Stk.h</h1><div class="fragment"><pre>00001 <span class="comment">/***************************************************/</span>
|
|
00013 <span class="comment">/***************************************************/</span>
|
|
00014
|
|
00015 <span class="preprocessor">#ifndef STK_STK_H</span>
|
|
00016 <span class="preprocessor"></span><span class="preprocessor">#define STK_STK_H</span>
|
|
00017 <span class="preprocessor"></span>
|
|
00018 <span class="preprocessor">#include <string></span>
|
|
00019 <span class="preprocessor">#include <iostream></span>
|
|
00020 <span class="preprocessor">#include <sstream></span>
|
|
00021 <span class="preprocessor">#include <valarray></span>
|
|
00022
|
|
00023 <span class="comment">// Most data in STK is passed and calculated with the</span>
|
|
00024 <span class="comment">// following user-definable floating-point type. You</span>
|
|
00025 <span class="comment">// can change this to "float" if you prefer or perhaps</span>
|
|
00026 <span class="comment">// a "long double" in the future.</span>
|
|
00027 <span class="keyword">typedef</span> <span class="keywordtype">double</span> StkFloat;
|
|
00028
|
|
00029 <span class="comment">// The "MY_FLOAT" type was deprecated in STK</span>
|
|
00030 <span class="comment">// versions higher than 4.1.3 and replaced with the variable</span>
|
|
00031 <span class="comment">// "StkFloat". </span>
|
|
00032 <span class="preprocessor">#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)</span>
|
|
00033 <span class="preprocessor"></span> <span class="keyword">typedef</span> StkFloat MY_FLOAT;
|
|
00034 <span class="preprocessor"> #pragma deprecated(MY_FLOAT)</span>
|
|
00035 <span class="preprocessor"></span><span class="preprocessor">#elif defined(__GXX__) </span>
|
|
00036 <span class="preprocessor"></span> <span class="keyword">typedef</span> StkFloat MY_FLOAT __attribute__ ((deprecated));
|
|
00037 <span class="preprocessor">#else</span>
|
|
00038 <span class="preprocessor"></span> <span class="keyword">typedef</span> StkFloat MY_FLOAT; <span class="comment">// temporary</span>
|
|
00039 <span class="preprocessor">#endif</span>
|
|
00040 <span class="preprocessor"></span>
|
|
00041
|
|
00043
|
|
<a name="l00048"></a><a class="code" href="classStkError.html">00048</a> <span class="keyword">class </span><a class="code" href="classStkError.html">StkError</a>
|
|
00049 {
|
|
00050 <span class="keyword">public</span>:
|
|
00051 <span class="keyword">enum</span> Type {
|
|
00052 STATUS,
|
|
00053 WARNING,
|
|
00054 DEBUG_WARNING,
|
|
00055 FUNCTION_ARGUMENT,
|
|
00056 FILE_NOT_FOUND,
|
|
00057 FILE_UNKNOWN_FORMAT,
|
|
00058 FILE_ERROR,
|
|
00059 PROCESS_THREAD,
|
|
00060 PROCESS_SOCKET,
|
|
00061 PROCESS_SOCKET_IPADDR,
|
|
00062 AUDIO_SYSTEM,
|
|
00063 MIDI_SYSTEM,
|
|
00064 UNSPECIFIED
|
|
00065 };
|
|
00066
|
|
00067 <span class="keyword">protected</span>:
|
|
00068 std::string message_;
|
|
00069 Type type_;
|
|
00070
|
|
00071 <span class="keyword">public</span>:
|
|
<a name="l00073"></a><a class="code" href="classStkError.html#a0">00073</a> <a class="code" href="classStkError.html#a0">StkError</a>(<span class="keyword">const</span> std::string& message, Type type = StkError::UNSPECIFIED) : message_(message), type_(type) {}
|
|
00074
|
|
<a name="l00076"></a><a class="code" href="classStkError.html#a1">00076</a> <span class="keyword">virtual</span> <a class="code" href="classStkError.html#a1">~StkError</a>(<span class="keywordtype">void</span>) {};
|
|
00077
|
|
<a name="l00079"></a><a class="code" href="classStkError.html#a2">00079</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classStkError.html#a2">printMessage</a>(<span class="keywordtype">void</span>) { std::cerr << <span class="charliteral">'\n'</span> << message_ << <span class="stringliteral">"\n\n"</span>; }
|
|
00080
|
|
<a name="l00082"></a><a class="code" href="classStkError.html#a3">00082</a> <span class="keyword">virtual</span> <span class="keyword">const</span> Type& <a class="code" href="classStkError.html#a3">getType</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> type_; }
|
|
00083
|
|
<a name="l00085"></a><a class="code" href="classStkError.html#a4">00085</a> <span class="keyword">virtual</span> <span class="keyword">const</span> std::string& <a class="code" href="classStkError.html#a4">getMessage</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> message_; }
|
|
00086
|
|
<a name="l00088"></a><a class="code" href="classStkError.html#a5">00088</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="classStkError.html#a5">getMessageCString</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> message_.c_str(); }
|
|
00089 };
|
|
00090
|
|
00091
|
|
<a name="l00092"></a><a class="code" href="classStk.html">00092</a> <span class="keyword">class </span><a class="code" href="classStk.html">Stk</a>
|
|
00093 {
|
|
00094 <span class="keyword">public</span>:
|
|
00095
|
|
00096 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> StkFormat;
|
|
<a name="l00097"></a><a class="code" href="classStk.html#s0">00097</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s0">STK_SINT8</a>;
|
|
<a name="l00098"></a><a class="code" href="classStk.html#s1">00098</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s1">STK_SINT16</a>;
|
|
<a name="l00099"></a><a class="code" href="classStk.html#s2">00099</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s2">STK_SINT24</a>;
|
|
<a name="l00100"></a><a class="code" href="classStk.html#s3">00100</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s3">STK_SINT32</a>;
|
|
<a name="l00101"></a><a class="code" href="classStk.html#s4">00101</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s4">STK_FLOAT32</a>;
|
|
<a name="l00102"></a><a class="code" href="classStk.html#s5">00102</a> <span class="keyword">static</span> <span class="keyword">const</span> StkFormat <a class="code" href="classStk.html#s5">STK_FLOAT64</a>;
|
|
00104
|
|
<a name="l00105"></a><a class="code" href="classStk.html#e0">00105</a> <span class="keyword">static</span> StkFloat <a class="code" href="classStk.html#e0">sampleRate</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> srate_; }
|
|
00106
|
|
00108
|
|
<a name="l00116"></a><a class="code" href="classStk.html#e1">00116</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e1">setSampleRate</a>(StkFloat rate) { <span class="keywordflow">if</span> (rate > 0.0) srate_ = rate; }
|
|
00117
|
|
<a name="l00119"></a><a class="code" href="classStk.html#e2">00119</a> <span class="keyword">static</span> std::string <a class="code" href="classStk.html#e2">rawwavePath</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> rawwavepath_; }
|
|
00120
|
|
00122 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e3">setRawwavePath</a>(std::string path);
|
|
00123
|
|
00125 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e4">swap16</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *ptr);
|
|
00126
|
|
00128 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e5">swap32</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *ptr);
|
|
00129
|
|
00131 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e6">swap64</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *ptr);
|
|
00132
|
|
00134 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e7">sleep</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> milliseconds);
|
|
00135
|
|
00137 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e8">handleError</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> *message, StkError::Type type );
|
|
00138
|
|
00140 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classStk.html#e8">handleError</a>( std::string message, StkError::Type type );
|
|
00141
|
|
00142 <span class="keyword">private</span>:
|
|
00143 <span class="keyword">static</span> StkFloat srate_;
|
|
00144 <span class="keyword">static</span> std::string rawwavepath_;
|
|
00145
|
|
00146 <span class="keyword">protected</span>:
|
|
00147
|
|
00148 std::ostringstream errorString_;
|
|
00149
|
|
00151 <a class="code" href="classStk.html#b0">Stk</a>(<span class="keywordtype">void</span>);
|
|
00152
|
|
00154 <span class="keyword">virtual</span> <a class="code" href="classStk.html#b1">~Stk</a>(<span class="keywordtype">void</span>);
|
|
00155
|
|
00157 <span class="keywordtype">void</span> <a class="code" href="classStk.html#e8">handleError</a>( StkError::Type type );
|
|
00158 };
|
|
00159
|
|
00160
|
|
00161 <span class="comment">/***************************************************/</span>
|
|
00175 <span class="comment">/***************************************************/</span>
|
|
00176
|
|
<a name="l00177"></a><a class="code" href="classStkFrames.html">00177</a> <span class="keyword">class </span><a class="code" href="classStkFrames.html">StkFrames</a>
|
|
00178 {
|
|
00179 <span class="keyword">public</span>:
|
|
00180
|
|
00182 <a class="code" href="classStkFrames.html#a0">StkFrames</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrames = 0, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nChannels = 1, <span class="keywordtype">bool</span> <a class="code" href="classStkFrames.html#a8">interleaved</a> = <span class="keyword">true</span> );
|
|
00183
|
|
00185 <a class="code" href="classStkFrames.html#a0">StkFrames</a>( <span class="keyword">const</span> StkFloat& value, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nChannels, <span class="keywordtype">bool</span> <a class="code" href="classStkFrames.html#a8">interleaved</a> = <span class="keyword">true</span> );
|
|
00186
|
|
00188
|
|
<a name="l00194"></a><a class="code" href="classStkFrames.html#a2">00194</a> StkFloat& <a class="code" href="classStkFrames.html#a2">operator[]</a>( size_t n ) { <span class="keywordflow">return</span> data_[n]; };
|
|
00195
|
|
00197
|
|
<a name="l00201"></a><a class="code" href="classStkFrames.html#a3">00201</a> StkFloat <a class="code" href="classStkFrames.html#a2">operator[]</a>( size_t n )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_[n]; };
|
|
00202
|
|
<a name="l00204"></a><a class="code" href="classStkFrames.html#a4">00204</a> size_t <a class="code" href="classStkFrames.html#a4">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> size_; };
|
|
00205
|
|
00207
|
|
00211 <span class="keywordtype">void</span> <a class="code" href="classStkFrames.html#a5">resize</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nChannels = 1, StkFloat value = 0.0 );
|
|
00212
|
|
<a name="l00214"></a><a class="code" href="classStkFrames.html#a6">00214</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classStkFrames.html#a6">channels</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> nChannels_; };
|
|
00215
|
|
<a name="l00217"></a><a class="code" href="classStkFrames.html#a7">00217</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classStkFrames.html#a7">frames</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> nFrames_; };
|
|
00218
|
|
<a name="l00220"></a><a class="code" href="classStkFrames.html#a8">00220</a> <span class="keywordtype">bool</span> <a class="code" href="classStkFrames.html#a8">interleaved</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> interleaved_; };
|
|
00221
|
|
<a name="l00223"></a><a class="code" href="classStkFrames.html#a9">00223</a> <span class="keywordtype">void</span> <a class="code" href="classStkFrames.html#a9">setInterleaved</a>( <span class="keywordtype">bool</span> isInterleaved ) { interleaved_ = isInterleaved; };
|
|
00224
|
|
00225 <span class="keyword">private</span>:
|
|
00226 std::valarray<StkFloat> data_;
|
|
00227 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrames_;
|
|
00228 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nChannels_;
|
|
00229 size_t size_;
|
|
00230 <span class="keywordtype">bool</span> interleaved_;
|
|
00231
|
|
00232 };
|
|
00233
|
|
00234
|
|
00235 <span class="comment">// Here are a few other useful typedefs.</span>
|
|
00236 <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">short</span> SINT16;
|
|
00237 <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">int</span> SINT32;
|
|
00238 <span class="keyword">typedef</span> <span class="keywordtype">float</span> FLOAT32;
|
|
00239 <span class="keyword">typedef</span> <span class="keywordtype">double</span> FLOAT64;
|
|
00240
|
|
00241 <span class="comment">// The default sampling rate.</span>
|
|
00242 <span class="keyword">const</span> StkFloat SRATE = 44100.0;
|
|
00243
|
|
00244 <span class="comment">// The default real-time audio input and output buffer size. If</span>
|
|
00245 <span class="comment">// clicks are occuring in the input and/or output sound stream, a</span>
|
|
00246 <span class="comment">// larger buffer size may help. Larger buffer sizes, however, produce</span>
|
|
00247 <span class="comment">// more latency.</span>
|
|
00248 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> RT_BUFFER_SIZE = 512;
|
|
00249
|
|
00250 <span class="comment">// The default rawwave path value is set with the preprocessor</span>
|
|
00251 <span class="comment">// definition RAWWAVE_PATH. This can be specified as an argument to</span>
|
|
00252 <span class="comment">// the configure script, in an integrated development environment, or</span>
|
|
00253 <span class="comment">// below. The global STK rawwave path variable can be dynamically set</span>
|
|
00254 <span class="comment">// with the Stk::setRawwavePath() function. This value is</span>
|
|
00255 <span class="comment">// concatenated to the beginning of all references to rawwave files in</span>
|
|
00256 <span class="comment">// the various STK core classes (ex. Clarinet.cpp). If you wish to</span>
|
|
00257 <span class="comment">// move the rawwaves directory to a different location in your file</span>
|
|
00258 <span class="comment">// system, you will need to set this path definition appropriately.</span>
|
|
00259 <span class="preprocessor">#if !defined(RAWWAVE_PATH)</span>
|
|
00260 <span class="preprocessor"></span><span class="preprocessor"> #define RAWWAVE_PATH "../../rawwaves/"</span>
|
|
00261 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
00262 <span class="preprocessor"></span>
|
|
00263 <span class="keyword">const</span> StkFloat PI = 3.14159265359;
|
|
00264 <span class="keyword">const</span> StkFloat TWO_PI = 2 * PI;
|
|
00265 <span class="keyword">const</span> StkFloat ONE_OVER_128 = 0.0078125;
|
|
00266
|
|
00267 <span class="preprocessor">#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)</span>
|
|
00268 <span class="preprocessor"></span><span class="preprocessor"> #define __OS_WINDOWS__</span>
|
|
00269 <span class="preprocessor"></span><span class="preprocessor"> #define __STK_REALTIME__</span>
|
|
00270 <span class="preprocessor"></span><span class="preprocessor">#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__LINUX_JACK__)</span>
|
|
00271 <span class="preprocessor"></span><span class="preprocessor"> #define __OS_LINUX__</span>
|
|
00272 <span class="preprocessor"></span><span class="preprocessor"> #define __STK_REALTIME__</span>
|
|
00273 <span class="preprocessor"></span><span class="preprocessor">#elif defined(__IRIX_AL__)</span>
|
|
00274 <span class="preprocessor"></span><span class="preprocessor"> #define __OS_IRIX__</span>
|
|
00275 <span class="preprocessor"></span><span class="preprocessor"> #define __STK_REALTIME__</span>
|
|
00276 <span class="preprocessor"></span><span class="preprocessor">#elif defined(__MACOSX_CORE__)</span>
|
|
00277 <span class="preprocessor"></span><span class="preprocessor"> #define __OS_MACOSX__</span>
|
|
00278 <span class="preprocessor"></span><span class="preprocessor"> #define __STK_REALTIME__</span>
|
|
00279 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
00280 <span class="preprocessor"></span>
|
|
00281 <span class="comment">//#define _STK_DEBUG_</span>
|
|
00282
|
|
00283 <span class="preprocessor">#endif</span>
|
|
</pre></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-2004 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|