Merge pull request #10006 from Tilka/pulse

AudioCommon: fix bogus error + cleanup
This commit is contained in:
Léo Lam
2021-08-08 13:16:54 +02:00
committed by GitHub
12 changed files with 30 additions and 57 deletions

View File

@ -41,11 +41,6 @@ bool AlsaSound::Init()
return true; return true;
} }
void AlsaSound::Update()
{
// don't need to do anything here.
}
// Called on audio thread. // Called on audio thread.
void AlsaSound::SoundLoop() void AlsaSound::SoundLoop()
{ {

View File

@ -23,13 +23,13 @@ public:
~AlsaSound() override; ~AlsaSound() override;
bool Init() override; bool Init() override;
void SoundLoop() override;
void Update() override;
bool SetRunning(bool running) override; bool SetRunning(bool running) override;
static bool isValid() { return true; } static bool IsValid() { return true; }
private: private:
void SoundLoop();
// maximum number of frames the buffer can hold // maximum number of frames the buffer can hold
static constexpr size_t BUFFER_SIZE_MAX = 8192; static constexpr size_t BUFFER_SIZE_MAX = 8192;

View File

@ -30,17 +30,17 @@ static std::unique_ptr<SoundStream> CreateSoundStreamForBackend(std::string_view
{ {
if (backend == BACKEND_CUBEB) if (backend == BACKEND_CUBEB)
return std::make_unique<CubebStream>(); return std::make_unique<CubebStream>();
else if (backend == BACKEND_OPENAL && OpenALStream::isValid()) else if (backend == BACKEND_OPENAL && OpenALStream::IsValid())
return std::make_unique<OpenALStream>(); return std::make_unique<OpenALStream>();
else if (backend == BACKEND_NULLSOUND) else if (backend == BACKEND_NULLSOUND)
return std::make_unique<NullSound>(); return std::make_unique<NullSound>();
else if (backend == BACKEND_ALSA && AlsaSound::isValid()) else if (backend == BACKEND_ALSA && AlsaSound::IsValid())
return std::make_unique<AlsaSound>(); return std::make_unique<AlsaSound>();
else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid()) else if (backend == BACKEND_PULSEAUDIO && PulseAudio::IsValid())
return std::make_unique<PulseAudio>(); return std::make_unique<PulseAudio>();
else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid()) else if (backend == BACKEND_OPENSLES && OpenSLESStream::IsValid())
return std::make_unique<OpenSLESStream>(); return std::make_unique<OpenSLESStream>();
else if (backend == BACKEND_WASAPI && WASAPIStream::isValid()) else if (backend == BACKEND_WASAPI && WASAPIStream::IsValid())
return std::make_unique<WASAPIStream>(); return std::make_unique<WASAPIStream>();
return {}; return {};
} }
@ -96,7 +96,7 @@ std::string GetDefaultSoundBackend()
#if defined ANDROID #if defined ANDROID
backend = BACKEND_OPENSLES; backend = BACKEND_OPENSLES;
#elif defined __linux__ #elif defined __linux__
if (AlsaSound::isValid()) if (AlsaSound::IsValid())
backend = BACKEND_ALSA; backend = BACKEND_ALSA;
#elif defined(__APPLE__) || defined(_WIN32) #elif defined(__APPLE__) || defined(_WIN32)
backend = BACKEND_CUBEB; backend = BACKEND_CUBEB;
@ -115,15 +115,15 @@ std::vector<std::string> GetSoundBackends()
backends.emplace_back(BACKEND_NULLSOUND); backends.emplace_back(BACKEND_NULLSOUND);
backends.emplace_back(BACKEND_CUBEB); backends.emplace_back(BACKEND_CUBEB);
if (AlsaSound::isValid()) if (AlsaSound::IsValid())
backends.emplace_back(BACKEND_ALSA); backends.emplace_back(BACKEND_ALSA);
if (PulseAudio::isValid()) if (PulseAudio::IsValid())
backends.emplace_back(BACKEND_PULSEAUDIO); backends.emplace_back(BACKEND_PULSEAUDIO);
if (OpenALStream::isValid()) if (OpenALStream::IsValid())
backends.emplace_back(BACKEND_OPENAL); backends.emplace_back(BACKEND_OPENAL);
if (OpenSLESStream::isValid()) if (OpenSLESStream::IsValid())
backends.emplace_back(BACKEND_OPENSLES); backends.emplace_back(BACKEND_OPENSLES);
if (WASAPIStream::isValid()) if (WASAPIStream::IsValid())
backends.emplace_back(BACKEND_WASAPI); backends.emplace_back(BACKEND_WASAPI);
return backends; return backends;
@ -197,8 +197,6 @@ void SendAIBuffer(const short* samples, unsigned int num_samples)
{ {
pMixer->PushSamples(samples, num_samples); pMixer->PushSamples(samples, num_samples);
} }
g_sound_stream->Update();
} }
void StartAudioDump() void StartAudioDump()

View File

@ -3,10 +3,6 @@
#include "AudioCommon/NullSoundStream.h" #include "AudioCommon/NullSoundStream.h"
void NullSound::SoundLoop()
{
}
bool NullSound::Init() bool NullSound::Init()
{ {
return true; return true;
@ -20,7 +16,3 @@ bool NullSound::SetRunning(bool running)
void NullSound::SetVolume(int volume) void NullSound::SetVolume(int volume)
{ {
} }
void NullSound::Update()
{
}

View File

@ -9,10 +9,8 @@ class NullSound final : public SoundStream
{ {
public: public:
bool Init() override; bool Init() override;
void SoundLoop() override;
bool SetRunning(bool running) override; bool SetRunning(bool running) override;
void SetVolume(int volume) override; void SetVolume(int volume) override;
void Update() override;
static bool isValid() { return true; } static bool IsValid() { return true; }
}; };

View File

@ -83,7 +83,7 @@ static bool InitLibrary()
return true; return true;
} }
bool OpenALStream::isValid() bool OpenALStream::IsValid()
{ {
return InitLibrary(); return InitLibrary();
} }
@ -126,9 +126,6 @@ bool OpenALStream::Init()
OpenALStream::~OpenALStream() OpenALStream::~OpenALStream()
{ {
m_run_thread.Clear(); m_run_thread.Clear();
// kick the thread if it's waiting
m_sound_sync_event.Set();
m_thread.join(); m_thread.join();
palSourceStop(m_source); palSourceStop(m_source);
@ -155,11 +152,6 @@ void OpenALStream::SetVolume(int volume)
palSourcef(m_source, AL_GAIN, m_volume); palSourcef(m_source, AL_GAIN, m_volume);
} }
void OpenALStream::Update()
{
m_sound_sync_event.Set();
}
bool OpenALStream::SetRunning(bool running) bool OpenALStream::SetRunning(bool running)
{ {
if (running) if (running)

View File

@ -56,19 +56,17 @@ public:
OpenALStream() : m_source(0) {} OpenALStream() : m_source(0) {}
~OpenALStream() override; ~OpenALStream() override;
bool Init() override; bool Init() override;
void SoundLoop() override;
void SetVolume(int volume) override; void SetVolume(int volume) override;
bool SetRunning(bool running) override; bool SetRunning(bool running) override;
void Update() override;
static bool isValid(); static bool IsValid();
private: private:
void SoundLoop();
std::thread m_thread; std::thread m_thread;
Common::Flag m_run_thread; Common::Flag m_run_thread;
Common::Event m_sound_sync_event;
std::vector<short> m_realtime_buffer; std::vector<short> m_realtime_buffer;
std::array<ALuint, OAL_BUFFERS> m_buffers; std::array<ALuint, OAL_BUFFERS> m_buffers;
ALuint m_source; ALuint m_source;

View File

@ -14,9 +14,9 @@ class OpenSLESStream final : public SoundStream
public: public:
~OpenSLESStream() override; ~OpenSLESStream() override;
bool Init() override; bool Init() override;
bool SetRunning(bool running) override { return running; } bool SetRunning(bool running) override { return true; }
void SetVolume(int volume) override; void SetVolume(int volume) override;
static bool isValid() { return true; } static bool IsValid() { return true; }
private: private:
std::thread thread; std::thread thread;

View File

@ -20,14 +20,14 @@ public:
~PulseAudio() override; ~PulseAudio() override;
bool Init() override; bool Init() override;
bool SetRunning(bool running) override { return running; } bool SetRunning(bool running) override { return true; }
static bool isValid() { return true; } static bool IsValid() { return true; }
void StateCallback(pa_context* c); void StateCallback(pa_context* c);
void WriteCallback(pa_stream* s, size_t length); void WriteCallback(pa_stream* s, size_t length);
void UnderflowCallback(pa_stream* s); void UnderflowCallback(pa_stream* s);
private: private:
void SoundLoop() override; void SoundLoop();
bool PulseInit(); bool PulseInit();
void PulseShutdown(); void PulseShutdown();

View File

@ -16,11 +16,10 @@ protected:
public: public:
SoundStream() : m_mixer(new Mixer(48000)) {} SoundStream() : m_mixer(new Mixer(48000)) {}
virtual ~SoundStream() {} virtual ~SoundStream() {}
static bool isValid() { return false; } static bool IsValid() { return false; }
Mixer* GetMixer() const { return m_mixer.get(); } Mixer* GetMixer() const { return m_mixer.get(); }
virtual bool Init() { return false; } virtual bool Init() { return false; }
virtual void SetVolume(int) {} virtual void SetVolume(int) {}
virtual void SoundLoop() {} // Returns true if successful.
virtual void Update() {}
virtual bool SetRunning(bool running) { return false; } virtual bool SetRunning(bool running) { return false; }
}; };

View File

@ -49,7 +49,7 @@ WASAPIStream::~WASAPIStream()
m_thread.join(); m_thread.join();
} }
bool WASAPIStream::isValid() bool WASAPIStream::IsValid()
{ {
return true; return true;
} }

View File

@ -35,13 +35,14 @@ public:
~WASAPIStream(); ~WASAPIStream();
bool Init() override; bool Init() override;
bool SetRunning(bool running) override; bool SetRunning(bool running) override;
void SoundLoop() override;
static bool isValid(); static bool IsValid();
static std::vector<std::string> GetAvailableDevices(); static std::vector<std::string> GetAvailableDevices();
static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name); static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name);
private: private:
void SoundLoop();
u32 m_frames_in_buffer = 0; u32 m_frames_in_buffer = 0;
std::atomic<bool> m_running = false; std::atomic<bool> m_running = false;
std::thread m_thread; std::thread m_thread;