comparison src/audio/esd/SDL_esdaudio.c @ 2060:866052b01ee5

indent is evil
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:48:03 +0000
parents 5f6550e5184f
children e27bdcc80744
comparison
equal deleted inserted replaced
2059:4685ccd33d0e 2060:866052b01ee5
59 static struct 59 static struct
60 { 60 {
61 const char *name; 61 const char *name;
62 void **func; 62 void **func;
63 } esd_functions[] = { 63 } esd_functions[] = {
64 SDL_ESD_SYM(esd_open_sound), 64 SDL_ESD_SYM(esd_open_sound),
65 SDL_ESD_SYM(esd_close), 65 SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),};
66 SDL_ESD_SYM(esd_play_stream),
67 };
68 #undef SDL_ESD_SYM 66 #undef SDL_ESD_SYM
69 67
70 static void 68 static void
71 UnloadESDLibrary() 69 UnloadESDLibrary()
72 { 70 {
135 } 133 }
136 } 134 }
137 } 135 }
138 136
139 /* Use timer for general audio synchronization */ 137 /* Use timer for general audio synchronization */
140 ticks = ((Sint32) (this->hidden->next_frame-SDL_GetTicks())) - FUDGE_TICKS; 138 ticks =
139 ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
141 if (ticks > 0) { 140 if (ticks > 0) {
142 SDL_Delay(ticks); 141 SDL_Delay(ticks);
143 } 142 }
144 } 143 }
145 144
149 int written = 0; 148 int written = 0;
150 149
151 /* Write the audio data, checking for EAGAIN on broken audio drivers */ 150 /* Write the audio data, checking for EAGAIN on broken audio drivers */
152 do { 151 do {
153 written = write(this->hidden->audio_fd, 152 written = write(this->hidden->audio_fd,
154 this->hidden->mixbuf, 153 this->hidden->mixbuf, this->hidden->mixlen);
155 this->hidden->mixlen);
156 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) { 154 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
157 SDL_Delay(1); /* Let a little CPU time go by */ 155 SDL_Delay(1); /* Let a little CPU time go by */
158 } 156 }
159 } 157 }
160 while ((written < 0) && 158 while ((written < 0) &&
227 SDL_AudioFormat test_format = 0; 225 SDL_AudioFormat test_format = 0;
228 int found = 0; 226 int found = 0;
229 227
230 /* Initialize all variables that we clean on shutdown */ 228 /* Initialize all variables that we clean on shutdown */
231 this->hidden = (struct SDL_PrivateAudioData *) 229 this->hidden = (struct SDL_PrivateAudioData *)
232 SDL_malloc((sizeof *this->hidden)); 230 SDL_malloc((sizeof *this->hidden));
233 if (this->hidden == NULL) { 231 if (this->hidden == NULL) {
234 SDL_OutOfMemory(); 232 SDL_OutOfMemory();
235 return 0; 233 return 0;
236 } 234 }
237 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 235 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
244 #ifdef DEBUG_AUDIO 242 #ifdef DEBUG_AUDIO
245 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); 243 fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
246 #endif 244 #endif
247 found = 1; 245 found = 1;
248 switch (test_format) { 246 switch (test_format) {
249 case AUDIO_U8: 247 case AUDIO_U8:
250 format |= ESD_BITS8; 248 format |= ESD_BITS8;
251 break; 249 break;
252 case AUDIO_S16SYS: 250 case AUDIO_S16SYS:
253 format |= ESD_BITS16; 251 format |= ESD_BITS16;
254 break; 252 break;
255 default: 253 default:
256 found = 0; 254 found = 0;
257 break; 255 break;
258 } 256 }
259 } 257 }
260 258
261 if (!found) { 259 if (!found) {
262 ESD_CloseDevice(this); 260 ESD_CloseDevice(this);
268 format |= ESD_MONO; 266 format |= ESD_MONO;
269 } else { 267 } else {
270 format |= ESD_STEREO; 268 format |= ESD_STEREO;
271 } 269 }
272 #if 0 270 #if 0
273 this->spec.samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ 271 this->spec.samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
274 #endif 272 #endif
275 273
276 /* Open a connection to the ESD audio server */ 274 /* Open a connection to the ESD audio server */
277 this->hidden->audio_fd = 275 this->hidden->audio_fd =
278 SDL_NAME(esd_play_stream)(format,this->spec.freq,NULL,get_progname()); 276 SDL_NAME(esd_play_stream) (format, this->spec.freq, NULL,
277 get_progname());
279 278
280 if (this->hidden->audio_fd < 0) { 279 if (this->hidden->audio_fd < 0) {
281 ESD_CloseDevice(this); 280 ESD_CloseDevice(this);
282 SDL_SetError("Couldn't open ESD connection"); 281 SDL_SetError("Couldn't open ESD connection");
283 return 0; 282 return 0;
284 } 283 }
285 284
286 /* Calculate the final parameters for this audio specification */ 285 /* Calculate the final parameters for this audio specification */
287 SDL_CalculateAudioSpec(&this->spec); 286 SDL_CalculateAudioSpec(&this->spec);
288 this->hidden->frame_ticks = (float) (this->spec.samples*1000) / this->spec.freq; 287 this->hidden->frame_ticks =
288 (float) (this->spec.samples * 1000) / this->spec.freq;
289 this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks; 289 this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
290 290
291 /* Allocate mixing buffer */ 291 /* Allocate mixing buffer */
292 this->hidden->mixlen = this->spec.size; 292 this->hidden->mixlen = this->spec.size;
293 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); 293 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
310 { 310 {
311 UnloadESDLibrary(); 311 UnloadESDLibrary();
312 } 312 }
313 313
314 static int 314 static int
315 ESD_Init(SDL_AudioDriverImpl *impl) 315 ESD_Init(SDL_AudioDriverImpl * impl)
316 { 316 {
317 if (LoadESDLibrary() < 0) { 317 if (LoadESDLibrary() < 0) {
318 return 0; 318 return 0;
319 } else { 319 } else {
320 int connection = 0; 320 int connection = 0;