mirror of
https://github.com/thestk/stk
synced 2026-01-12 12:31:53 +00:00
80 lines
5.6 KiB
HTML
80 lines
5.6 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><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 pointer to an array of audio data 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="classWvOut.html">WvOut</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><span class="comment">// foursine.cpp STK tutorial program</span>
|
|
|
|
<span class="preprocessor">#include "WaveLoop.h"</span>
|
|
<span class="preprocessor">#include "WvOut.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, j;
|
|
<a class="code" href="classWvOut.html">WvOut</a> *output = 0;
|
|
<a class="code" href="classWaveLoop.html">WaveLoop</a> *inputs[4];
|
|
<span class="keywordflow">for</span> ( i=0; i<4; i++ ) inputs[i] = 0;
|
|
|
|
<span class="comment">// Define and load the sine waves</span>
|
|
<span class="keywordflow">try</span> {
|
|
<span class="keywordflow">for</span> ( i=0; i<4; i++ ) {
|
|
inputs[i] = <span class="keyword">new</span> <a class="code" href="classWaveLoop.html">WaveLoop</a>( <span class="stringliteral">"rawwaves/sinewave.raw"</span>, <span class="keyword">true</span> );
|
|
inputs[i]-><a class="code" href="classWaveLoop.html#a2">setFrequency</a>( 220.0 * (i+1) );
|
|
}
|
|
}
|
|
<span class="keywordflow">catch</span> (<a class="code" href="classStkError.html">StkError</a> &) {
|
|
<span class="keywordflow">goto</span> cleanup;
|
|
}
|
|
|
|
<span class="comment">// Define and open a 16-bit, four-channel AIFF formatted output file</span>
|
|
<span class="keywordflow">try</span> {
|
|
output = <span class="keyword">new</span> <a class="code" href="classWvOut.html">WvOut</a>( <span class="stringliteral">"foursine.aif"</span>, 4, WvOut::WVOUT_AIF, Stk::STK_SINT16 );
|
|
}
|
|
<span class="keywordflow">catch</span> (<a class="code" href="classStkError.html">StkError</a> &) {
|
|
<span class="keywordflow">goto</span> cleanup;
|
|
}
|
|
|
|
<span class="comment">// Write two seconds of four sines to the output file</span>
|
|
StkFloat frame[4];
|
|
<span class="keywordflow">for</span> ( j=0; j<88200; j++ ) {
|
|
<span class="keywordflow">for</span> ( i=0; i<4; i++ )
|
|
frame[i] = inputs[i]-><a class="code" href="classWvIn.html#a16">tick</a>();
|
|
|
|
output-><a class="code" href="classWvOut.html#a12">tickFrame</a>( frame );
|
|
}
|
|
|
|
<span class="comment">// Now write the first sine to all four channels for two seconds</span>
|
|
<span class="keywordflow">for</span> ( j=0; j<88200; j++ ) {
|
|
output-><a class="code" href="classWvOut.html#a9">tick</a>( inputs[0]->tick() );
|
|
}
|
|
|
|
cleanup:
|
|
<span class="keywordflow">for</span> ( i=0; i<4; i++ ) <span class="keyword">delete</span> inputs[i];
|
|
<span class="keyword">delete</span> output;
|
|
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div><p>
|
|
[<a href="polyvoices.html">Next tutorial</a>] [<a href="tutorial.html">Main tutorial page</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>©1995-2004 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|