2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-21 08:17:03 +02:00
|
|
|
// Refer to the license.txt file included.
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2014-02-10 19:54:46 +01:00
|
|
|
#pragma once
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2015-05-10 06:20:27 +02:00
|
|
|
#include <atomic>
|
2015-07-07 15:30:27 +02:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
2015-05-10 06:20:27 +02:00
|
|
|
#include <thread>
|
|
|
|
|
2009-09-10 00:56:23 +02:00
|
|
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
2009-09-09 23:26:33 +02:00
|
|
|
#include <alsa/asoundlib.h>
|
2009-09-10 00:56:23 +02:00
|
|
|
#endif
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "AudioCommon/SoundStream.h"
|
2014-09-08 03:06:58 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2014-03-18 15:37:45 +01:00
|
|
|
class AlsaSound final : public SoundStream
|
2009-09-09 23:26:33 +02:00
|
|
|
{
|
|
|
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
|
|
|
public:
|
2015-05-24 10:13:02 +02:00
|
|
|
AlsaSound();
|
2017-10-22 01:23:40 +02:00
|
|
|
~AlsaSound() override;
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2017-10-22 01:23:40 +02:00
|
|
|
bool Init() override;
|
2015-05-24 12:02:30 +02:00
|
|
|
void SoundLoop() override;
|
|
|
|
void Update() override;
|
2017-10-22 01:23:40 +02:00
|
|
|
bool SetRunning(bool running) override;
|
2009-09-09 23:26:33 +02:00
|
|
|
|
2014-08-30 22:29:15 +02:00
|
|
|
static bool isValid() { return true; }
|
2018-04-12 14:18:04 +02:00
|
|
|
|
2009-09-09 23:26:33 +02:00
|
|
|
private:
|
2015-09-30 10:41:33 +02:00
|
|
|
// maximum number of frames the buffer can hold
|
|
|
|
static constexpr size_t BUFFER_SIZE_MAX = 8192;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-09-30 10:41:33 +02:00
|
|
|
// minimum number of frames to deliver in one transfer
|
|
|
|
static constexpr u32 FRAME_COUNT_MIN = 256;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-09-30 10:41:33 +02:00
|
|
|
// number of channels per frame
|
|
|
|
static constexpr u32 CHANNEL_COUNT = 2;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-05-10 08:30:24 +02:00
|
|
|
enum class ALSAThreadStatus
|
|
|
|
{
|
|
|
|
RUNNING,
|
2015-09-29 13:51:34 +02:00
|
|
|
PAUSED,
|
2015-05-10 08:30:24 +02:00
|
|
|
STOPPING,
|
|
|
|
STOPPED,
|
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2009-09-09 23:26:33 +02:00
|
|
|
bool AlsaInit();
|
|
|
|
void AlsaShutdown();
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-09-30 10:41:33 +02:00
|
|
|
s16 mix_buffer[BUFFER_SIZE_MAX * CHANNEL_COUNT];
|
2011-01-27 22:34:37 +01:00
|
|
|
std::thread thread;
|
2015-05-10 08:30:24 +02:00
|
|
|
std::atomic<ALSAThreadStatus> m_thread_status;
|
2015-07-07 15:30:27 +02:00
|
|
|
std::condition_variable cv;
|
|
|
|
std::mutex cv_m;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2009-09-09 23:26:33 +02:00
|
|
|
snd_pcm_t* handle;
|
2015-10-03 03:34:32 +02:00
|
|
|
unsigned int frames_to_deliver;
|
2009-09-09 23:26:33 +02:00
|
|
|
#endif
|
|
|
|
};
|