testaudiocapture: Let specific devices be opened.
authorRyan C. Gordon
Tue, 02 Aug 2016 13:38:56 -0400
changeset 102370d344873cd93
parent 10236 a9231c55e5cc
child 10238 6fa358b97f4b
testaudiocapture: Let specific devices be opened.
test/testaudiocapture.c
     1.1 --- a/test/testaudiocapture.c	Mon Aug 01 13:36:43 2016 -0400
     1.2 +++ b/test/testaudiocapture.c	Tue Aug 02 13:38:56 2016 -0400
     1.3 @@ -108,6 +108,11 @@
     1.4  int
     1.5  main(int argc, char **argv)
     1.6  {
     1.7 +    /* (argv[1] == NULL means "open default device.") */
     1.8 +    const char *devname = argv[1];
     1.9 +    int devcount;
    1.10 +    int i;
    1.11 +
    1.12      /* Enable standard application logging */
    1.13      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.14  
    1.15 @@ -124,6 +129,11 @@
    1.16  
    1.17      SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
    1.18  
    1.19 +    devcount = SDL_GetNumAudioDevices(SDL_TRUE);
    1.20 +    for (i = 0; i < devcount; i++) {
    1.21 +        SDL_Log(" Capture device #%d: '%s'\n", i, SDL_GetAudioDeviceName(i, SDL_TRUE));
    1.22 +    }
    1.23 +
    1.24      SDL_zero(spec);
    1.25      spec.freq = 44100;
    1.26      spec.format = AUDIO_F32SYS;
    1.27 @@ -139,7 +149,12 @@
    1.28          return 1;
    1.29      }
    1.30  
    1.31 -    devid = SDL_OpenAudioDevice(NULL, 1, &spec, &spec, 0);
    1.32 +    SDL_Log("Opening device %s%s%s...\n",
    1.33 +            devname ? "'" : "",
    1.34 +            devname ? devname : "[[default]]",
    1.35 +            devname ? "'" : "");
    1.36 +
    1.37 +    devid = SDL_OpenAudioDevice(argv[1], SDL_TRUE, &spec, &spec, 0);
    1.38      if (!devid) {
    1.39          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
    1.40          SDL_free(sound);