Commit ea2239b3 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Fixed CoreAudio to compile with Mac OS X 10.6 SDK and 64-bit targets.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%403797
parent 39abd7a2
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
#include <AudioUnit/AUNTComponent.h> #include <AudioUnit/AUNTComponent.h>
#endif #endif
...@@ -91,19 +93,25 @@ AudioBootStrap COREAUDIO_bootstrap = { ...@@ -91,19 +93,25 @@ AudioBootStrap COREAUDIO_bootstrap = {
}; };
/* The CoreAudio callback */ /* The CoreAudio callback */
static OSStatus audioCallback (void *inRefCon, static OSStatus audioCallback (void *inRefCon,
AudioUnitRenderActionFlags inActionFlags, AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp, const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber, UInt32 inBusNumber,
AudioBuffer *ioData) UInt32 inNumberFrames,
AudioBufferList *ioData)
{ {
SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon; SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon;
UInt32 remaining, len; UInt32 remaining, len;
AudioBuffer *abuf;
void *ptr; void *ptr;
UInt32 i;
/* Only do anything if audio is enabled and not paused */ /* Only do anything if audio is enabled and not paused */
if ( ! this->enabled || this->paused ) { if ( ! this->enabled || this->paused ) {
SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize); for (i = 0; i < ioData->mNumberBuffers; i++) {
abuf = &ioData->mBuffers[i];
SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
}
return 0; return 0;
} }
...@@ -114,29 +122,32 @@ static OSStatus audioCallback (void *inRefCon, ...@@ -114,29 +122,32 @@ static OSStatus audioCallback (void *inRefCon,
assert(!this->convert.needed); assert(!this->convert.needed);
assert(this->spec.channels == ioData->mNumberChannels); assert(this->spec.channels == ioData->mNumberChannels);
*/ */
remaining = ioData->mDataByteSize; for (i = 0; i < ioData->mNumberBuffers; i++) {
ptr = ioData->mData; abuf = &ioData->mBuffers[i];
while (remaining > 0) { remaining = abuf->mDataByteSize;
if (bufferOffset >= bufferSize) { ptr = abuf->mData;
/* Generate the data */ while (remaining > 0) {
SDL_memset(buffer, this->spec.silence, bufferSize); if (bufferOffset >= bufferSize) {
SDL_mutexP(this->mixer_lock); /* Generate the data */
(*this->spec.callback)(this->spec.userdata, SDL_memset(buffer, this->spec.silence, bufferSize);
buffer, bufferSize); SDL_mutexP(this->mixer_lock);
SDL_mutexV(this->mixer_lock); (*this->spec.callback)(this->spec.userdata,
bufferOffset = 0; buffer, bufferSize);
} SDL_mutexV(this->mixer_lock);
bufferOffset = 0;
}
len = bufferSize - bufferOffset; len = bufferSize - bufferOffset;
if (len > remaining) if (len > remaining)
len = remaining; len = remaining;
SDL_memcpy(ptr, (char *)buffer + bufferOffset, len); SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
ptr = (char *)ptr + len; ptr = (char *)ptr + len;
remaining -= len; remaining -= len;
bufferOffset += len; bufferOffset += len;
}
} }
return 0; return 0;
} }
...@@ -159,7 +170,7 @@ Uint8 *Core_GetAudioBuf(_THIS) ...@@ -159,7 +170,7 @@ Uint8 *Core_GetAudioBuf(_THIS)
void Core_CloseAudio(_THIS) void Core_CloseAudio(_THIS)
{ {
OSStatus result; OSStatus result;
struct AudioUnitInputCallback callback; struct AURenderCallbackStruct callback;
/* stop processing the audio unit */ /* stop processing the audio unit */
result = AudioOutputUnitStop (outputAudioUnit); result = AudioOutputUnitStop (outputAudioUnit);
...@@ -172,7 +183,7 @@ void Core_CloseAudio(_THIS) ...@@ -172,7 +183,7 @@ void Core_CloseAudio(_THIS)
callback.inputProc = 0; callback.inputProc = 0;
callback.inputProcRefCon = 0; callback.inputProcRefCon = 0;
result = AudioUnitSetProperty (outputAudioUnit, result = AudioUnitSetProperty (outputAudioUnit,
kAudioUnitProperty_SetInputCallback, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input, kAudioUnitScope_Input,
0, 0,
&callback, &callback,
...@@ -203,7 +214,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -203,7 +214,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
OSStatus result = noErr; OSStatus result = noErr;
Component comp; Component comp;
ComponentDescription desc; ComponentDescription desc;
struct AudioUnitInputCallback callback; struct AURenderCallbackStruct callback;
AudioStreamBasicDescription requestedDesc; AudioStreamBasicDescription requestedDesc;
/* Setup a AudioStreamBasicDescription with the requested format */ /* Setup a AudioStreamBasicDescription with the requested format */
...@@ -224,9 +235,9 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -224,9 +235,9 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
/* Locate the default output audio unit */ /* Locate the default output audio unit */
desc.componentType = kAudioUnitComponentType; desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_Output; desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitID_DefaultOutput; desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0; desc.componentFlags = 0;
desc.componentFlagsMask = 0; desc.componentFlagsMask = 0;
...@@ -256,7 +267,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -256,7 +267,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
callback.inputProc = audioCallback; callback.inputProc = audioCallback;
callback.inputProcRefCon = this; callback.inputProcRefCon = this;
result = AudioUnitSetProperty (outputAudioUnit, result = AudioUnitSetProperty (outputAudioUnit,
kAudioUnitProperty_SetInputCallback, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input, kAudioUnitScope_Input,
0, 0,
&callback, &callback,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment