comparison src/audio/arts/SDL_artsaudio.c @ 2060:866052b01ee5

indent is evil
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:48:03 +0000
parents 5f6550e5184f
children 85ed90a755fa
comparison
equal deleted inserted replaced
2059:4685ccd33d0e 2060:866052b01ee5
64 static struct 64 static struct
65 { 65 {
66 const char *name; 66 const char *name;
67 void **func; 67 void **func;
68 } arts_functions[] = { 68 } arts_functions[] = {
69 SDL_ARTS_SYM(arts_init), 69 SDL_ARTS_SYM(arts_init),
70 SDL_ARTS_SYM(arts_free), 70 SDL_ARTS_SYM(arts_free),
71 SDL_ARTS_SYM(arts_play_stream), 71 SDL_ARTS_SYM(arts_play_stream),
72 SDL_ARTS_SYM(arts_stream_set), 72 SDL_ARTS_SYM(arts_stream_set),
73 SDL_ARTS_SYM(arts_stream_get), 73 SDL_ARTS_SYM(arts_stream_get),
74 SDL_ARTS_SYM(arts_write), 74 SDL_ARTS_SYM(arts_write),
75 SDL_ARTS_SYM(arts_close_stream), 75 SDL_ARTS_SYM(arts_close_stream), SDL_ARTS_SYM(arts_error_text),};
76 SDL_ARTS_SYM(arts_error_text),
77 };
78 #undef SDL_ARTS_SYM 76 #undef SDL_ARTS_SYM
79 77
80 static void 78 static void
81 UnloadARTSLibrary() 79 UnloadARTSLibrary()
82 { 80 {
145 } 143 }
146 } 144 }
147 } 145 }
148 146
149 /* Use timer for general audio synchronization */ 147 /* Use timer for general audio synchronization */
150 ticks = ((Sint32) (this->hidden->next_frame-SDL_GetTicks())) - FUDGE_TICKS; 148 ticks =
149 ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
151 if (ticks > 0) { 150 if (ticks > 0) {
152 SDL_Delay(ticks); 151 SDL_Delay(ticks);
153 } 152 }
154 } 153 }
155 154
156 static void 155 static void
157 ARTS_PlayDevice(_THIS) 156 ARTS_PlayDevice(_THIS)
158 { 157 {
159 /* Write the audio data */ 158 /* Write the audio data */
160 int written = SDL_NAME(arts_write) ( 159 int written = SDL_NAME(arts_write) (this->hidden->stream,
161 this->hidden->stream, 160 this->hidden->mixbuf,
162 this->hidden->mixbuf, 161 this->hidden->mixlen);
163 this->hidden->mixlen);
164 162
165 /* If timer synchronization is enabled, set the next write frame */ 163 /* If timer synchronization is enabled, set the next write frame */
166 if (this->hidden->frame_ticks) { 164 if (this->hidden->frame_ticks) {
167 this->hidden->next_frame += this->hidden->frame_ticks; 165 this->hidden->next_frame += this->hidden->frame_ticks;
168 } 166 }
216 int bits = 0, frag_spec = 0; 214 int bits = 0, frag_spec = 0;
217 SDL_AudioFormat test_format = 0, format = 0; 215 SDL_AudioFormat test_format = 0, format = 0;
218 216
219 /* Initialize all variables that we clean on shutdown */ 217 /* Initialize all variables that we clean on shutdown */
220 this->hidden = (struct SDL_PrivateAudioData *) 218 this->hidden = (struct SDL_PrivateAudioData *)
221 SDL_malloc((sizeof *this->hidden)); 219 SDL_malloc((sizeof *this->hidden));
222 if (this->hidden == NULL) { 220 if (this->hidden == NULL) {
223 SDL_OutOfMemory(); 221 SDL_OutOfMemory();
224 return 0; 222 return 0;
225 } 223 }
226 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 224 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
255 } 253 }
256 this->spec.format = test_format; 254 this->spec.format = test_format;
257 255
258 if ((rc = SDL_NAME(arts_init) ()) != 0) { 256 if ((rc = SDL_NAME(arts_init) ()) != 0) {
259 ARTS_CloseDevice(this); 257 ARTS_CloseDevice(this);
260 SDL_SetError( "Unable to initialize ARTS: %s", 258 SDL_SetError("Unable to initialize ARTS: %s",
261 SDL_NAME(arts_error_text)(rc) ); 259 SDL_NAME(arts_error_text) (rc));
262 return 0; 260 return 0;
263 } 261 }
264 this->hidden->stream = SDL_NAME(arts_play_stream) ( 262 this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
265 this->spec.freq, 263 bits,
266 bits, this->spec.channels, 264 this->spec.channels,
267 "SDL"); 265 "SDL");
268 266
269 /* Calculate the final parameters for this audio specification */ 267 /* Calculate the final parameters for this audio specification */
270 SDL_CalculateAudioSpec(&this->spec); 268 SDL_CalculateAudioSpec(&this->spec);
271 269
272 /* Determine the power of two of the fragment size */ 270 /* Determine the power of two of the fragment size */
278 } 276 }
279 frag_spec |= 0x00020000; /* two fragments, for low latency */ 277 frag_spec |= 0x00020000; /* two fragments, for low latency */
280 278
281 #ifdef ARTS_P_PACKET_SETTINGS 279 #ifdef ARTS_P_PACKET_SETTINGS
282 SDL_NAME(arts_stream_set) (this->hidden->stream, 280 SDL_NAME(arts_stream_set) (this->hidden->stream,
283 ARTS_P_PACKET_SETTINGS, frag_spec); 281 ARTS_P_PACKET_SETTINGS, frag_spec);
284 #else 282 #else
285 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_SIZE, 283 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_SIZE,
286 frag_spec & 0xffff); 284 frag_spec & 0xffff);
287 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_COUNT, 285 SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_COUNT,
288 frag_spec >> 16); 286 frag_spec >> 16);
314 UnloadARTSLibrary(); 312 UnloadARTSLibrary();
315 } 313 }
316 314
317 315
318 static int 316 static int
319 ARTS_Init(SDL_AudioDriverImpl *impl) 317 ARTS_Init(SDL_AudioDriverImpl * impl)
320 { 318 {
321 if (LoadARTSLibrary() < 0) { 319 if (LoadARTSLibrary() < 0) {
322 return 0; 320 return 0;
323 } else { 321 } else {
324 if (SDL_NAME(arts_init) () != 0) { 322 if (SDL_NAME(arts_init) () != 0) {