comparison src/audio/bsd/SDL_bsdaudio.c @ 2060:866052b01ee5

indent is evil
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:48:03 +0000
parents 5f6550e5184f
children c66852194386
comparison
equal deleted inserted replaced
2059:4685ccd33d0e 2060:866052b01ee5
120 } else { 120 } else {
121 build_device_list(0, &outputDevices, &outputDeviceCount); 121 build_device_list(0, &outputDevices, &outputDeviceCount);
122 return outputDeviceCount; 122 return outputDeviceCount;
123 } 123 }
124 124
125 return 0; /* shouldn't ever hit this. */ 125 return 0; /* shouldn't ever hit this. */
126 } 126 }
127 127
128 static const char * 128 static const char *
129 BSDAUDIO_GetDeviceName(int index, int iscapture) 129 BSDAUDIO_GetDeviceName(int index, int iscapture)
130 { 130 {
147 147
148 if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) { 148 if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
149 fprintf(stderr, "AUDIO_GETINFO failed.\n"); 149 fprintf(stderr, "AUDIO_GETINFO failed.\n");
150 return; 150 return;
151 } 151 }
152 152 /* *INDENT-OFF* */
153 fprintf(stderr, "\n" 153 fprintf(stderr, "\n"
154 "[play/record info]\n" 154 "[play/record info]\n"
155 "buffer size : %d bytes\n" 155 "buffer size : %d bytes\n"
156 "sample rate : %i Hz\n" 156 "sample rate : %i Hz\n"
157 "channels : %i\n" 157 "channels : %i\n"
175 info.play.eof, 175 info.play.eof,
176 info.play.pause ? "yes" : "no", 176 info.play.pause ? "yes" : "no",
177 info.play.error ? "yes" : "no", 177 info.play.error ? "yes" : "no",
178 info.play.waiting ? "yes" : "no", 178 info.play.waiting ? "yes" : "no",
179 info.play.active ? "yes" : "no"); 179 info.play.active ? "yes" : "no");
180 180 /* *INDENT-ON* */
181
182 /* *INDENT-OFF* */
181 fprintf(stderr, "\n" 183 fprintf(stderr, "\n"
182 "[audio info]\n" 184 "[audio info]\n"
183 "monitor_gain : %i\n" 185 "monitor_gain : %i\n"
184 "hw block size : %d bytes\n" 186 "hw block size : %d bytes\n"
185 "hi watermark : %i\n" 187 "hi watermark : %i\n"
190 info.blocksize, 192 info.blocksize,
191 info.hiwat, info.lowat, 193 info.hiwat, info.lowat,
192 (info.mode == AUMODE_PLAY) ? "PLAY" 194 (info.mode == AUMODE_PLAY) ? "PLAY"
193 : (info.mode = AUMODE_RECORD) ? "RECORD" 195 : (info.mode = AUMODE_RECORD) ? "RECORD"
194 : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?")); 196 : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
197 /* *INDENT-ON* */
195 #endif /* DEBUG_AUDIO */ 198 #endif /* DEBUG_AUDIO */
196 } 199 }
197 200
198 201
199 /* This function waits until it is possible to write a full sound buffer */ 202 /* This function waits until it is possible to write a full sound buffer */
204 /* See if we need to use timed audio synchronization */ 207 /* See if we need to use timed audio synchronization */
205 if (this->hidden->frame_ticks) { 208 if (this->hidden->frame_ticks) {
206 /* Use timer for general audio synchronization */ 209 /* Use timer for general audio synchronization */
207 Sint32 ticks; 210 Sint32 ticks;
208 211
209 ticks = ((Sint32)(this->hidden->next_frame-SDL_GetTicks()))-FUDGE_TICKS; 212 ticks =
213 ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) -
214 FUDGE_TICKS;
210 if (ticks > 0) { 215 if (ticks > 0) {
211 SDL_Delay(ticks); 216 SDL_Delay(ticks);
212 } 217 }
213 } else { 218 } else {
214 /* Use select() for audio synchronization */ 219 /* Use select() for audio synchronization */
220 timeout.tv_sec = 10; 225 timeout.tv_sec = 10;
221 timeout.tv_usec = 0; 226 timeout.tv_usec = 0;
222 #ifdef DEBUG_AUDIO 227 #ifdef DEBUG_AUDIO
223 fprintf(stderr, "Waiting for audio to get ready\n"); 228 fprintf(stderr, "Waiting for audio to get ready\n");
224 #endif 229 #endif
225 if (select(this->hidden->audio_fd+1,NULL,&fdset,NULL,&timeout) <= 0) { 230 if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
231 <= 0) {
226 const char *message = 232 const char *message =
227 "Audio timeout - buggy audio driver? (disabled)"; 233 "Audio timeout - buggy audio driver? (disabled)";
228 /* In general we should never print to the screen, 234 /* In general we should never print to the screen,
229 but in this case we have no other way of letting 235 but in this case we have no other way of letting
230 the user know what happened. 236 the user know what happened.
250 int written, p = 0; 256 int written, p = 0;
251 257
252 /* Write the audio data, checking for EAGAIN on broken audio drivers */ 258 /* Write the audio data, checking for EAGAIN on broken audio drivers */
253 do { 259 do {
254 written = write(this->hidden->audio_fd, 260 written = write(this->hidden->audio_fd,
255 &this->hidden->mixbuf[p], 261 &this->hidden->mixbuf[p], this->hidden->mixlen - p);
256 this->hidden->mixlen - p);
257 262
258 if (written > 0) 263 if (written > 0)
259 p += written; 264 p += written;
260 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) { 265 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
261 /* Non recoverable error has occurred. It should be reported!!! */ 266 /* Non recoverable error has occurred. It should be reported!!! */
315 audio_info_t info; 320 audio_info_t info;
316 321
317 /* We don't care what the devname is...we'll try to open anything. */ 322 /* We don't care what the devname is...we'll try to open anything. */
318 /* ...but default to first name in the list... */ 323 /* ...but default to first name in the list... */
319 if (devname == NULL) { 324 if (devname == NULL) {
320 if ( ((iscapture) && (inputDeviceCount == 0)) || 325 if (((iscapture) && (inputDeviceCount == 0)) ||
321 ((!iscapture) && (outputDeviceCount == 0)) ) { 326 ((!iscapture) && (outputDeviceCount == 0))) {
322 SDL_SetError("No such audio device"); 327 SDL_SetError("No such audio device");
323 return 0; 328 return 0;
324 } 329 }
325 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]); 330 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
326 } 331 }
327 332
328 /* Initialize all variables that we clean on shutdown */ 333 /* Initialize all variables that we clean on shutdown */
329 this->hidden = (struct SDL_PrivateAudioData *) 334 this->hidden = (struct SDL_PrivateAudioData *)
330 SDL_malloc((sizeof *this->hidden)); 335 SDL_malloc((sizeof *this->hidden));
331 if (this->hidden == NULL) { 336 if (this->hidden == NULL) {
332 SDL_OutOfMemory(); 337 SDL_OutOfMemory();
333 return 0; 338 return 0;
334 } 339 }
335 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 340 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
427 /* We're ready to rock and roll. :-) */ 432 /* We're ready to rock and roll. :-) */
428 return (0); 433 return (0);
429 } 434 }
430 435
431 static int 436 static int
432 BSDAUDIO_Init(SDL_AudioDriverImpl *impl) 437 BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
433 { 438 {
434 /* Set the function pointers */ 439 /* Set the function pointers */
435 impl->DetectDevices = BSDAUDIO_DetectDevices; 440 impl->DetectDevices = BSDAUDIO_DetectDevices;
436 impl->GetDeviceName = BSDAUDIO_GetDeviceName; 441 impl->GetDeviceName = BSDAUDIO_GetDeviceName;
437 impl->OpenDevice = BSDAUDIO_OpenDevice; 442 impl->OpenDevice = BSDAUDIO_OpenDevice;