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:
parent
d901fd2e38
commit
6bea0a2f53
|
@ -51,7 +51,8 @@ void AOSound::SoundLoop()
|
||||||
{
|
{
|
||||||
soundCriticalSection.Enter();
|
soundCriticalSection.Enter();
|
||||||
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
|
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
|
||||||
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
|
if(!g_muted)
|
||||||
|
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
|
||||||
soundCriticalSection.Leave();
|
soundCriticalSection.Leave();
|
||||||
|
|
||||||
if (! threadData)
|
if (! threadData)
|
||||||
|
@ -105,4 +106,12 @@ AOSound::~AOSound() {
|
||||||
// FIXME: crashes dolphin
|
// FIXME: crashes dolphin
|
||||||
// ao_shutdown();
|
// ao_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOSound::Mute(bool bMute) {
|
||||||
|
if((bMute && g_muted) || (!bMute && !g_muted))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_muted = bMute;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
|
|
||||||
|
virtual void Mute(bool bMute);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
public:
|
public:
|
||||||
AOSound(CMixer *mixer) : SoundStream(mixer) {}
|
AOSound(CMixer *mixer) : SoundStream(mixer) {}
|
||||||
|
|
|
@ -67,7 +67,7 @@ void AlsaSound::SoundLoop()
|
||||||
// nakee: What is the optimal value?
|
// nakee: What is the optimal value?
|
||||||
int frames_to_deliver = 4096;
|
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 = 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)
|
if (rc == -EPIPE)
|
||||||
{
|
{
|
||||||
// Underrun
|
// Underrun
|
||||||
|
@ -181,6 +181,13 @@ bool AlsaSound::AlsaInit()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AlsaSound::Mute(bool bMute) {
|
||||||
|
if((bMute && g_muted) || (!bMute && !g_muted))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_muted = bMute;
|
||||||
|
}
|
||||||
|
|
||||||
void AlsaSound::AlsaShutdown()
|
void AlsaSound::AlsaShutdown()
|
||||||
{
|
{
|
||||||
if (handle != NULL)
|
if (handle != NULL)
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
|
|
||||||
|
virtual void Mute(bool bMute);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool AlsaInit();
|
bool AlsaInit();
|
||||||
void AlsaShutdown();
|
void AlsaShutdown();
|
||||||
|
|
|
@ -192,3 +192,16 @@ void DSound::Stop()
|
||||||
soundSyncEvent.Shutdown();
|
soundSyncEvent.Shutdown();
|
||||||
thread = NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
virtual void SetVolume(int volume);
|
virtual void SetVolume(int volume);
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
virtual void Mute(bool bMute);
|
||||||
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();
|
||||||
|
|
|
@ -30,6 +30,8 @@ bool OpenALStream::Start()
|
||||||
ALCdevice *pDevice = NULL;
|
ALCdevice *pDevice = NULL;
|
||||||
bool bReturn = false;
|
bool bReturn = false;
|
||||||
|
|
||||||
|
g_uiSource = 0;
|
||||||
|
|
||||||
pDeviceList = new ALDeviceList();
|
pDeviceList = new ALDeviceList();
|
||||||
if ((pDeviceList) && (pDeviceList->GetNumDevices()))
|
if ((pDeviceList) && (pDeviceList->GetNumDevices()))
|
||||||
{
|
{
|
||||||
|
@ -125,6 +127,9 @@ void OpenALStream::SoundLoop()
|
||||||
alSourceQueueBuffers(uiSource, 1, &uiBuffers[iLoop]);
|
alSourceQueueBuffers(uiSource, 1, &uiBuffers[iLoop]);
|
||||||
}
|
}
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
|
g_uiSource = uiSource;
|
||||||
|
|
||||||
alSourcePlay(uiSource);
|
alSourcePlay(uiSource);
|
||||||
err = alGetError();
|
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
|
#endif //HAVE_OPENAL
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
virtual void SoundLoop();
|
virtual void SoundLoop();
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
virtual void Mute(bool bMute);
|
||||||
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();
|
||||||
|
@ -63,6 +64,7 @@ private:
|
||||||
Common::Event soundSyncEvent;
|
Common::Event soundSyncEvent;
|
||||||
|
|
||||||
short realtimeBuffer[OAL_BUFFER_SIZE];
|
short realtimeBuffer[OAL_BUFFER_SIZE];
|
||||||
|
ALuint g_uiSource;
|
||||||
#else
|
#else
|
||||||
public:
|
public:
|
||||||
OpenALStream(CMixer *mixer, void *hWnd = NULL): SoundStream(mixer) {}
|
OpenALStream(CMixer *mixer, void *hWnd = NULL): SoundStream(mixer) {}
|
||||||
|
|
|
@ -32,9 +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;
|
||||||
|
|
||||||
public:
|
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;}
|
virtual ~SoundStream() { delete m_mixer;}
|
||||||
|
|
||||||
static bool isValid() { return false; }
|
static bool isValid() { return false; }
|
||||||
|
@ -45,6 +46,7 @@ public:
|
||||||
virtual void Stop() {}
|
virtual void Stop() {}
|
||||||
virtual void Update() {}
|
virtual void Update() {}
|
||||||
virtual void Clear() {}
|
virtual void Clear() {}
|
||||||
|
virtual void Mute(bool bMute) {}
|
||||||
virtual void StartLogAudio(const char *filename) {
|
virtual void StartLogAudio(const char *filename) {
|
||||||
if (! m_logAudio) {
|
if (! m_logAudio) {
|
||||||
m_logAudio = true;
|
m_logAudio = true;
|
||||||
|
|
|
@ -42,6 +42,7 @@ PLUGIN_GLOBALS* globals = NULL;
|
||||||
DSPInitialize g_dspInitialize;
|
DSPInitialize g_dspInitialize;
|
||||||
u8* g_pMemory;
|
u8* g_pMemory;
|
||||||
extern std::vector<std::string> sMailLog, sMailTime;
|
extern std::vector<std::string> sMailLog, sMailTime;
|
||||||
|
bool g_bMuted = false;
|
||||||
|
|
||||||
SoundStream *soundStream = NULL;
|
SoundStream *soundStream = NULL;
|
||||||
|
|
||||||
|
@ -204,6 +205,8 @@ 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);
|
||||||
|
|
||||||
|
@ -314,6 +317,10 @@ unsigned short DSP_ReadControlRegister()
|
||||||
|
|
||||||
void DSP_Update(int cycles)
|
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!
|
// This is called OFTEN - better not do anything expensive!
|
||||||
CDSPHandler::GetInstance().Update(cycles);
|
CDSPHandler::GetInstance().Update(cycles);
|
||||||
}
|
}
|
||||||
|
@ -365,4 +372,6 @@ void DSP_ClearAudioBuffer()
|
||||||
{
|
{
|
||||||
if (soundStream)
|
if (soundStream)
|
||||||
soundStream->Clear();
|
soundStream->Clear();
|
||||||
|
if(*g_dspInitialize.pEmulatorState && soundStream && !g_bMuted)
|
||||||
|
soundStream->Mute(g_bMuted = true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue