Mercurial > sdl-ios-xcode
comparison src/audio/macosx/SDL_coreaudio.c @ 3617:023aa9699baa
Merged r4713:4714 from branches/SDL-1.2: CoreAudio 64-bit & Snow Leopard fixes.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 06 Jan 2010 20:31:21 +0000 |
parents | af4a5af3cd2b |
children | e474a820daeb |
comparison
equal
deleted
inserted
replaced
3616:0aaa7f52d1c6 | 3617:023aa9699baa |
---|---|
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include <CoreAudio/CoreAudio.h> | 24 #include <CoreAudio/CoreAudio.h> |
25 #include <CoreServices/CoreServices.h> | 25 #include <CoreServices/CoreServices.h> |
26 #include <AudioUnit/AudioUnit.h> | 26 #include <AudioUnit/AudioUnit.h> |
27 #if MAC_OS_X_VERSION_MAX_ALLOWED == 1050 | 27 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050 |
28 #include <AudioUnit/AUNTComponent.h> | 28 #include <AudioUnit/AUNTComponent.h> |
29 #endif | 29 #endif |
30 | 30 |
31 #include "SDL_audio.h" | 31 #include "SDL_audio.h" |
32 #include "../SDL_audio_c.h" | 32 #include "../SDL_audio_c.h" |
248 static OSStatus | 248 static OSStatus |
249 outputCallback(void *inRefCon, | 249 outputCallback(void *inRefCon, |
250 AudioUnitRenderActionFlags * ioActionFlags, | 250 AudioUnitRenderActionFlags * ioActionFlags, |
251 const AudioTimeStamp * inTimeStamp, | 251 const AudioTimeStamp * inTimeStamp, |
252 UInt32 inBusNumber, UInt32 inNumberFrames, | 252 UInt32 inBusNumber, UInt32 inNumberFrames, |
253 AudioBufferList * ioDataList) | 253 AudioBufferList * ioData) |
254 { | 254 { |
255 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; | 255 SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; |
256 AudioBuffer *ioData = &ioDataList->mBuffers[0]; | 256 AudioBuffer *abuf; |
257 UInt32 remaining, len; | 257 UInt32 remaining, len; |
258 void *ptr; | 258 void *ptr; |
259 UInt32 i; | |
259 | 260 |
260 /* Is there ever more than one buffer, and what do you do with it? */ | 261 /* Is there ever more than one buffer, and what do you do with it? */ |
261 if (ioDataList->mNumberBuffers != 1) { | 262 if (ioDataList->mNumberBuffers != 1) { |
262 return noErr; | 263 return noErr; |
263 } | 264 } |
264 | 265 |
265 /* Only do anything if audio is enabled and not paused */ | 266 /* Only do anything if audio is enabled and not paused */ |
266 if (!this->enabled || this->paused) { | 267 if (!this->enabled || this->paused) { |
267 SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize); | 268 for (i = 0; i < ioData->mNumberBuffers; i++) { |
269 abuf = &ioData->mBuffers[i]; | |
270 SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize); | |
271 } | |
268 return 0; | 272 return 0; |
269 } | 273 } |
270 | 274 |
271 /* No SDL conversion should be needed here, ever, since we accept | 275 /* No SDL conversion should be needed here, ever, since we accept |
272 any input format in OpenAudio, and leave the conversion to CoreAudio. | 276 any input format in OpenAudio, and leave the conversion to CoreAudio. |
274 /* | 278 /* |
275 assert(!this->convert.needed); | 279 assert(!this->convert.needed); |
276 assert(this->spec.channels == ioData->mNumberChannels); | 280 assert(this->spec.channels == ioData->mNumberChannels); |
277 */ | 281 */ |
278 | 282 |
279 remaining = ioData->mDataByteSize; | 283 for (i = 0; i < ioData->mNumberBuffers; i++) { |
280 ptr = ioData->mData; | 284 abuf = &ioData->mBuffers[i]; |
281 while (remaining > 0) { | 285 remaining = abuf->mDataByteSize; |
282 if (this->hidden->bufferOffset >= this->hidden->bufferSize) { | 286 ptr = abuf->mData; |
283 /* Generate the data */ | 287 while (remaining > 0) { |
284 SDL_memset(this->hidden->buffer, this->spec.silence, | 288 if (bufferOffset >= bufferSize) { |
285 this->hidden->bufferSize); | 289 /* Generate the data */ |
286 SDL_mutexP(this->mixer_lock); | 290 SDL_memset(buffer, this->spec.silence, bufferSize); |
287 (*this->spec.callback) (this->spec.userdata, this->hidden->buffer, | 291 SDL_mutexP(this->mixer_lock); |
288 this->hidden->bufferSize); | 292 (*this->spec.callback)(this->spec.userdata, |
289 SDL_mutexV(this->mixer_lock); | 293 buffer, bufferSize); |
290 this->hidden->bufferOffset = 0; | 294 SDL_mutexV(this->mixer_lock); |
291 } | 295 bufferOffset = 0; |
292 | 296 } |
293 len = this->hidden->bufferSize - this->hidden->bufferOffset; | 297 |
294 if (len > remaining) | 298 len = bufferSize - bufferOffset; |
295 len = remaining; | 299 if (len > remaining) |
296 SDL_memcpy(ptr, | 300 len = remaining; |
297 (char *) this->hidden->buffer + this->hidden->bufferOffset, | 301 SDL_memcpy(ptr, (char *)buffer + bufferOffset, len); |
298 len); | 302 ptr = (char *)ptr + len; |
299 ptr = (char *) ptr + len; | 303 remaining -= len; |
300 remaining -= len; | 304 bufferOffset += len; |
301 this->hidden->bufferOffset += len; | 305 } |
302 } | 306 } |
303 | 307 |
304 return 0; | 308 return 0; |
305 } | 309 } |
306 | 310 |
431 return 0; | 435 return 0; |
432 } | 436 } |
433 | 437 |
434 SDL_memset(&desc, '\0', sizeof(ComponentDescription)); | 438 SDL_memset(&desc, '\0', sizeof(ComponentDescription)); |
435 desc.componentType = kAudioUnitType_Output; | 439 desc.componentType = kAudioUnitType_Output; |
436 desc.componentSubType = kAudioUnitSubType_HALOutput; | 440 desc.componentSubType = kAudioUnitSubType_DefaultOutput; |
437 desc.componentManufacturer = kAudioUnitManufacturer_Apple; | 441 desc.componentManufacturer = kAudioUnitManufacturer_Apple; |
438 | 442 |
439 comp = FindNextComponent(NULL, &desc); | 443 comp = FindNextComponent(NULL, &desc); |
440 if (comp == NULL) { | 444 if (comp == NULL) { |
441 SDL_SetError("Couldn't find requested CoreAudio component"); | 445 SDL_SetError("Couldn't find requested CoreAudio component"); |
484 callback.inputProcRefCon = this; | 488 callback.inputProcRefCon = this; |
485 result = AudioUnitSetProperty(this->hidden->audioUnit, | 489 result = AudioUnitSetProperty(this->hidden->audioUnit, |
486 kAudioUnitProperty_SetRenderCallback, | 490 kAudioUnitProperty_SetRenderCallback, |
487 scope, bus, &callback, sizeof(callback)); | 491 scope, bus, &callback, sizeof(callback)); |
488 CHECK_RESULT | 492 CHECK_RESULT |
489 ("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); | 493 ("AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback)"); |
490 | 494 |
491 /* Calculate the final parameters for this audio specification */ | 495 /* Calculate the final parameters for this audio specification */ |
492 SDL_CalculateAudioSpec(&this->spec); | 496 SDL_CalculateAudioSpec(&this->spec); |
493 | 497 |
494 /* Allocate a sample buffer */ | 498 /* Allocate a sample buffer */ |