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
|
<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.6.2 -->
<div class="contents">
<h1><a class="anchor" id="multichannel">Multi-Channel I/O </a></h1><p>The ToolKit <a class="el" href="classstk_1_1WvIn.html" title="STK audio input abstract base class.">stk::WvIn</a> and <a class="el" href="classstk_1_1WvOut.html" title="STK audio output abstract base class.">stk::WvOut</a> classes (and their subclasses) support multi-channel audio data input and output. Several other abstract base classes, such as <a class="el" href="classstk_1_1Instrmnt.html" title="STK instrument abstract base class.">stk::Instrmnt</a>, <a class="el" href="classstk_1_1Generator.html" title="STK abstract unit generator parent class.">stk::Generator</a>, and <a class="el" href="classstk_1_1Effect.html" title="STK abstract effects parent class.">stk::Effect</a>, also support multi-channel computations though not all of their subclasses produce or take multi-channel data. A set of interleaved audio samples representing a single time "slice" is referred to as a <em>sample frame</em>. At a sample rate of 44.1 kHz, a four-channel audio stream will have 44100 sample frames per second and a total of 176400 individual samples per second.</p>
<p>Most STK classes process single-sample data streams via their <code>tick()</code> function. For classes supporting multi-channel data, one must distinguish the <code>tick()</code> functions taking or producing single <code>StkFloat</code> arguments from those taking <a class="el" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">stk::StkFrames</a>& arguments. If a single-sample version of the <code>tick()</code> function is called for these classes, a full sample frame is computed but only a single value is either input and/or output. For example, if the single-sample <code>tick()</code> function is called for subclasses of WvOut, the sample argument is written to all channels in the one computed frame. For classes returning values, an optional <code>channel</code> argument specifies which channel value is returned from the computed frame (the default is always channel 0). To input and/or output multichannel data to these classes, the overloaded <code>tick()</code> functions taking StkFrames reference arguments should be used.</p>
<p>Multi-channel support for realtime audio input and output is dependent on the audio device(s) available on your system.</p>
<p>The following example demonstrates the use of the <a class="el" href="classstk_1_1FileWvOut.html" title="STK audio file output class.">stk::FileWvOut</a> class for creating a four channel, 16-bit AIFF formatted audio file. We will use four sinewaves of different frequencies for the first two seconds and then a single sinewave for the last two seconds.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// foursine.cpp STK tutorial program</span>
<span class="preprocessor">#include "SineWave.h"</span>
<span class="preprocessor">#include "FileWvOut.h"</span>
<span class="preprocessor">#include <cstdlib></span>
<span class="keyword">using namespace </span>stk;
<span class="keywordtype">int</span> main()
{
<span class="comment">// Set the global sample rate before creating class instances.</span>
Stk::setSampleRate( 44100.0 );
<span class="keywordtype">int</span> i;
FileWvOut output;
SineWave inputs[4];
<span class="comment">// Set the sine wave frequencies.</span>
<span class="keywordflow">for</span> ( i=0; i<4; i++ )
inputs[i].setFrequency( 220.0 * (i+1) );
<span class="comment">// Define and open a 16-bit, four-channel AIFF formatted output file</span>
<span class="keywordflow">try</span> {
output.openFile( <span class="stringliteral">"foursine.aif"</span>, 4, FileWrite::FILE_AIF, Stk::STK_SINT16 );
}
<span class="keywordflow">catch</span> (StkError &) {
exit( 1 );
}
<span class="comment">// Write two seconds of four sines to the output file</span>
StkFrames frames( 88200, 4 );
<span class="keywordflow">for</span> ( i=0; i<4; i++ )
inputs[i].tick( frames, i );
output.tick( frames );
<span class="comment">// Now write the first sine to all four channels for two seconds</span>
<span class="keywordflow">for</span> ( i=0; i<88200; i++ ) {
output.tick( inputs[0].tick() );
}
<span class="keywordflow">return</span> 0;
}
</pre></div><p>[<a href="tutorial.html">Main tutorial page</a>] [<a href="polyvoices.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>©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>
</HTML>
|