| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <memory> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include "AudioCommon/SoundStream.h" |
| 11 |
#ifdef _WIN32 |
| 12 |
#include "Common/WorkQueueThread.h" |
| 13 |
#endif |
| 14 |
|
| 15 |
#ifdef HAVE_CUBEB |
| 16 |
#include <cubeb/cubeb.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
class CubebStream final : public SoundStream |
| 20 |
{ |
| 21 |
#ifdef HAVE_CUBEB |
| 22 |
public: |
| 23 |
CubebStream(); |
| 24 |
CubebStream(const CubebStream& other) = delete; |
| 25 |
CubebStream(CubebStream&& other) = delete; |
| 26 |
CubebStream& operator=(const CubebStream& other) = delete; |
| 27 |
CubebStream& operator=(CubebStream&& other) = delete; |
| 28 |
~CubebStream() override; |
| 29 |
bool Init() override; |
| 30 |
bool SetRunning(bool running) override; |
| 31 |
void SetVolume(int) override; |
| 32 |
static bool IsValid() { return true; } |
| 33 |
|
| 34 |
private: |
| 35 |
struct WiimoteStreamData |
| 36 |
{ |
| 37 |
CubebStream* self; |
| 38 |
std::size_t wiimote_index; |
| 39 |
}; |
| 40 |
|
| 41 |
bool m_stereo = false; |
| 42 |
std::shared_ptr<cubeb> m_ctx; |
| 43 |
cubeb_stream* m_stream = nullptr; |
| 44 |
std::array<WiimoteStreamData, 4> m_wiimote_stream_data{}; |
| 45 |
std::array<cubeb_stream*, 4> m_wiimote_streams{}; |
| 46 |
|
| 47 |
std::vector<short> m_short_buffer; |
| 48 |
std::vector<float> m_floatstereo_buffer; |
| 49 |
|
| 50 |
#ifdef _WIN32 |
| 51 |
Common::AsyncWorkThread m_work_queue; |
| 52 |
bool m_coinit_success = false; |
| 53 |
bool m_should_couninit = false; |
| 54 |
#endif |
| 55 |
|
| 56 |
static long DataCallback(cubeb_stream* stream, void* user_data, const void* , |
| 57 |
void* output_buffer, long num_frames); |
| 58 |
static void StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state); |
| 59 |
static long WiimoteDataCallback(cubeb_stream* stream, void* user_data, |
| 60 |
const void* , void* output_buffer, |
| 61 |
long num_frames); |
| 62 |
static void WiimoteStateCallback(cubeb_stream* stream, void* user_data, cubeb_state state); |
| 63 |
#endif |
| 64 |
}; |