Files
stk/doc/html/multichannel.html
2013-09-29 23:42:39 +02:00

66 lines
5.0 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"> &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.4.4 -->
<h1><a class="anchor" name="multichannel">Multi-Channel I/O</a></h1>The ToolKit <a class="el" href="classWvIn.html">WvIn</a> and <a class="el" href="classWvOut.html">WvOut</a> classes (and their subclasses) support multi-channel audio data input and output. 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>
Most STK classes process single-sample data streams via their <code>tick()</code> function. In order to distinguish single-sample and sample frame calculations, the <a class="el" href="classWvIn.html">WvIn</a> and <a class="el" href="classWvOut.html">WvOut</a> classes implement both <code>tick()</code> and <code>tickFrame()</code> functions. The <code>tickFrame()</code> functions take or return a reference to an <a class="el" href="classStkFrames.html">StkFrames</a> object representing one or more sample frames. For single-channel streams, the <code>tick()</code> and <code>tickFrame()</code> functions produce equivalent results. When <code>tick()</code> is called for a multi-channel stream, however, the function either returns a sample frame average (<a class="el" href="classWvIn.html">WvIn</a>) or writes a single sample argument to all channels (<a class="el" href="classWvOut.html">WvOut</a>).<p>
Multi-channel support for realtime audio input and output is dependent on the audio device(s) available on your system.<p>
The following example demonstrates the use of the <a class="el" href="classFileWvOut.html">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="keywordtype">int</span> main()
{
<span class="comment">// Set the global sample rate before creating class instances.</span>
<a class="code" href="classStk.html#e1">Stk::setSampleRate</a>( 44100.0 );
<span class="keywordtype">int</span> i;
<a class="code" href="classFileWvOut.html">FileWvOut</a> output;
<a class="code" href="classSineWave.html">SineWave</a> inputs[4];
<span class="comment">// Set the sine wave frequencies.</span>
<span class="keywordflow">for</span> ( i=0; i&lt;4; i++ )
inputs[i].<a class="code" href="classSineWave.html#a4">setFrequency</a>( 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.<a class="code" href="classFileWvOut.html#a3">openFile</a>( <span class="stringliteral">"foursine.aif"</span>, 4, <a class="code" href="classFileWrite.html#s3">FileWrite::FILE_AIF</a>, <a class="code" href="classStk.html#s1">Stk::STK_SINT16</a> );
}
<span class="keywordflow">catch</span> (<a class="code" href="classStkError.html">StkError</a> &amp;) {
exit( 1 );
}
<span class="comment">// Write two seconds of four sines to the output file</span>
<a class="code" href="classStkFrames.html">StkFrames</a> frames( 88200, 4 );
<span class="keywordflow">for</span> ( i=0; i&lt;4; i++ )
inputs[i].<a class="code" href="classGenerator.html#a3">tick</a>( frames, i );
output.<a class="code" href="classWvOut.html#a8">tickFrame</a>( 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&lt;88200; i++ ) {
output.<a class="code" href="classWvOut.html#a6">tick</a>( inputs[0].tick() );
}
<span class="keywordflow">return</span> 0;
}
</pre></div><p>
[<a href="tutorial.html">Main tutorial page</a>] &nbsp; [<a href="polyvoices.html">Next tutorial</a>] <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-2007 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>
</HTML>