| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include "AudioCommon/SoundStream.h" |
| 7 |
|
| 8 |
#ifdef _WIN32 |
| 9 |
#include <al.h> |
| 10 |
#include <alc.h> |
| 11 |
#include <alext.h> |
| 12 |
#include <thread> |
| 13 |
|
| 14 |
#include "Common/Event.h" |
| 15 |
|
| 16 |
|
| 17 |
#define OAL_BUFFERS 3 |
| 18 |
#define OAL_MAX_FRAMES 4096 |
| 19 |
#define STEREO_CHANNELS 2 |
| 20 |
#define SURROUND_CHANNELS 6 // number of channels in surround mode |
| 21 |
#define SIZE_SHORT 2 |
| 22 |
#define SIZE_INT32 4 |
| 23 |
#define SIZE_FLOAT 4 // size of a float in bytes |
| 24 |
#define FRAME_STEREO_SHORT STEREO_CHANNELS* SIZE_SHORT |
| 25 |
#define FRAME_SURROUND_FLOAT SURROUND_CHANNELS* SIZE_FLOAT |
| 26 |
#define FRAME_SURROUND_SHORT SURROUND_CHANNELS* SIZE_SHORT |
| 27 |
#define FRAME_SURROUND_INT32 SURROUND_CHANNELS* SIZE_INT32 |
| 28 |
#endif |
| 29 |
|
| 30 |
|
| 31 |
#ifndef AL_FORMAT_STEREO_FLOAT32 |
| 32 |
#define AL_FORMAT_STEREO_FLOAT32 0x10011 |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
#ifndef AL_FORMAT_51CHN16 |
| 37 |
#define AL_FORMAT_51CHN16 0x120B |
| 38 |
#endif |
| 39 |
#ifndef AL_FORMAT_51CHN32 |
| 40 |
#define AL_FORMAT_51CHN32 0x120C |
| 41 |
#endif |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#ifndef AL_FORMAT_STEREO32 |
| 46 |
#define AL_FORMAT_STEREO32 0x1203 |
| 47 |
#endif |
| 48 |
|
| 49 |
class OpenALStream final : public SoundStream |
| 50 |
{ |
| 51 |
#ifdef _WIN32 |
| 52 |
public: |
| 53 |
OpenALStream() = default; |
| 54 |
~OpenALStream() override; |
| 55 |
bool Init() override; |
| 56 |
void SetVolume(int volume) override; |
| 57 |
bool SetRunning(bool running) override; |
| 58 |
|
| 59 |
static bool IsValid(); |
| 60 |
|
| 61 |
private: |
| 62 |
void SoundLoop(); |
| 63 |
|
| 64 |
std::thread m_thread; |
| 65 |
Common::Flag m_run_thread; |
| 66 |
|
| 67 |
std::vector<short> m_realtime_buffer; |
| 68 |
std::array<ALuint, OAL_BUFFERS> m_buffers{}; |
| 69 |
ALuint m_source = 0; |
| 70 |
ALfloat m_volume = 1; |
| 71 |
|
| 72 |
#endif |
| 73 |
}; |