mirror of
https://github.com/thestk/stk
synced 2026-01-15 05:51:52 +00:00
78 lines
3.3 KiB
HTML
78 lines
3.3 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"><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.2.8.1 -->
|
|
<a name="instrmnts"><h2>Using Instruments</h2></a>
|
|
The ToolKit comes with a wide variety of synthesis algorithms, all of which inherit from the Instrmnt class. In this example, we'll fire up an instance of the BeeThree FM synthesis class and show how it's frequency can be modified over time.
|
|
<p>
|
|
<div class="fragment"><pre><font class="comment">// beethree.cpp</font>
|
|
|
|
<font class="preprocessor">#include "BeeThree.h"</font>
|
|
<font class="preprocessor">#include "RtWvOut.h"</font>
|
|
|
|
<font class="keywordtype">int</font> main()<font class="keyword"></font>
|
|
<font class="keyword"></font>{
|
|
<font class="comment">// Set the global sample rate before creating class instances.</font>
|
|
Stk::setSampleRate( 44100.0 );
|
|
|
|
Instrmnt *instrument = 0;
|
|
RtWvOut *output = 0;
|
|
MY_FLOAT frequency, amplitude, scaler;
|
|
|
|
<font class="keywordflow">try</font> {
|
|
<font class="comment">// Define and load the sine wave file</font>
|
|
instrument = <font class="keyword">new</font> BeeThree();
|
|
|
|
<font class="comment">// Define and open the default realtime output device for one-channel playback</font>
|
|
output = <font class="keyword">new</font> RtWvOut(1);
|
|
}
|
|
<font class="keywordflow">catch</font> (StkError &) {
|
|
<font class="keywordflow">goto</font> cleanup;
|
|
}
|
|
|
|
scaler = 1.0;
|
|
frequency = 220.0;
|
|
amplitude = 0.5;
|
|
instrument->noteOn( frequency, amplitude );
|
|
|
|
<font class="comment">// Play the instrument for 80000 samples, changing the frequency every 2000 samples</font>
|
|
<font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; i<80000; i++) {
|
|
<font class="keywordflow">try</font> {
|
|
output->tick( instrument->tick() );
|
|
}
|
|
<font class="keywordflow">catch</font> (StkError &) {
|
|
<font class="keywordflow">goto</font> cleanup;
|
|
}
|
|
|
|
<font class="keywordflow">if</font> ( i % 2000 == 0 ) {
|
|
scaler += 0.025;
|
|
instrument->setFrequency( frequency * scaler );
|
|
}
|
|
}
|
|
|
|
cleanup:
|
|
<font class="keyword">delete</font> instrument;
|
|
<font class="keyword">delete</font> output;
|
|
|
|
<font class="keywordflow">return</font> 0;
|
|
}</pre></div>
|
|
<p>
|
|
By using an Instrmnt pointer above, it is possible to replace the BeeThree class with any other STK instrument class. It should be noted, however, that a few classes do not respond to the setFrequency() function (Shakers, Drummer).
|
|
<p>
|
|
<HR>
|
|
|
|
<table>
|
|
<tr><td><A HREF="http://www-ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
|
|
<tr><td>©1995-2002 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|