Fixed annoying sound when pausing/shutting down (please test for ALL backends) (couldn't do this for CoreAudio and PulseAudio too)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4676 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2009-12-10 21:00:52 +00:00
parent d901fd2e38
commit 6bea0a2f53
10 changed files with 67 additions and 3 deletions

View File

@ -51,7 +51,8 @@ void AOSound::SoundLoop()
{
soundCriticalSection.Enter();
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
if(!g_muted)
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
soundCriticalSection.Leave();
if (! threadData)
@ -105,4 +106,12 @@ AOSound::~AOSound() {
// FIXME: crashes dolphin
// ao_shutdown();
}
void AOSound::Mute(bool bMute) {
if((bMute && g_muted) || (!bMute && !g_muted))
return;
g_muted = bMute;
}
#endif

View File

@ -64,6 +64,8 @@ public:
virtual void Update();
virtual void Mute(bool bMute);
#else
public:
AOSound(CMixer *mixer) : SoundStream(mixer) {}

View File

@ -67,7 +67,7 @@ void AlsaSound::SoundLoop()
// nakee: What is the optimal value?
int frames_to_deliver = 4096;
m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver);
int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
int rc = g_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
if (rc == -EPIPE)
{
// Underrun
@ -180,6 +180,13 @@ bool AlsaSound::AlsaInit()
NOTICE_LOG(AUDIO, "ALSA successfully initialized.\n");
return true;
}
void AlsaSound::Mute(bool bMute) {
if((bMute && g_muted) || (!bMute && !g_muted))
return;
g_muted = bMute;
}
void AlsaSound::AlsaShutdown()
{

View File

@ -47,6 +47,8 @@ public:
virtual void Update();
virtual void Mute(bool bMute);
private:
bool AlsaInit();
void AlsaShutdown();

View File

@ -192,3 +192,16 @@ void DSound::Stop()
soundSyncEvent.Shutdown();
thread = NULL;
}
void DSound::Mute(bool bMute) {
if((bMute && g_muted) || (!bMute && !g_muted))
return;
if(bMute)
dsBuffer->Stop();
else
dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
g_muted = bMute;
}

View File

@ -79,6 +79,7 @@ public:
virtual void SetVolume(int volume);
virtual void Stop();
virtual void Clear();
virtual void Mute(bool bMute);
static bool isValid() { return true; }
virtual bool usesMixer() const { return true; }
virtual void Update();

View File

@ -30,6 +30,8 @@ bool OpenALStream::Start()
ALCdevice *pDevice = NULL;
bool bReturn = false;
g_uiSource = 0;
pDeviceList = new ALDeviceList();
if ((pDeviceList) && (pDeviceList->GetNumDevices()))
{
@ -125,6 +127,9 @@ void OpenALStream::SoundLoop()
alSourceQueueBuffers(uiSource, 1, &uiBuffers[iLoop]);
}
//*/
g_uiSource = uiSource;
alSourcePlay(uiSource);
err = alGetError();
@ -173,5 +178,17 @@ void OpenALStream::SoundLoop()
}
void OpenALStream::Mute(bool bMute) {
if((bMute && g_muted) || (!bMute && !g_muted))
return;
if(bMute && g_uiSource)
alSourceStop(g_uiSource);
else if(g_uiSource)
alSourcePlay(g_uiSource);
g_muted = bMute;
}
#endif //HAVE_OPENAL

View File

@ -51,6 +51,7 @@ public:
virtual void SoundLoop();
virtual void Stop();
virtual void Clear();
virtual void Mute(bool bMute);
static bool isValid() { return true; }
virtual bool usesMixer() const { return true; }
virtual void Update();
@ -63,6 +64,7 @@ private:
Common::Event soundSyncEvent;
short realtimeBuffer[OAL_BUFFER_SIZE];
ALuint g_uiSource;
#else
public:
OpenALStream(CMixer *mixer, void *hWnd = NULL): SoundStream(mixer) {}

View File

@ -32,9 +32,10 @@ protected:
volatile int threadData;
bool m_logAudio;
WaveFileWriter g_wave_writer;
bool g_muted;
public:
SoundStream(CMixer *mixer) : m_mixer(mixer), threadData(0) {}
SoundStream(CMixer *mixer) : m_mixer(mixer), threadData(0), g_muted(false) {}
virtual ~SoundStream() { delete m_mixer;}
static bool isValid() { return false; }
@ -45,6 +46,7 @@ public:
virtual void Stop() {}
virtual void Update() {}
virtual void Clear() {}
virtual void Mute(bool bMute) {}
virtual void StartLogAudio(const char *filename) {
if (! m_logAudio) {
m_logAudio = true;

View File

@ -42,6 +42,7 @@ PLUGIN_GLOBALS* globals = NULL;
DSPInitialize g_dspInitialize;
u8* g_pMemory;
extern std::vector<std::string> sMailLog, sMailTime;
bool g_bMuted = false;
SoundStream *soundStream = NULL;
@ -204,6 +205,8 @@ void Initialize(void *init)
{
g_dspInitialize = *(DSPInitialize*)init;
g_bMuted = false;
g_Config.Load();
g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
@ -314,6 +317,10 @@ unsigned short DSP_ReadControlRegister()
void DSP_Update(int cycles)
{
// Handle muting
if(g_bMuted && !*g_dspInitialize.pEmulatorState && soundStream)
soundStream->Mute(g_bMuted = false);
// This is called OFTEN - better not do anything expensive!
CDSPHandler::GetInstance().Update(cycles);
}
@ -365,4 +372,6 @@ void DSP_ClearAudioBuffer()
{
if (soundStream)
soundStream->Clear();
if(*g_dspInitialize.pEmulatorState && soundStream && !g_bMuted)
soundStream->Mute(g_bMuted = true);
}