Release 4.0.12 tarball
[rtaudio.git] / doc / html / duplex.html
index 6e85d6918a3484ecb96d67cfcf6efcc1c0cd7d56..d397a8d3486780895265768daab98caaf5ec1cb3 100644 (file)
@@ -8,83 +8,84 @@
 <CENTER>
 <a class="qindex" href="index.html">Home</a> &nbsp; <a class="qindex" href="annotated.html">Class/Enum List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </CENTER>
 <HR>
-<!-- Generated by Doxygen 1.6.2 -->
+<!-- Generated by Doxygen 1.8.2 -->
+</div><!-- top -->
+<div class="header">
+  <div class="headertitle">
+<div class="title">Duplex Mode </div>  </div>
+</div><!--header-->
 <div class="contents">
-
-
-<h1><a class="anchor" id="duplex">Duplex Mode </a></h1><p>Finally, it is easy to use <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> for simultaneous audio input/output, or duplex operation. In this example, we simply pass the input data back to the output.</p>
-<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;<a class="code" href="RtAudio_8h.html">RtAudio.h</a>&quot;</span>
-<span class="preprocessor">#include &lt;iostream&gt;</span>
-<span class="preprocessor">#include &lt;cstdlib&gt;</span>
-<span class="preprocessor">#include &lt;cstring&gt;</span>
-
-<span class="comment">// Pass-through function.</span>
-<span class="keywordtype">int</span> inout( <span class="keywordtype">void</span> *outputBuffer, <span class="keywordtype">void</span> *inputBuffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nBufferFrames,
-           <span class="keywordtype">double</span> streamTime, <a class="code" href="RtAudio_8h.html#a80e306d363583da3b0a1b65d9b57c806" title="RtAudio stream status (over- or underflow) flags.">RtAudioStreamStatus</a> status, <span class="keywordtype">void</span> *data )
-{
-  <span class="comment">// Since the number of input and output channels is equal, we can do</span>
-  <span class="comment">// a simple buffer copy operation here.</span>
-  <span class="keywordflow">if</span> ( status ) std::cout &lt;&lt; <span class="stringliteral">&quot;Stream over/underflow detected.&quot;</span> &lt;&lt; std::endl;
-
-  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *bytes = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *) data;
-  memcpy( outputBuffer, inputBuffer, *bytes );
-  <span class="keywordflow">return</span> 0;
-}
-
-<span class="keywordtype">int</span> main()
-{
- <a class="code" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> adac;
-  <span class="keywordflow">if</span> ( adac.<a class="code" href="classRtAudio.html#a747ce2d73803641bbb66d6e78092aa1a" title="A public function that queries for the number of audio devices available.">getDeviceCount</a>() &lt; 1 ) {
-    std::cout &lt;&lt; <span class="stringliteral">&quot;\nNo audio devices found!\n&quot;</span>;
-    exit( 0 );
-  }
-
-  <span class="comment">// Set the same number of channels for both input and output.</span>
-  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bufferBytes, bufferFrames = 512;
-  <a class="code" href="structRtAudio_1_1StreamParameters.html" title="The structure for specifying input or ouput stream parameters.">RtAudio::StreamParameters</a> iParams, oParams;
-  iParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#ab3c72bcf3ef12149ae9a4fb597cc5489">deviceId</a> = 0; <span class="comment">// first available device</span>
-  iParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#a88a10091b6e284e21235cc6f25332ebd">nChannels</a> = 2;
-  oParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#ab3c72bcf3ef12149ae9a4fb597cc5489">deviceId</a> = 0; <span class="comment">// first available device</span>
-  oParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#a88a10091b6e284e21235cc6f25332ebd">nChannels</a> = 2;
-
-  <span class="keywordflow">try</span> {
-    adac.<a class="code" href="classRtAudio.html#afacc99740fa4c5606fb35467cdea6da8" title="A public function for opening a stream with the specified parameters.">openStream</a>( &amp;oParams, &amp;iParams, RTAUDIO_SINT32, 44100, &amp;bufferFrames, &amp;inout, (<span class="keywordtype">void</span> *)&amp;bufferBytes );
-  }
-  <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html" title="Exception handling class for RtAudio &amp;amp; RtMidi.">RtError</a>&amp; e ) {
-    e.<a class="code" href="classRtError.html#ada41f7472122f45bc5b4677f066e0943" title="Prints thrown error message to stderr.">printMessage</a>();
-    exit( 0 );
-  }
-
-  bufferBytes = bufferFrames * 2 * 4;
-
-  <span class="keywordflow">try</span> {
-    adac.<a class="code" href="classRtAudio.html#aec017a89629ccef66a90b60be22a2f80" title="A function that starts a stream.">startStream</a>();
-
-    <span class="keywordtype">char</span> input;
-    std::cout &lt;&lt; <span class="stringliteral">&quot;\nRunning ... press &lt;enter&gt; to quit.\n&quot;</span>;
-    std::cin.get(input);
-
-    <span class="comment">// Stop the stream.</span>
-    adac.<a class="code" href="classRtAudio.html#af4c241ff86936ecc8108f0d9dfe3efdd" title="Stop a stream, allowing any samples remaining in the output queue to be played.">stopStream</a>();
-  }
-  <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html" title="Exception handling class for RtAudio &amp;amp; RtMidi.">RtError</a>&amp; e ) {
-    e.<a class="code" href="classRtError.html#ada41f7472122f45bc5b4677f066e0943" title="Prints thrown error message to stderr.">printMessage</a>();
-    <span class="keywordflow">goto</span> cleanup;
-  }
-
- cleanup:
-  <span class="keywordflow">if</span> ( adac.<a class="code" href="classRtAudio.html#a3863e45ff81dbe97176de0ee7545917f" title="Returns true if a stream is open and false if not.">isStreamOpen</a>() ) adac.<a class="code" href="classRtAudio.html#a90d599002ad32cf250a4cb866f2cc93a" title="A function that closes a stream and frees any associated stream memory.">closeStream</a>();
-
-  <span class="keywordflow">return</span> 0;
-}
-</pre></div><p>In this example, audio recorded by the stream input will be played out during the next round of audio processing.</p>
+<div class="textblock"><p>Finally, it is easy to use <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> for simultaneous audio input/output, or duplex operation. In this example, we simply pass the input data back to the output.</p>
+<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="RtAudio_8h.html">RtAudio.h</a>&quot;</span></div>
+<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
+<div class="line"><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
+<div class="line"><span class="preprocessor">#include &lt;cstring&gt;</span></div>
+<div class="line"></div>
+<div class="line"><span class="comment">// Pass-through function.</span></div>
+<div class="line"><span class="keywordtype">int</span> inout( <span class="keywordtype">void</span> *outputBuffer, <span class="keywordtype">void</span> *inputBuffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nBufferFrames,</div>
+<div class="line">           <span class="keywordtype">double</span> streamTime, <a class="code" href="RtAudio_8h.html#a80e306d363583da3b0a1b65d9b57c806" title="RtAudio stream status (over- or underflow) flags.">RtAudioStreamStatus</a> status, <span class="keywordtype">void</span> *data )</div>
+<div class="line">{</div>
+<div class="line">  <span class="comment">// Since the number of input and output channels is equal, we can do</span></div>
+<div class="line">  <span class="comment">// a simple buffer copy operation here.</span></div>
+<div class="line">  <span class="keywordflow">if</span> ( status ) std::cout &lt;&lt; <span class="stringliteral">&quot;Stream over/underflow detected.&quot;</span> &lt;&lt; std::endl;</div>
+<div class="line"></div>
+<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *bytes = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *) data;</div>
+<div class="line">  memcpy( outputBuffer, inputBuffer, *bytes );</div>
+<div class="line">  <span class="keywordflow">return</span> 0;</div>
+<div class="line">}</div>
+<div class="line"></div>
+<div class="line"><span class="keywordtype">int</span> main()</div>
+<div class="line">{</div>
+<div class="line"> <a class="code" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> adac;</div>
+<div class="line">  <span class="keywordflow">if</span> ( adac.<a class="code" href="classRtAudio.html#a747ce2d73803641bbb66d6e78092aa1a" title="A public function that queries for the number of audio devices available.">getDeviceCount</a>() &lt; 1 ) {</div>
+<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;\nNo audio devices found!\n&quot;</span>;</div>
+<div class="line">    exit( 0 );</div>
+<div class="line">  }</div>
+<div class="line"></div>
+<div class="line">  <span class="comment">// Set the same number of channels for both input and output.</span></div>
+<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bufferBytes, bufferFrames = 512;</div>
+<div class="line">  <a class="code" href="structRtAudio_1_1StreamParameters.html" title="The structure for specifying input or ouput stream parameters.">RtAudio::StreamParameters</a> iParams, oParams;</div>
+<div class="line">  iParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#ab3c72bcf3ef12149ae9a4fb597cc5489">deviceId</a> = 0; <span class="comment">// first available device</span></div>
+<div class="line">  iParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#a88a10091b6e284e21235cc6f25332ebd">nChannels</a> = 2;</div>
+<div class="line">  oParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#ab3c72bcf3ef12149ae9a4fb597cc5489">deviceId</a> = 0; <span class="comment">// first available device</span></div>
+<div class="line">  oParams.<a class="code" href="structRtAudio_1_1StreamParameters.html#a88a10091b6e284e21235cc6f25332ebd">nChannels</a> = 2;</div>
+<div class="line"></div>
+<div class="line">  <span class="keywordflow">try</span> {</div>
+<div class="line">    adac.<a class="code" href="classRtAudio.html#a6907539d2527775df778ebce32ef1e3b" title="A public function for opening a stream with the specified parameters.">openStream</a>( &amp;oParams, &amp;iParams, RTAUDIO_SINT32, 44100, &amp;bufferFrames, &amp;inout, (<span class="keywordtype">void</span> *)&amp;bufferBytes );</div>
+<div class="line">  }</div>
+<div class="line">  <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html" title="Exception handling class for RtAudio &amp; RtMidi.">RtError</a>&amp; e ) {</div>
+<div class="line">    e.<a class="code" href="classRtError.html#a251dcdac396c998c91706dd2dd3b8bfc" title="Prints thrown error message to stderr.">printMessage</a>();</div>
+<div class="line">    exit( 0 );</div>
+<div class="line">  }</div>
+<div class="line"></div>
+<div class="line">  bufferBytes = bufferFrames * 2 * 4;</div>
+<div class="line"></div>
+<div class="line">  <span class="keywordflow">try</span> {</div>
+<div class="line">    adac.<a class="code" href="classRtAudio.html#aec017a89629ccef66a90b60be22a2f80" title="A function that starts a stream.">startStream</a>();</div>
+<div class="line"></div>
+<div class="line">    <span class="keywordtype">char</span> input;</div>
+<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;\nRunning ... press &lt;enter&gt; to quit.\n&quot;</span>;</div>
+<div class="line">    std::cin.get(input);</div>
+<div class="line"></div>
+<div class="line">    <span class="comment">// Stop the stream.</span></div>
+<div class="line">    adac.<a class="code" href="classRtAudio.html#af4c241ff86936ecc8108f0d9dfe3efdd" title="Stop a stream, allowing any samples remaining in the output queue to be played.">stopStream</a>();</div>
+<div class="line">  }</div>
+<div class="line">  <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html" title="Exception handling class for RtAudio &amp; RtMidi.">RtError</a>&amp; e ) {</div>
+<div class="line">    e.<a class="code" href="classRtError.html#a251dcdac396c998c91706dd2dd3b8bfc" title="Prints thrown error message to stderr.">printMessage</a>();</div>
+<div class="line">    <span class="keywordflow">goto</span> cleanup;</div>
+<div class="line">  }</div>
+<div class="line"></div>
+<div class="line"> cleanup:</div>
+<div class="line">  <span class="keywordflow">if</span> ( adac.<a class="code" href="classRtAudio.html#a3863e45ff81dbe97176de0ee7545917f" title="Returns true if a stream is open and false if not.">isStreamOpen</a>() ) adac.<a class="code" href="classRtAudio.html#a90d599002ad32cf250a4cb866f2cc93a" title="A function that closes a stream and frees any associated stream memory.">closeStream</a>();</div>
+<div class="line"></div>
+<div class="line">  <span class="keywordflow">return</span> 0;</div>
+<div class="line">}</div>
+</div><!-- fragment --><p>In this example, audio recorded by the stream input will be played out during the next round of audio processing.</p>
 <p>Note that a duplex stream can make use of two different devices (except when using the Linux Jack and Windows ASIO APIs). However, this may cause timing problems due to possible device clock variations, unless a common external "sync" is provided. </p>
-</div>
+</div></div><!-- contents -->
 <HR>
-
 <table><tr><td><img src="../images/mcgill.gif" width=165></td>
-  <td>&copy;2001-2010 Gary P. Scavone, McGill University. All Rights Reserved.<br>Maintained by <a href="http://www.music.mcgill.ca/~gary/">Gary P. Scavone</a>.</td></tr>
+  <td>&copy;2001-2013 Gary P. Scavone, McGill University. All Rights Reserved.<br>Maintained by <a href="http://www.music.mcgill.ca/~gary/">Gary P. Scavone</a>.</td></tr>
 </table>
-
 </BODY>
 </HTML>