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
commit 8e1dbdb257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 30 additions and 57 deletions

View File

@ -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()
{

View File

@ -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;

View File

@ -30,17 +30,17 @@ static std::unique_ptr<SoundStream> CreateSoundStreamForBackend(std::string_view
{
if (backend == BACKEND_CUBEB)
return std::make_unique<CubebStream>();
else if (backend == BACKEND_OPENAL && OpenALStream::isValid())
else if (backend == BACKEND_OPENAL && OpenALStream::IsValid())
return std::make_unique<OpenALStream>();
else if (backend == BACKEND_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>();
else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid())
else if (backend == BACKEND_PULSEAUDIO && PulseAudio::IsValid())
return std::make_unique<PulseAudio>();
else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
else if (backend == BACKEND_OPENSLES && OpenSLESStream::IsValid())
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 {};
}
@ -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<std::string> 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()

View File

@ -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()
{
}

View File

@ -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; }
};

View File

@ -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)

View File

@ -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<short> m_realtime_buffer;
std::array<ALuint, OAL_BUFFERS> m_buffers;
ALuint m_source;

View File

@ -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;

View File

@ -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();

View File

@ -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; }
};

View File

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

View File

@ -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<std::string> GetAvailableDevices();
static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name);
private:
void SoundLoop();
u32 m_frames_in_buffer = 0;
std::atomic<bool> m_running = false;
std::thread m_thread;