Etterna 0.74.4
Loading...
Searching...
No Matches
DSoundHelpers.h
1#ifndef DSOUND_HELPERS
2#define DSOUND_HELPERS 1
3
4#ifdef _WIN32
5#include <windows.h>
6#include <wtypes.h>
7#endif
8
9struct IDirectSound;
10struct IDirectSoundBuffer;
11
12class DSound
13{
14 public:
15 IDirectSound* GetDS() const { return m_pDS; }
16 bool IsEmulated() const;
17
18 DSound();
19 ~DSound();
20 std::string Init();
21
22 private:
23 IDirectSound* m_pDS;
24 static BOOL CALLBACK EnumCallback(LPGUID lpGuid,
25 LPCSTR lpcstrDescription,
26 LPCSTR lpcstrModule,
27 LPVOID lpContext);
28
29 void SetPrimaryBufferMode();
30};
31
33{
34 public:
35 enum hw
36 {
37 HW_HARDWARE,
38 HW_SOFTWARE,
39 HW_DONT_CARE
40 };
41
42 /* If samplerate is DYNAMIC_SAMPLERATE, then call SetSampleRate before
43 * you use the sample. */
44 enum
45 {
46 DYNAMIC_SAMPLERATE = -1
47 };
48
49 DSoundBuf();
50 std::string Init(DSound& ds,
51 hw hardware,
52 int iChannels,
53 int iSampleRate,
54 int iSampleBits,
55 int iWriteAhead);
56
57 bool get_output_buf(char** pBuffer, unsigned* iBuffersize, int iChunksize);
58 void release_output_buf(char* pBuffer, unsigned iBuffersize);
59
60 void Play();
61 void Stop();
62 void SetVolume(float fVolume);
63 void SetSampleRate(int iRate);
64 int GetSampleRate() const { return m_iSampleRate; }
65
66 ~DSoundBuf();
67 int64_t GetPosition() const;
68 int64_t GetOutputPosition() const { return m_iWriteCursorPos; }
69
70 private:
71 int buffersize_frames() const { return m_iBufferSize / bytes_per_frame(); }
72 int bytes_per_frame() const { return m_iChannels * m_iSampleBits / 8; }
73
74 void CheckWriteahead(int iCursorStart, int iCursorEnd);
75 void CheckUnderrun(int iCursorStart, int iCursorEnd);
76
77 IDirectSoundBuffer* m_pBuffer;
78
79 int m_iChannels, m_iSampleRate, m_iSampleBits, m_iWriteAhead;
80 int m_iVolume;
81
82 int m_iBufferSize;
83
84 int m_iWriteCursor, m_iBufferBytesFilled; /* bytes */
85 int m_iExtraWriteahead;
86 int64_t m_iWriteCursorPos; /* frames */
87 mutable int64_t m_iLastPosition;
88 bool m_bPlaying;
89
90 bool m_bBufferLocked;
91 char *m_pLockedBuf1, *m_pLockedBuf2;
92 int m_iLockedSize1, m_iLockedSize2;
93 char* m_pTempBuffer;
94
95 int m_iLastCursors[4][2];
96};
97
98#endif
Definition DSoundHelpers.h:33
Definition DSoundHelpers.h:13