File: fundamentals.html

package info (click to toggle)
stk 4.4.4-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 24,856 kB
  • sloc: cpp: 33,976; tcl: 2,375; sh: 2,319; ansic: 163; perl: 114; makefile: 37
file content (74 lines) | stat: -rw-r--r-- 11,281 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<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"> &nbsp; <img src="ccrma.gif"> &nbsp; <img src="mcgill.gif"><P>
<a class="qindex" href="index.html">Home</a> &nbsp; <a class="qindex" href="information.html">Information</a> &nbsp; <a class="qindex" href="classes.html">Classes</a> &nbsp; <a class="qindex" href="download.html">Download</a> &nbsp; <a class="qindex" href="usage.html">Usage</a> &nbsp; <a class="qindex" href="maillist.html">Mail List</a> &nbsp; <a class="qindex" href="system.html">Requirements</a> &nbsp; <a class="qindex" href="links.html">Links</a> &nbsp; <a class="qindex" href="faq.html">FAQ</a> &nbsp; <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
<HR>
<!-- Generated by Doxygen 1.6.2 -->
<div class="contents">


<h1><a class="anchor" id="fundamentals">STK Fundamentals </a></h1><p>The Synthesis ToolKit is implemented in the C++ programming language. STK does not attempt to provide a new programming environment or paradigm but rather provides a set of objects that can be used within a normal C++ programming framework. Therefore, it is expected that users of STK will have some familiarity with C/C++ programming concepts. That said, the STK classes do have some particular idiosyncrasies that we will mention here. Starting with STK version 4.4, all STK classes except <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a>, <a class="el" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>, and <a class="el" href="classRtError.html" title="Exception handling class for RtAudio &amp; RtMidi.">RtError</a> are defined within the stk namespace.</p>
<h2><a class="anchor" id="Signal">
Computations:</a></h2>
<p>Audio and control signals throughout STK use a floating-point data type, <code>StkFloat</code>, the exact precision of which can be controlled via a typedef statement in <a class="el" href="Stk_8h_source.html">Stk.h</a>. By default, an StkFloat is a double-precision floating-point value. Thus, the ToolKit can use any normalization scheme desired. The base instruments and algorithms are implemented with a general audio sample dynamic maximum of +/-1.0.</p>
<p>In general, the computation and/or passing of values is performed on a "single-sample" basis. For example, the <a class="el" href="classstk_1_1Noise.html" title="STK noise generator.">stk::Noise</a> class outputs random floating-point numbers in the range +/-1.0. The computation of such values occurs in the <a class="el" href="classstk_1_1Noise.html#a8ac40f69475eb744e803d557e8438a6d" title="Compute and return one output sample.">stk::Noise::tick()</a> function. The following program will generate 20 random floating-point (<code>StkFloat</code>) values in the range -1.0 to +1.0:</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;Noise.h&quot;</span>
<span class="keyword">using namespace </span>stk;

<span class="keywordtype">int</span> main()
{
  StkFloat output;
  Noise noise;

  <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;20; i++ ) {
    output = noise.tick();
    std::cout &lt;&lt; <span class="stringliteral">&quot;i = &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; : output = &quot;</span> &lt;&lt; output &lt;&lt; std::endl;
  }

  <span class="keywordflow">return</span> 0;
}
</pre></div><p>Nearly all STK classes implement <code>tick()</code> functions that take and/or return sample values. Within the <code>tick()</code> function, the fundamental sample calculations are performed for a given class. Most STK classes consume/generate a single sample per operation and their <code>tick()</code> method takes/returns each sample "by value". In addition, every class implementing a <code>tick()</code> function also provides one or more overloaded <code>tick()</code> functions that can be used for vectorized computations, as shown in the next example.</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;Noise.h&quot;</span>
<span class="keyword">using namespace </span>stk;

<span class="keywordtype">int</span> main()
{
  StkFrames output(20, 1);   <span class="comment">// initialize StkFrames to 20 frames and 1 channel (default: interleaved)</span>
  Noise noise;

  noise.tick( output );
  <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;output.size(); i++ ) {
    std::cout &lt;&lt; <span class="stringliteral">&quot;i = &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; : output = &quot;</span> &lt;&lt; output[i] &lt;&lt; std::endl;
  }

  <span class="keywordflow">return</span> 0;
}
</pre></div><p>In this way, it might be possible to achieve improved processing efficiency using vectorized computations. The StkFrames class is a relatively new addition to the ToolKit to provide a general "mechanism" for handling and passing vectorized, multi-channel audio data. The StkFrames "type" provides functions to set and/or determine the number of audio channels and sample frames it holds. Further, the StkFrames class provides data interpolation and subscripting functionality by frame/channel values.</p>
<h2><a class="anchor" id="STK">
Inheritance:</a></h2>
<p>Nearly all STK classes inherit from the Stk abstract base class, which provides common functionality related to error reporting, sample rate control, and byte swapping. Several other base classes exist that roughly group many of the classes according to function as follows:</p>
<ul>
<li><a class="el" href="classstk_1_1Generator.html" title="STK abstract unit generator parent class.">stk::Generator</a>: source signal unit generator classes [<a class="el" href="classstk_1_1Envelope.html" title="STK linear line envelope class.">stk::Envelope</a>, <a class="el" href="classstk_1_1ADSR.html" title="STK ADSR envelope class.">stk::ADSR</a>, <a class="el" href="classstk_1_1Asymp.html" title="STK asymptotic curve envelope class.">stk::Asymp</a>, <a class="el" href="classstk_1_1Noise.html" title="STK noise generator.">stk::Noise</a>, stk::SubNoise, <a class="el" href="classstk_1_1Modulate.html" title="STK periodic/random modulator.">stk::Modulate</a>, <a class="el" href="classstk_1_1SingWave.html" title="STK &quot;singing&quot; looped soundfile class.">stk::SingWave</a>, <a class="el" href="classstk_1_1SineWave.html" title="STK sinusoid oscillator class.">stk::SineWave</a>, <a class="el" href="classstk_1_1Blit.html" title="STK band-limited impulse train class.">stk::Blit</a>, <a class="el" href="classstk_1_1BlitSaw.html" title="STK band-limited sawtooth wave class.">stk::BlitSaw</a>, <a class="el" href="classstk_1_1BlitSquare.html" title="STK band-limited square wave class.">stk::BlitSquare</a>, <a class="el" href="classstk_1_1Granulate.html" title="STK granular synthesis class.">stk::Granulate</a>]</li>
<li><a class="el" href="classstk_1_1Filter.html" title="STK abstract filter class.">stk::Filter</a>: digital filtering classes [<a class="el" href="classstk_1_1OneZero.html" title="STK one-zero filter class.">stk::OneZero</a>, <a class="el" href="classstk_1_1OnePole.html" title="STK one-pole filter class.">stk::OnePole</a>, <a class="el" href="classstk_1_1PoleZero.html" title="STK one-pole, one-zero filter class.">stk::PoleZero</a>, <a class="el" href="classstk_1_1TwoZero.html" title="STK two-zero filter class.">stk::TwoZero</a>, <a class="el" href="classstk_1_1TwoPole.html" title="STK two-pole filter class.">stk::TwoPole</a>, <a class="el" href="classstk_1_1BiQuad.html" title="STK biquad (two-pole, two-zero) filter class.">stk::BiQuad</a>, <a class="el" href="classstk_1_1FormSwep.html" title="STK sweepable formant filter class.">stk::FormSwep</a>, <a class="el" href="classstk_1_1Delay.html" title="STK non-interpolating delay line class.">stk::Delay</a>, <a class="el" href="classstk_1_1DelayL.html" title="STK linear interpolating delay line class.">stk::DelayL</a>, <a class="el" href="classstk_1_1DelayA.html" title="STK allpass interpolating delay line class.">stk::DelayA</a>, <a class="el" href="classstk_1_1TapDelay.html" title="STK non-interpolating tapped delay line class.">stk::TapDelay</a>]</li>
<li><a class="el" href="classstk_1_1Function.html" title="STK abstract function parent class.">stk::Function</a>: input to output function mappings [<a class="el" href="classstk_1_1BowTable.html" title="STK bowed string table class.">stk::BowTable</a>, <a class="el" href="classstk_1_1JetTable.html" title="STK jet table class.">stk::JetTable</a>, <a class="el" href="classstk_1_1ReedTable.html" title="STK reed table class.">stk::ReedTable</a>]</li>
<li><a class="el" href="classstk_1_1Instrmnt.html" title="STK instrument abstract base class.">stk::Instrmnt</a>: sound synthesis algorithms, including physical, FM, modal, and particle models</li>
<li><a class="el" href="classstk_1_1Effect.html" title="STK abstract effects parent class.">stk::Effect</a>: sound processing effect classes [<a class="el" href="classstk_1_1Echo.html" title="STK echo effect class.">stk::Echo</a>, <a class="el" href="classstk_1_1Chorus.html" title="STK chorus effect class.">stk::Chorus</a>, <a class="el" href="classstk_1_1PitShift.html" title="STK simple pitch shifter effect class.">stk::PitShift</a>, <a class="el" href="classstk_1_1PRCRev.html" title="Perry&#39;s simple reverberator class.">stk::PRCRev</a>, <a class="el" href="classstk_1_1JCRev.html" title="John Chowning&#39;s reverberator class.">stk::JCRev</a>, <a class="el" href="classstk_1_1NRev.html" title="CCRMA&#39;s NRev reverberator class.">stk::NRev</a>]</li>
<li><a class="el" href="classstk_1_1WvOut.html" title="STK audio output abstract base class.">stk::WvOut</a>: audio data output classes [<a class="el" href="classstk_1_1FileWvOut.html" title="STK audio file output class.">stk::FileWvOut</a>, <a class="el" href="classstk_1_1RtWvOut.html" title="STK realtime audio (blocking) output class.">stk::RtWvOut</a>, <a class="el" href="classstk_1_1InetWvOut.html" title="STK internet streaming output class.">stk::InetWvOut</a>]</li>
<li><a class="el" href="classstk_1_1WvIn.html" title="STK audio input abstract base class.">stk::WvIn</a>: audio data input classes [<a class="el" href="classstk_1_1FileWvIn.html" title="STK audio file input class.">stk::FileWvIn</a>, <a class="el" href="classstk_1_1FileLoop.html" title="STK file looping / oscillator class.">stk::FileLoop</a>, <a class="el" href="classstk_1_1RtWvIn.html" title="STK realtime audio (blocking) input class.">stk::RtWvIn</a>, <a class="el" href="classstk_1_1InetWvIn.html" title="STK internet streaming input class.">stk::InetWvIn</a>]</li>
</ul>
<p>[<a href="tutorial.html">Main tutorial page</a>] &nbsp; [<a href="hello.html">Next tutorial</a>] </p>
</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>&copy;1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>

</BODY>
</HTML>