Use new 1.3 API for getting audio driver name.
2 /* Program to load a wave file and loop playing it using SDL sound */
4 /* loopwaves.c is much more robust in handling WAVE files --
5 This is only for simple WAVEs
7 #include "SDL_config.h"
17 #include "SDL_audio.h"
22 Uint8 *sound; /* Pointer to wave data */
23 Uint32 soundlen; /* Length of wave data */
24 int soundpos; /* Current play position */
28 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
38 fillerup(void *unused, Uint8 * stream, int len)
43 /* Set up the pointers */
44 waveptr = wave.sound + wave.soundpos;
45 waveleft = wave.soundlen - wave.soundpos;
48 while (waveleft <= len) {
49 SDL_memcpy(stream, waveptr, waveleft);
53 waveleft = wave.soundlen;
56 SDL_memcpy(stream, waveptr, len);
68 main(int argc, char *argv[])
70 /* Load the SDL library */
71 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
72 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
76 if (argv[1] == NULL) {
77 argv[1] = "sample.wav";
79 /* Load the wave file into memory */
80 if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
81 fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
85 wave.spec.callback = fillerup;
89 signal(SIGHUP, poked);
91 signal(SIGINT, poked);
93 signal(SIGQUIT, poked);
95 signal(SIGTERM, poked);
96 #endif /* HAVE_SIGNAL_H */
98 /* Initialize fillerup() variables */
99 if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
100 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
101 SDL_FreeWAV(wave.sound);
105 /* Right now we're using the 1.2 SDL_OpenAudio(), but if we move to the
106 1.3 device enumeration version, we shouldn't hardcore device id #1 for
107 SDL_GetAudioDeviceName(), below. */
108 printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
109 printf("Using audio device: %s\n", SDL_GetAudioDeviceName(1, 0));
111 /* Let the audio run */
113 while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
116 /* Clean up on signal */
118 SDL_FreeWAV(wave.sound);