SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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_MixAudio(stream, waveptr, waveleft, SDL_MIX_MAXVOLUME);
53 waveleft = wave.soundlen;
56 SDL_MixAudio(stream, waveptr, len, SDL_MIX_MAXVOLUME);
68 main(int argc, char *argv[])
72 /* Print available audio drivers */
73 n = SDL_GetNumAudioDrivers();
75 printf("No built-in audio drivers\n");
77 printf("Built-in audio drivers:");
78 for (i = 0; i < n; ++i) {
82 printf(" %s", SDL_GetAudioDriver(i));
87 /* Load the SDL library */
88 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
89 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
92 if (argv[1] == NULL) {
93 argv[1] = "sample.wav";
95 /* Load the wave file into memory */
96 if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
97 fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
101 wave.spec.callback = fillerup;
103 /* Set the signals */
105 signal(SIGHUP, poked);
107 signal(SIGINT, poked);
109 signal(SIGQUIT, poked);
111 signal(SIGTERM, poked);
112 #endif /* HAVE_SIGNAL_H */
114 /* Initialize fillerup() variables */
115 if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
116 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
117 SDL_FreeWAV(wave.sound);
122 /* Let the audio run */
123 printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
124 while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
127 /* Clean up on signal */
129 SDL_FreeWAV(wave.sound);