mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
Merge pull request #3110 from booto/alsa-buffer-type
AlsaSound: fix buffer type, clean up macros
This commit is contained in:
commit
6305437327
@ -9,21 +9,11 @@
|
|||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#define FRAME_COUNT_MIN 256
|
|
||||||
#define BUFFER_SIZE_MAX 8192
|
|
||||||
#define BUFFER_SIZE_BYTES (BUFFER_SIZE_MAX*2*2)
|
|
||||||
|
|
||||||
AlsaSound::AlsaSound()
|
AlsaSound::AlsaSound()
|
||||||
: m_thread_status(ALSAThreadStatus::STOPPED)
|
: m_thread_status(ALSAThreadStatus::STOPPED)
|
||||||
, handle(nullptr)
|
, handle(nullptr)
|
||||||
, frames_to_deliver(FRAME_COUNT_MIN)
|
, frames_to_deliver(FRAME_COUNT_MIN)
|
||||||
{
|
{
|
||||||
mix_buffer = new u8[BUFFER_SIZE_BYTES];
|
|
||||||
}
|
|
||||||
|
|
||||||
AlsaSound::~AlsaSound()
|
|
||||||
{
|
|
||||||
delete [] mix_buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AlsaSound::Start()
|
bool AlsaSound::Start()
|
||||||
@ -63,7 +53,7 @@ void AlsaSound::SoundLoop()
|
|||||||
std::unique_lock<std::mutex> lock(cv_m);
|
std::unique_lock<std::mutex> lock(cv_m);
|
||||||
cv.wait(lock, [this]{return !m_muted || m_thread_status.load() != ALSAThreadStatus::RUNNING;});
|
cv.wait(lock, [this]{return !m_muted || m_thread_status.load() != ALSAThreadStatus::RUNNING;});
|
||||||
|
|
||||||
m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver);
|
m_mixer->Mix(mix_buffer, frames_to_deliver);
|
||||||
int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
|
int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
|
||||||
if (rc == -EPIPE)
|
if (rc == -EPIPE)
|
||||||
{
|
{
|
||||||
@ -145,7 +135,7 @@ bool AlsaSound::AlsaInit()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params_set_channels(handle, hwparams, 2);
|
err = snd_pcm_hw_params_set_channels(handle, hwparams, CHANNEL_COUNT);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(AUDIO, "Channels count not available: %s\n", snd_strerror(err));
|
ERROR_LOG(AUDIO, "Channels count not available: %s\n", snd_strerror(err));
|
||||||
@ -156,7 +146,7 @@ bool AlsaSound::AlsaInit()
|
|||||||
err = snd_pcm_hw_params_set_periods_max(handle, hwparams, &periods, &dir);
|
err = snd_pcm_hw_params_set_periods_max(handle, hwparams, &periods, &dir);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(AUDIO, "Cannot set Minimum periods: %s\n", snd_strerror(err));
|
ERROR_LOG(AUDIO, "Cannot set maximum periods per buffer: %s\n", snd_strerror(err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +154,7 @@ bool AlsaSound::AlsaInit()
|
|||||||
err = snd_pcm_hw_params_set_buffer_size_max(handle, hwparams, &buffer_size_max);
|
err = snd_pcm_hw_params_set_buffer_size_max(handle, hwparams, &buffer_size_max);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(AUDIO, "Cannot set minimum buffer size: %s\n", snd_strerror(err));
|
ERROR_LOG(AUDIO, "Cannot set maximum buffer size: %s\n", snd_strerror(err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ class AlsaSound final : public SoundStream
|
|||||||
#if defined(HAVE_ALSA) && HAVE_ALSA
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
||||||
public:
|
public:
|
||||||
AlsaSound();
|
AlsaSound();
|
||||||
virtual ~AlsaSound();
|
|
||||||
|
|
||||||
bool Start() override;
|
bool Start() override;
|
||||||
void SoundLoop() override;
|
void SoundLoop() override;
|
||||||
@ -35,6 +34,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// maximum number of frames the buffer can hold
|
||||||
|
static constexpr size_t BUFFER_SIZE_MAX = 8192;
|
||||||
|
|
||||||
|
// minimum number of frames to deliver in one transfer
|
||||||
|
static constexpr u32 FRAME_COUNT_MIN = 256;
|
||||||
|
|
||||||
|
// number of channels per frame
|
||||||
|
static constexpr u32 CHANNEL_COUNT = 2;
|
||||||
|
|
||||||
enum class ALSAThreadStatus
|
enum class ALSAThreadStatus
|
||||||
{
|
{
|
||||||
RUNNING,
|
RUNNING,
|
||||||
@ -45,7 +53,7 @@ private:
|
|||||||
bool AlsaInit();
|
bool AlsaInit();
|
||||||
void AlsaShutdown();
|
void AlsaShutdown();
|
||||||
|
|
||||||
u8 *mix_buffer;
|
s16 mix_buffer[BUFFER_SIZE_MAX * CHANNEL_COUNT];
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
std::atomic<ALSAThreadStatus> m_thread_status;
|
std::atomic<ALSAThreadStatus> m_thread_status;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user