Fixed CoreAudio to compile with Mac OS X 10.6 SDK and 64-bit targets. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Sat, 12 Sep 2009 15:04:32 +0000
branchSDL-1.2
changeset 418995213cf5efcc
parent 4188 9701c96e2cbb
child 4190 386181851388
Fixed CoreAudio to compile with Mac OS X 10.6 SDK and 64-bit targets.
src/audio/macosx/SDL_coreaudio.c
     1.1 --- a/src/audio/macosx/SDL_coreaudio.c	Sat Sep 12 14:05:39 2009 +0000
     1.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Sat Sep 12 15:04:32 2009 +0000
     1.3 @@ -21,8 +21,10 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 +#include <CoreAudio/CoreAudio.h>
     1.8 +#include <CoreServices/CoreServices.h>
     1.9  #include <AudioUnit/AudioUnit.h>
    1.10 -#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
    1.11 +#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
    1.12  #include <AudioUnit/AUNTComponent.h>
    1.13  #endif
    1.14  
    1.15 @@ -91,19 +93,25 @@
    1.16  };
    1.17  
    1.18  /* The CoreAudio callback */
    1.19 -static OSStatus     audioCallback (void                             *inRefCon, 
    1.20 -                                    AudioUnitRenderActionFlags      inActionFlags,
    1.21 -                                    const AudioTimeStamp            *inTimeStamp, 
    1.22 -                                    UInt32                          inBusNumber, 
    1.23 -                                    AudioBuffer                     *ioData)
    1.24 +static OSStatus     audioCallback (void                            *inRefCon,
    1.25 +                                   AudioUnitRenderActionFlags      *ioActionFlags,
    1.26 +                                   const AudioTimeStamp            *inTimeStamp,
    1.27 +                                   UInt32                          inBusNumber,
    1.28 +                                   UInt32                          inNumberFrames,
    1.29 +                                   AudioBufferList                 *ioData)
    1.30  {
    1.31      SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon;
    1.32      UInt32 remaining, len;
    1.33 +    AudioBuffer *abuf;
    1.34      void *ptr;
    1.35 +    UInt32 i;
    1.36  
    1.37      /* Only do anything if audio is enabled and not paused */
    1.38      if ( ! this->enabled || this->paused ) {
    1.39 -        SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
    1.40 +        for (i = 0; i < ioData->mNumberBuffers; i++) {
    1.41 +            abuf = &ioData->mBuffers[i];
    1.42 +            SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
    1.43 +        }
    1.44          return 0;
    1.45      }
    1.46      
    1.47 @@ -114,29 +122,32 @@
    1.48      assert(!this->convert.needed);
    1.49      assert(this->spec.channels == ioData->mNumberChannels);
    1.50       */
    1.51 -    
    1.52 -    remaining = ioData->mDataByteSize;
    1.53 -    ptr = ioData->mData;
    1.54 -    while (remaining > 0) {
    1.55 -        if (bufferOffset >= bufferSize) {
    1.56 -            /* Generate the data */
    1.57 -            SDL_memset(buffer, this->spec.silence, bufferSize);
    1.58 -            SDL_mutexP(this->mixer_lock);
    1.59 -            (*this->spec.callback)(this->spec.userdata,
    1.60 -                        buffer, bufferSize);
    1.61 -            SDL_mutexV(this->mixer_lock);
    1.62 -            bufferOffset = 0;
    1.63 +
    1.64 +    for (i = 0; i < ioData->mNumberBuffers; i++) {
    1.65 +        abuf = &ioData->mBuffers[i];
    1.66 +        remaining = abuf->mDataByteSize;
    1.67 +        ptr = abuf->mData;
    1.68 +        while (remaining > 0) {
    1.69 +            if (bufferOffset >= bufferSize) {
    1.70 +                /* Generate the data */
    1.71 +                SDL_memset(buffer, this->spec.silence, bufferSize);
    1.72 +                SDL_mutexP(this->mixer_lock);
    1.73 +                (*this->spec.callback)(this->spec.userdata,
    1.74 +                            buffer, bufferSize);
    1.75 +                SDL_mutexV(this->mixer_lock);
    1.76 +                bufferOffset = 0;
    1.77 +            }
    1.78 +        
    1.79 +            len = bufferSize - bufferOffset;
    1.80 +            if (len > remaining)
    1.81 +                len = remaining;
    1.82 +            SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
    1.83 +            ptr = (char *)ptr + len;
    1.84 +            remaining -= len;
    1.85 +            bufferOffset += len;
    1.86          }
    1.87 -        
    1.88 -        len = bufferSize - bufferOffset;
    1.89 -        if (len > remaining)
    1.90 -            len = remaining;
    1.91 -        SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
    1.92 -        ptr = (char *)ptr + len;
    1.93 -        remaining -= len;
    1.94 -        bufferOffset += len;
    1.95      }
    1.96 -    
    1.97 +
    1.98      return 0;
    1.99  }
   1.100  
   1.101 @@ -159,7 +170,7 @@
   1.102  void Core_CloseAudio(_THIS)
   1.103  {
   1.104      OSStatus result;
   1.105 -    struct AudioUnitInputCallback callback;
   1.106 +    struct AURenderCallbackStruct callback;
   1.107  
   1.108      /* stop processing the audio unit */
   1.109      result = AudioOutputUnitStop (outputAudioUnit);
   1.110 @@ -172,7 +183,7 @@
   1.111      callback.inputProc = 0;
   1.112      callback.inputProcRefCon = 0;
   1.113      result = AudioUnitSetProperty (outputAudioUnit, 
   1.114 -                        kAudioUnitProperty_SetInputCallback, 
   1.115 +                        kAudioUnitProperty_SetRenderCallback,
   1.116                          kAudioUnitScope_Input, 
   1.117                          0,
   1.118                          &callback, 
   1.119 @@ -203,7 +214,7 @@
   1.120      OSStatus result = noErr;
   1.121      Component comp;
   1.122      ComponentDescription desc;
   1.123 -    struct AudioUnitInputCallback callback;
   1.124 +    struct AURenderCallbackStruct callback;
   1.125      AudioStreamBasicDescription requestedDesc;
   1.126  
   1.127      /* Setup a AudioStreamBasicDescription with the requested format */
   1.128 @@ -224,9 +235,9 @@
   1.129  
   1.130  
   1.131      /* Locate the default output audio unit */
   1.132 -    desc.componentType = kAudioUnitComponentType;
   1.133 -    desc.componentSubType = kAudioUnitSubType_Output;
   1.134 -    desc.componentManufacturer = kAudioUnitID_DefaultOutput;
   1.135 +    desc.componentType = kAudioUnitType_Output;
   1.136 +    desc.componentSubType = kAudioUnitSubType_DefaultOutput;
   1.137 +    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
   1.138      desc.componentFlags = 0;
   1.139      desc.componentFlagsMask = 0;
   1.140      
   1.141 @@ -256,7 +267,7 @@
   1.142      callback.inputProc = audioCallback;
   1.143      callback.inputProcRefCon = this;
   1.144      result = AudioUnitSetProperty (outputAudioUnit, 
   1.145 -                        kAudioUnitProperty_SetInputCallback, 
   1.146 +                        kAudioUnitProperty_SetRenderCallback,
   1.147                          kAudioUnitScope_Input, 
   1.148                          0,
   1.149                          &callback,