diff --git a/Source/Core/AudioCommon/AlsaSoundStream.cpp b/Source/Core/AudioCommon/AlsaSoundStream.cpp index 8008e1bd00..c45d7bee1c 100644 --- a/Source/Core/AudioCommon/AlsaSoundStream.cpp +++ b/Source/Core/AudioCommon/AlsaSoundStream.cpp @@ -41,11 +41,6 @@ bool AlsaSound::Init() return true; } -void AlsaSound::Update() -{ - // don't need to do anything here. -} - // Called on audio thread. void AlsaSound::SoundLoop() { diff --git a/Source/Core/AudioCommon/AlsaSoundStream.h b/Source/Core/AudioCommon/AlsaSoundStream.h index d4f7d02150..d3e34386a7 100644 --- a/Source/Core/AudioCommon/AlsaSoundStream.h +++ b/Source/Core/AudioCommon/AlsaSoundStream.h @@ -23,13 +23,13 @@ public: ~AlsaSound() override; bool Init() override; - void SoundLoop() override; - void Update() override; bool SetRunning(bool running) override; - static bool isValid() { return true; } + static bool IsValid() { return true; } private: + void SoundLoop(); + // maximum number of frames the buffer can hold static constexpr size_t BUFFER_SIZE_MAX = 8192; diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 6623b5ad8b..d3bdcde445 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -30,17 +30,17 @@ static std::unique_ptr CreateSoundStreamForBackend(std::string_view { if (backend == BACKEND_CUBEB) return std::make_unique(); - else if (backend == BACKEND_OPENAL && OpenALStream::isValid()) + else if (backend == BACKEND_OPENAL && OpenALStream::IsValid()) return std::make_unique(); else if (backend == BACKEND_NULLSOUND) return std::make_unique(); - else if (backend == BACKEND_ALSA && AlsaSound::isValid()) + else if (backend == BACKEND_ALSA && AlsaSound::IsValid()) return std::make_unique(); - else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid()) + else if (backend == BACKEND_PULSEAUDIO && PulseAudio::IsValid()) return std::make_unique(); - else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid()) + else if (backend == BACKEND_OPENSLES && OpenSLESStream::IsValid()) return std::make_unique(); - else if (backend == BACKEND_WASAPI && WASAPIStream::isValid()) + else if (backend == BACKEND_WASAPI && WASAPIStream::IsValid()) return std::make_unique(); return {}; } @@ -96,7 +96,7 @@ std::string GetDefaultSoundBackend() #if defined ANDROID backend = BACKEND_OPENSLES; #elif defined __linux__ - if (AlsaSound::isValid()) + if (AlsaSound::IsValid()) backend = BACKEND_ALSA; #elif defined(__APPLE__) || defined(_WIN32) backend = BACKEND_CUBEB; @@ -115,15 +115,15 @@ std::vector GetSoundBackends() backends.emplace_back(BACKEND_NULLSOUND); backends.emplace_back(BACKEND_CUBEB); - if (AlsaSound::isValid()) + if (AlsaSound::IsValid()) backends.emplace_back(BACKEND_ALSA); - if (PulseAudio::isValid()) + if (PulseAudio::IsValid()) backends.emplace_back(BACKEND_PULSEAUDIO); - if (OpenALStream::isValid()) + if (OpenALStream::IsValid()) backends.emplace_back(BACKEND_OPENAL); - if (OpenSLESStream::isValid()) + if (OpenSLESStream::IsValid()) backends.emplace_back(BACKEND_OPENSLES); - if (WASAPIStream::isValid()) + if (WASAPIStream::IsValid()) backends.emplace_back(BACKEND_WASAPI); return backends; @@ -197,8 +197,6 @@ void SendAIBuffer(const short* samples, unsigned int num_samples) { pMixer->PushSamples(samples, num_samples); } - - g_sound_stream->Update(); } void StartAudioDump() diff --git a/Source/Core/AudioCommon/NullSoundStream.cpp b/Source/Core/AudioCommon/NullSoundStream.cpp index 0918e8bb35..3c7a0ebb98 100644 --- a/Source/Core/AudioCommon/NullSoundStream.cpp +++ b/Source/Core/AudioCommon/NullSoundStream.cpp @@ -3,10 +3,6 @@ #include "AudioCommon/NullSoundStream.h" -void NullSound::SoundLoop() -{ -} - bool NullSound::Init() { return true; @@ -20,7 +16,3 @@ bool NullSound::SetRunning(bool running) void NullSound::SetVolume(int volume) { } - -void NullSound::Update() -{ -} diff --git a/Source/Core/AudioCommon/NullSoundStream.h b/Source/Core/AudioCommon/NullSoundStream.h index 0a39250c99..f186787900 100644 --- a/Source/Core/AudioCommon/NullSoundStream.h +++ b/Source/Core/AudioCommon/NullSoundStream.h @@ -9,10 +9,8 @@ class NullSound final : public SoundStream { public: bool Init() override; - void SoundLoop() override; bool SetRunning(bool running) override; void SetVolume(int volume) override; - void Update() override; - static bool isValid() { return true; } + static bool IsValid() { return true; } }; diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 96b2a5d628..3e56fe8e08 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -83,7 +83,7 @@ static bool InitLibrary() return true; } -bool OpenALStream::isValid() +bool OpenALStream::IsValid() { return InitLibrary(); } @@ -126,9 +126,6 @@ bool OpenALStream::Init() OpenALStream::~OpenALStream() { m_run_thread.Clear(); - // kick the thread if it's waiting - m_sound_sync_event.Set(); - m_thread.join(); palSourceStop(m_source); @@ -155,11 +152,6 @@ void OpenALStream::SetVolume(int volume) palSourcef(m_source, AL_GAIN, m_volume); } -void OpenALStream::Update() -{ - m_sound_sync_event.Set(); -} - bool OpenALStream::SetRunning(bool running) { if (running) diff --git a/Source/Core/AudioCommon/OpenALStream.h b/Source/Core/AudioCommon/OpenALStream.h index 962e7a2ac4..c252838568 100644 --- a/Source/Core/AudioCommon/OpenALStream.h +++ b/Source/Core/AudioCommon/OpenALStream.h @@ -56,19 +56,17 @@ public: OpenALStream() : m_source(0) {} ~OpenALStream() override; bool Init() override; - void SoundLoop() override; void SetVolume(int volume) override; bool SetRunning(bool running) override; - void Update() override; - static bool isValid(); + static bool IsValid(); private: + void SoundLoop(); + std::thread m_thread; Common::Flag m_run_thread; - Common::Event m_sound_sync_event; - std::vector m_realtime_buffer; std::array m_buffers; ALuint m_source; diff --git a/Source/Core/AudioCommon/OpenSLESStream.h b/Source/Core/AudioCommon/OpenSLESStream.h index 97c2070a7b..08e8d0ed4a 100644 --- a/Source/Core/AudioCommon/OpenSLESStream.h +++ b/Source/Core/AudioCommon/OpenSLESStream.h @@ -14,9 +14,9 @@ class OpenSLESStream final : public SoundStream public: ~OpenSLESStream() override; bool Init() override; - bool SetRunning(bool running) override { return running; } + bool SetRunning(bool running) override { return true; } void SetVolume(int volume) override; - static bool isValid() { return true; } + static bool IsValid() { return true; } private: std::thread thread; diff --git a/Source/Core/AudioCommon/PulseAudioStream.h b/Source/Core/AudioCommon/PulseAudioStream.h index ef0852cfb4..acbf0dadcb 100644 --- a/Source/Core/AudioCommon/PulseAudioStream.h +++ b/Source/Core/AudioCommon/PulseAudioStream.h @@ -20,14 +20,14 @@ public: ~PulseAudio() override; bool Init() override; - bool SetRunning(bool running) override { return running; } - static bool isValid() { return true; } + bool SetRunning(bool running) override { return true; } + static bool IsValid() { return true; } void StateCallback(pa_context* c); void WriteCallback(pa_stream* s, size_t length); void UnderflowCallback(pa_stream* s); private: - void SoundLoop() override; + void SoundLoop(); bool PulseInit(); void PulseShutdown(); diff --git a/Source/Core/AudioCommon/SoundStream.h b/Source/Core/AudioCommon/SoundStream.h index 771c606245..9e1be0d33f 100644 --- a/Source/Core/AudioCommon/SoundStream.h +++ b/Source/Core/AudioCommon/SoundStream.h @@ -16,11 +16,10 @@ protected: public: SoundStream() : m_mixer(new Mixer(48000)) {} virtual ~SoundStream() {} - static bool isValid() { return false; } + static bool IsValid() { return false; } Mixer* GetMixer() const { return m_mixer.get(); } virtual bool Init() { return false; } virtual void SetVolume(int) {} - virtual void SoundLoop() {} - virtual void Update() {} + // Returns true if successful. virtual bool SetRunning(bool running) { return false; } }; diff --git a/Source/Core/AudioCommon/WASAPIStream.cpp b/Source/Core/AudioCommon/WASAPIStream.cpp index efe630689a..d65471226b 100644 --- a/Source/Core/AudioCommon/WASAPIStream.cpp +++ b/Source/Core/AudioCommon/WASAPIStream.cpp @@ -49,7 +49,7 @@ WASAPIStream::~WASAPIStream() m_thread.join(); } -bool WASAPIStream::isValid() +bool WASAPIStream::IsValid() { return true; } diff --git a/Source/Core/AudioCommon/WASAPIStream.h b/Source/Core/AudioCommon/WASAPIStream.h index e9a751ee99..6f3218cc4b 100644 --- a/Source/Core/AudioCommon/WASAPIStream.h +++ b/Source/Core/AudioCommon/WASAPIStream.h @@ -35,13 +35,14 @@ public: ~WASAPIStream(); bool Init() override; bool SetRunning(bool running) override; - void SoundLoop() override; - static bool isValid(); + static bool IsValid(); static std::vector GetAvailableDevices(); static Microsoft::WRL::ComPtr GetDeviceByName(std::string_view name); private: + void SoundLoop(); + u32 m_frames_in_buffer = 0; std::atomic m_running = false; std::thread m_thread;