Merged r4713:4714 from branches/SDL-1.2: CoreAudio 64-bit & Snow Leopard fixes.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 06 Jan 2010 20:31:21 +0000
changeset 3617023aa9699baa
parent 3616 0aaa7f52d1c6
child 3618 276a6474a449
Merged r4713:4714 from branches/SDL-1.2: CoreAudio 64-bit & Snow Leopard fixes.
src/audio/macosx/SDL_coreaudio.c
     1.1 --- a/src/audio/macosx/SDL_coreaudio.c	Wed Jan 06 20:17:35 2010 +0000
     1.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Wed Jan 06 20:31:21 2010 +0000
     1.3 @@ -24,7 +24,7 @@
     1.4  #include <CoreAudio/CoreAudio.h>
     1.5  #include <CoreServices/CoreServices.h>
     1.6  #include <AudioUnit/AudioUnit.h>
     1.7 -#if MAC_OS_X_VERSION_MAX_ALLOWED == 1050
     1.8 +#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
     1.9  #include <AudioUnit/AUNTComponent.h>
    1.10  #endif
    1.11  
    1.12 @@ -250,12 +250,13 @@
    1.13                 AudioUnitRenderActionFlags * ioActionFlags,
    1.14                 const AudioTimeStamp * inTimeStamp,
    1.15                 UInt32 inBusNumber, UInt32 inNumberFrames,
    1.16 -               AudioBufferList * ioDataList)
    1.17 +               AudioBufferList * ioData)
    1.18  {
    1.19      SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
    1.20 -    AudioBuffer *ioData = &ioDataList->mBuffers[0];
    1.21 +    AudioBuffer *abuf;
    1.22      UInt32 remaining, len;
    1.23      void *ptr;
    1.24 +    UInt32 i;
    1.25  
    1.26      /* Is there ever more than one buffer, and what do you do with it? */
    1.27      if (ioDataList->mNumberBuffers != 1) {
    1.28 @@ -264,7 +265,10 @@
    1.29  
    1.30      /* Only do anything if audio is enabled and not paused */
    1.31      if (!this->enabled || this->paused) {
    1.32 -        SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
    1.33 +        for (i = 0; i < ioData->mNumberBuffers; i++) {
    1.34 +            abuf = &ioData->mBuffers[i];
    1.35 +            SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
    1.36 +        }
    1.37          return 0;
    1.38      }
    1.39  
    1.40 @@ -276,29 +280,29 @@
    1.41         assert(this->spec.channels == ioData->mNumberChannels);
    1.42       */
    1.43  
    1.44 -    remaining = ioData->mDataByteSize;
    1.45 -    ptr = ioData->mData;
    1.46 -    while (remaining > 0) {
    1.47 -        if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
    1.48 -            /* Generate the data */
    1.49 -            SDL_memset(this->hidden->buffer, this->spec.silence,
    1.50 -                       this->hidden->bufferSize);
    1.51 -            SDL_mutexP(this->mixer_lock);
    1.52 -            (*this->spec.callback) (this->spec.userdata, this->hidden->buffer,
    1.53 -                                    this->hidden->bufferSize);
    1.54 -            SDL_mutexV(this->mixer_lock);
    1.55 -            this->hidden->bufferOffset = 0;
    1.56 +    for (i = 0; i < ioData->mNumberBuffers; i++) {
    1.57 +        abuf = &ioData->mBuffers[i];
    1.58 +        remaining = abuf->mDataByteSize;
    1.59 +        ptr = abuf->mData;
    1.60 +        while (remaining > 0) {
    1.61 +            if (bufferOffset >= bufferSize) {
    1.62 +                /* Generate the data */
    1.63 +                SDL_memset(buffer, this->spec.silence, bufferSize);
    1.64 +                SDL_mutexP(this->mixer_lock);
    1.65 +                (*this->spec.callback)(this->spec.userdata,
    1.66 +                            buffer, bufferSize);
    1.67 +                SDL_mutexV(this->mixer_lock);
    1.68 +                bufferOffset = 0;
    1.69 +            }
    1.70 +
    1.71 +            len = bufferSize - bufferOffset;
    1.72 +            if (len > remaining)
    1.73 +                len = remaining;
    1.74 +            SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
    1.75 +            ptr = (char *)ptr + len;
    1.76 +            remaining -= len;
    1.77 +            bufferOffset += len;
    1.78          }
    1.79 -
    1.80 -        len = this->hidden->bufferSize - this->hidden->bufferOffset;
    1.81 -        if (len > remaining)
    1.82 -            len = remaining;
    1.83 -        SDL_memcpy(ptr,
    1.84 -                   (char *) this->hidden->buffer + this->hidden->bufferOffset,
    1.85 -                   len);
    1.86 -        ptr = (char *) ptr + len;
    1.87 -        remaining -= len;
    1.88 -        this->hidden->bufferOffset += len;
    1.89      }
    1.90  
    1.91      return 0;
    1.92 @@ -433,7 +437,7 @@
    1.93  
    1.94      SDL_memset(&desc, '\0', sizeof(ComponentDescription));
    1.95      desc.componentType = kAudioUnitType_Output;
    1.96 -    desc.componentSubType = kAudioUnitSubType_HALOutput;
    1.97 +    desc.componentSubType = kAudioUnitSubType_DefaultOutput;
    1.98      desc.componentManufacturer = kAudioUnitManufacturer_Apple;
    1.99  
   1.100      comp = FindNextComponent(NULL, &desc);
   1.101 @@ -486,7 +490,7 @@
   1.102                                    kAudioUnitProperty_SetRenderCallback,
   1.103                                    scope, bus, &callback, sizeof(callback));
   1.104      CHECK_RESULT
   1.105 -        ("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
   1.106 +        ("AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback)");
   1.107  
   1.108      /* Calculate the final parameters for this audio specification */
   1.109      SDL_CalculateAudioSpec(&this->spec);