From 4920dbed13b0bef0e17fe0ad9d73b9f702a5e523 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 May 2015 23:48:22 -0400 Subject: [PATCH] AudioCommon: Migrate threadData to OpenALStream and AOSoundStream This is only ever used in these two sound streams. Seems silly to have it as a class member. Converted it to an atomic as well. --- Source/Core/AudioCommon/AOSoundStream.cpp | 5 +++-- Source/Core/AudioCommon/AOSoundStream.h | 2 ++ Source/Core/AudioCommon/OpenALStream.cpp | 5 +++-- Source/Core/AudioCommon/OpenALStream.h | 3 +++ Source/Core/AudioCommon/SoundStream.h | 6 +----- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Source/Core/AudioCommon/AOSoundStream.cpp b/Source/Core/AudioCommon/AOSoundStream.cpp index 7def6331a3..7aa9de9ac4 100644 --- a/Source/Core/AudioCommon/AOSoundStream.cpp +++ b/Source/Core/AudioCommon/AOSoundStream.cpp @@ -32,7 +32,7 @@ void AOSound::SoundLoop() buf_size = format.bits/8 * format.channels * format.rate; - while (!threadData) + while (m_run_thread.load()) { m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2); @@ -47,6 +47,7 @@ void AOSound::SoundLoop() bool AOSound::Start() { + m_run_thread.store(true); memset(realtimeBuffer, 0, sizeof(realtimeBuffer)); thread = std::thread(&AOSound::SoundLoop, this); @@ -60,7 +61,7 @@ void AOSound::Update() void AOSound::Stop() { - threadData = 1; + m_run_thread.store(false); soundSyncEvent.Set(); { diff --git a/Source/Core/AudioCommon/AOSoundStream.h b/Source/Core/AudioCommon/AOSoundStream.h index 23799f7627..26f618aa44 100644 --- a/Source/Core/AudioCommon/AOSoundStream.h +++ b/Source/Core/AudioCommon/AOSoundStream.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -19,6 +20,7 @@ class AOSound final : public SoundStream { #if defined(HAVE_AO) && HAVE_AO std::thread thread; + std::atomic m_run_thread; std::mutex soundCriticalSection; Common::Event soundSyncEvent; diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 57c2e286d6..c8cb9d23eb 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -23,6 +23,7 @@ static soundtouch::SoundTouch soundTouch; // bool OpenALStream::Start() { + m_run_thread.store(true); bool bReturn = false; ALDeviceList pDeviceList; @@ -72,7 +73,7 @@ bool OpenALStream::Start() void OpenALStream::Stop() { - threadData = 1; + m_run_thread.store(false); // kick the thread if it's waiting soundSyncEvent.Set(); @@ -183,7 +184,7 @@ void OpenALStream::SoundLoop() soundTouch.setSetting(SETTING_SEEKWINDOW_MS, 28); soundTouch.setSetting(SETTING_OVERLAP_MS, 12); - while (!threadData) + while (m_run_thread.load()) { // num_samples_to_render in this update - depends on SystemTimers::AUDIO_DMA_PERIOD. const u32 stereo_16_bit_size = 4; diff --git a/Source/Core/AudioCommon/OpenALStream.h b/Source/Core/AudioCommon/OpenALStream.h index a8fbd8a1f2..d43fcdec19 100644 --- a/Source/Core/AudioCommon/OpenALStream.h +++ b/Source/Core/AudioCommon/OpenALStream.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "AudioCommon/SoundStream.h" @@ -72,6 +73,8 @@ public: private: std::thread thread; + std::atomic m_run_thread; + Common::Event soundSyncEvent; short realtimeBuffer[OAL_MAX_SAMPLES * STEREO_CHANNELS]; diff --git a/Source/Core/AudioCommon/SoundStream.h b/Source/Core/AudioCommon/SoundStream.h index ff30f36f37..94541c3b90 100644 --- a/Source/Core/AudioCommon/SoundStream.h +++ b/Source/Core/AudioCommon/SoundStream.h @@ -11,17 +11,13 @@ class SoundStream { protected: - CMixer* m_mixer; - // We set this to shut down the sound thread. - // 0=keep playing, 1=stop playing NOW. - volatile int threadData; bool m_logAudio; WaveFileWriter g_wave_writer; bool m_muted; public: - SoundStream(CMixer* mixer) : m_mixer(mixer), threadData(0), m_logAudio(false), m_muted(false) {} + SoundStream(CMixer* mixer) : m_mixer(mixer), m_logAudio(false), m_muted(false) {} virtual ~SoundStream() { delete m_mixer; } static bool isValid() { return false; }