#pragma once
#include "WindowsAudio.h"
#include <mmreg.h>
struct IDirectSound8;
struct IDirectSoundBuffer;
class DSoundAudioBackend : public WindowsAudioBackend {
public:
~DSoundAudioBackend();
bool Init(HWND window, StreamCallback callback, int sampleRate) override;
int GetSampleRate() const override { return sampleRate_; }
private:
int RunThread();
static unsigned int WINAPI soundThread(void *param);
bool CreateBuffer();
bool WriteDataToBuffer(DWORD offset,
char* soundData,
DWORD soundBytes);
CRITICAL_SECTION soundCriticalSection;
HWND window_ = nullptr;
HANDLE hThread_ = nullptr;
StreamCallback callback_;
IDirectSound8 *ds_ = nullptr;
IDirectSoundBuffer *dsBuffer_ = nullptr;
int bufferSize_ = 0;
int totalRenderedBytes_ = 0;
int sampleRate_ = 0;
volatile int threadData_ = 0;
enum {
BUFSIZE = 0x4000,
MAXWAIT = 20,
};
int currentPos_ = 0;
int lastPos_ = 0;
short realtimeBuffer_[BUFSIZE * 2];
};