Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created August 7, 2018 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcima/d97798253554a19bbc34e2e293cd0225 to your computer and use it in GitHub Desktop.
Save jpcima/d97798253554a19bbc34e2e293cd0225 to your computer and use it in GitHub Desktop.
RtAudio example using API names
#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