Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
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],
97 &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
98 fprintf (stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError ());
102 wave.spec.callback = fillerup;
104 /* Set the signals */
106 signal (SIGHUP, poked);
108 signal (SIGINT, poked);
110 signal (SIGQUIT, poked);
112 signal (SIGTERM, poked);
113 #endif /* HAVE_SIGNAL_H */
115 /* Initialize fillerup() variables */
116 if (SDL_OpenAudio (&wave.spec, NULL) < 0) {
117 fprintf (stderr, "Couldn't open audio: %s\n", SDL_GetError ());
118 SDL_FreeWAV (wave.sound);
123 /* Let the audio run */
124 printf ("Using audio driver: %s\n", SDL_GetCurrentAudioDriver ());
125 while (!done && (SDL_GetAudioStatus () == SDL_AUDIO_PLAYING))
128 /* Clean up on signal */
130 SDL_FreeWAV (wave.sound);