forked from Arakula/vsthost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DSoundDev.h
240 lines (193 loc) · 9.82 KB
/
DSoundDev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*****************************************************************************/
/* DSoundHost.h: DirectSound host functionality */
/*****************************************************************************/
/* This class hierarchy implements a double-buffering record/model based on */
/* Windows' DirectSound */
/*****************************************************************************/
/******************************************************************************
Copyright (C) 2006 Hermann Seib
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#if !defined(AFX_DSOUNDHOST_H__2007F5D3_8DE6_11D8_8219_4000001054B2__INCLUDED_)
#define AFX_DSOUNDHOST_H__2007F5D3_8DE6_11D8_8219_4000001054B2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*****************************************************************************/
/* CDSoundDeviceList class declaration */
/*****************************************************************************/
class CDSoundDeviceList : public CStringArray
{
public:
CDSoundDeviceList();
virtual ~CDSoundDeviceList();
LPGUID GetGUID(int nDevNum);
LPGUID GetGUID(LPCSTR lpszDesc);
CString GetName(int nDevNum);
CString GetName(LPCSTR lpszDesc);
protected:
static BOOL CALLBACK EnumDevices(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext);
CPtrArray Guids;
CStringArray Names;
};
/*****************************************************************************/
/* CDSoundInputList class declaration */
/*****************************************************************************/
class CDSoundInputList : public CDSoundDeviceList
{
public:
CDSoundInputList();
};
/*****************************************************************************/
/* CDSoundOutputList class declaration */
/*****************************************************************************/
class CDSoundOutputList : public CDSoundDeviceList
{
public:
CDSoundOutputList();
};
/*****************************************************************************/
/* CDSoundDevice class declaration */
/*****************************************************************************/
class CDSoundDevice
{
public:
CDSoundDevice();
virtual ~CDSoundDevice();
BOOL BoostPriority();
BOOL IsOpen() /* return whether device is open */
{ return bIsOpen; }
LPCSTR DeviceName ( ) /* return opened device' name */
{ return bIsOpen ? szDevName : ""; }
void SetupWaveformat(LPWAVEFORMATEX pwf, DWORD dwSamplesPerSec = 44100, WORD wBitsPerSample = 16, WORD nChannels = 2);
DWORD GetBufferSize() { return sbpn[ePosMiddle].dwOffset; }
virtual BOOL Open(LPCSTR lpszDesc,
DWORD dwFlags,
DWORD dwSamples, /* size of ONE buffer of double-buff */
LPWAVEFORMATEX pwfx);
virtual BOOL Close();
virtual BOOL Start(DWORD dwFlags = -1) { return FALSE; }
virtual BOOL IsStarted() { return FALSE; }
virtual BOOL Stop() { return TRUE; }
virtual DWORD GetDriverPos() { return 0; }
virtual DWORD GetDriverBuf() { return (GetDriverPos() >= GetBufferSize()); }
virtual DWORD GetBufferPos() { return 0; }
virtual BOOL GetFormat(LPWAVEFORMATEX lpWF) { return FALSE; }
virtual BOOL ReadBuffer(int nBuffer, LPVOID lpBuf, DWORD &rdwSamples);
virtual BOOL WriteBuffer(int nBuffer, LPVOID lpBuf, DWORD &rdwSamples);
virtual void OnOpen() { }
virtual void OnSwitch(int nBuffer) { }
virtual void OnStop() { }
protected:
char szDevName[MAXPNAMELEN]; /* device name */
BOOL bIsOpen; /* flag whether opened */
WAVEFORMATEX wf; /* format for open */
DSCBUFFERDESC sbd; /* secondary buffer description */
enum /* notification positions: */
{
ePosStart = 0, /* Start of Buffer */
ePosMiddle, /* Middle of Buffer */
ePosStop, /* Playback / Capture Stop */
ePosMax
};
DSBPOSITIONNOTIFY sbpn[ePosMax]; /* sec.buffer pos. notifications */
HANDLE hEvent; /* event handle for double-buffering */
CWinThread * pEvtThread; /* event thread procedure */
BOOL volatile bEvtCancel; /* event thread cancel flag */
protected:
void SetupSBDesc(LPDSCBUFFERDESC pbd, DWORD dwFlags = 0, DWORD dwSamples = 0, LPWAVEFORMATEX pwf = NULL);
virtual BOOL Open(LPGUID lpGuid);
virtual BOOL Lock(DWORD dwCursor, DWORD dwBytes, LPVOID *lplpvPtr1, LPDWORD lpdwBytes1, LPVOID *lplpvPtr2 = NULL, LPDWORD lpdwBytes2 = 0, DWORD dwFlags = 0) { return FALSE; }
virtual BOOL Unlock(LPVOID lpPtr1, DWORD dwBytes1, LPVOID lpPtr2 = NULL, DWORD dwBytes2 = 0) { return FALSE; }
virtual LPGUID GetGuid(LPCSTR lpszDesc) { return NULL; }
virtual void Release() { }
static UINT EvtThreadProc(LPVOID pParam);
BOOL StartEvt();
void KillEvt();
};
/*****************************************************************************/
/* CDSoundInDevice class declaration */
/*****************************************************************************/
class CDSoundInDevice : public CDSoundDevice
{
public:
CDSoundInDevice();
virtual ~CDSoundInDevice();
// base class overrides
virtual DWORD GetDriverPos(); /* get driver's current position */
virtual DWORD GetBufferPos(); /* get our read position */
virtual BOOL Start(DWORD dwFlags = -1); /* start recording */
virtual BOOL IsStarted(); /* return whether started */
virtual BOOL Stop(); /* stop recording */
virtual BOOL GetFormat(LPWAVEFORMATEX lpWF);
virtual BOOL Open(LPCSTR lpszDesc,
DWORD dwFlags,
DWORD dwSamples, /* size of ONE buffer of double-buff */
LPWAVEFORMATEX pwfx)
{ return CDSoundDevice::Open(lpszDesc, dwFlags, dwSamples, pwfx); }
virtual BOOL Close();
// input-specific functionality
virtual BOOL GetCaps(LPDSCBCAPS lpDSCBCaps);
protected:
LPDIRECTSOUNDCAPTURE lpDS;
LPDIRECTSOUNDCAPTUREBUFFER lpDSB;
LPDIRECTSOUNDNOTIFY lpDSN;
GUID guid; /* help buffer */
protected:
virtual LPGUID GetGuid(LPCSTR lpszDesc);
virtual BOOL Open(LPGUID lpGuid);
virtual BOOL Lock(DWORD dwCursor, DWORD dwBytes, LPVOID *lplpvPtr1, LPDWORD lpdwBytes1, LPVOID *lplpvPtr2 = NULL, LPDWORD lpdwBytes2 = 0, DWORD dwFlags = 0);
virtual BOOL Unlock(LPVOID lpPtr1, DWORD dwBytes1, LPVOID lpPtr2 = NULL, DWORD dwBytes2 = 0);
virtual void Release();
};
/*****************************************************************************/
/* CDSoundOutDevice class declaration */
/*****************************************************************************/
class CDSoundOutDevice : public CDSoundDevice
{
public:
CDSoundOutDevice();
virtual ~CDSoundOutDevice();
// base class overrides
virtual DWORD GetDriverPos(); /* get driver's current position */
virtual BOOL SetDriverPos(DWORD dwPos);
virtual DWORD GetBufferPos(); /* get our write position */
virtual BOOL Start(DWORD dwFlags = -1); /* start playing */
virtual BOOL IsStarted(); /* return whether started */
virtual BOOL Stop(); /* stop playing */
virtual BOOL GetFormat(LPWAVEFORMATEX lpWF);
virtual BOOL Open(LPCSTR lpszDesc,
DWORD dwFlags,
DWORD dwSamples, /* size of ONE buffer of double-buff */
LPWAVEFORMATEX pwfx)
{ return CDSoundDevice::Open(lpszDesc, dwFlags, dwSamples, pwfx); }
virtual BOOL Close();
// output-specific functionality
virtual BOOL GetCaps(LPDSBCAPS lpDSBufferCaps);
virtual BOOL GetVolume(LPLONG lpVolume);
virtual BOOL SetVolume(LONG lVolume);
virtual BOOL GetPan(LPLONG lpPan);
virtual BOOL SetPan(LONG lPan);
protected:
LPDIRECTSOUND lpDS;
LPDIRECTSOUNDBUFFER lpDSB;
LPDIRECTSOUNDNOTIFY lpDSN;
GUID guid; /* help buffer */
protected:
virtual LPGUID GetGuid(LPCSTR lpszDesc);
virtual BOOL Open(LPGUID lpGuid);
virtual BOOL Lock(DWORD dwCursor, DWORD dwBytes, LPVOID *lplpvPtr1, LPDWORD lpdwBytes1, LPVOID *lplpvPtr2 = NULL, LPDWORD lpdwBytes2 = 0, DWORD dwFlags = 0);
virtual BOOL Unlock(LPVOID lpPtr1, DWORD dwBytes1, LPVOID lpPtr2 = NULL, DWORD dwBytes2 = 0);
virtual void Release();
};
#endif // !defined(AFX_DSOUNDHOST_H__2007F5D3_8DE6_11D8_8219_4000001054B2__INCLUDED_)