From c729b86c0045779f0020c17393a95e9c84722083 Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Sun, 2 Jan 2011 02:49:30 +0000 Subject: [PATCH] Audio volume slider support for OS X. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6720 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/Src/AudioCommon.cpp | 6 ----- .../Core/AudioCommon/Src/AudioCommonConfig.h | 2 +- .../AudioCommon/Src/CoreAudioSoundStream.cpp | 24 ++++++++++++------- .../AudioCommon/Src/CoreAudioSoundStream.h | 15 ++++++++---- .../Plugins/Plugin_DSP_HLE/Src/ConfigDlg.cpp | 2 +- .../Plugin_DSP_LLE/Src/DSPConfigDlgLLE.cpp | 4 ++-- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Source/Core/AudioCommon/Src/AudioCommon.cpp b/Source/Core/AudioCommon/Src/AudioCommon.cpp index 7bb1dfbd8d..20c025ecab 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommon.cpp @@ -22,9 +22,7 @@ #include "XAudio2Stream.h" #include "AOSoundStream.h" #include "AlsaSoundStream.h" -#ifdef __APPLE__ #include "CoreAudioSoundStream.h" -#endif #include "OpenALStream.h" #include "PulseAudioStream.h" @@ -49,10 +47,8 @@ namespace AudioCommon soundStream = new AOSound(mixer); else if (backend == BACKEND_ALSA && AlsaSound::isValid()) soundStream = new AlsaSound(mixer); -#ifdef __APPLE__ else if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid()) soundStream = new CoreAudioSound(mixer); -#endif else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid()) soundStream = new PulseAudio(mixer); @@ -109,10 +105,8 @@ namespace AudioCommon backends.push_back(BACKEND_AOSOUND); if (AlsaSound::isValid()) backends.push_back(BACKEND_ALSA); -#ifdef __APPLE__ if (CoreAudioSound::isValid()) backends.push_back(BACKEND_COREAUDIO); -#endif if (PulseAudio::isValid()) backends.push_back(BACKEND_PULSEAUDIO); diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.h b/Source/Core/AudioCommon/Src/AudioCommonConfig.h index 524251bb86..46d9345f4a 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.h +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.h @@ -34,7 +34,7 @@ struct AudioCommonConfig { bool m_EnableDTKMusic; - bool m_EnableThrottle; + bool m_EnableThrottle; bool m_EnableJIT; int m_Volume; #ifdef __APPLE__ diff --git a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp index 131330c675..57e2e448ea 100644 --- a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.cpp @@ -112,6 +112,18 @@ bool CoreAudioSound::Start() return true; } +void CoreAudioSound::SetVolume(int volume) +{ + OSStatus err; + + err = AudioUnitSetParameter(audioUnit, + kHALOutputParam_Volume, + kAudioUnitParameterFlag_Output, 0, + volume / 100., 0); + if (err != noErr) + ERROR_LOG(AUDIO, "error setting volume"); +} + void CoreAudioSound::SoundLoop() { } @@ -121,22 +133,16 @@ void CoreAudioSound::Stop() OSStatus err; err = AudioOutputUnitStop(audioUnit); - if (err != noErr) { + if (err != noErr) ERROR_LOG(AUDIO, "error stopping audiounit"); - return; - } err = AudioUnitUninitialize(audioUnit); - if (err != noErr) { + if (err != noErr) ERROR_LOG(AUDIO, "error uninitializing audiounit"); - return; - } err = CloseComponent(audioUnit); - if (err != noErr) { + if (err != noErr) ERROR_LOG(AUDIO, "error closing audio component"); - return; - } } void CoreAudioSound::Update() diff --git a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h index c397e085ac..6a1b96a5a8 100644 --- a/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h +++ b/Source/Core/AudioCommon/Src/CoreAudioSoundStream.h @@ -18,23 +18,24 @@ #ifndef _COREAUDIO_SOUND_STREAM_H #define _COREAUDIO_SOUND_STREAM_H -#include +#ifdef __APPLE__ #include -#include +#endif -#include "Common.h" #include "SoundStream.h" class CoreAudioSound : public SoundStream { - ComponentDescription desc; - AudioUnit audioUnit; +#ifdef __APPLE__ + ComponentDescription desc; + AudioUnit audioUnit; public: CoreAudioSound(CMixer *mixer); virtual ~CoreAudioSound(); virtual bool Start(); + virtual void SetVolume(int volume); virtual void SoundLoop(); virtual void Stop(); @@ -48,6 +49,10 @@ public: virtual void Update(); void RenderSamples(void *target, UInt32 size); +#else +public: + CoreAudioSound(CMixer *mixer) : SoundStream(mixer) {} +#endif }; #endif diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/ConfigDlg.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/ConfigDlg.cpp index ab9d810b8b..7e95ef8de0 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/ConfigDlg.cpp @@ -78,7 +78,6 @@ DSPConfigDialogHLE::DSPConfigDialogHLE(wxWindow *parent, wxWindowID id, SetToolTip(wxT("Changing this will have no effect while the emulator is running!")); m_BackendSelection-> SetToolTip(wxT("Changing this will have no effect while the emulator is running!")); - m_volumeSlider->SetToolTip(wxT("This setting only affects DSound, OpenAL, XAudio2, and PulseAudio.")); // Create sizer and add items to dialog wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL); @@ -182,6 +181,7 @@ bool DSPConfigDialogHLE::SupportsVolumeChanges(std::string backend) // but getting the backend from string etc. is probably // too much just to enable/disable a stupid slider... return (backend == BACKEND_DIRECTSOUND || + backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2 || backend == BACKEND_PULSEAUDIO); diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/DSPConfigDlgLLE.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/DSPConfigDlgLLE.cpp index d9ad6c1189..df356b1288 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/DSPConfigDlgLLE.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/DSPConfigDlgLLE.cpp @@ -64,7 +64,6 @@ DSPConfigDialogLLE::DSPConfigDialogLLE(wxWindow *parent, wxWindowID id, const wx m_buttonEnableJIT->SetToolTip(wxT("Enables dynamic recompilation of DSP code.\n") wxT("Changing this will have no effect while the emulator is running!")); m_BackendSelection->SetToolTip(wxT("Changing this will have no effect while the emulator is running!")); - m_volumeSlider->SetToolTip(wxT("This setting only affects DSound, OpenAL, and PulseAudio.")); // Create sizer and add items to dialog wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL); @@ -151,7 +150,8 @@ bool DSPConfigDialogLLE::SupportsVolumeChanges(std::string backend) // but getting the backend from string etc. is probably // too much just to enable/disable a stupid slider... return (backend == BACKEND_DIRECTSOUND || - backend == BACKEND_OPENAL || + backend == BACKEND_COREAUDIO || + backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2 || backend == BACKEND_PULSEAUDIO); }