test/loopwave.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
child 8535 e8ee0708ef5c
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
    78 int
    78 int
    79 main(int argc, char *argv[])
    79 main(int argc, char *argv[])
    80 {
    80 {
    81     int i;
    81     int i;
    82 
    82 
       
    83 	/* Enable standard application logging */
       
    84 	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
       
    85 
    83     /* Load the SDL library */
    86     /* Load the SDL library */
    84     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
    87     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
    85         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    88         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    86         return (1);
    89         return (1);
    87     }
    90     }
    88 
    91 
    89     if (argv[1] == NULL) {
    92     if (argv[1] == NULL) {
    90         argv[1] = "sample.wav";
    93         argv[1] = "sample.wav";
    91     }
    94     }
    92     /* Load the wave file into memory */
    95     /* Load the wave file into memory */
    93     if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
    96     if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
    94         fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
    97         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
    95         quit(1);
    98         quit(1);
    96     }
    99     }
    97 
   100 
    98     wave.spec.callback = fillerup;
   101     wave.spec.callback = fillerup;
    99 #if HAVE_SIGNAL_H
   102 #if HAVE_SIGNAL_H
   107 #endif
   110 #endif
   108     signal(SIGTERM, poked);
   111     signal(SIGTERM, poked);
   109 #endif /* HAVE_SIGNAL_H */
   112 #endif /* HAVE_SIGNAL_H */
   110 
   113 
   111     /* Show the list of available drivers */
   114     /* Show the list of available drivers */
   112     printf("Available audio drivers: ");
   115     SDL_Log("Available audio drivers:");
   113     for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
   116     for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
   114         if (i == 0) {
   117 		SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
   115             printf("%s", SDL_GetAudioDriver(i));
       
   116         } else {
       
   117             printf(", %s", SDL_GetAudioDriver(i));
       
   118         }
       
   119     }
   118     }
   120     printf("\n");
       
   121 
   119 
   122     /* Initialize fillerup() variables */
   120     /* Initialize fillerup() variables */
   123     if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
   121     if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
   124         fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   122         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
   125         SDL_FreeWAV(wave.sound);
   123         SDL_FreeWAV(wave.sound);
   126         quit(2);
   124         quit(2);
   127     }
   125     }
   128 
   126 
   129     printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   127     SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   130 
   128 
   131     /* Let the audio run */
   129     /* Let the audio run */
   132     SDL_PauseAudio(0);
   130     SDL_PauseAudio(0);
   133     while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
   131     while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
   134         SDL_Delay(1000);
   132         SDL_Delay(1000);