comparison test/loopwave.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
25 } wave; 25 } wave;
26 26
27 27
28 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 28 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
29 static void 29 static void
30 quit (int rc) 30 quit(int rc)
31 { 31 {
32 SDL_Quit (); 32 SDL_Quit();
33 exit (rc); 33 exit(rc);
34 } 34 }
35 35
36 36
37 void SDLCALL 37 void SDLCALL
38 fillerup (void *unused, Uint8 * stream, int len) 38 fillerup(void *unused, Uint8 * stream, int len)
39 { 39 {
40 Uint8 *waveptr; 40 Uint8 *waveptr;
41 int waveleft; 41 int waveleft;
42 42
43 /* Set up the pointers */ 43 /* Set up the pointers */
44 waveptr = wave.sound + wave.soundpos; 44 waveptr = wave.sound + wave.soundpos;
45 waveleft = wave.soundlen - wave.soundpos; 45 waveleft = wave.soundlen - wave.soundpos;
46 46
47 /* Go! */ 47 /* Go! */
48 while (waveleft <= len) { 48 while (waveleft <= len) {
49 SDL_MixAudio (stream, waveptr, waveleft, SDL_MIX_MAXVOLUME); 49 SDL_MixAudio(stream, waveptr, waveleft, SDL_MIX_MAXVOLUME);
50 stream += waveleft; 50 stream += waveleft;
51 len -= waveleft; 51 len -= waveleft;
52 waveptr = wave.sound; 52 waveptr = wave.sound;
53 waveleft = wave.soundlen; 53 waveleft = wave.soundlen;
54 wave.soundpos = 0; 54 wave.soundpos = 0;
55 } 55 }
56 SDL_MixAudio (stream, waveptr, len, SDL_MIX_MAXVOLUME); 56 SDL_MixAudio(stream, waveptr, len, SDL_MIX_MAXVOLUME);
57 wave.soundpos += len; 57 wave.soundpos += len;
58 } 58 }
59 59
60 static int done = 0; 60 static int done = 0;
61 void 61 void
62 poked (int sig) 62 poked(int sig)
63 { 63 {
64 done = 1; 64 done = 1;
65 } 65 }
66 66
67 int 67 int
68 main (int argc, char *argv[]) 68 main(int argc, char *argv[])
69 { 69 {
70 int i, n; 70 int i, n;
71 71
72 /* Print available audio drivers */ 72 /* Print available audio drivers */
73 n = SDL_GetNumAudioDrivers (); 73 n = SDL_GetNumAudioDrivers();
74 if (n == 0) { 74 if (n == 0) {
75 printf ("No built-in audio drivers\n"); 75 printf("No built-in audio drivers\n");
76 } else { 76 } else {
77 printf ("Built-in audio drivers:"); 77 printf("Built-in audio drivers:");
78 for (i = 0; i < n; ++i) { 78 for (i = 0; i < n; ++i) {
79 if (i > 0) { 79 if (i > 0) {
80 printf (","); 80 printf(",");
81 } 81 }
82 printf (" %s", SDL_GetAudioDriver (i)); 82 printf(" %s", SDL_GetAudioDriver(i));
83 } 83 }
84 printf ("\n"); 84 printf("\n");
85 } 85 }
86 86
87 /* Load the SDL library */ 87 /* Load the SDL library */
88 if (SDL_Init (SDL_INIT_AUDIO) < 0) { 88 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
89 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 89 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
90 return (1); 90 return (1);
91 } 91 }
92 if (argv[1] == NULL) { 92 if (argv[1] == NULL) {
93 argv[1] = "sample.wav"; 93 argv[1] = "sample.wav";
94 } 94 }
95 /* Load the wave file into memory */ 95 /* Load the wave file into memory */
96 if (SDL_LoadWAV (argv[1], 96 if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
97 &wave.spec, &wave.sound, &wave.soundlen) == NULL) { 97 fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
98 fprintf (stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError ()); 98 quit(1);
99 quit (1);
100 } 99 }
101 100
102 wave.spec.callback = fillerup; 101 wave.spec.callback = fillerup;
103 #if HAVE_SIGNAL_H 102 #if HAVE_SIGNAL_H
104 /* Set the signals */ 103 /* Set the signals */
105 #ifdef SIGHUP 104 #ifdef SIGHUP
106 signal (SIGHUP, poked); 105 signal(SIGHUP, poked);
107 #endif 106 #endif
108 signal (SIGINT, poked); 107 signal(SIGINT, poked);
109 #ifdef SIGQUIT 108 #ifdef SIGQUIT
110 signal (SIGQUIT, poked); 109 signal(SIGQUIT, poked);
111 #endif 110 #endif
112 signal (SIGTERM, poked); 111 signal(SIGTERM, poked);
113 #endif /* HAVE_SIGNAL_H */ 112 #endif /* HAVE_SIGNAL_H */
114 113
115 /* Initialize fillerup() variables */ 114 /* Initialize fillerup() variables */
116 if (SDL_OpenAudio (&wave.spec, NULL) < 0) { 115 if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
117 fprintf (stderr, "Couldn't open audio: %s\n", SDL_GetError ()); 116 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
118 SDL_FreeWAV (wave.sound); 117 SDL_FreeWAV(wave.sound);
119 quit (2); 118 quit(2);
120 } 119 }
121 SDL_PauseAudio (0); 120 SDL_PauseAudio(0);
122 121
123 /* Let the audio run */ 122 /* Let the audio run */
124 printf ("Using audio driver: %s\n", SDL_GetCurrentAudioDriver ()); 123 printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
125 while (!done && (SDL_GetAudioStatus () == SDL_AUDIO_PLAYING)) 124 while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
126 SDL_Delay (1000); 125 SDL_Delay(1000);
127 126
128 /* Clean up on signal */ 127 /* Clean up on signal */
129 SDL_CloseAudio (); 128 SDL_CloseAudio();
130 SDL_FreeWAV (wave.sound); 129 SDL_FreeWAV(wave.sound);
131 SDL_Quit (); 130 SDL_Quit();
132 return (0); 131 return (0);
133 } 132 }