From 804b9e99f82d5672e7500d66f2f5d5de3e681e81 Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Thu, 24 Sep 2009 21:35:06 +0000 Subject: [PATCH] Add CoreAudio Backend, still needs a bit of work. Will cleanup AudioCommon.cpp, and finish off CoreAudioStream.cpp if I ever get running games working in Snow Leopard. Interpreter seems to run in to a spinlock, dunno why yet, and Jit just crashes out. Core problems is probably something I won't be able to fix git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4316 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/Src/AudioCommon.cpp | 3 + .../AudioCommon/Src/AudioCommonConfig.cpp | 2 +- .../Core/AudioCommon/Src/AudioCommonConfig.h | 1 + .../AudioCommon/Src/CoreAudioSoundStream.cpp | 88 +++++++++++++++++++ .../AudioCommon/Src/CoreAudioSoundStream.h | 58 ++++++++++++ Source/Core/AudioCommon/Src/SConscript | 4 + Source/Plugins/Plugin_DSP_HLE/Src/SConscript | 2 + Source/Plugins/Plugin_DSP_LLE/Src/SConscript | 2 +- 8 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp create mode 100644 Source/Core/AudioCommon/Src/CoreAudioSoundStream.h diff --git a/Source/Core/AudioCommon/Src/AudioCommon.cpp b/Source/Core/AudioCommon/Src/AudioCommon.cpp index f87e31a949..e5f2d45f3e 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommon.cpp @@ -21,6 +21,7 @@ #include "AOSoundStream.h" #include "AlsaSoundStream.h" #include "NullSoundStream.h" +#include "CoreAudioSoundStream.h" #include "OpenALStream.h" namespace AudioCommon @@ -32,6 +33,7 @@ namespace AudioCommon mixer = new CMixer(); std::string backend = ac_Config.sBackend; + if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid()) soundStream = new CoreAudioSound(mixer); if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd); if (backend == BACKEND_AOSOUND && AOSound::isValid()) soundStream = new AOSound(mixer); if (backend == BACKEND_OPENAL && OpenALStream::isValid()) soundStream = new OpenALStream(mixer); @@ -83,6 +85,7 @@ namespace AudioCommon { std::vector backends; + if (CoreAudioSound::isValid()) backends.push_back(BACKEND_COREAUDIO); if (DSound::isValid()) backends.push_back(BACKEND_DIRECTSOUND); if (AOSound::isValid()) backends.push_back(BACKEND_AOSOUND); if (OpenALStream::isValid()) backends.push_back(BACKEND_OPENAL); diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp index ff1216f131..bce356d7bf 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp @@ -27,7 +27,7 @@ void AudioCommonConfig::Load(IniFile &file) { file.Get("Config", "Backend", &sBackend, "DSound"); #elif defined(__APPLE__) std::string temp; - file.Get("Config", "Backend", &temp, "AOSound"); + file.Get("Config", "Backend", &temp, "CoreAudio"); strncpy(sBackend, temp.c_str(), 128); #else file.Get("Config", "Backend", &sBackend, "AOSound"); diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.h b/Source/Core/AudioCommon/Src/AudioCommonConfig.h index b1932762af..1d4ad4a0e1 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.h +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.h @@ -22,6 +22,7 @@ #include "IniFile.h" // Backend Types +#define BACKEND_COREAUDIO "CoreAudio" #define BACKEND_DIRECTSOUND "DSound" #define BACKEND_AOSOUND "AOSound" #define BACKEND_OPENAL "OpenAL" diff --git a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp new file mode 100644 index 0000000000..49c0af6f26 --- /dev/null +++ b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp @@ -0,0 +1,88 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "CoreAudioSoundStream.h" + + +AudioDeviceID outputDeviceId; +AudioStreamBasicDescription outputStreamBasicDescription; +AudioDeviceIOProcID outputProcId; +UInt32 outputBufferByteCount; + +static OSStatus outputIoProc(AudioDeviceID inDevice, const AudioTimeStamp *inNow,const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *inClientData) +{ + +} + +void CoreAudioSound::SoundLoop() +{ + CoreAudioInit(); + +} +CoreAudioSound::CoreAudioSound(CMixer *mixer) : SoundStream(mixer) +{ +} + +CoreAudioSound::~CoreAudioSound() +{ +} +bool CoreAudioSound::CoreAudioInit() +{ + + OSStatus status; + UInt32 size; + size = sizeof(outputDeviceId); + status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &outputDeviceId); + if (outputDeviceId == kAudioDeviceUnknown) { + printf("CoreAudioDevice Unknown\n"); + return false; + } + + size = sizeof(outputStreamBasicDescription); + status = AudioDeviceGetProperty(outputDeviceId, 0, false, kAudioDevicePropertyStreamFormat, &size, &outputStreamBasicDescription); + + size = sizeof(outputBufferByteCount); + + outputBufferByteCount = 8192; + status = AudioDeviceSetProperty(outputDeviceId, 0, 0, false, kAudioDevicePropertyBufferSize, size, &outputBufferByteCount); + + status = AudioDeviceGetProperty(outputDeviceId, 0, false, kAudioDevicePropertyBufferSize, &size, &outputBufferByteCount); + + + status = AudioDeviceCreateIOProcID( outputDeviceId, outputIoProc, NULL, &outputProcId ); + + return true; + +} + +bool CoreAudioSound::Start() +{ + AudioDeviceStart(outputDeviceId,outputProcId); + return true; +} + + +void CoreAudioSound::Stop() +{ + return; + +} +void CoreAudioSound::Update() +{ + return; + +} \ No newline at end of file diff --git a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h new file mode 100644 index 0000000000..b336708a4a --- /dev/null +++ b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h @@ -0,0 +1,58 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _COREAUDIO_SOUND_STREAM_H +#define _COREAUDIO_SOUND_STREAM_H + +#include "Common.h" +#include "SoundStream.h" +#if defined(__APPLE__) +#include +#endif + +#include "Thread.h" + +class CoreAudioSound : public SoundStream +{ +#if defined(__APPLE__) +public: + CoreAudioSound(CMixer *mixer); + virtual ~CoreAudioSound(); + + virtual bool Start(); + virtual void SoundLoop(); + virtual void Stop(); + + static bool isValid() { + return true; + } + virtual bool usesMixer() const { + return true; + } + + virtual void Update(); + +private: + bool CoreAudioInit(); +#else +public: + CoreAudioSound(CMixer *mixer) : SoundStream(mixer) {} +#endif +}; + +#endif + diff --git a/Source/Core/AudioCommon/Src/SConscript b/Source/Core/AudioCommon/Src/SConscript index 64b0e22810..a206f5b39b 100644 --- a/Source/Core/AudioCommon/Src/SConscript +++ b/Source/Core/AudioCommon/Src/SConscript @@ -2,6 +2,7 @@ # -*- python -*- Import('env') +import sys files = [ 'AudioCommonConfig.cpp', @@ -21,5 +22,8 @@ if acenv['HAVE_AO']: if acenv['HAVE_ALSA']: files += [ 'AlsaSoundStream.cpp' ] +if sys.platform == 'darwin': + files += [ 'CoreAudioSoundStream.cpp' ] + acenv['FRAMEWORKS'] = [ 'CoreAudio' ] acenv.StaticLibrary(env['local_libs'] + 'audiocommon', files) diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/SConscript b/Source/Plugins/Plugin_DSP_HLE/Src/SConscript index d31141e0d2..29bb11adbd 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/SConscript +++ b/Source/Plugins/Plugin_DSP_HLE/Src/SConscript @@ -42,5 +42,7 @@ dspenv.Append( CXXFLAGS = [ '-fPIC' ], LIBS = [ 'common', 'audiocommon' ], ) +if sys.platform == 'darwin': + dspenv['FRAMEWORKS'] = [ 'CoreAudio' ] dspenv.SharedLibrary(env['plugin_dir']+name, files) diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/SConscript b/Source/Plugins/Plugin_DSP_LLE/Src/SConscript index 9857ebc34b..aecae20ba0 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/SConscript +++ b/Source/Plugins/Plugin_DSP_LLE/Src/SConscript @@ -42,5 +42,5 @@ else: LIBS = [ 'dspcore', 'audiocommon', 'common' ], ) if sys.platform == 'darwin': - lleenv['FRAMEWORKS'] = ['CoreFoundation', 'System'] + lleenv['FRAMEWORKS'] = ['CoreFoundation', 'System', 'CoreAudio'] lleenv.SharedLibrary(env['plugin_dir']+name, files)