Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created August 7, 2018 20:17
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/fe3c5012f1e26c3131dfac7dee387f17 to your computer and use it in GitHub Desktop.
Save jpcima/fe3c5012f1e26c3131dfac7dee387f17 to your computer and use it in GitHub Desktop.
RtAudio example using API names
#include <rtaudio_c.h>
#include <getopt.h>
#include <stdio.h>
static void print_compiled_apis()
{
const rtaudio_api_t *apis = rtaudio_compiled_api();
while (*apis != RTAUDIO_API_UNSPECIFIED) {
printf(" * %s\n", rtaudio_compiled_api_name(*apis));
++apis;
}
}
int main(int argc, char *argv[])
{
rtaudio_api_t api = RTAUDIO_API_UNSPECIFIED;
const char *desired_api = NULL;
printf("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_compiled_api_by_name(desired_api);
}
else if (arg == 'h') {
print_compiled_apis();
return 0;
}
}
if (desired_api && api == RTAUDIO_API_UNSPECIFIED) {
printf("API unavailable '%s'.\n", desired_api);
print_compiled_apis();
return 1;
}
rtaudio_t audiosys = rtaudio_create(api);
api = rtaudio_current_api(audiosys);
printf("Audio is open with API '%s'.\n", rtaudio_compiled_api_name(api));
/* ... */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment