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