<!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.h Source File</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 class="current"><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 class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_d583404e3b046262ade615a4e7154c3b.html">include</a> </div> </div> <div class="contents"> <h1>AsyncAudioIO.h</h1><a href="AsyncAudioIO_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00036"></a>00036 <span class="preprocessor">#ifndef ASYNC_AUDIO_IO_INCLUDED</span> <a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define ASYNC_AUDIO_IO_INCLUDED</span> <a name="l00038"></a>00038 <span class="preprocessor"></span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="comment">/****************************************************************************</span> <a name="l00041"></a>00041 <span class="comment"> *</span> <a name="l00042"></a>00042 <span class="comment"> * System Includes</span> <a name="l00043"></a>00043 <span class="comment"> *</span> <a name="l00044"></a>00044 <span class="comment"> ****************************************************************************/</span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#include <cstdio></span> <a name="l00047"></a>00047 <span class="preprocessor">#include <string></span> <a name="l00048"></a>00048 <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="comment">/****************************************************************************</span> <a name="l00051"></a>00051 <span class="comment"> *</span> <a name="l00052"></a>00052 <span class="comment"> * Project Includes</span> <a name="l00053"></a>00053 <span class="comment"> *</span> <a name="l00054"></a>00054 <span class="comment"> ****************************************************************************/</span> <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="preprocessor">#include <<a class="code" href="AsyncFdWatch_8h.html" title="Contains a watch for file descriptors.">AsyncFdWatch.h</a>></span> <a name="l00057"></a>00057 <span class="preprocessor">#include <<a class="code" href="AsyncTimer_8h.html" title="Contains a single shot or periodic timer that emits a signal on timeout.">AsyncTimer.h</a>></span> <a name="l00058"></a>00058 <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> <a name="l00059"></a>00059 <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> <a name="l00060"></a>00060 <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="comment">/****************************************************************************</span> <a name="l00063"></a>00063 <span class="comment"> *</span> <a name="l00064"></a>00064 <span class="comment"> * Local Includes</span> <a name="l00065"></a>00065 <span class="comment"> *</span> <a name="l00066"></a>00066 <span class="comment"> ****************************************************************************/</span> <a name="l00067"></a>00067 <a name="l00068"></a>00068 <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="comment">/****************************************************************************</span> <a name="l00071"></a>00071 <span class="comment"> *</span> <a name="l00072"></a>00072 <span class="comment"> * Forward declarations</span> <a name="l00073"></a>00073 <span class="comment"> *</span> <a name="l00074"></a>00074 <span class="comment"> ****************************************************************************/</span> <a name="l00075"></a>00075 <a name="l00076"></a>00076 <a name="l00077"></a>00077 <a name="l00078"></a>00078 <span class="comment">/****************************************************************************</span> <a name="l00079"></a>00079 <span class="comment"> *</span> <a name="l00080"></a>00080 <span class="comment"> * Namespace</span> <a name="l00081"></a>00081 <span class="comment"> *</span> <a name="l00082"></a>00082 <span class="comment"> ****************************************************************************/</span> <a name="l00083"></a>00083 <a name="l00084"></a>00084 <span class="keyword">namespace </span>Async <a name="l00085"></a>00085 { <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="comment">/****************************************************************************</span> <a name="l00088"></a>00088 <span class="comment"> *</span> <a name="l00089"></a>00089 <span class="comment"> * Forward declarations of classes inside of the declared namespace</span> <a name="l00090"></a>00090 <span class="comment"> *</span> <a name="l00091"></a>00091 <span class="comment"> ****************************************************************************/</span> <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keyword">class </span>AudioDevice; <a name="l00094"></a>00094 <span class="keyword">class </span>AudioValve; <a name="l00095"></a>00095 <span class="keyword">class </span>AudioFifo; <a name="l00096"></a>00096 <a name="l00097"></a>00097 <a name="l00098"></a>00098 <span class="comment">/****************************************************************************</span> <a name="l00099"></a>00099 <span class="comment"> *</span> <a name="l00100"></a>00100 <span class="comment"> * Defines & typedefs</span> <a name="l00101"></a>00101 <span class="comment"> *</span> <a name="l00102"></a>00102 <span class="comment"> ****************************************************************************/</span> <a name="l00103"></a>00103 <a name="l00104"></a>00104 <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="comment">/****************************************************************************</span> <a name="l00107"></a>00107 <span class="comment"> *</span> <a name="l00108"></a>00108 <span class="comment"> * Exported Global Variables</span> <a name="l00109"></a>00109 <span class="comment"> *</span> <a name="l00110"></a>00110 <span class="comment"> ****************************************************************************/</span> <a name="l00111"></a>00111 <a name="l00112"></a>00112 <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="comment">/****************************************************************************</span> <a name="l00115"></a>00115 <span class="comment"> *</span> <a name="l00116"></a>00116 <span class="comment"> * Class definitions</span> <a name="l00117"></a>00117 <span class="comment"> *</span> <a name="l00118"></a>00118 <span class="comment"> ****************************************************************************/</span> <a name="l00119"></a>00119 <a name="l00134"></a><a class="code" href="classAsync_1_1AudioIO.html">00134</a> <span class="keyword">class </span><a class="code" href="classAsync_1_1AudioIO.html" title="A class for handling audio input/output to an audio device.">AudioIO</a> : <span class="keyword">public</span> Async::<a class="code" href="classAsync_1_1AudioSource.html" title="The base class for an audio source.">AudioSource</a>, <span class="keyword">public</span> Async::<a class="code" href="classAsync_1_1AudioSink.html" title="The base class for an audio sink.">AudioSink</a> <a name="l00135"></a>00135 { <a name="l00136"></a>00136 <span class="keyword">public</span>: <a name="l00140"></a><a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529">00140</a> <span class="keyword">typedef</span> <span class="keyword">enum</span> <a name="l00141"></a>00141 { <a name="l00142"></a><a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529ad980bc2123c355f49f3a3ad1ac1eb461">00142</a> <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529ad980bc2123c355f49f3a3ad1ac1eb461" title="No mode. The same as close.">MODE_NONE</a>, <a name="l00143"></a><a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529a454a78d4301a2b5fcdc9a14922948a2f">00143</a> <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529a454a78d4301a2b5fcdc9a14922948a2f" title="Read.">MODE_RD</a>, <a name="l00144"></a><a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529ae1fce72086232e1ef93d17a2e032a717">00144</a> <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529ae1fce72086232e1ef93d17a2e032a717" title="Write.">MODE_WR</a>, <a name="l00145"></a><a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529af9fe65824033e97c01daa096ec75db8e">00145</a> <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529af9fe65824033e97c01daa096ec75db8e" title="Both read and write.">MODE_RDWR</a> <a name="l00146"></a>00146 } <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529" title="The different modes to open a device in.">Mode</a>; <a name="l00147"></a>00147 <a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#ad9512b57c7509bdf7ba79279313a9013" title="Set the sample rate used when doing future opens.">setSampleRate</a>(<span class="keywordtype">int</span> rate); <a name="l00158"></a>00158 <a name="l00173"></a>00173 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#a978686e3209d019fddd8e4ea860a9748" title="Set the blocksize used when opening audio devices.">setBlocksize</a>(<span class="keywordtype">int</span> size); <a name="l00174"></a>00174 <a name="l00179"></a>00179 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#a6f9d615d8265e562a719f29ac8e503be" title="Find out what the blocksize is set to.">blocksize</a>(<span class="keywordtype">void</span>); <a name="l00180"></a>00180 <a name="l00194"></a>00194 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#a58f08f10ac4973c4aba902a50e64f181" title="Set the buffer count used when opening audio devices.">setBufferCount</a>(<span class="keywordtype">int</span> count); <a name="l00195"></a>00195 <a name="l00205"></a>00205 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#a728c8d8eb10d34b782c0b8fa52102efc" title="Set the number of channels used when doing future opens.">setChannels</a>(<span class="keywordtype">int</span> channels); <a name="l00206"></a>00206 <a name="l00212"></a>00212 <a class="code" href="classAsync_1_1AudioIO.html#a3635949f609f1c4a06ea4532c1882f75" title="Constructor.">AudioIO</a>(<span class="keyword">const</span> std::string& dev_name, <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#abef00b2a149a1465897fc27ddd5b3294" title="Return the audio channel used.">channel</a>); <a name="l00213"></a>00213 <a name="l00217"></a>00217 <a class="code" href="classAsync_1_1AudioIO.html#a85e119cde5b0a329ce2828788272c7af" title="Destructor.">~AudioIO</a>(<span class="keywordtype">void</span>); <a name="l00218"></a>00218 <a name="l00224"></a>00224 <span class="keywordtype">bool</span> <a class="code" href="classAsync_1_1AudioIO.html#a389e12cafc0ac9d7ba8c3836d7871051" title="Check if the audio device is capable of full duplex operation.">isFullDuplexCapable</a>(<span class="keywordtype">void</span>); <a name="l00225"></a>00225 <a name="l00232"></a>00232 <span class="keywordtype">bool</span> <a class="code" href="classAsync_1_1AudioIO.html#a60aa4a111385aeea9e3142a6670fe859" title="Open the audio device in the specified mode.">open</a>(<a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529" title="The different modes to open a device in.">Mode</a> <a class="code" href="classAsync_1_1AudioIO.html#a8ed7982564e5a558915cced8ae70d2bc" title="Find out how many samples there are in the output buffer.">mode</a>); <a name="l00233"></a>00233 <a name="l00237"></a>00237 <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#a9b489517c73a42cc1c5a781736be5702" title="Close the adio device.">close</a>(<span class="keywordtype">void</span>); <a name="l00238"></a>00238 <a name="l00249"></a>00249 <span class="comment">//int samplesToWrite(void) const;</span> <a name="l00250"></a>00250 <a name="l00251"></a>00251 <span class="comment">/*</span> <a name="l00252"></a>00252 <span class="comment"> * @brief Call this method to clear all samples in the buffer</span> <a name="l00253"></a>00253 <span class="comment"> *</span> <a name="l00254"></a>00254 <span class="comment"> * This method is used to clear all the samples that are in the buffer.</span> <a name="l00255"></a>00255 <span class="comment"> * That is, all samples in the buffer will be thrown away. Remaining</span> <a name="l00256"></a>00256 <span class="comment"> * samples that have already been written to the sound card will be</span> <a name="l00257"></a>00257 <span class="comment"> * flushed and when finished, the allSamplesFlushed signal is emitted.</span> <a name="l00258"></a>00258 <span class="comment"> */</span> <a name="l00259"></a>00259 <span class="comment">//void clearSamples(void);</span> <a name="l00260"></a>00260 <a name="l00261"></a>00261 <span class="comment">/*</span> <a name="l00262"></a>00262 <span class="comment"> * @brief Check if the audio device is busy flushing samples</span> <a name="l00263"></a>00263 <span class="comment"> * @return Returns \em true if flushing the buffer or else \em false</span> <a name="l00264"></a>00264 <span class="comment"> */</span> <a name="l00265"></a>00265 <span class="comment">//bool isFlushing(void) const { return is_flushing; }</span> <a name="l00266"></a>00266 <a name="l00267"></a>00267 <span class="comment">/*</span> <a name="l00268"></a>00268 <span class="comment"> * @brief Find out the current IO mode</span> <a name="l00269"></a>00269 <span class="comment"> * @return Returns the current IO mode</span> <a name="l00270"></a>00270 <span class="comment"> */</span> <a name="l00271"></a><a class="code" href="classAsync_1_1AudioIO.html#a8ed7982564e5a558915cced8ae70d2bc">00271</a> <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529" title="The different modes to open a device in.">Mode</a> <a class="code" href="classAsync_1_1AudioIO.html#a8ed7982564e5a558915cced8ae70d2bc" title="Find out how many samples there are in the output buffer.">mode</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> io_mode; } <a name="l00272"></a>00272 <a name="l00282"></a><a class="code" href="classAsync_1_1AudioIO.html#abf44bb0d6148b7c8bf0376ec200d1d2c">00282</a> <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#abf44bb0d6148b7c8bf0376ec200d1d2c" title="Set the gain to use.">setGain</a>(<span class="keywordtype">float</span> <a class="code" href="classAsync_1_1AudioIO.html#af680b696dba4a0ec6f76c886252aab6e" title="Return the gain.">gain</a>) { m_gain = gain; } <a name="l00283"></a>00283 <a name="l00288"></a><a class="code" href="classAsync_1_1AudioIO.html#af680b696dba4a0ec6f76c886252aab6e">00288</a> <span class="keywordtype">float</span> <a class="code" href="classAsync_1_1AudioIO.html#af680b696dba4a0ec6f76c886252aab6e" title="Return the gain.">gain</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_gain; } <a name="l00289"></a>00289 <a name="l00294"></a><a class="code" href="classAsync_1_1AudioIO.html#aaf3c934faa7ac41578edaaf2d506fafb">00294</a> <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#aaf3c934faa7ac41578edaaf2d506fafb" title="Return the sample rate.">sampleRate</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sample_rate; } <a name="l00295"></a>00295 <a name="l00300"></a><a class="code" href="classAsync_1_1AudioIO.html#abef00b2a149a1465897fc27ddd5b3294">00300</a> <span class="keywordtype">int</span> <a class="code" href="classAsync_1_1AudioIO.html#abef00b2a149a1465897fc27ddd5b3294" title="Return the audio channel used.">channel</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_channel; } <a name="l00301"></a>00301 <a name="l00309"></a><a class="code" href="classAsync_1_1AudioIO.html#a7c48d73409ebd957a0c04a85b37e73bd">00309</a> <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#a7c48d73409ebd957a0c04a85b37e73bd" title="Resume audio output to the sink.">resumeOutput</a>(<span class="keywordtype">void</span>) {} <a name="l00310"></a>00310 <a name="l00318"></a><a class="code" href="classAsync_1_1AudioIO.html#ae461bbea57b5108e0eb91961d8312c8e">00318</a> <span class="keywordtype">void</span> <a class="code" href="classAsync_1_1AudioIO.html#ae461bbea57b5108e0eb91961d8312c8e" title="The registered sink has flushed all samples.">allSamplesFlushed</a>(<span class="keywordtype">void</span>) {} <a name="l00319"></a>00319 <a name="l00320"></a>00320 <span class="preprocessor">#if 0</span> <a name="l00321"></a>00321 <span class="preprocessor"></span> <a name="l00327"></a>00327 <span class="keywordtype">int</span> <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); <a name="l00328"></a>00328 <a name="l00336"></a>00336 <span class="keywordtype">void</span> <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="l00337"></a>00337 <span class="preprocessor">#endif</span> <a name="l00338"></a>00338 <span class="preprocessor"></span> <a name="l00339"></a>00339 <a name="l00340"></a>00340 <span class="keyword">protected</span>: <a name="l00341"></a>00341 <a name="l00342"></a>00342 <span class="keyword">private</span>: <a name="l00343"></a>00343 <span class="keyword">class </span>InputFifo; <a name="l00344"></a>00344 <span class="keyword">class </span>DelayedFlushAudioReader; <a name="l00345"></a>00345 <a name="l00346"></a>00346 <a class="code" href="classAsync_1_1AudioIO.html#a89b25e780078902fbfc25383b2877529" title="The different modes to open a device in.">Mode</a> io_mode; <a name="l00347"></a>00347 <a class="code" href="classAsync_1_1AudioIO.html#a8fbf9b3017983991713e2cbb819dfd5a">AudioDevice</a> *audio_dev; <a name="l00348"></a>00348 <span class="keywordtype">float</span> m_gain; <a name="l00349"></a>00349 <span class="keywordtype">int</span> sample_rate; <a name="l00350"></a>00350 <span class="keywordtype">int</span> m_channel; <a name="l00351"></a>00351 <a class="code" href="classAsync_1_1AudioValve.html" title="Implements a &quot;valve&quot; for audio.">AudioValve</a> *input_valve; <a name="l00352"></a>00352 InputFifo *input_fifo; <a name="l00353"></a>00353 DelayedFlushAudioReader *audio_reader; <a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="comment">// Methods accessed by the Async::AudioDevice class</span> <a name="l00356"></a><a class="code" href="classAsync_1_1AudioIO.html#a8fbf9b3017983991713e2cbb819dfd5a">00356</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classAsync_1_1AudioIO.html#a8fbf9b3017983991713e2cbb819dfd5a">AudioDevice</a>; <a name="l00357"></a>00357 <a class="code" href="classAsync_1_1AudioIO.html#a8fbf9b3017983991713e2cbb819dfd5a">AudioDevice</a> *device(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> audio_dev; } <a name="l00358"></a>00358 <span class="keywordtype">int</span> readSamples(<span class="keywordtype">float</span> *samples, <span class="keywordtype">int</span> count); <a name="l00359"></a>00359 <span class="keywordtype">bool</span> doFlush(<span class="keywordtype">void</span>) <span class="keyword">const</span>; <a name="l00360"></a>00360 <span class="keywordtype">bool</span> isIdle(<span class="keywordtype">void</span>) <span class="keyword">const</span>; <a name="l00361"></a>00361 <span class="keywordtype">int</span> audioRead(<span class="keywordtype">float</span> *samples, <span class="keywordtype">int</span> count); <a name="l00362"></a>00362 <span class="keywordtype">unsigned</span> samplesAvailable(<span class="keywordtype">void</span>); <a name="l00363"></a>00363 <a name="l00364"></a>00364 }; <span class="comment">/* class AudioIO */</span> <a name="l00365"></a>00365 <a name="l00366"></a>00366 <a name="l00367"></a>00367 } <span class="comment">/* namespace */</span> <a name="l00368"></a>00368 <a name="l00369"></a>00369 <span class="preprocessor">#endif </span><span class="comment">/* ASYNC_AUDIO_IO_INCLUDED */</span> <a name="l00370"></a>00370 <a name="l00371"></a>00371 <a name="l00372"></a>00372 <span class="comment">/*</span> <a name="l00373"></a>00373 <span class="comment"> * This file has not been truncated</span> <a name="l00374"></a>00374 <span class="comment"> */</span> <a name="l00375"></a>00375 </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>