You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
7.1KB

  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.4.4 -->
  12. <h1><a class="anchor" name="probe">Probing Device Capabilities</a></h1>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>
  13. <div class="fragment"><pre class="fragment"><span class="comment">// audioprobe.cpp</span>
  14. <span class="preprocessor">#include &lt;iostream&gt;</span>
  15. <span class="preprocessor">#include "<a class="code" href="RtAudio_8h.html">RtAudio.h</a>"</span>
  16. <span class="keywordtype">int</span> main()
  17. {
  18. <a class="code" href="classRtAudio.html">RtAudio</a> audio;
  19. <span class="comment">// Determine the number of devices available</span>
  20. <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> devices = audio.<a class="code" href="classRtAudio.html#a3">getDeviceCount</a>();
  21. <span class="comment">// Scan through devices for various capabilities</span>
  22. <a class="code" href="structRtAudio_1_1DeviceInfo.html">RtAudio::DeviceInfo</a> info;
  23. <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=1; i&lt;=devices; i++ ) {
  24. info = audio.<a class="code" href="classRtAudio.html#a4">getDeviceInfo</a>( i );
  25. <span class="keywordflow">if</span> ( info.<a class="code" href="structRtAudio_1_1DeviceInfo.html#o0">probed</a> == <span class="keyword">true</span> ) {
  26. <span class="comment">// Print, for example, the maximum number of output channels for each device</span>
  27. std::cout &lt;&lt; <span class="stringliteral">"device = "</span> &lt;&lt; i;
  28. std::cout &lt;&lt; <span class="stringliteral">": maximum output channels = "</span> &lt;&lt; info.<a class="code" href="structRtAudio_1_1DeviceInfo.html#o2">outputChannels</a> &lt;&lt; <span class="stringliteral">"\n"</span>;
  29. }
  30. }
  31. <span class="keywordflow">return</span> 0;
  32. }
  33. </pre></div><p>
  34. The <a class="el" href="structRtAudio_1_1DeviceInfo.html">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>
  35. <div class="fragment"><pre class="fragment"> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structRtAudio_1_1DeviceInfo.html">RtAudio::DeviceInfo</a> {
  36. <span class="keywordtype">bool</span> probed; <span class="comment">// true if the device capabilities were successfully probed.</span>
  37. std::string name; <span class="comment">// Character string device identifier.</span>
  38. <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> outputChannels; <span class="comment">// Maximum output channels supported by device.</span>
  39. <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> inputChannels; <span class="comment">// Maximum input channels supported by device.</span>
  40. <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> duplexChannels; <span class="comment">// Maximum simultaneous input/output channels supported by device.</span>
  41. <span class="keywordtype">bool</span> isDefaultOutput; <span class="comment">// true if this is the default output device.</span>
  42. <span class="keywordtype">bool</span> isDefaultInput; <span class="comment">// true if this is the default input device.</span>
  43. std::vector&lt;unsigned int&gt; sampleRates; <span class="comment">// Supported sample rates.</span>
  44. <a class="code" href="RtAudio_8h.html#a1">RtAudioFormat</a> nativeFormats; <span class="comment">// Bit mask of supported data formats.</span>
  45. };
  46. </pre></div><p>
  47. The following data formats are defined and fully supported by <a class="el" href="classRtAudio.html">RtAudio</a>:<p>
  48. <div class="fragment"><pre class="fragment"> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="RtAudio_8h.html#a1">RtAudioFormat</a>;
  49. <span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat RTAUDIO_SINT8; <span class="comment">// Signed 8-bit integer</span>
  50. <span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat RTAUDIO_SINT16; <span class="comment">// Signed 16-bit integer</span>
  51. <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>
  52. <span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat RTAUDIO_SINT32; <span class="comment">// Signed 32-bit integer</span>
  53. <span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat RTAUDIO_FLOAT32; <span class="comment">// 32-bit float normalized between +/- 1.0</span>
  54. <span class="keyword">static</span> <span class="keyword">const</span> RtAudioFormat RTAUDIO_FLOAT64; <span class="comment">// 64-bit double normalized between +/- 1.0</span>
  55. </pre></div><p>
  56. The <code>nativeFormats</code> member of the <a class="el" href="structRtAudio_1_1DeviceInfo.html">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">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">RtAudio::DeviceInfo</a> structure is false, the remaining structure members are undefined and the device is probably unusable.<p>
  57. Some audio devices may require a minimum channel value greater than one. <a class="el" href="classRtAudio.html">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>
  58. 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">RtAudio</a> does not rely on the queried values when attempting to open a stream. <HR>
  59. <table><tr><td><img src="../images/mcgill.gif" width=165></td>
  60. <td>&copy;2001-2008 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>
  61. </table>
  62. </BODY>
  63. </HTML>