2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-21 06:17:03 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2015-05-10 04:20:27 +00:00
|
|
|
#include <atomic>
|
2015-07-07 13:30:27 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
2015-05-10 04:20:27 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2009-09-09 22:56:23 +00:00
|
|
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
2009-09-09 21:26:33 +00:00
|
|
|
#include <alsa/asoundlib.h>
|
2009-09-09 22:56:23 +00:00
|
|
|
#endif
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "AudioCommon/SoundStream.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2014-03-18 14:37:45 +00:00
|
|
|
class AlsaSound final : public SoundStream
|
2009-09-09 21:26:33 +00:00
|
|
|
{
|
|
|
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
|
|
|
public:
|
2015-05-24 08:13:02 +00:00
|
|
|
AlsaSound();
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2015-05-24 10:02:30 +00:00
|
|
|
bool Start() override;
|
|
|
|
void SoundLoop() override;
|
|
|
|
void Stop() override;
|
|
|
|
void Update() override;
|
2015-07-07 13:30:27 +00:00
|
|
|
void Clear(bool) override;
|
2009-09-09 21:26:33 +00:00
|
|
|
|
2014-08-30 20:29:15 +00:00
|
|
|
static bool isValid()
|
|
|
|
{
|
2009-09-09 21:26:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-09-30 08:41:33 +00:00
|
|
|
// 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;
|
|
|
|
|
2015-05-10 06:30:24 +00:00
|
|
|
enum class ALSAThreadStatus
|
|
|
|
{
|
|
|
|
RUNNING,
|
|
|
|
STOPPING,
|
|
|
|
STOPPED,
|
|
|
|
};
|
|
|
|
|
2009-09-09 21:26:33 +00:00
|
|
|
bool AlsaInit();
|
|
|
|
void AlsaShutdown();
|
|
|
|
|
2015-09-30 08:41:33 +00:00
|
|
|
s16 mix_buffer[BUFFER_SIZE_MAX * CHANNEL_COUNT];
|
2011-01-27 21:34:37 +00:00
|
|
|
std::thread thread;
|
2015-05-10 06:30:24 +00:00
|
|
|
std::atomic<ALSAThreadStatus> m_thread_status;
|
2015-07-07 13:30:27 +00:00
|
|
|
std::condition_variable cv;
|
|
|
|
std::mutex cv_m;
|
2009-09-09 21:26:33 +00:00
|
|
|
|
|
|
|
snd_pcm_t *handle;
|
2015-10-03 01:34:32 +00:00
|
|
|
unsigned int frames_to_deliver;
|
2009-09-09 21:26:33 +00:00
|
|
|
#endif
|
|
|
|
};
|