2015-01-11 20:00:56 +00:00
|
|
|
#pragma once
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-06-27 09:46:10 +00:00
|
|
|
// This should only be included from WindowsAudio.cpp and DSoundStream.cpp.
|
2012-11-17 22:44:29 +00:00
|
|
|
|
2017-06-27 09:46:10 +00:00
|
|
|
#include "WindowsAudio.h"
|
|
|
|
#include <mmreg.h>
|
2021-02-14 17:25:20 +00:00
|
|
|
|
|
|
|
struct IDirectSound8;
|
|
|
|
struct IDirectSoundBuffer;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-06-27 09:46:10 +00:00
|
|
|
class DSoundAudioBackend : public WindowsAudioBackend {
|
2015-01-11 20:00:56 +00:00
|
|
|
public:
|
2022-12-11 04:32:12 +00:00
|
|
|
~DSoundAudioBackend();
|
2017-06-27 09:46:10 +00:00
|
|
|
|
|
|
|
bool Init(HWND window, StreamCallback callback, int sampleRate) override; // If fails, can safely delete the object
|
2023-03-24 09:40:10 +00:00
|
|
|
int GetSampleRate() const override { return sampleRate_; }
|
2017-06-27 09:46:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int RunThread();
|
|
|
|
static unsigned int WINAPI soundThread(void *param);
|
|
|
|
bool CreateBuffer();
|
|
|
|
bool WriteDataToBuffer(DWORD offset, // Our own write cursor.
|
|
|
|
char* soundData, // Start of our data.
|
|
|
|
DWORD soundBytes); // Size of block to copy.
|
|
|
|
|
|
|
|
CRITICAL_SECTION soundCriticalSection;
|
2023-03-24 09:40:10 +00:00
|
|
|
HWND window_ = nullptr;
|
2017-06-27 09:46:10 +00:00
|
|
|
HANDLE hThread_ = nullptr;
|
|
|
|
|
|
|
|
StreamCallback callback_;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-06-27 09:46:10 +00:00
|
|
|
IDirectSound8 *ds_ = nullptr;
|
|
|
|
IDirectSoundBuffer *dsBuffer_ = nullptr;
|
|
|
|
|
2023-03-24 09:40:10 +00:00
|
|
|
int bufferSize_ = 0; // bytes
|
|
|
|
int totalRenderedBytes_ = 0;
|
|
|
|
int sampleRate_ = 0;
|
2017-06-27 09:46:10 +00:00
|
|
|
|
2021-02-15 18:29:34 +00:00
|
|
|
volatile int threadData_ = 0;
|
2017-06-27 09:46:10 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
BUFSIZE = 0x4000,
|
|
|
|
MAXWAIT = 20, //ms
|
|
|
|
};
|
|
|
|
|
2023-03-24 09:40:10 +00:00
|
|
|
int currentPos_ = 0;
|
|
|
|
int lastPos_ = 0;
|
2017-06-27 09:46:10 +00:00
|
|
|
short realtimeBuffer_[BUFSIZE * 2];
|
|
|
|
};
|