Mercurial > sdl-ios-xcode
comparison src/audio/macosx/SDL_coreaudio.c @ 2060:866052b01ee5
indent is evil
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 28 Oct 2006 16:48:03 +0000 |
parents | c2fed8bb6700 |
children | 21942f552734 |
comparison
equal
deleted
inserted
replaced
2059:4685ccd33d0e | 2060:866052b01ee5 |
---|---|
41 static int inputDeviceCount = 0; | 41 static int inputDeviceCount = 0; |
42 static COREAUDIO_DeviceList *outputDevices = NULL; | 42 static COREAUDIO_DeviceList *outputDevices = NULL; |
43 static int outputDeviceCount = 0; | 43 static int outputDeviceCount = 0; |
44 | 44 |
45 static void | 45 static void |
46 free_device_list(COREAUDIO_DeviceList **devices, int *devCount) | 46 free_device_list(COREAUDIO_DeviceList ** devices, int *devCount) |
47 { | 47 { |
48 if (*devices) { | 48 if (*devices) { |
49 int i = *devCount; | 49 int i = *devCount; |
50 while (i--) | 50 while (i--) |
51 SDL_free((void *) (*devices)[i].name); | 51 SDL_free((void *) (*devices)[i].name); |
55 *devCount = 0; | 55 *devCount = 0; |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 static void | 59 static void |
60 build_device_list(int iscapture, COREAUDIO_DeviceList **devices, int *devCount) | 60 build_device_list(int iscapture, COREAUDIO_DeviceList ** devices, |
61 int *devCount) | |
61 { | 62 { |
62 Boolean outWritable = 0; | 63 Boolean outWritable = 0; |
63 OSStatus result = noErr; | 64 OSStatus result = noErr; |
64 UInt32 size = 0; | 65 UInt32 size = 0; |
65 AudioDeviceID *devs = NULL; | 66 AudioDeviceID *devs = NULL; |
67 UInt32 max = 0; | 68 UInt32 max = 0; |
68 | 69 |
69 free_device_list(devices, devCount); | 70 free_device_list(devices, devCount); |
70 | 71 |
71 result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, | 72 result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, |
72 &size, &outWritable); | 73 &size, &outWritable); |
73 | 74 |
74 if (result != kAudioHardwareNoError) | 75 if (result != kAudioHardwareNoError) |
75 return; | 76 return; |
76 | 77 |
77 devs = (AudioDeviceID *) alloca(size); | 78 devs = (AudioDeviceID *) alloca(size); |
78 if (devs == NULL) | 79 if (devs == NULL) |
79 return; | 80 return; |
80 | 81 |
81 max = size / sizeof (AudioDeviceID); | 82 max = size / sizeof(AudioDeviceID); |
82 *devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof (**devices)); | 83 *devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof(**devices)); |
83 if (*devices == NULL) | 84 if (*devices == NULL) |
84 return; | 85 return; |
85 | 86 |
86 result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, | 87 result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, |
87 &size, devs); | 88 &size, devs); |
88 if (result != kAudioHardwareNoError) | 89 if (result != kAudioHardwareNoError) |
89 return; | 90 return; |
90 | 91 |
91 for (i = 0; i < max; i++) { | 92 for (i = 0; i < max; i++) { |
92 CFStringRef cfstr = NULL; | 93 CFStringRef cfstr = NULL; |
95 AudioBufferList *buflist = NULL; | 96 AudioBufferList *buflist = NULL; |
96 int usable = 0; | 97 int usable = 0; |
97 CFIndex len = 0; | 98 CFIndex len = 0; |
98 | 99 |
99 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, | 100 result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, |
100 kAudioDevicePropertyStreamConfiguration, | 101 kAudioDevicePropertyStreamConfiguration, |
101 &size, &outWritable); | 102 &size, &outWritable); |
102 if (result != noErr) | 103 if (result != noErr) |
103 continue; | 104 continue; |
104 | 105 |
105 buflist = (AudioBufferList *) SDL_malloc(size); | 106 buflist = (AudioBufferList *) SDL_malloc(size); |
106 if (buflist == NULL) | 107 if (buflist == NULL) |
107 continue; | 108 continue; |
108 | 109 |
109 result = AudioDeviceGetProperty(dev, 0, iscapture, | 110 result = AudioDeviceGetProperty(dev, 0, iscapture, |
110 kAudioDevicePropertyStreamConfiguration, | 111 kAudioDevicePropertyStreamConfiguration, |
111 &size, buflist); | 112 &size, buflist); |
112 | 113 |
113 if (result == noErr) { | 114 if (result == noErr) { |
114 UInt32 j; | 115 UInt32 j; |
115 for (j = 0; j < buflist->mNumberBuffers; j++) { | 116 for (j = 0; j < buflist->mNumberBuffers; j++) { |
116 if (buflist->mBuffers[j].mNumberChannels > 0) { | 117 if (buflist->mBuffers[j].mNumberChannels > 0) { |
123 SDL_free(buflist); | 124 SDL_free(buflist); |
124 | 125 |
125 if (!usable) | 126 if (!usable) |
126 continue; | 127 continue; |
127 | 128 |
128 size = sizeof (CFStringRef); | 129 size = sizeof(CFStringRef); |
129 result = AudioDeviceGetProperty(dev, 0, iscapture, | 130 result = AudioDeviceGetProperty(dev, 0, iscapture, |
130 kAudioObjectPropertyName, | 131 kAudioObjectPropertyName, |
131 &size, &cfstr); | 132 &size, &cfstr); |
132 | 133 |
133 if (result != kAudioHardwareNoError) | 134 if (result != kAudioHardwareNoError) |
135 | 136 |
136 len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), | 137 len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), |
137 kCFStringEncodingUTF8); | 138 kCFStringEncodingUTF8); |
138 | 139 |
139 ptr = (char *) SDL_malloc(len + 1); | 140 ptr = (char *) SDL_malloc(len + 1); |
140 usable = ( (ptr != NULL) && | 141 usable = ((ptr != NULL) && |
141 (CFStringGetCString(cfstr,ptr,len+1,kCFStringEncodingUTF8)) ); | 142 (CFStringGetCString |
143 (cfstr, ptr, len + 1, kCFStringEncodingUTF8))); | |
142 | 144 |
143 CFRelease(cfstr); | 145 CFRelease(cfstr); |
144 | 146 |
145 if (usable) { | 147 if (usable) { |
146 len = strlen(ptr); | 148 len = strlen(ptr); |
147 /* Some devices have whitespace at the end...trim it. */ | 149 /* Some devices have whitespace at the end...trim it. */ |
148 while ((len > 0) && (ptr[len-1] == ' ')) { | 150 while ((len > 0) && (ptr[len - 1] == ' ')) { |
149 len--; | 151 len--; |
150 } | 152 } |
151 usable = (len > 0); | 153 usable = (len > 0); |
152 } | 154 } |
153 | 155 |
154 if (!usable) { | 156 if (!usable) { |
155 SDL_free(ptr); | 157 SDL_free(ptr); |
156 } else { | 158 } else { |
157 ptr[len] = '\0'; | 159 ptr[len] = '\0'; |
158 | 160 |
159 #if DEBUG_COREAUDIO | 161 #if DEBUG_COREAUDIO |
160 printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n", | 162 printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n", |
161 ((iscapture) ? "capture" : "output"), | 163 ((iscapture) ? "capture" : "output"), |
162 (int) *devCount, ptr, (int) dev); | 164 (int) *devCount, ptr, (int) dev); |
163 #endif | 165 #endif |
164 | 166 |
165 (*devices)[*devCount].id = dev; | 167 (*devices)[*devCount].id = dev; |
166 (*devices)[*devCount].name = ptr; | 168 (*devices)[*devCount].name = ptr; |
167 (*devCount)++; | 169 (*devCount)++; |
168 } | 170 } |
184 free_device_list(&inputDevices, &inputDeviceCount); | 186 free_device_list(&inputDevices, &inputDeviceCount); |
185 } | 187 } |
186 | 188 |
187 | 189 |
188 static int | 190 static int |
189 find_device_id(const char *devname, int iscapture, AudioDeviceID *id) | 191 find_device_id(const char *devname, int iscapture, AudioDeviceID * id) |
190 { | 192 { |
191 int i = ((iscapture) ? inputDeviceCount : outputDeviceCount); | 193 int i = ((iscapture) ? inputDeviceCount : outputDeviceCount); |
192 COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices); | 194 COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices); |
193 while (i--) { | 195 while (i--) { |
194 if (SDL_strcmp(devname, devs->name) == 0) { | 196 if (SDL_strcmp(devname, devs->name) == 0) { |
211 } else { | 213 } else { |
212 build_device_list(0, &outputDevices, &outputDeviceCount); | 214 build_device_list(0, &outputDevices, &outputDeviceCount); |
213 return outputDeviceCount; | 215 return outputDeviceCount; |
214 } | 216 } |
215 | 217 |
216 return 0; /* shouldn't ever hit this. */ | 218 return 0; /* shouldn't ever hit this. */ |
217 } | 219 } |
218 | 220 |
219 | 221 |
220 static const char * | 222 static const char * |
221 COREAUDIO_GetDeviceName(int index, int iscapture) | 223 COREAUDIO_GetDeviceName(int index, int iscapture) |
239 | 241 |
240 | 242 |
241 /* The CoreAudio callback */ | 243 /* The CoreAudio callback */ |
242 static OSStatus | 244 static OSStatus |
243 outputCallback(void *inRefCon, | 245 outputCallback(void *inRefCon, |
244 AudioUnitRenderActionFlags *ioActionFlags, | 246 AudioUnitRenderActionFlags * ioActionFlags, |
245 const AudioTimeStamp * inTimeStamp, | 247 const AudioTimeStamp * inTimeStamp, |
246 UInt32 inBusNumber, UInt32 inNumberFrames, | 248 UInt32 inBusNumber, UInt32 inNumberFrames, |
247 AudioBufferList *ioDataList) | 249 AudioBufferList * ioDataList) |
248 { | 250 { |
249 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; | 251 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; |
250 AudioBuffer *ioData = &ioDataList->mBuffers[0]; | 252 AudioBuffer *ioData = &ioDataList->mBuffers[0]; |
251 UInt32 remaining, len; | 253 UInt32 remaining, len; |
252 void *ptr; | 254 void *ptr; |
286 | 288 |
287 len = this->hidden->bufferSize - this->hidden->bufferOffset; | 289 len = this->hidden->bufferSize - this->hidden->bufferOffset; |
288 if (len > remaining) | 290 if (len > remaining) |
289 len = remaining; | 291 len = remaining; |
290 SDL_memcpy(ptr, | 292 SDL_memcpy(ptr, |
291 (char *) this->hidden->buffer + this->hidden->bufferOffset, | 293 (char *) this->hidden->buffer + this->hidden->bufferOffset, |
292 len); | 294 len); |
293 ptr = (char *) ptr + len; | 295 ptr = (char *) ptr + len; |
294 remaining -= len; | 296 remaining -= len; |
295 this->hidden->bufferOffset += len; | 297 this->hidden->bufferOffset += len; |
296 } | 298 } |
297 | 299 |
298 return 0; | 300 return 0; |
299 } | 301 } |
300 | 302 |
301 static OSStatus | 303 static OSStatus |
302 inputCallback(void *inRefCon, | 304 inputCallback(void *inRefCon, |
303 AudioUnitRenderActionFlags *ioActionFlags, | 305 AudioUnitRenderActionFlags * ioActionFlags, |
304 const AudioTimeStamp * inTimeStamp, | 306 const AudioTimeStamp * inTimeStamp, |
305 UInt32 inBusNumber, UInt32 inNumberFrames, | 307 UInt32 inBusNumber, UInt32 inNumberFrames, |
306 AudioBufferList *ioData) | 308 AudioBufferList * ioData) |
307 { | 309 { |
308 //err = AudioUnitRender(afr->fAudioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, afr->fAudioBuffer); | 310 //err = AudioUnitRender(afr->fAudioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, afr->fAudioBuffer); |
309 // !!! FIXME: write me! | 311 // !!! FIXME: write me! |
310 return noErr; | 312 return noErr; |
311 } | 313 } |
319 OSStatus result = noErr; | 321 OSStatus result = noErr; |
320 AURenderCallbackStruct callback; | 322 AURenderCallbackStruct callback; |
321 const AudioUnitElement output_bus = 0; | 323 const AudioUnitElement output_bus = 0; |
322 const AudioUnitElement input_bus = 1; | 324 const AudioUnitElement input_bus = 1; |
323 const int iscapture = this->iscapture; | 325 const int iscapture = this->iscapture; |
324 const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); | 326 const AudioUnitElement bus = |
325 const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : | 327 ((iscapture) ? input_bus : output_bus); |
326 kAudioUnitScope_Input); | 328 const AudioUnitScope scope = |
329 ((iscapture) ? kAudioUnitScope_Output : | |
330 kAudioUnitScope_Input); | |
327 | 331 |
328 /* stop processing the audio unit */ | 332 /* stop processing the audio unit */ |
329 result = AudioOutputUnitStop(this->hidden->audioUnit); | 333 result = AudioOutputUnitStop(this->hidden->audioUnit); |
330 | 334 |
331 /* Remove the input callback */ | 335 /* Remove the input callback */ |
332 SDL_memset(&callback, '\0', sizeof (AURenderCallbackStruct)); | 336 SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct)); |
333 result = AudioUnitSetProperty(this->hidden->audioUnit, | 337 result = AudioUnitSetProperty(this->hidden->audioUnit, |
334 kAudioUnitProperty_SetRenderCallback, | 338 kAudioUnitProperty_SetRenderCallback, |
335 scope, bus, &callback, | 339 scope, bus, &callback, |
336 sizeof (callback)); | 340 sizeof(callback)); |
337 | 341 |
338 CloseComponent(this->hidden->audioUnit); | 342 CloseComponent(this->hidden->audioUnit); |
339 this->hidden->audioUnitOpened = 0; | 343 this->hidden->audioUnitOpened = 0; |
340 } | 344 } |
341 SDL_free(this->hidden->buffer); | 345 SDL_free(this->hidden->buffer); |
360 UInt32 size = 0; | 364 UInt32 size = 0; |
361 UInt32 alive = 0; | 365 UInt32 alive = 0; |
362 pid_t pid = 0; | 366 pid_t pid = 0; |
363 | 367 |
364 if (devname == NULL) { | 368 if (devname == NULL) { |
365 size = sizeof (AudioDeviceID); | 369 size = sizeof(AudioDeviceID); |
366 const AudioHardwarePropertyID propid = | 370 const AudioHardwarePropertyID propid = |
367 ((iscapture) ? kAudioHardwarePropertyDefaultInputDevice : | 371 ((iscapture) ? kAudioHardwarePropertyDefaultInputDevice : |
368 kAudioHardwarePropertyDefaultOutputDevice); | 372 kAudioHardwarePropertyDefaultOutputDevice); |
369 | 373 |
370 result = AudioHardwareGetProperty(propid, &size, &devid); | 374 result = AudioHardwareGetProperty(propid, &size, &devid); |
371 CHECK_RESULT("AudioHardwareGetProperty (default device)"); | 375 CHECK_RESULT("AudioHardwareGetProperty (default device)"); |
372 } else { | 376 } else { |
373 if (!find_device_id(devname, iscapture, &devid)) { | 377 if (!find_device_id(devname, iscapture, &devid)) { |
374 SDL_SetError("CoreAudio: No such audio device."); | 378 SDL_SetError("CoreAudio: No such audio device."); |
375 return 0; | 379 return 0; |
376 } | 380 } |
377 } | 381 } |
378 | 382 |
379 size = sizeof (alive); | 383 size = sizeof(alive); |
380 result = AudioDeviceGetProperty(devid, 0, iscapture, | 384 result = AudioDeviceGetProperty(devid, 0, iscapture, |
381 kAudioDevicePropertyDeviceIsAlive, | 385 kAudioDevicePropertyDeviceIsAlive, |
382 &size, &alive); | 386 &size, &alive); |
383 CHECK_RESULT("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)"); | 387 CHECK_RESULT |
388 ("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)"); | |
384 | 389 |
385 if (!alive) { | 390 if (!alive) { |
386 SDL_SetError("CoreAudio: requested device exists, but isn't alive."); | 391 SDL_SetError("CoreAudio: requested device exists, but isn't alive."); |
387 return 0; | 392 return 0; |
388 } | 393 } |
389 | 394 |
390 size = sizeof (pid); | 395 size = sizeof(pid); |
391 result = AudioDeviceGetProperty(devid, 0, iscapture, | 396 result = AudioDeviceGetProperty(devid, 0, iscapture, |
392 kAudioDevicePropertyHogMode, &size, &pid); | 397 kAudioDevicePropertyHogMode, &size, &pid); |
393 | 398 |
394 /* some devices don't support this property, so errors are fine here. */ | 399 /* some devices don't support this property, so errors are fine here. */ |
395 if ((result == noErr) && (pid != -1)) { | 400 if ((result == noErr) && (pid != -1)) { |
402 } | 407 } |
403 | 408 |
404 | 409 |
405 static int | 410 static int |
406 prepare_audiounit(_THIS, const char *devname, int iscapture, | 411 prepare_audiounit(_THIS, const char *devname, int iscapture, |
407 const AudioStreamBasicDescription *strdesc) | 412 const AudioStreamBasicDescription * strdesc) |
408 { | 413 { |
409 OSStatus result = noErr; | 414 OSStatus result = noErr; |
410 AURenderCallbackStruct callback; | 415 AURenderCallbackStruct callback; |
411 ComponentDescription desc; | 416 ComponentDescription desc; |
412 Component comp = NULL; | 417 Component comp = NULL; |
414 UInt32 enableIO = 0; | 419 UInt32 enableIO = 0; |
415 const AudioUnitElement output_bus = 0; | 420 const AudioUnitElement output_bus = 0; |
416 const AudioUnitElement input_bus = 1; | 421 const AudioUnitElement input_bus = 1; |
417 const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); | 422 const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); |
418 const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : | 423 const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : |
419 kAudioUnitScope_Input); | 424 kAudioUnitScope_Input); |
420 | 425 |
421 if (!find_device_by_name(this, devname, iscapture)) { | 426 if (!find_device_by_name(this, devname, iscapture)) { |
422 SDL_SetError("Couldn't find requested CoreAudio device"); | 427 SDL_SetError("Couldn't find requested CoreAudio device"); |
423 return 0; | 428 return 0; |
424 } | 429 } |
443 // !!! FIXME: this is wrong? | 448 // !!! FIXME: this is wrong? |
444 enableIO = ((iscapture) ? 1 : 0); | 449 enableIO = ((iscapture) ? 1 : 0); |
445 result = AudioUnitSetProperty(this->hidden->audioUnit, | 450 result = AudioUnitSetProperty(this->hidden->audioUnit, |
446 kAudioOutputUnitProperty_EnableIO, | 451 kAudioOutputUnitProperty_EnableIO, |
447 kAudioUnitScope_Input, input_bus, | 452 kAudioUnitScope_Input, input_bus, |
448 &enableIO, sizeof (enableIO)); | 453 &enableIO, sizeof(enableIO)); |
449 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO input)"); | 454 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO input)"); |
450 | 455 |
451 // !!! FIXME: this is wrong? | 456 // !!! FIXME: this is wrong? |
452 enableIO = ((iscapture) ? 0 : 1); | 457 enableIO = ((iscapture) ? 0 : 1); |
453 result = AudioUnitSetProperty(this->hidden->audioUnit, | 458 result = AudioUnitSetProperty(this->hidden->audioUnit, |
454 kAudioOutputUnitProperty_EnableIO, | 459 kAudioOutputUnitProperty_EnableIO, |
455 kAudioUnitScope_Output, output_bus, | 460 kAudioUnitScope_Output, output_bus, |
456 &enableIO, sizeof (enableIO)); | 461 &enableIO, sizeof(enableIO)); |
457 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO output)"); | 462 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO output)"); |
458 | 463 |
459 result = AudioUnitSetProperty(this->hidden->audioUnit, | 464 result = AudioUnitSetProperty(this->hidden->audioUnit, |
460 kAudioOutputUnitProperty_CurrentDevice, | 465 kAudioOutputUnitProperty_CurrentDevice, |
461 kAudioUnitScope_Global, 0, | 466 kAudioUnitScope_Global, 0, |
462 &this->hidden->deviceID, | 467 &this->hidden->deviceID, |
463 sizeof (AudioDeviceID)); | 468 sizeof(AudioDeviceID)); |
464 CHECK_RESULT("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)"); | 469 CHECK_RESULT |
470 ("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)"); | |
465 | 471 |
466 /* Set the data format of the audio unit. */ | 472 /* Set the data format of the audio unit. */ |
467 result = AudioUnitSetProperty(this->hidden->audioUnit, | 473 result = AudioUnitSetProperty(this->hidden->audioUnit, |
468 kAudioUnitProperty_StreamFormat, | 474 kAudioUnitProperty_StreamFormat, |
469 scope, bus, strdesc, sizeof (*strdesc)); | 475 scope, bus, strdesc, sizeof(*strdesc)); |
470 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)"); | 476 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)"); |
471 | 477 |
472 /* Set the audio callback */ | 478 /* Set the audio callback */ |
473 SDL_memset(&callback, '\0', sizeof (AURenderCallbackStruct)); | 479 SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct)); |
474 callback.inputProc = ((iscapture) ? inputCallback : outputCallback); | 480 callback.inputProc = ((iscapture) ? inputCallback : outputCallback); |
475 callback.inputProcRefCon = this; | 481 callback.inputProcRefCon = this; |
476 result = AudioUnitSetProperty(this->hidden->audioUnit, | 482 result = AudioUnitSetProperty(this->hidden->audioUnit, |
477 kAudioUnitProperty_SetRenderCallback, | 483 kAudioUnitProperty_SetRenderCallback, |
478 scope, bus, &callback, sizeof (callback)); | 484 scope, bus, &callback, sizeof(callback)); |
479 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); | 485 CHECK_RESULT |
486 ("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); | |
480 | 487 |
481 /* Calculate the final parameters for this audio specification */ | 488 /* Calculate the final parameters for this audio specification */ |
482 SDL_CalculateAudioSpec(&this->spec); | 489 SDL_CalculateAudioSpec(&this->spec); |
483 | 490 |
484 /* Allocate a sample buffer */ | 491 /* Allocate a sample buffer */ |
504 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); | 511 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); |
505 int valid_datatype = 0; | 512 int valid_datatype = 0; |
506 | 513 |
507 /* Initialize all variables that we clean on shutdown */ | 514 /* Initialize all variables that we clean on shutdown */ |
508 this->hidden = (struct SDL_PrivateAudioData *) | 515 this->hidden = (struct SDL_PrivateAudioData *) |
509 SDL_malloc((sizeof *this->hidden)); | 516 SDL_malloc((sizeof *this->hidden)); |
510 if (this->hidden == NULL) { | 517 if (this->hidden == NULL) { |
511 SDL_OutOfMemory(); | 518 SDL_OutOfMemory(); |
512 return (0); | 519 return (0); |
513 } | 520 } |
514 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 521 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
559 strdesc.mBytesPerPacket = | 566 strdesc.mBytesPerPacket = |
560 strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; | 567 strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; |
561 | 568 |
562 if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { | 569 if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { |
563 COREAUDIO_CloseDevice(this); | 570 COREAUDIO_CloseDevice(this); |
564 return 0; /* prepare_audiounit() will call SDL_SetError()... */ | 571 return 0; /* prepare_audiounit() will call SDL_SetError()... */ |
565 } | 572 } |
566 | 573 |
567 return 1; /* good to go. */ | 574 return 1; /* good to go. */ |
568 } | 575 } |
569 | 576 |
570 static int | 577 static int |
571 COREAUDIO_Init(SDL_AudioDriverImpl *impl) | 578 COREAUDIO_Init(SDL_AudioDriverImpl * impl) |
572 { | 579 { |
573 /* Set the function pointers */ | 580 /* Set the function pointers */ |
574 impl->DetectDevices = COREAUDIO_DetectDevices; | 581 impl->DetectDevices = COREAUDIO_DetectDevices; |
575 impl->GetDeviceName = COREAUDIO_GetDeviceName; | 582 impl->GetDeviceName = COREAUDIO_GetDeviceName; |
576 impl->OpenDevice = COREAUDIO_OpenDevice; | 583 impl->OpenDevice = COREAUDIO_OpenDevice; |
577 impl->CloseDevice = COREAUDIO_CloseDevice; | 584 impl->CloseDevice = COREAUDIO_CloseDevice; |
578 impl->Deinitialize = COREAUDIO_Deinitialize; | 585 impl->Deinitialize = COREAUDIO_Deinitialize; |
579 impl->ProvidesOwnCallbackThread = 1; | 586 impl->ProvidesOwnCallbackThread = 1; |
580 | 587 |
581 build_device_lists(); /* do an initial check for devices... */ | 588 build_device_lists(); /* do an initial check for devices... */ |
582 | 589 |
583 return 1; | 590 return 1; |
584 } | 591 } |
585 | 592 |
586 AudioBootStrap COREAUDIO_bootstrap = { | 593 AudioBootStrap COREAUDIO_bootstrap = { |