Code cleanup, removed extern declaration in sound streams

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4688 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2009-12-13 11:51:29 +00:00
parent 4fe3e46725
commit afef9fb5f0
11 changed files with 23 additions and 68 deletions

View File

@ -19,12 +19,9 @@
#include "AOSoundStream.h" #include "AOSoundStream.h"
#include "Mixer.h" #include "Mixer.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h"
#if defined(HAVE_AO) && HAVE_AO #if defined(HAVE_AO) && HAVE_AO
extern DSPInitialize g_dspInitialize;
void AOSound::SoundLoop() void AOSound::SoundLoop()
{ {
uint_32 numBytesToRender = 256; uint_32 numBytesToRender = 256;
@ -54,8 +51,7 @@ void AOSound::SoundLoop()
{ {
soundCriticalSection.Enter(); soundCriticalSection.Enter();
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2); m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
if(!g_muted) ao_play(device, (char*)realtimeBuffer, numBytesToRender);
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
soundCriticalSection.Leave(); soundCriticalSection.Leave();
if (! threadData) if (! threadData)
@ -86,19 +82,6 @@ void AOSound::Update()
soundSyncEvent.Set(); soundSyncEvent.Set();
} }
void AOSound::Clear()
{
if(!*g_dspInitialize.pEmulatorState)
{
g_muted = false;
}
else
{
g_muted = true;
}
Update();
}
void AOSound::Stop() void AOSound::Stop()
{ {
soundCriticalSection.Enter(); soundCriticalSection.Enter();

View File

@ -52,8 +52,6 @@ public:
virtual void Stop(); virtual void Stop();
virtual void Clear();
static bool isValid() { static bool isValid() {
return true; return true;
} }

View File

@ -17,14 +17,11 @@
#include "Common.h" #include "Common.h"
#include "Thread.h" #include "Thread.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h"
#include "AlsaSoundStream.h" #include "AlsaSoundStream.h"
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
#define BUFFER_SIZE_BYTES (BUFFER_SIZE*2*2) #define BUFFER_SIZE_BYTES (BUFFER_SIZE*2*2)
extern DSPInitialize g_dspInitialize;
AlsaSound::AlsaSound(CMixer *mixer) : SoundStream(mixer), thread_data(0), handle(NULL) AlsaSound::AlsaSound(CMixer *mixer) : SoundStream(mixer), thread_data(0), handle(NULL)
{ {
mix_buffer = new u8[BUFFER_SIZE_BYTES]; mix_buffer = new u8[BUFFER_SIZE_BYTES];
@ -55,18 +52,6 @@ void AlsaSound::Stop()
thread = NULL; thread = NULL;
} }
void AlsaSound::Clear()
{
if(!*g_dspInitialize.pEmulatorState)
{
g_muted = false;
}
else
{
g_muted = true;
}
}
void AlsaSound::Update() void AlsaSound::Update()
{ {
// don't need to do anything here. // don't need to do anything here.
@ -76,12 +61,12 @@ void AlsaSound::Update()
void AlsaSound::SoundLoop() void AlsaSound::SoundLoop()
{ {
AlsaInit(); AlsaInit();
// nakee: What is the optimal value?
int frames_to_deliver = BUFFER_SIZE;
while (!thread_data) while (!thread_data)
{ {
// nakee: What is the optimal value?
int frames_to_deliver = 4096;
m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver); m_mixer->Mix(reinterpret_cast<short *>(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) if (rc == -EPIPE)
{ {
// Underrun // Underrun

View File

@ -37,7 +37,6 @@ public:
virtual bool Start(); virtual bool Start();
virtual void SoundLoop(); virtual void SoundLoop();
virtual void Stop(); virtual void Stop();
virtual void Clear();
static bool isValid() { static bool isValid() {
return true; return true;

View File

@ -18,10 +18,8 @@
#include <windows.h> #include <windows.h>
#include <cmath> #include <cmath>
#include <dxerr.h> #include <dxerr.h>
#include "AudioCommon.h"
#include "DSoundStream.h" #include "DSoundStream.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h"
extern DSPInitialize g_dspInitialize;
bool DSound::CreateBuffer() bool DSound::CreateBuffer()
{ {
@ -169,15 +167,16 @@ void DSound::Update()
soundSyncEvent.Set(); 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 else
{ {
dsBuffer->Stop(); dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
} }
} }

View File

@ -78,7 +78,7 @@ public:
virtual void SoundLoop(); virtual void SoundLoop();
virtual void SetVolume(int volume); virtual void SetVolume(int volume);
virtual void Stop(); virtual void Stop();
virtual void Clear(); virtual void Clear(bool mute);
static bool isValid() { return true; } static bool isValid() { return true; }
virtual bool usesMixer() const { return true; } virtual bool usesMixer() const { return true; }
virtual void Update(); virtual void Update();

View File

@ -17,15 +17,12 @@
#include "aldlist.h" #include "aldlist.h"
#include "OpenALStream.h" #include "OpenALStream.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h"
#if defined HAVE_OPENAL && HAVE_OPENAL #if defined HAVE_OPENAL && HAVE_OPENAL
#define AUDIO_NUMBUFFERS (4) #define AUDIO_NUMBUFFERS (4)
//#define AUDIO_SERVICE_UPDATE_PERIOD (20) //#define AUDIO_SERVICE_UPDATE_PERIOD (20)
extern DSPInitialize g_dspInitialize;
bool OpenALStream::Start() bool OpenALStream::Start()
{ {
ALDeviceList *pDeviceList = NULL; 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 else
{ {
alSourceStop(g_uiSource); alSourcePlay(g_uiSource);
} }
} }

View File

@ -22,7 +22,6 @@
#include "SoundStream.h" #include "SoundStream.h"
#include "Thread.h" #include "Thread.h"
#if defined HAVE_OPENAL && HAVE_OPENAL #if defined HAVE_OPENAL && HAVE_OPENAL
#ifdef _WIN32 #ifdef _WIN32
#include "../../../../Externals/OpenAL/include/al.h" #include "../../../../Externals/OpenAL/include/al.h"
@ -39,7 +38,6 @@
#define OAL_BUFFER_SIZE 1024*1024 #define OAL_BUFFER_SIZE 1024*1024
#endif #endif
class OpenALStream: public SoundStream class OpenALStream: public SoundStream
{ {
#if defined HAVE_OPENAL && HAVE_OPENAL #if defined HAVE_OPENAL && HAVE_OPENAL
@ -50,7 +48,7 @@ public:
virtual bool Start(); virtual bool Start();
virtual void SoundLoop(); virtual void SoundLoop();
virtual void Stop(); virtual void Stop();
virtual void Clear(); virtual void Clear(bool mute);
static bool isValid() { return true; } static bool isValid() { return true; }
virtual bool usesMixer() const { return true; } virtual bool usesMixer() const { return true; }
virtual void Update(); virtual void Update();
@ -70,7 +68,4 @@ public:
#endif // HAVE_OPENAL #endif // HAVE_OPENAL
}; };
#endif // OPENALSTREAM #endif // OPENALSTREAM

View File

@ -32,10 +32,10 @@ protected:
volatile int threadData; volatile int threadData;
bool m_logAudio; bool m_logAudio;
WaveFileWriter g_wave_writer; WaveFileWriter g_wave_writer;
bool g_muted; bool m_muted;
public: 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;} virtual ~SoundStream() { delete m_mixer;}
static bool isValid() { return false; } static bool isValid() { return false; }
@ -45,7 +45,7 @@ public:
virtual void SoundLoop() {} virtual void SoundLoop() {}
virtual void Stop() {} virtual void Stop() {}
virtual void Update() {} virtual void Update() {}
virtual void Clear() {} virtual void Clear(bool mute) { m_muted = mute; }
virtual void StartLogAudio(const char *filename) { virtual void StartLogAudio(const char *filename) {
if (! m_logAudio) { if (! m_logAudio) {
m_logAudio = true; m_logAudio = true;

View File

@ -205,8 +205,6 @@ void Initialize(void *init)
{ {
g_dspInitialize = *(DSPInitialize*)init; g_dspInitialize = *(DSPInitialize*)init;
g_bMuted = false;
g_Config.Load(); g_Config.Load();
g_pMemory = g_dspInitialize.pGetMemoryPointer(0); g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
@ -367,5 +365,5 @@ void DSP_SendAIBuffer(unsigned int address, int sample_rate)
void DSP_ClearAudioBuffer() void DSP_ClearAudioBuffer()
{ {
if (soundStream) if (soundStream)
soundStream->Clear(); soundStream->Clear(*g_dspInitialize.pEmulatorState);
} }

View File

@ -370,6 +370,6 @@ void DSP_SendAIBuffer(unsigned int address, int sample_rate)
void DSP_ClearAudioBuffer() void DSP_ClearAudioBuffer()
{ {
if(soundStream) if(soundStream)
soundStream->Clear(); soundStream->Clear(*g_dspInitialize.pEmulatorState);
} }