comparison src/audio/dma/SDL_dmaaudio.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
72 { 72 {
73 int caps = 0; 73 int caps = 0;
74 struct audio_buf_info info; 74 struct audio_buf_info info;
75 if ((ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) && 75 if ((ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) &&
76 (caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) && 76 (caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
77 (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0)) 77 (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0)) {
78 {
79 size_t len = info.fragstotal * info.fragsize; 78 size_t len = info.fragstotal * info.fragsize;
80 Uint8 *buf = (Uint8 *) mmap(NULL, len, PROT_WRITE, MAP_SHARED, fd, 0); 79 Uint8 *buf = (Uint8 *) mmap(NULL, len, PROT_WRITE, MAP_SHARED, fd, 0);
81 if (buf != MAP_FAILED) { 80 if (buf != MAP_FAILED) {
82 munmap(buf, len); 81 munmap(buf, len);
83 return 1; 82 return 1;
115 free_device_list(&outputDevices, &outputDeviceCount); 114 free_device_list(&outputDevices, &outputDeviceCount);
116 free_device_list(&inputDevices, &inputDeviceCount); 115 free_device_list(&inputDevices, &inputDeviceCount);
117 } 116 }
118 117
119 118
120 static void DMA_Deinitialize(void) 119 static void
120 DMA_Deinitialize(void)
121 { 121 {
122 free_device_lists(); 122 free_device_lists();
123 } 123 }
124 124
125 static int 125 static int
131 } else { 131 } else {
132 build_device_list(0, &outputDevices, &outputDeviceCount); 132 build_device_list(0, &outputDevices, &outputDeviceCount);
133 return outputDeviceCount; 133 return outputDeviceCount;
134 } 134 }
135 135
136 return 0; /* shouldn't ever hit this. */ 136 return 0; /* shouldn't ever hit this. */
137 } 137 }
138 138
139 139
140 static const char * 140 static const char *
141 DMA_GetDeviceName(int index, int iscapture) 141 DMA_GetDeviceName(int index, int iscapture)
238 struct audio_buf_info info; 238 struct audio_buf_info info;
239 239
240 /* We don't care what the devname is...we'll try to open anything. */ 240 /* We don't care what the devname is...we'll try to open anything. */
241 /* ...but default to first name in the list... */ 241 /* ...but default to first name in the list... */
242 if (devname == NULL) { 242 if (devname == NULL) {
243 if ( ((iscapture) && (inputDeviceCount == 0)) || 243 if (((iscapture) && (inputDeviceCount == 0)) ||
244 ((!iscapture) && (outputDeviceCount == 0)) ) { 244 ((!iscapture) && (outputDeviceCount == 0))) {
245 SDL_SetError("No such audio device"); 245 SDL_SetError("No such audio device");
246 return 0; 246 return 0;
247 } 247 }
248 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]); 248 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
249 } 249 }
250 250
251 /* Initialize all variables that we clean on shutdown */ 251 /* Initialize all variables that we clean on shutdown */
252 this->hidden = (struct SDL_PrivateAudioData *) 252 this->hidden = (struct SDL_PrivateAudioData *)
253 SDL_malloc((sizeof *this->hidden)); 253 SDL_malloc((sizeof *this->hidden));
254 if (this->hidden == NULL) { 254 if (this->hidden == NULL) {
255 SDL_OutOfMemory(); 255 SDL_OutOfMemory();
256 return 0; 256 return 0;
257 } 257 }
258 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 258 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
378 /* Check to see if we need to use select() workaround */ 378 /* Check to see if we need to use select() workaround */
379 { 379 {
380 char *workaround; 380 char *workaround;
381 workaround = SDL_getenv("SDL_DSP_NOSELECT"); 381 workaround = SDL_getenv("SDL_DSP_NOSELECT");
382 if (workaround) { 382 if (workaround) {
383 frame_ticks = (float) (this->spec.samples*1000) / this->spec.freq; 383 frame_ticks =
384 (float) (this->spec.samples * 1000) / this->spec.freq;
384 next_frame = SDL_GetTicks() + frame_ticks; 385 next_frame = SDL_GetTicks() + frame_ticks;
385 } 386 }
386 } 387 }
387 388
388 /* Trigger audio playback */ 389 /* Trigger audio playback */
509 return (dma_buf + (filling * this->spec.size)); 510 return (dma_buf + (filling * this->spec.size));
510 } 511 }
511 512
512 513
513 static int 514 static int
514 DMA_Init(SDL_AudioDriverImpl *impl) 515 DMA_Init(SDL_AudioDriverImpl * impl)
515 { 516 {
516 /* Set the function pointers */ 517 /* Set the function pointers */
517 impl->DetectDevices = DMA_DetectDevices; 518 impl->DetectDevices = DMA_DetectDevices;
518 impl->GetDeviceName = DMA_GetDeviceName; 519 impl->GetDeviceName = DMA_GetDeviceName;
519 impl->OpenDevice = DMA_OpenDevice; 520 impl->OpenDevice = DMA_OpenDevice;