Fix api name functions for C, replace map with array.
[rtaudio-cdist.git] / tests / audioprobe.cpp
1 /******************************************/
2 /*
3   audioprobe.cpp
4   by Gary P. Scavone, 2001
5
6   Probe audio system and prints device info.
7 */
8 /******************************************/
9
10 #include "RtAudio.h"
11 #include <iostream>
12 #include <map>
13
14 int main()
15 {
16   // Create an api map.
17   std::map<int, std::string> apiMap;
18   apiMap[RtAudio::MACOSX_CORE] = "OS-X Core Audio";
19   apiMap[RtAudio::WINDOWS_ASIO] = "Windows ASIO";
20   apiMap[RtAudio::WINDOWS_DS] = "Windows Direct Sound";
21   apiMap[RtAudio::WINDOWS_WASAPI] = "Windows WASAPI";
22   apiMap[RtAudio::UNIX_JACK] = "Jack Client";
23   apiMap[RtAudio::LINUX_ALSA] = "Linux ALSA";
24   apiMap[RtAudio::LINUX_PULSE] = "Linux PulseAudio";
25   apiMap[RtAudio::LINUX_OSS] = "Linux OSS";
26   apiMap[RtAudio::RTAUDIO_DUMMY] = "RtAudio Dummy";
27
28   std::vector< RtAudio::Api > apis;
29   RtAudio :: getCompiledApi( apis );
30
31   std::cout << "\nRtAudio Version " << RtAudio::getVersion() << std::endl;
32
33   std::cout << "\nCompiled APIs:\n";
34   for ( unsigned int i=0; i<apis.size(); i++ )
35     std::cout << "  " << apiMap[ apis[i] ] << std::endl;
36
37   RtAudio audio;
38   RtAudio::DeviceInfo info;
39
40   std::cout << "\nCurrent API: " << apiMap[ audio.getCurrentApi() ] << std::endl;
41
42   unsigned int devices = audio.getDeviceCount();
43   std::cout << "\nFound " << devices << " device(s) ...\n";
44
45   for (unsigned int i=0; i<devices; i++) {
46     info = audio.getDeviceInfo(i);
47
48     std::cout << "\nDevice Name = " << info.name << '\n';
49     if ( info.probed == false )
50       std::cout << "Probe Status = UNsuccessful\n";
51     else {
52       std::cout << "Probe Status = Successful\n";
53       std::cout << "Output Channels = " << info.outputChannels << '\n';
54       std::cout << "Input Channels = " << info.inputChannels << '\n';
55       std::cout << "Duplex Channels = " << info.duplexChannels << '\n';
56       if ( info.isDefaultOutput ) std::cout << "This is the default output device.\n";
57       else std::cout << "This is NOT the default output device.\n";
58       if ( info.isDefaultInput ) std::cout << "This is the default input device.\n";
59       else std::cout << "This is NOT the default input device.\n";
60       if ( info.nativeFormats == 0 )
61         std::cout << "No natively supported data formats(?)!";
62       else {
63         std::cout << "Natively supported data formats:\n";
64         if ( info.nativeFormats & RTAUDIO_SINT8 )
65           std::cout << "  8-bit int\n";
66         if ( info.nativeFormats & RTAUDIO_SINT16 )
67           std::cout << "  16-bit int\n";
68         if ( info.nativeFormats & RTAUDIO_SINT24 )
69           std::cout << "  24-bit int\n";
70         if ( info.nativeFormats & RTAUDIO_SINT32 )
71           std::cout << "  32-bit int\n";
72         if ( info.nativeFormats & RTAUDIO_FLOAT32 )
73           std::cout << "  32-bit float\n";
74         if ( info.nativeFormats & RTAUDIO_FLOAT64 )
75           std::cout << "  64-bit float\n";
76       }
77       if ( info.sampleRates.size() < 1 )
78         std::cout << "No supported sample rates found!";
79       else {
80         std::cout << "Supported sample rates = ";
81         for (unsigned int j=0; j<info.sampleRates.size(); j++)
82           std::cout << info.sampleRates[j] << " ";
83       }
84       std::cout << std::endl;
85     }
86   }
87   std::cout << std::endl;
88
89   return 0;
90 }