test/loopwave.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1660 8b9d79e7eacf
child 1668 4da1ee79c9af
     1.1 --- a/test/loopwave.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/loopwave.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -16,114 +16,118 @@
     1.4  #include "SDL.h"
     1.5  #include "SDL_audio.h"
     1.6  
     1.7 -struct {
     1.8 -	SDL_AudioSpec spec;
     1.9 -	Uint8   *sound;			/* Pointer to wave data */
    1.10 -	Uint32   soundlen;		/* Length of wave data */
    1.11 -	int      soundpos;		/* Current play position */
    1.12 +struct
    1.13 +{
    1.14 +    SDL_AudioSpec spec;
    1.15 +    Uint8 *sound;               /* Pointer to wave data */
    1.16 +    Uint32 soundlen;            /* Length of wave data */
    1.17 +    int soundpos;               /* Current play position */
    1.18  } wave;
    1.19  
    1.20  
    1.21  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.22 -static void quit(int rc)
    1.23 +static void
    1.24 +quit (int rc)
    1.25  {
    1.26 -	SDL_Quit();
    1.27 -	exit(rc);
    1.28 +    SDL_Quit ();
    1.29 +    exit (rc);
    1.30  }
    1.31  
    1.32  
    1.33 -void SDLCALL fillerup(void *unused, Uint8 *stream, int len)
    1.34 +void SDLCALL
    1.35 +fillerup (void *unused, Uint8 * stream, int len)
    1.36  {
    1.37 -	Uint8 *waveptr;
    1.38 -	int    waveleft;
    1.39 +    Uint8 *waveptr;
    1.40 +    int waveleft;
    1.41  
    1.42 -	/* Set up the pointers */
    1.43 -	waveptr = wave.sound + wave.soundpos;
    1.44 -	waveleft = wave.soundlen - wave.soundpos;
    1.45 +    /* Set up the pointers */
    1.46 +    waveptr = wave.sound + wave.soundpos;
    1.47 +    waveleft = wave.soundlen - wave.soundpos;
    1.48  
    1.49 -	/* Go! */
    1.50 -	while ( waveleft <= len ) {
    1.51 -		SDL_MixAudio(stream, waveptr, waveleft, SDL_MIX_MAXVOLUME);
    1.52 -		stream += waveleft;
    1.53 -		len -= waveleft;
    1.54 -		waveptr = wave.sound;
    1.55 -		waveleft = wave.soundlen;
    1.56 -		wave.soundpos = 0;
    1.57 -	}
    1.58 -	SDL_MixAudio(stream, waveptr, len, SDL_MIX_MAXVOLUME);
    1.59 -	wave.soundpos += len;
    1.60 +    /* Go! */
    1.61 +    while (waveleft <= len) {
    1.62 +        SDL_MixAudio (stream, waveptr, waveleft, SDL_MIX_MAXVOLUME);
    1.63 +        stream += waveleft;
    1.64 +        len -= waveleft;
    1.65 +        waveptr = wave.sound;
    1.66 +        waveleft = wave.soundlen;
    1.67 +        wave.soundpos = 0;
    1.68 +    }
    1.69 +    SDL_MixAudio (stream, waveptr, len, SDL_MIX_MAXVOLUME);
    1.70 +    wave.soundpos += len;
    1.71  }
    1.72  
    1.73  static int done = 0;
    1.74 -void poked(int sig)
    1.75 +void
    1.76 +poked (int sig)
    1.77  {
    1.78 -	done = 1;
    1.79 +    done = 1;
    1.80  }
    1.81  
    1.82 -int main(int argc, char *argv[])
    1.83 +int
    1.84 +main (int argc, char *argv[])
    1.85  {
    1.86 -	int i, n;
    1.87 +    int i, n;
    1.88  
    1.89 -	/* Print available audio drivers */
    1.90 -	n = SDL_GetNumAudioDrivers();
    1.91 -	if ( n == 0 ) {
    1.92 -		printf("No built-in audio drivers\n");
    1.93 -	} else {
    1.94 -		printf("Built-in audio drivers:");
    1.95 -		for ( i = 0; i < n; ++i ) {
    1.96 -			if ( i > 0 ) {
    1.97 -				printf(",");
    1.98 -			}
    1.99 -			printf(" %s", SDL_GetAudioDriver(i));
   1.100 -		}
   1.101 -		printf("\n");
   1.102 -	}
   1.103 +    /* Print available audio drivers */
   1.104 +    n = SDL_GetNumAudioDrivers ();
   1.105 +    if (n == 0) {
   1.106 +        printf ("No built-in audio drivers\n");
   1.107 +    } else {
   1.108 +        printf ("Built-in audio drivers:");
   1.109 +        for (i = 0; i < n; ++i) {
   1.110 +            if (i > 0) {
   1.111 +                printf (",");
   1.112 +            }
   1.113 +            printf (" %s", SDL_GetAudioDriver (i));
   1.114 +        }
   1.115 +        printf ("\n");
   1.116 +    }
   1.117  
   1.118 -	/* Load the SDL library */
   1.119 -	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
   1.120 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   1.121 -		return(1);
   1.122 -	}
   1.123 -	if ( argv[1] == NULL ) {
   1.124 -		argv[1] = "sample.wav";
   1.125 -	}
   1.126 -	/* Load the wave file into memory */
   1.127 -	if ( SDL_LoadWAV(argv[1],
   1.128 -			&wave.spec, &wave.sound, &wave.soundlen) == NULL ) {
   1.129 -		fprintf(stderr, "Couldn't load %s: %s\n",
   1.130 -						argv[1], SDL_GetError());
   1.131 -		quit(1);
   1.132 -	}
   1.133 +    /* Load the SDL library */
   1.134 +    if (SDL_Init (SDL_INIT_AUDIO) < 0) {
   1.135 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.136 +        return (1);
   1.137 +    }
   1.138 +    if (argv[1] == NULL) {
   1.139 +        argv[1] = "sample.wav";
   1.140 +    }
   1.141 +    /* Load the wave file into memory */
   1.142 +    if (SDL_LoadWAV (argv[1],
   1.143 +                     &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
   1.144 +        fprintf (stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError ());
   1.145 +        quit (1);
   1.146 +    }
   1.147  
   1.148 -	wave.spec.callback = fillerup;
   1.149 +    wave.spec.callback = fillerup;
   1.150  #if HAVE_SIGNAL_H
   1.151 -	/* Set the signals */
   1.152 +    /* Set the signals */
   1.153  #ifdef SIGHUP
   1.154 -	signal(SIGHUP, poked);
   1.155 +    signal (SIGHUP, poked);
   1.156  #endif
   1.157 -	signal(SIGINT, poked);
   1.158 +    signal (SIGINT, poked);
   1.159  #ifdef SIGQUIT
   1.160 -	signal(SIGQUIT, poked);
   1.161 +    signal (SIGQUIT, poked);
   1.162  #endif
   1.163 -	signal(SIGTERM, poked);
   1.164 +    signal (SIGTERM, poked);
   1.165  #endif /* HAVE_SIGNAL_H */
   1.166  
   1.167 -	/* Initialize fillerup() variables */
   1.168 -	if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) {
   1.169 -		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   1.170 -		SDL_FreeWAV(wave.sound);
   1.171 -		quit(2);
   1.172 -	}
   1.173 -	SDL_PauseAudio(0);
   1.174 +    /* Initialize fillerup() variables */
   1.175 +    if (SDL_OpenAudio (&wave.spec, NULL) < 0) {
   1.176 +        fprintf (stderr, "Couldn't open audio: %s\n", SDL_GetError ());
   1.177 +        SDL_FreeWAV (wave.sound);
   1.178 +        quit (2);
   1.179 +    }
   1.180 +    SDL_PauseAudio (0);
   1.181  
   1.182 -	/* Let the audio run */
   1.183 -	printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   1.184 -	while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
   1.185 -		SDL_Delay(1000);
   1.186 +    /* Let the audio run */
   1.187 +    printf ("Using audio driver: %s\n", SDL_GetCurrentAudioDriver ());
   1.188 +    while (!done && (SDL_GetAudioStatus () == SDL_AUDIO_PLAYING))
   1.189 +        SDL_Delay (1000);
   1.190  
   1.191 -	/* Clean up on signal */
   1.192 -	SDL_CloseAudio();
   1.193 -	SDL_FreeWAV(wave.sound);
   1.194 -	SDL_Quit();
   1.195 -	return(0);
   1.196 +    /* Clean up on signal */
   1.197 +    SDL_CloseAudio ();
   1.198 +    SDL_FreeWAV (wave.sound);
   1.199 +    SDL_Quit ();
   1.200 +    return (0);
   1.201  }