CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/DSoundStream.h
Views: 1401
1
#pragma once
2
3
// This should only be included from WindowsAudio.cpp and DSoundStream.cpp.
4
5
#include "WindowsAudio.h"
6
#include <mmreg.h>
7
8
struct IDirectSound8;
9
struct IDirectSoundBuffer;
10
11
class DSoundAudioBackend : public WindowsAudioBackend {
12
public:
13
~DSoundAudioBackend();
14
15
bool Init(HWND window, StreamCallback callback, int sampleRate) override; // If fails, can safely delete the object
16
int GetSampleRate() const override { return sampleRate_; }
17
18
private:
19
int RunThread();
20
static unsigned int WINAPI soundThread(void *param);
21
bool CreateBuffer();
22
bool WriteDataToBuffer(DWORD offset, // Our own write cursor.
23
char* soundData, // Start of our data.
24
DWORD soundBytes); // Size of block to copy.
25
26
CRITICAL_SECTION soundCriticalSection;
27
HWND window_ = nullptr;
28
HANDLE hThread_ = nullptr;
29
30
StreamCallback callback_;
31
32
IDirectSound8 *ds_ = nullptr;
33
IDirectSoundBuffer *dsBuffer_ = nullptr;
34
35
int bufferSize_ = 0; // bytes
36
int totalRenderedBytes_ = 0;
37
int sampleRate_ = 0;
38
39
volatile int threadData_ = 0;
40
41
enum {
42
BUFSIZE = 0x4000,
43
MAXWAIT = 20, //ms
44
};
45
46
int currentPos_ = 0;
47
int lastPos_ = 0;
48
short realtimeBuffer_[BUFSIZE * 2];
49
};
50
51