From afef9fb5f03e202d398e22054561a6e3385f9e17 Mon Sep 17 00:00:00 2001 From: ayuanx Date: Sun, 13 Dec 2009 11:51:29 +0000 Subject: [PATCH] Code cleanup, removed extern declaration in sound streams git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4688 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/Src/AOSoundStream.cpp | 19 +---------------- Source/Core/AudioCommon/Src/AOSoundStream.h | 2 -- .../Core/AudioCommon/Src/AlsaSoundStream.cpp | 21 +++---------------- Source/Core/AudioCommon/Src/AlsaSoundStream.h | 3 +-- Source/Core/AudioCommon/Src/DSoundStream.cpp | 13 ++++++------ Source/Core/AudioCommon/Src/DSoundStream.h | 2 +- Source/Core/AudioCommon/Src/OpenALStream.cpp | 12 +++++------ Source/Core/AudioCommon/Src/OpenALStream.h | 7 +------ Source/Core/AudioCommon/Src/SoundStream.h | 6 +++--- Source/Plugins/Plugin_DSP_HLE/Src/main.cpp | 4 +--- Source/Plugins/Plugin_DSP_LLE/Src/main.cpp | 2 +- 11 files changed, 23 insertions(+), 68 deletions(-) diff --git a/Source/Core/AudioCommon/Src/AOSoundStream.cpp b/Source/Core/AudioCommon/Src/AOSoundStream.cpp index e09a4cff29..632bc450c8 100644 --- a/Source/Core/AudioCommon/Src/AOSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/AOSoundStream.cpp @@ -19,12 +19,9 @@ #include "AOSoundStream.h" #include "Mixer.h" -#include "../../../PluginSpecs/pluginspecs_dsp.h" #if defined(HAVE_AO) && HAVE_AO -extern DSPInitialize g_dspInitialize; - void AOSound::SoundLoop() { uint_32 numBytesToRender = 256; @@ -54,8 +51,7 @@ void AOSound::SoundLoop() { soundCriticalSection.Enter(); m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2); - if(!g_muted) - ao_play(device, (char*)realtimeBuffer, numBytesToRender); + ao_play(device, (char*)realtimeBuffer, numBytesToRender); soundCriticalSection.Leave(); if (! threadData) @@ -86,19 +82,6 @@ void AOSound::Update() soundSyncEvent.Set(); } -void AOSound::Clear() -{ - if(!*g_dspInitialize.pEmulatorState) - { - g_muted = false; - } - else - { - g_muted = true; - } - Update(); -} - void AOSound::Stop() { soundCriticalSection.Enter(); diff --git a/Source/Core/AudioCommon/Src/AOSoundStream.h b/Source/Core/AudioCommon/Src/AOSoundStream.h index dbe0a09471..afba7b363f 100644 --- a/Source/Core/AudioCommon/Src/AOSoundStream.h +++ b/Source/Core/AudioCommon/Src/AOSoundStream.h @@ -51,8 +51,6 @@ public: virtual void SoundLoop(); virtual void Stop(); - - virtual void Clear(); static bool isValid() { return true; diff --git a/Source/Core/AudioCommon/Src/AlsaSoundStream.cpp b/Source/Core/AudioCommon/Src/AlsaSoundStream.cpp index 3f74c4993c..60224ba3db 100644 --- a/Source/Core/AudioCommon/Src/AlsaSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/AlsaSoundStream.cpp @@ -17,14 +17,11 @@ #include "Common.h" #include "Thread.h" -#include "../../../PluginSpecs/pluginspecs_dsp.h" #include "AlsaSoundStream.h" #define BUFFER_SIZE 4096 #define BUFFER_SIZE_BYTES (BUFFER_SIZE*2*2) -extern DSPInitialize g_dspInitialize; - AlsaSound::AlsaSound(CMixer *mixer) : SoundStream(mixer), thread_data(0), handle(NULL) { mix_buffer = new u8[BUFFER_SIZE_BYTES]; @@ -55,18 +52,6 @@ void AlsaSound::Stop() thread = NULL; } -void AlsaSound::Clear() -{ - if(!*g_dspInitialize.pEmulatorState) - { - g_muted = false; - } - else - { - g_muted = true; - } -} - void AlsaSound::Update() { // don't need to do anything here. @@ -76,12 +61,12 @@ void AlsaSound::Update() void AlsaSound::SoundLoop() { AlsaInit(); + // nakee: What is the optimal value? + int frames_to_deliver = BUFFER_SIZE; while (!thread_data) { - // nakee: What is the optimal value? - int frames_to_deliver = 4096; m_mixer->Mix(reinterpret_cast(mix_buffer), frames_to_deliver); - int rc = g_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver); + int rc = m_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver); if (rc == -EPIPE) { // Underrun diff --git a/Source/Core/AudioCommon/Src/AlsaSoundStream.h b/Source/Core/AudioCommon/Src/AlsaSoundStream.h index 75f48541c1..cbb8d6f6f3 100644 --- a/Source/Core/AudioCommon/Src/AlsaSoundStream.h +++ b/Source/Core/AudioCommon/Src/AlsaSoundStream.h @@ -36,8 +36,7 @@ public: virtual bool Start(); virtual void SoundLoop(); - virtual void Stop(); - virtual void Clear(); + virtual void Stop(); static bool isValid() { return true; diff --git a/Source/Core/AudioCommon/Src/DSoundStream.cpp b/Source/Core/AudioCommon/Src/DSoundStream.cpp index 11911f4dcc..a51b3f9af5 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/DSoundStream.cpp @@ -18,10 +18,8 @@ #include #include #include +#include "AudioCommon.h" #include "DSoundStream.h" -#include "../../../PluginSpecs/pluginspecs_dsp.h" - -extern DSPInitialize g_dspInitialize; bool DSound::CreateBuffer() { @@ -169,15 +167,16 @@ void DSound::Update() soundSyncEvent.Set(); } -void DSound::Clear() +void DSound::Clear(bool mute) { - if(!*g_dspInitialize.pEmulatorState) + m_muted = mute; + if (m_muted) { - dsBuffer->Play(0, 0, DSBPLAY_LOOPING); + dsBuffer->Stop(); } else { - dsBuffer->Stop(); + dsBuffer->Play(0, 0, DSBPLAY_LOOPING); } } diff --git a/Source/Core/AudioCommon/Src/DSoundStream.h b/Source/Core/AudioCommon/Src/DSoundStream.h index cad273d268..9fd2aaf8bb 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.h +++ b/Source/Core/AudioCommon/Src/DSoundStream.h @@ -78,7 +78,7 @@ public: virtual void SoundLoop(); virtual void SetVolume(int volume); virtual void Stop(); - virtual void Clear(); + virtual void Clear(bool mute); static bool isValid() { return true; } virtual bool usesMixer() const { return true; } virtual void Update(); diff --git a/Source/Core/AudioCommon/Src/OpenALStream.cpp b/Source/Core/AudioCommon/Src/OpenALStream.cpp index 57d4bcaa17..908573719d 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.cpp +++ b/Source/Core/AudioCommon/Src/OpenALStream.cpp @@ -17,15 +17,12 @@ #include "aldlist.h" #include "OpenALStream.h" -#include "../../../PluginSpecs/pluginspecs_dsp.h" #if defined HAVE_OPENAL && HAVE_OPENAL #define AUDIO_NUMBUFFERS (4) //#define AUDIO_SERVICE_UPDATE_PERIOD (20) -extern DSPInitialize g_dspInitialize; - bool OpenALStream::Start() { ALDeviceList *pDeviceList = NULL; @@ -97,15 +94,16 @@ void OpenALStream::Update() } } -void OpenALStream::Clear() +void OpenALStream::Clear(bool mute) { - if(!*g_dspInitialize.pEmulatorState) + m_muted = mute; + if(m_muted) { - alSourcePlay(g_uiSource); + alSourceStop(g_uiSource); } else { - alSourceStop(g_uiSource); + alSourcePlay(g_uiSource); } } diff --git a/Source/Core/AudioCommon/Src/OpenALStream.h b/Source/Core/AudioCommon/Src/OpenALStream.h index 229af1226c..5e5d7d3463 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.h +++ b/Source/Core/AudioCommon/Src/OpenALStream.h @@ -22,7 +22,6 @@ #include "SoundStream.h" #include "Thread.h" - #if defined HAVE_OPENAL && HAVE_OPENAL #ifdef _WIN32 #include "../../../../Externals/OpenAL/include/al.h" @@ -39,7 +38,6 @@ #define OAL_BUFFER_SIZE 1024*1024 #endif - class OpenALStream: public SoundStream { #if defined HAVE_OPENAL && HAVE_OPENAL @@ -50,7 +48,7 @@ public: virtual bool Start(); virtual void SoundLoop(); virtual void Stop(); - virtual void Clear(); + virtual void Clear(bool mute); static bool isValid() { return true; } virtual bool usesMixer() const { return true; } virtual void Update(); @@ -70,7 +68,4 @@ public: #endif // HAVE_OPENAL }; - - - #endif // OPENALSTREAM diff --git a/Source/Core/AudioCommon/Src/SoundStream.h b/Source/Core/AudioCommon/Src/SoundStream.h index 111eaecc06..e07d41078d 100644 --- a/Source/Core/AudioCommon/Src/SoundStream.h +++ b/Source/Core/AudioCommon/Src/SoundStream.h @@ -32,10 +32,10 @@ protected: volatile int threadData; bool m_logAudio; WaveFileWriter g_wave_writer; - bool g_muted; + bool m_muted; public: - SoundStream(CMixer *mixer) : m_mixer(mixer), threadData(0), g_muted(false) {} + SoundStream(CMixer *mixer) : m_mixer(mixer), threadData(0), m_muted(false) {} virtual ~SoundStream() { delete m_mixer;} static bool isValid() { return false; } @@ -45,7 +45,7 @@ public: virtual void SoundLoop() {} virtual void Stop() {} virtual void Update() {} - virtual void Clear() {} + virtual void Clear(bool mute) { m_muted = mute; } virtual void StartLogAudio(const char *filename) { if (! m_logAudio) { m_logAudio = true; diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp index 963b8e643f..9821a58601 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/main.cpp @@ -205,8 +205,6 @@ void Initialize(void *init) { g_dspInitialize = *(DSPInitialize*)init; - g_bMuted = false; - g_Config.Load(); g_pMemory = g_dspInitialize.pGetMemoryPointer(0); @@ -367,5 +365,5 @@ void DSP_SendAIBuffer(unsigned int address, int sample_rate) void DSP_ClearAudioBuffer() { if (soundStream) - soundStream->Clear(); + soundStream->Clear(*g_dspInitialize.pEmulatorState); } diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp index 4028320c9e..42f6c74162 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp @@ -370,6 +370,6 @@ void DSP_SendAIBuffer(unsigned int address, int sample_rate) void DSP_ClearAudioBuffer() { if(soundStream) - soundStream->Clear(); + soundStream->Clear(*g_dspInitialize.pEmulatorState); }