diff --git a/gambatte_qt/src/framework/framework.pro b/gambatte_qt/src/framework/framework.pro index cbde9edc..b443165b 100644 --- a/gambatte_qt/src/framework/framework.pro +++ b/gambatte_qt/src/framework/framework.pro @@ -64,17 +64,16 @@ macx { framework/src/getfullmodetoggler_macx.cpp SOURCES += framework/src/SDL_Joystick/src/darwin/SDL_sysjoystick.c \ # framework/src/audioengines/openalengine.cpp \ - framework/src/audioengines/coreaudioengine.cpp \ + framework/src/audioengines/audiotoolboxengine.cpp \ framework/src/fullmodetogglers/quartztoggler.cpp HEADERS += framework/src/fullmodetogglers/quartztoggler.h # LIBS += -dead_strip LIBS += -framework IOKit \ - -framework CoreServices \ + -framework AudioToolbox \ -framework CoreFoundation \ -framework Carbon \ -framework ApplicationServices \ # -framework OpenAL \ - -framework AudioUnit } else:unix { DEFINES += PLATFORM_UNIX diff --git a/gambatte_qt/src/framework/src/addaudioengines_macx.cpp b/gambatte_qt/src/framework/src/addaudioengines_macx.cpp index 841a82f1..b3f90b87 100644 --- a/gambatte_qt/src/framework/src/addaudioengines_macx.cpp +++ b/gambatte_qt/src/framework/src/addaudioengines_macx.cpp @@ -18,9 +18,9 @@ #include "addaudioengines.h" //#include "audioengines/openalengine.h" -#include "audioengines/coreaudioengine.h" +#include "audioengines/audiotoolboxengine.h" void addAudioEngines(auto_vector &audioEngines, WId /*winId*/) { - audioEngines.push_back(new CoreAudioEngine); + audioEngines.push_back(new AudioToolboxEngine); // audioEngines.push_back(createOpenAlEngine().release()); } diff --git a/gambatte_qt/src/framework/src/audioengines/coreaudioengine.cpp b/gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.cpp similarity index 76% rename from gambatte_qt/src/framework/src/audioengines/coreaudioengine.cpp rename to gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.cpp index e954aa90..badab397 100644 --- a/gambatte_qt/src/framework/src/audioengines/coreaudioengine.cpp +++ b/gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.cpp @@ -16,8 +16,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // -#include "coreaudioengine.h" -#include +#include "audiotoolboxengine.h" #include #include @@ -82,8 +81,8 @@ class MutexLocker : Uncopyable { } -CoreAudioEngine::CoreAudioEngine() -: AudioEngine("CoreAudio"), +AudioToolboxEngine::AudioToolboxEngine() +: AudioEngine("AudioToolbox"), outUnit(0), outUnitState(unit_closed), mutex(0), @@ -93,11 +92,11 @@ CoreAudioEngine::CoreAudioEngine() { } -CoreAudioEngine::~CoreAudioEngine() { +AudioToolboxEngine::~AudioToolboxEngine() { uninit(); } -std::size_t CoreAudioEngine::read( +std::size_t AudioToolboxEngine::read( void *const stream, std::size_t frames, Float64 const rateScalar) { MutexLocker mutlock(mutex); @@ -114,7 +113,7 @@ std::size_t CoreAudioEngine::read( return frames; } -OSStatus CoreAudioEngine::renderProc(void *refCon, +OSStatus AudioToolboxEngine::renderProc(void *refCon, AudioUnitRenderActionFlags *, AudioTimeStamp const *timeStamp, UInt32 /*busNumber*/, @@ -122,28 +121,29 @@ OSStatus CoreAudioEngine::renderProc(void *refCon, AudioBufferList *ioData) { ioData->mBuffers[0].mDataByteSize = - static_cast(refCon)->read(ioData->mBuffers[0].mData, + static_cast(refCon)->read(ioData->mBuffers[0].mData, numFrames, timeStamp->mRateScalar) * 4; return 0; } -long CoreAudioEngine::doInit(long const rate, int const latency, int const volume) { +long AudioToolboxEngine::doInit(long const rate, int const latency, int const volume) { { - ComponentDescription desc; + AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_DefaultOutput; desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentFlags = 0; desc.componentFlagsMask = 0; - Component comp; - if ((comp = FindNextComponent(0, &desc)) == 0) { + AudioComponent comp; + if ((comp = AudioComponentFindNext(nil, &desc)) == nil) { std::fprintf(stderr, "Failed to find output unit component\n"); return -1; } - if (ComponentResult err = OpenAComponent(comp, &outUnit)) { + OSStatus err = AudioComponentInstanceNew(comp, &outUnit); + if (err != noErr) { std::fprintf(stderr, "Failed to open output unit component: %d\n", static_cast(err)); return -1; @@ -152,7 +152,8 @@ long CoreAudioEngine::doInit(long const rate, int const latency, int const volum outUnitState = unit_opened; } - if (ComponentResult err = AudioUnitInitialize(outUnit)) { + OSStatus err = AudioUnitInitialize(outUnit); + if (err != noErr) { std::fprintf(stderr, "Failed to initialize output unit component: %d\n", static_cast(err)); return -1; @@ -172,9 +173,9 @@ long CoreAudioEngine::doInit(long const rate, int const latency, int const volum #ifdef WORDS_BIGENDIAN desc.mFormatFlags |= kAudioFormatFlagIsBigEndian; #endif - if (ComponentResult err = - AudioUnitSetProperty(outUnit, kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, 0, &desc, sizeof desc)) { + OSStatus err = AudioUnitSetProperty(outUnit, kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, 0, &desc, sizeof desc); + if (err != noErr) { std::fprintf(stderr, "Failed to set the input format: %d\n", static_cast(err)); return -1; @@ -182,9 +183,11 @@ long CoreAudioEngine::doInit(long const rate, int const latency, int const volum } { - if (ComponentResult err = - AudioUnitSetParameter(outUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, - pow(10, (log2(volume) - log2(100.0))/2.0), 0)) { + AudioUnitParameterValue param = pow(10, (log2(volume) - log2(100.0))/2.0); + OSStatus err = AudioUnitSetParameter(outUnit, kHALOutputParam_Volume, + kAudioUnitScope_Global, 0, + param, 0); + if (err != noErr) { std::fprintf(stderr, "Failed to set volume: %d\n", static_cast(err)); return -1; @@ -196,10 +199,10 @@ long CoreAudioEngine::doInit(long const rate, int const latency, int const volum renderCallback.inputProc = renderProc; renderCallback.inputProcRefCon = this; - if (ComponentResult err = - AudioUnitSetProperty(outUnit, kAudioUnitProperty_SetRenderCallback, - kAudioUnitScope_Input, 0, - &renderCallback, sizeof renderCallback)) { + OSStatus err = AudioUnitSetProperty(outUnit, kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, 0, + &renderCallback, sizeof renderCallback); + if (err != noErr) { std::fprintf(stderr, "Failed to set render callback: %d\n", static_cast(err)); return -1; @@ -222,11 +225,11 @@ long CoreAudioEngine::doInit(long const rate, int const latency, int const volum return rate; } -void CoreAudioEngine::uninit() { +void AudioToolboxEngine::uninit() { if (outUnitState >= unit_inited) AudioUnitUninitialize(outUnit); if (outUnitState >= unit_opened) - CloseComponent(outUnit); + AudioComponentInstanceDispose(outUnit); destroyMutex(mutex); destroyCond(availCond); @@ -235,16 +238,17 @@ void CoreAudioEngine::uninit() { rbuf.reset(0); } -void CoreAudioEngine::pause() { +void AudioToolboxEngine::pause() { if (running) { AudioOutputUnitStop(outUnit); running = false; } } -int CoreAudioEngine::doWrite(void *const buffer, std::size_t samples) { +int AudioToolboxEngine::doWrite(void *const buffer, std::size_t samples) { if (!running) { - if (ComponentResult err = AudioOutputUnitStart(outUnit)) { + OSStatus err = AudioOutputUnitStart(outUnit); + if (err != noErr) { std::fprintf(stderr, "Failed to start output unit: %d\n", static_cast(err)); return -1; @@ -266,7 +270,7 @@ int CoreAudioEngine::doWrite(void *const buffer, std::size_t samples) { return 0; } -int CoreAudioEngine::write( +int AudioToolboxEngine::write( void *buffer, std::size_t samples, BufferState &preBufState_out, long &rate_out) { MutexLocker mutlock(mutex); @@ -279,7 +283,7 @@ int CoreAudioEngine::write( return doWrite(buffer, samples); } -int CoreAudioEngine::write(void *buffer, std::size_t samples) { +int AudioToolboxEngine::write(void *buffer, std::size_t samples) { MutexLocker mutlock(mutex); if (mutlock.err) return -1; @@ -287,7 +291,7 @@ int CoreAudioEngine::write(void *buffer, std::size_t samples) { return doWrite(buffer, samples); } -AudioEngine::BufferState CoreAudioEngine::bufferState() const { +AudioEngine::BufferState AudioToolboxEngine::bufferState() const { MutexLocker mutlock(mutex); BufferState bstate = { 0, 0 }; bstate.fromUnderrun = rbuf.used() / 2; @@ -295,7 +299,7 @@ AudioEngine::BufferState CoreAudioEngine::bufferState() const { return bstate; } -long CoreAudioEngine::rateEstimate() const { +long AudioToolboxEngine::rateEstimate() const { MutexLocker mutlock(mutex); return rateEst + 0.5; } diff --git a/gambatte_qt/src/framework/src/audioengines/coreaudioengine.h b/gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.h similarity index 93% rename from gambatte_qt/src/framework/src/audioengines/coreaudioengine.h rename to gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.h index cc3c68b4..047856bb 100644 --- a/gambatte_qt/src/framework/src/audioengines/coreaudioengine.h +++ b/gambatte_qt/src/framework/src/audioengines/audiotoolboxengine.h @@ -21,13 +21,13 @@ #include "../audioengine.h" #include "ringbuffer.h" -#include +#include #include -class CoreAudioEngine : public AudioEngine { +class AudioToolboxEngine : public AudioEngine { public: - CoreAudioEngine(); - virtual ~CoreAudioEngine(); + AudioToolboxEngine(); + virtual ~AudioToolboxEngine(); virtual void uninit(); virtual int write(void *buffer, std::size_t frames); virtual int write(void *buffer, std::size_t samples,