Created
August 7, 2018 18:49
-
-
Save jpcima/d97798253554a19bbc34e2e293cd0225 to your computer and use it in GitHub Desktop.
RtAudio example using API names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <RtAudio.h> | |
#include <getopt.h> | |
#include <iostream> | |
static void print_compiled_apis() | |
{ | |
std::vector<RtAudio::Api> available; | |
RtAudio::getCompiledApi(available); | |
for (RtAudio::Api api : available) | |
std::cout << " * " << RtAudio::getCompiledApiName(api) << "\n"; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
RtAudio::Api api = RtAudio::UNSPECIFIED; | |
const char *desired_api = nullptr; | |
std::cout << "usage: example [-d api] [-h]\n\n"; | |
int arg; | |
while ((arg = getopt(argc, argv, "d:h")) != -1) { | |
if (arg == 'd') { | |
desired_api = optarg; | |
api = RtAudio::getCompiledApiByName(desired_api); | |
} | |
else if (arg == 'h') { | |
print_compiled_apis(); | |
return 0; | |
} | |
} | |
if (desired_api && api == RtAudio::UNSPECIFIED) { | |
std::cout << "API unavailable '" << desired_api << "'.\n"; | |
print_compiled_apis(); | |
return 1; | |
} | |
RtAudio *audiosys = new RtAudio(api); | |
api = audiosys->getCurrentApi(); | |
std::cout << "Audio is open with API '" << RtAudio::getCompiledApiName(api) << "'.\n"; | |
/* ... */ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment