Release 4.0.12 tarball
[rtaudio.git] / doc / html / probe.html
1 <HTML>
2 <HEAD>
3 <TITLE>The RtAudio Home Page</TITLE>
4 <LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
5 <LINK REL="SHORTCUT ICON" HREF="http://www.music.mcgill.ca/~gary/favicon.ico">
6 </HEAD>
7 <BODY BGCOLOR="#FFFFFF">
8 <CENTER>
9 <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>
10 <HR>
11 <!-- Generated by Doxygen 1.8.2 -->
12 </div><!-- top -->
13 <div class="header">
14   <div class="headertitle">
15 <div class="title">Probing Device Capabilities </div>  </div>
16 </div><!--header-->
17 <div class="contents">
18 <div class="textblock"><p>A programmer may wish to query the available audio device capabilities before deciding which to use. The following example outlines how this can be done.</p>
19 <div class="fragment"><div class="line"><span class="comment">// audioprobe.cpp</span></div>
20 <div class="line"></div>
21 <div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
22 <div class="line"><span class="preprocessor">#include &quot;<a class="code" href="RtAudio_8h.html">RtAudio.h</a>&quot;</span></div>
23 <div class="line"></div>
24 <div class="line"><span class="keywordtype">int</span> main()</div>
25 <div class="line">{</div>
26 <div class="line">  <a class="code" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> audio;</div>
27 <div class="line"></div>
28 <div class="line">  <span class="comment">// Determine the number of devices available</span></div>
29 <div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> devices = audio.<a class="code" href="classRtAudio.html#a747ce2d73803641bbb66d6e78092aa1a" title="A public function that queries for the number of audio devices available.">getDeviceCount</a>();</div>
30 <div class="line"></div>
31 <div class="line">  <span class="comment">// Scan through devices for various capabilities</span></div>
32 <div class="line">  <a class="code" href="structRtAudio_1_1DeviceInfo.html" title="The public device information structure for returning queried values.">RtAudio::DeviceInfo</a> info;</div>
33 <div class="line">  <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;=devices; i++ ) {</div>
34 <div class="line"></div>
35 <div class="line">    info = audio.<a class="code" href="classRtAudio.html#a02d7ff44ad1d7eae22283a052f3dfda8" title="Return an RtAudio::DeviceInfo structure for a specified device number.">getDeviceInfo</a>( i );</div>
36 <div class="line"></div>
37 <div class="line">    <span class="keywordflow">if</span> ( info.<a class="code" href="structRtAudio_1_1DeviceInfo.html#a97573717ccb1e75a834a0a108cd6982d">probed</a> == <span class="keyword">true</span> ) {</div>
38 <div class="line">      <span class="comment">// Print, for example, the maximum number of output channels for each device</span></div>
39 <div class="line">      std::cout &lt;&lt; <span class="stringliteral">&quot;device = &quot;</span> &lt;&lt; i;</div>
40 <div class="line">      std::cout &lt;&lt; <span class="stringliteral">&quot;: maximum output channels = &quot;</span> &lt;&lt; info.<a class="code" href="structRtAudio_1_1DeviceInfo.html#a81aaf488f8158ef55b1bb678f66feb7d">outputChannels</a> &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
41 <div class="line">    }</div>
42 <div class="line">  }</div>
43 <div class="line"></div>
44 <div class="line">  <span class="keywordflow">return</span> 0;</div>
45 <div class="line">}</div>
46 </div><!-- fragment --><p>The <a class="el" href="structRtAudio_1_1DeviceInfo.html" title="The public device information structure for returning queried values.">RtAudio::DeviceInfo</a> structure is defined in <a class="el" href="RtAudio_8h.html">RtAudio.h</a> and provides a variety of information useful in assessing the capabilities of a device:</p>
47 <div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structRtAudio_1_1DeviceInfo.html" title="The public device information structure for returning queried values.">RtAudio::DeviceInfo</a> {</div>
48 <div class="line">  <span class="keywordtype">bool</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a97573717ccb1e75a834a0a108cd6982d">probed</a>;                           <span class="comment">// true if the device capabilities were successfully probed.</span></div>
49 <div class="line">  std::string <a class="code" href="structRtAudio_1_1DeviceInfo.html#a24df596ab8d54f2eb540c7cf16212b3b">name</a>;                      <span class="comment">// Character string device identifier.</span></div>
50 <div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a81aaf488f8158ef55b1bb678f66feb7d">outputChannels</a>;           <span class="comment">// Maximum output channels supported by device.</span></div>
51 <div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a56247b458a937ae84d98ca9c4b243275">inputChannels</a>;            <span class="comment">// Maximum input channels supported by device.</span></div>
52 <div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a3e8ad34c2d14e24293a0beafc26186e7">duplexChannels</a>;           <span class="comment">// Maximum simultaneous input/output channels supported by device.</span></div>
53 <div class="line">  <span class="keywordtype">bool</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a5365245e73ffe29a05734de4474acd58">isDefaultOutput</a>;                  <span class="comment">// true if this is the default output device.</span></div>
54 <div class="line">  <span class="keywordtype">bool</span> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a7c8aca084bd908799b6be5954b80def2">isDefaultInput</a>;                   <span class="comment">// true if this is the default input device.</span></div>
55 <div class="line">  std::vector&lt;unsigned int&gt; <a class="code" href="structRtAudio_1_1DeviceInfo.html#afa65f5f92f66ce7aacd3ff35e11b230f">sampleRates</a>; <span class="comment">// Supported sample rates.</span></div>
56 <div class="line">  <a class="code" href="RtAudio_8h.html#aafca92882d25915560018873221e44b8" title="RtAudio data format type.">RtAudioFormat</a> <a class="code" href="structRtAudio_1_1DeviceInfo.html#a23251b549b89b2fe04a57fcd7cb76ea4">nativeFormats</a>;           <span class="comment">// Bit mask of supported data formats.</span></div>
57 <div class="line">};</div>
58 </div><!-- fragment --><p>The following data formats are defined and fully supported by <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a>:</p>
59 <div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="RtAudio_8h.html#aafca92882d25915560018873221e44b8" title="RtAudio data format type.">RtAudioFormat</a>;</div>
60 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_SINT8;   <span class="comment">// Signed 8-bit integer</span></div>
61 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_SINT16;  <span class="comment">// Signed 16-bit integer</span></div>
62 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_SINT24;  <span class="comment">// Signed 24-bit integer (lower 3 bytes of 32-bit signed integer.)</span></div>
63 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_SINT32;  <span class="comment">// Signed 32-bit integer</span></div>
64 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_FLOAT32; <span class="comment">// 32-bit float normalized between +/- 1.0</span></div>
65 <div class="line"><span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat  RTAUDIO_FLOAT64; <span class="comment">// 64-bit double normalized between +/- 1.0</span></div>
66 </div><!-- fragment --><p>The <code>nativeFormats</code> member of the <a class="el" href="structRtAudio_1_1DeviceInfo.html" title="The public device information structure for returning queried values.">RtAudio::DeviceInfo</a> structure is a bit mask of the above formats which are natively supported by the device. However, <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> will automatically provide format conversion if a particular format is not natively supported. When the <code>probed</code> member of the <a class="el" href="structRtAudio_1_1DeviceInfo.html" title="The public device information structure for returning queried values.">RtAudio::DeviceInfo</a> structure is false, the remaining structure members are undefined and the device is probably unusable.</p>
67 <p>Some audio devices may require a minimum channel value greater than one. <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> will provide automatic channel number compensation when the number of channels set by the user is less than that required by the device. Channel compensation is <em>NOT</em> possible when the number of channels set by the user is greater than that supported by the device.</p>
68 <p>It should be noted that the capabilities reported by a device driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. For this reason, <a class="el" href="classRtAudio.html" title="Realtime audio i/o C++ classes.">RtAudio</a> does not rely on the queried values when attempting to open a stream. </p>
69 </div></div><!-- contents -->
70 <HR>
71 <table><tr><td><img src="../images/mcgill.gif" width=165></td>
72   <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>
73 </table>
74 </BODY>
75 </HTML>