summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/AlsaSoundStream.cpp
diff options
context:
space:
mode:
authorLinktothepast <kostamarino@gmail.com>2015-09-28 16:50:35 +0300
committerLinktothepast <kostamarino@gmail.com>2015-09-28 16:50:35 +0300
commit748be565b8df535ef558e74b38cd0f4d615f8a21 (patch)
treeb151efee0a87e99125f2401325a9bddecf84fc73 /Source/Core/AudioCommon/AlsaSoundStream.cpp
parentcf17fccdd3093a1b8476b10183b1c4bde36da74d (diff)
parentce493b897d6d3735c930a8465cc0c26bbe5feb86 (diff)
Merge remote-tracking branch 'dolphin-emu/master' into gameinis
Diffstat (limited to 'Source/Core/AudioCommon/AlsaSoundStream.cpp')
-rw-r--r--Source/Core/AudioCommon/AlsaSoundStream.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/Source/Core/AudioCommon/AlsaSoundStream.cpp b/Source/Core/AudioCommon/AlsaSoundStream.cpp
index 5902edba94..a132cb5de3 100644
--- a/Source/Core/AudioCommon/AlsaSoundStream.cpp
+++ b/Source/Core/AudioCommon/AlsaSoundStream.cpp
@@ -2,9 +2,12 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include <mutex>
+
#include "AudioCommon/AlsaSoundStream.h"
#include "Common/CommonTypes.h"
#include "Common/Thread.h"
+#include "Common/Logging/Log.h"
#define FRAME_COUNT_MIN 256
#define BUFFER_SIZE_MAX 8192
@@ -26,6 +29,12 @@ AlsaSound::~AlsaSound()
bool AlsaSound::Start()
{
m_thread_status.store(ALSAThreadStatus::RUNNING);
+ if (!AlsaInit())
+ {
+ m_thread_status.store(ALSAThreadStatus::STOPPED);
+ return false;
+ }
+
thread = std::thread(&AlsaSound::SoundLoop, this);
return true;
}
@@ -33,6 +42,10 @@ bool AlsaSound::Start()
void AlsaSound::Stop()
{
m_thread_status.store(ALSAThreadStatus::STOPPING);
+
+ //Give the opportunity to the audio thread
+ //to realize we are stopping the emulation
+ cv.notify_one();
thread.join();
}
@@ -44,15 +57,14 @@ void AlsaSound::Update()
// Called on audio thread.
void AlsaSound::SoundLoop()
{
- if (!AlsaInit()) {
- m_thread_status.store(ALSAThreadStatus::STOPPED);
- return;
- }
Common::SetCurrentThreadName("Audio thread - alsa");
while (m_thread_status.load() == ALSAThreadStatus::RUNNING)
{
+ std::unique_lock<std::mutex> lock(cv_m);
+ cv.wait(lock, [this]{return !m_muted || m_thread_status.load() != ALSAThreadStatus::RUNNING;});
+
m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver);
- int rc = m_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
+ int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
if (rc == -EPIPE)
{
// Underrun
@@ -67,6 +79,24 @@ void AlsaSound::SoundLoop()
m_thread_status.store(ALSAThreadStatus::STOPPED);
}
+
+void AlsaSound::Clear(bool muted)
+{
+ m_muted = muted;
+ if (m_muted)
+ {
+ std::lock_guard<std::mutex> lock(cv_m);
+ snd_pcm_drop(handle);
+ }
+ else
+ {
+ std::unique_lock<std::mutex> lock(cv_m);
+ snd_pcm_prepare(handle);
+ lock.unlock();
+ cv.notify_one();
+ }
+}
+
bool AlsaSound::AlsaInit()
{
unsigned int sample_rate = m_mixer->GetSampleRate();