Files
dolphin/Source/Core/AudioCommon/AlsaSoundStream.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.2 KiB
C++
Raw Normal View History

// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <atomic>
2015-07-07 15:30:27 +02:00
#include <condition_variable>
#include <mutex>
#include <thread>
#if defined(HAVE_ALSA) && HAVE_ALSA
#include <alsa/asoundlib.h>
#endif
2014-02-17 05:18:15 -05:00
#include "AudioCommon/SoundStream.h"
2014-09-07 20:06:58 -05:00
#include "Common/CommonTypes.h"
2014-03-18 10:37:45 -04:00
class AlsaSound final : public SoundStream
{
#if defined(HAVE_ALSA) && HAVE_ALSA
public:
2015-05-24 04:13:02 -04:00
AlsaSound();
~AlsaSound() override;
bool Init() override;
bool SetRunning(bool running) override;
2021-08-08 00:23:58 +01:00
static bool IsValid() { return true; }
2018-04-12 14:18:04 +02:00
private:
void SoundLoop();
2015-09-30 16:41:33 +08: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,
2015-09-30 00:51:34 +13:00
PAUSED,
STOPPING,
STOPPED,
};
bool AlsaInit();
void AlsaShutdown();
2015-09-30 16:41:33 +08:00
s16 mix_buffer[BUFFER_SIZE_MAX * CHANNEL_COUNT];
std::thread thread;
std::atomic<ALSAThreadStatus> m_thread_status;
2015-07-07 15:30:27 +02:00
std::condition_variable cv;
std::mutex cv_m;
snd_pcm_t* handle;
2015-10-02 20:34:32 -05:00
unsigned int frames_to_deliver;
#endif
};