975ff0eda069d7df9744c5d8eef5d63b3d1af97a
[rtaudio-cdist.git] / doc / doxygen / probe.txt
1 /*! \page probe Probing Device Capabilities
2
3 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.
4
5 \code
6
7 // audioprobe.cpp
8
9 #include <iostream>
10 #include "RtAudio.h"
11
12 int main()
13 {
14   RtAudio audio;
15
16   // Determine the number of devices available
17   unsigned int devices = audio.getDeviceCount();
18
19   // Scan through devices for various capabilities
20   RtAudio::DeviceInfo info;
21   for ( unsigned int i=0; i<devices; i++ ) {
22
23     info = audio.getDeviceInfo( i );
24
25     if ( info.probed == true ) {
26       // Print, for example, the maximum number of output channels for each device
27       std::cout << "device = " << i;
28       std::cout << ": maximum output channels = " << info.outputChannels << "\n";
29     }
30   }
31
32   return 0;
33 }
34 \endcode
35
36 The RtAudio::DeviceInfo structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device:
37
38 \code
39   typedef struct RtAudio::DeviceInfo {
40     bool probed;                           // true if the device capabilities were successfully probed.
41     std::string name;                      // Character string device identifier.
42     unsigned int outputChannels;           // Maximum output channels supported by device.
43     unsigned int inputChannels;            // Maximum input channels supported by device.
44     unsigned int duplexChannels;           // Maximum simultaneous input/output channels supported by device.
45     bool isDefaultOutput;                  // true if this is the default output device.
46     bool isDefaultInput;                   // true if this is the default input device.
47     std::vector<unsigned int> sampleRates; // Supported sample rates.
48     unsigned int preferredSampleRate;      // Preferred sample rate, eg. for WASAPI the system sample rate.
49     RtAudioFormat nativeFormats;           // Bit mask of supported data formats.
50   };
51 \endcode
52
53 The following data formats are defined and fully supported by RtAudio:
54
55 \code
56   typedef unsigned long RtAudioFormat;
57   static const RtAudioFormat  RTAUDIO_SINT8;   // Signed 8-bit integer
58   static const RtAudioFormat  RTAUDIO_SINT16;  // Signed 16-bit integer
59   static const RtAudioFormat  RTAUDIO_SINT24;  // Signed 24-bit integer (lower 3 bytes of 32-bit signed integer.)
60   static const RtAudioFormat  RTAUDIO_SINT32;  // Signed 32-bit integer
61   static const RtAudioFormat  RTAUDIO_FLOAT32; // 32-bit float normalized between +/- 1.0
62   static const RtAudioFormat  RTAUDIO_FLOAT64; // 64-bit double normalized between +/- 1.0
63 \endcode
64
65 The \c nativeFormats member of the RtAudio::DeviceInfo structure is a bit mask of the above formats which are natively supported by the device.  However, RtAudio will automatically provide format conversion if a particular format is not natively supported.  When the \c probed member of the RtAudio::DeviceInfo structure is false, the remaining structure members are undefined and the device is probably unusable.
66
67 Some audio devices may require a minimum channel value greater than one.  RtAudio 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 <I>NOT</I> possible when the number of channels set by the user is greater than that supported by the device.
68
69 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, RtAudio does not rely on the queried values when attempting to open a stream.
70
71 */