<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Async: AsyncAudioIO_demo.cpp</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>AsyncAudioIO_demo.cpp</h1><p>An example of how to use the <a class="el" href="classAsync_1_1AudioIO.html" title="A class for handling audio input/output to an audio device.">Async::AudioIO</a> class</p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <<a class="code" href="AsyncCppApplication_8h.html" title="The core class for writing asyncronous cpp applications.">AsyncCppApplication.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncAudioIO_8h.html" title="Contains a class for handling audio input/output to an audio device.">AsyncAudioIO.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncAudioSink_8h.html" title="This file contains the base class for an audio sink.">AsyncAudioSink.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncAudioSource_8h.html" title="This file contains the base class for an audio source.">AsyncAudioSource.h</a>></span> <span class="keyword">using namespace </span>std; <span class="keyword">using namespace </span>Async; <span class="keyword">class </span>MyClass : <span class="keyword">public</span> Async::<a name="_a0"></a><a class="code" href="classAsync_1_1AudioSink.html" title="The base class for an audio sink.">AudioSink</a>, <span class="keyword">public</span> Async::<a name="_a1"></a><a class="code" href="classAsync_1_1AudioSource.html" title="The base class for an audio source.">AudioSource</a> { <span class="keyword">public</span>: MyClass(<span class="keywordtype">void</span>) { <span class="comment">// Create a new audio IO object</span> audio_io = <span class="keyword">new</span> <a name="_a2"></a><a class="code" href="classAsync_1_1AudioIO.html" title="A class for handling audio input/output to an audio device.">AudioIO</a>(<span class="stringliteral">"/dev/dsp"</span>, 0); <span class="comment">// Open it for both reading and writing</span> audio_io->open(AudioIO::MODE_RDWR); <span class="comment">// Register this object as the audio source for sound output</span> audio_io->registerSource(<span class="keyword">this</span>); <span class="comment">// Register the audio device as the audio source for this object</span> <a name="a3"></a><a class="code" href="classAsync_1_1AudioSink.html#a355c87f3f763af97de92f5b9ac4b6327" title="Register an audio source to provide samples to this sink.">registerSource</a>(audio_io); } ~MyClass(<span class="keywordtype">void</span>) { <span class="keyword">delete</span> audio_io; } <span class="comment">// AudioSink functions</span> <span class="keywordtype">int</span> <a name="a4"></a><a class="code" href="classAsync_1_1AudioSink.html#a490aa6380d6b0069fc501f0d9f62e236" title="Write samples into this audio sink.">writeSamples</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> *samples, <span class="keywordtype">int</span> count) { <span class="comment">// Just loop incoming samples back to the audio device</span> <span class="keywordflow">return</span> <a name="a5"></a><a class="code" href="classAsync_1_1AudioSource.html#ad23a249abf0f8fd39d364301364740a6">sinkWriteSamples</a>(samples, count); } <span class="keywordtype">void</span> <a name="a6"></a><a class="code" href="classAsync_1_1AudioSink.html#adde14468248671c6c5c85eb47234e0fa" title="Tell the sink to flush the previously written samples.">flushSamples</a>(<span class="keywordtype">void</span>) { <a name="a7"></a><a class="code" href="classAsync_1_1AudioSource.html#a5837ec95fef7d668d1c5241cee54646c">sinkFlushSamples</a>(); } <span class="comment">// AudioSource functions</span> <span class="keywordtype">void</span> <a name="a8"></a><a class="code" href="classAsync_1_1AudioSource.html#ac187f89a6094ec066dab5b4fd3108754" title="Resume audio output to the sink.">resumeOutput</a>(<span class="keywordtype">void</span>) { <a name="a9"></a><a class="code" href="classAsync_1_1AudioSink.html#a4c16d7b78aade12abc0b57ec1db95f62" title="Tell the source that we are ready to accept more samples.">sourceResumeOutput</a>(); } <span class="keywordtype">void</span> <a name="a10"></a><a class="code" href="classAsync_1_1AudioSource.html#a563adf6411eddbd056abf206a12354b6" title="The registered sink has flushed all samples.">allSamplesFlushed</a>(<span class="keywordtype">void</span>) { <a name="a11"></a><a class="code" href="classAsync_1_1AudioSink.html#a2548622eb5c52ef80f3bd297f290be3c" title="Tell the source that all samples have been flushed.">sourceAllSamplesFlushed</a>(); } <span class="keyword">private</span>: <a class="code" href="classAsync_1_1AudioIO.html" title="A class for handling audio input/output to an audio device.">AudioIO</a> *audio_io; }; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <a name="_a12"></a><a class="code" href="classAsync_1_1CppApplication.html" title="An application class for writing non GUI applications.">CppApplication</a> app; MyClass my_class; app.<a name="a13"></a><a class="code" href="classAsync_1_1CppApplication.html#a9a921d33644bbb18767fb4d599f53bf4" title="Execute the application main loop.">exec</a>(); } </pre></div> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>