test/testaudiocapture.c
changeset 10237 0d344873cd93
parent 10231 4b0893d63092
child 10244 656799817375
equal deleted inserted replaced
10236:a9231c55e5cc 10237:0d344873cd93
   106 }
   106 }
   107 
   107 
   108 int
   108 int
   109 main(int argc, char **argv)
   109 main(int argc, char **argv)
   110 {
   110 {
       
   111     /* (argv[1] == NULL means "open default device.") */
       
   112     const char *devname = argv[1];
       
   113     int devcount;
       
   114     int i;
       
   115 
   111     /* Enable standard application logging */
   116     /* Enable standard application logging */
   112     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   117     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   113 
   118 
   114     /* Load the SDL library */
   119     /* Load the SDL library */
   115     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
   120     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
   122     SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
   127     SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
   123     #endif
   128     #endif
   124 
   129 
   125     SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   130     SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   126 
   131 
       
   132     devcount = SDL_GetNumAudioDevices(SDL_TRUE);
       
   133     for (i = 0; i < devcount; i++) {
       
   134         SDL_Log(" Capture device #%d: '%s'\n", i, SDL_GetAudioDeviceName(i, SDL_TRUE));
       
   135     }
       
   136 
   127     SDL_zero(spec);
   137     SDL_zero(spec);
   128     spec.freq = 44100;
   138     spec.freq = 44100;
   129     spec.format = AUDIO_F32SYS;
   139     spec.format = AUDIO_F32SYS;
   130     spec.channels = 1;
   140     spec.channels = 1;
   131     spec.samples = 1024;
   141     spec.samples = 1024;
   137         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
   147         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
   138         SDL_Quit();
   148         SDL_Quit();
   139         return 1;
   149         return 1;
   140     }
   150     }
   141 
   151 
   142     devid = SDL_OpenAudioDevice(NULL, 1, &spec, &spec, 0);
   152     SDL_Log("Opening device %s%s%s...\n",
       
   153             devname ? "'" : "",
       
   154             devname ? devname : "[[default]]",
       
   155             devname ? "'" : "");
       
   156 
       
   157     devid = SDL_OpenAudioDevice(argv[1], SDL_TRUE, &spec, &spec, 0);
   143     if (!devid) {
   158     if (!devid) {
   144         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
   159         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
   145         SDL_free(sound);
   160         SDL_free(sound);
   146         SDL_Quit();
   161         SDL_Quit();
   147         exit(1);
   162         exit(1);