-
Notifications
You must be signed in to change notification settings - Fork 4
/
IDirectSoundBufferEx.cpp
executable file
·504 lines (385 loc) · 16 KB
/
IDirectSoundBufferEx.cpp
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
//////////////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003-2007, Arne Bockholdt, [email protected]
//
// This file is part of Direct Sound Control.
//
// Direct Sound Control 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 3 of the License, or
// (at your option) any later version.
//
// Direct Sound Control 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 General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Direct Sound Control. If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "idirectsoundBufferex.h"
#include "idirectsound3dBufferex.h"
#include "idirectsound3dlistenerex.h"
#include "idirectsoundex.h"
//////////////////////////////////////////////////////////////////////////////////////////////
IDirectSoundBuffer8Ex::IDirectSoundBuffer8Ex(void)
{
m_lpDirectSoundBuffer8 = NULL;
m_bIsPrimary = false;
m_dwOldWriteCursorPos = 0;
m_nWriteCursorIdent = 0;
#ifdef ENABLE_LOG
m_cszClassName = IDIRECTSOUNDBUFFER8EX_CLASS_NAME;
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "Constructor called....");
#endif // ENABLE_LOG
}
//////////////////////////////////////////////////////////////////////////////////////////////
IDirectSoundBuffer8Ex::~IDirectSoundBuffer8Ex(void)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "Destructor called....");
#endif // ENABLE_LOG
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::QueryInterface( REFIID refIID, LPVOID * pVoid )
{
*pVoid = (LPVOID) NULL;
HRESULT hRes;
if(( refIID == IID_IDirectSoundBuffer ) || ( refIID == IID_IDirectSoundBuffer8 ))
{
LPVOID pTemp;
hRes = m_lpDirectSoundBuffer8->QueryInterface( refIID, &pTemp );
if( hRes == S_OK )
{
m_lpDirectSoundBuffer8 = (LPDIRECTSOUNDBUFFER8) pTemp;
*pVoid = (LPVOID) this;
//m_lpDirectSoundBuffer8->AddRef();
}
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "QueryInterface called,Interface=IID_IDirectSoundBuffer8");
#endif // ENABLE_LOG
return hRes;
}
if(( refIID == IID_IDirectSound3DBuffer ) || ( refIID == IID_IDirectSound3DBuffer8 ))
{
IDirectSound3DBuffer8Ex* pDS3DBX = new IDirectSound3DBuffer8Ex;
hRes = m_lpDirectSoundBuffer8->QueryInterface( refIID, (LPVOID*) &(pDS3DBX->m_lpDirectSound3DBuffer8) );
if( hRes == S_OK )
*pVoid = (LPVOID) pDS3DBX;
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "QueryInterface called,Interface=IID_IDirectSound3DBuffer8");
#endif // ENABLE_LOG
return hRes;
}
if(( refIID == IID_IDirectSound3DListener8 ) || ( refIID == IID_IDirectSound3DListener8 ))
{
IDirectSound3DListener8Ex* pDS3DLX = new IDirectSound3DListener8Ex;
hRes = m_lpDirectSoundBuffer8->QueryInterface( refIID, (LPVOID*) &(pDS3DLX->m_lpDirectSound3DListener8) );
if( hRes == S_OK )
*pVoid = (LPVOID) pDS3DLX;
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "QueryInterface called,Interface=IID_IDirectSound3DListener8");
#endif // ENABLE_LOG
return hRes;
}
// Unknown interface, let DX handle this...
hRes = m_lpDirectSoundBuffer8->QueryInterface( refIID, pVoid );
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
::LogMessage( m_cszClassName, this, "QueryInterface for unknown interface IID called....");
#endif // ENABLE_LOG
return hRes;
}
//////////////////////////////////////////////////////////////////////////////////////////////
ULONG IDirectSoundBuffer8Ex::AddRef()
{
ULONG nRefCnt = m_lpDirectSoundBuffer8->AddRef();
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
CString sLogString;
sLogString.Format("AddRef called....,nRefCnt=%u", nRefCnt );
::LogMessage( m_cszClassName, this, sLogString.GetBuffer());
}
#endif // ENABLE_LOG
return nRefCnt;
}
//////////////////////////////////////////////////////////////////////////////////////////////
ULONG IDirectSoundBuffer8Ex::Release()
{
ULONG nRefCnt = m_lpDirectSoundBuffer8->Release();
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
CString sLogString;
sLogString.Format("Release called....,nRefCnt=%u", nRefCnt );
::LogMessage( m_cszClassName, this, sLogString.GetBuffer());
}
#endif // ENABLE_LOG
if ( nRefCnt == 0 )
{
delete this;
return 0;
}
return nRefCnt;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// IDirectSoundBuffer methods
HRESULT IDirectSoundBuffer8Ex::GetCaps (LPDSBCAPS pDSBufferCaps)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetCaps called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetCaps( pDSBufferCaps );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetCurrentPosition (LPDWORD pdwCurrentPlayCursor, LPDWORD pdwCurrentWriteCursor)
{
HRESULT hRes = m_lpDirectSoundBuffer8->GetCurrentPosition( pdwCurrentPlayCursor,pdwCurrentWriteCursor );
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
sprintf_s( m_acLogBuffer, "GetCurrentPosition called,HRES=0x%x,PlayCursor=%u,WriteCursor=%u", hRes,(pdwCurrentPlayCursor==NULL?0:*pdwCurrentPlayCursor), (pdwCurrentWriteCursor==NULL?0:*pdwCurrentWriteCursor) );
LogMessage( m_cszClassName, this, m_acLogBuffer );
}
#endif // ENABLE_LOG
if( g_bStoppedDriverWorkaround == true )
{
if( pdwCurrentWriteCursor != NULL )
{
DWORD dwStatus;
m_lpDirectSoundBuffer8->GetStatus( &dwStatus );
if( dwStatus & DSBSTATUS_PLAYING )
{
if( m_dwOldWriteCursorPos == *pdwCurrentWriteCursor )
{
if( ++m_nWriteCursorIdent > 1 )
{
#ifdef ENABLE_LOG
LogMessage( m_cszClassName, this, "Driver has stopped playing...enabling workaround" );
#endif // ENABLE_LOG
m_lpDirectSoundBuffer8->Stop();
m_lpDirectSoundBuffer8->Play(0, 0, dwStatus & DSBPLAY_LOOPING );
}
}
else
m_nWriteCursorIdent = 0;
m_dwOldWriteCursorPos = *pdwCurrentWriteCursor;
}
}
}
return hRes;
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetFormat (LPWAVEFORMATEX pwfxFormat, DWORD dwSizeAllocated, LPDWORD pdwSizeWritten)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetFormat called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetFormat( pwfxFormat, dwSizeAllocated, pdwSizeWritten );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetVolume (LPLONG plVolume)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetVolume called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetVolume( plVolume );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetPan (LPLONG plPan)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetPan called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetPan( plPan );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetFrequency ( LPDWORD pdwFrequency )
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetFrequency called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetFrequency ( pdwFrequency );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetStatus (LPDWORD pdwStatus)
{
HRESULT hRes = m_lpDirectSoundBuffer8->GetStatus ( pdwStatus );
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
sprintf_s( m_acLogBuffer, "GetStatus called,HRES=0x%x,Status=%u", hRes, (pdwStatus==NULL?0:*pdwStatus) );
LogMessage( m_cszClassName, this, m_acLogBuffer );
}
#endif // ENABLE_LOG
return hRes;
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Initialize(LPDIRECTSOUND pDirectSound, LPCDSBUFFERDESC pcDSBufferDesc)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "Initialize called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->Initialize ( ((IDirectSound8Ex*)pDirectSound)->m_lpDirectSound8, pcDSBufferDesc );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Lock (DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags)
{
HRESULT hRes = m_lpDirectSoundBuffer8->Lock ( dwOffset, dwBytes, ppvAudioPtr1, pdwAudioBytes1,ppvAudioPtr2, pdwAudioBytes2, dwFlags);
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
sprintf_s( m_acLogBuffer, "Lock,HRES=0x%x,Offset=%u,Bytes=%u,Ptr1=0x%x,BytesPtr1=0x%x,Ptr2=0x%x,BytesPtr2=0x%x,Flags=0x%x",hRes,dwOffset,dwBytes,(DWORD) ppvAudioPtr1, (DWORD) pdwAudioBytes1, (DWORD) ppvAudioPtr2, (DWORD) pdwAudioBytes2, dwFlags );
LogMessage( m_cszClassName, this, m_acLogBuffer );
}
#endif // ENABLE_LOG
return hRes;
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Play (DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "Play called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->Play ( dwReserved1, dwPriority, dwFlags );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::SetCurrentPosition (DWORD dwNewPosition)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetCurrentPosition called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->SetCurrentPosition ( dwNewPosition );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::SetFormat(LPCWAVEFORMATEX pcfxFormat)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetFormat called....");
#endif // ENABLE_LOG
if(( g_bForcePrimaryBufferFormat == true ) && this->GetPrimaryBuffer() )
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
CString sMessage;
sMessage.Format("FORCING PRIMARY BUFFER FORMAT,Format=%ub %uhz %uch", g_nPrimaryBufferBits,g_nPrimaryBufferSamples,g_nPrimaryBufferChannels );
::LogMessage(m_cszClassName, this, sMessage.GetBuffer() );
}
#endif // ENABLE_LOG
WAVEFORMATEX fxFormat;
fxFormat.wFormatTag = WAVE_FORMAT_PCM;
fxFormat.cbSize = 0;
fxFormat.nChannels = (WORD) g_nPrimaryBufferChannels;
fxFormat.wBitsPerSample = (WORD) g_nPrimaryBufferBits;
fxFormat.nSamplesPerSec = g_nPrimaryBufferSamples;
fxFormat.nBlockAlign = (fxFormat.nChannels * fxFormat.wBitsPerSample) / 8;
fxFormat.nAvgBytesPerSec= fxFormat.nBlockAlign * fxFormat.nSamplesPerSec;
return m_lpDirectSoundBuffer8->SetFormat ( &fxFormat );
}
return m_lpDirectSoundBuffer8->SetFormat ( pcfxFormat );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::SetVolume (LONG lVolume)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetVolume called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->SetVolume( lVolume );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::SetPan (LONG lPan)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetPan called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->SetPan( lPan );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::SetFrequency (DWORD dwFrequency)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetFrequency called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->SetFrequency ( dwFrequency );
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Stop ()
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "Stop called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->Stop ();
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Unlock (LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2)
{
HRESULT hRes = m_lpDirectSoundBuffer8->Unlock(pvAudioPtr1, dwAudioBytes1, pvAudioPtr2, dwAudioBytes2 );
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
{
sprintf_s( m_acLogBuffer, "Unlock,HRES=0x%x,Ptr1=0x%x,Bytes1=%u,Ptr2=0x%x,Bytes2=%u,", hRes, (DWORD) pvAudioPtr1, dwAudioBytes1, (DWORD) pvAudioPtr2, dwAudioBytes2 );
LogMessage( m_cszClassName, this, m_acLogBuffer );
}
#endif // ENABLE_LOG
return hRes;
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::Restore()
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "Restore called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->Restore();
}
//////////////////////////////////////////////////////////////////////////////////////////////
// IDirectSoundBuffer8 methods
HRESULT IDirectSoundBuffer8Ex::SetFX(DWORD dwEffectsCount, LPDSEFFECTDESC pDSFXDesc, LPDWORD pdwResultCodes)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "SetFX called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->SetFX(dwEffectsCount, pDSFXDesc, pdwResultCodes);
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::AcquireResources (DWORD dwFlags, DWORD dwEffectsCount, LPDWORD pdwResultCodes)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "AcquireResources called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->AcquireResources( dwFlags, dwEffectsCount, pdwResultCodes);
}
//////////////////////////////////////////////////////////////////////////////////////////////
HRESULT IDirectSoundBuffer8Ex::GetObjectInPath(REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, LPVOID *ppObject)
{
#ifdef ENABLE_LOG
if( g_bLogDirectSoundBuffer == true )
LogMessage( m_cszClassName, this, "GetObjectInPath called....");
#endif // ENABLE_LOG
return m_lpDirectSoundBuffer8->GetObjectInPath(rguidObject, dwIndex, rguidInterface, ppObject);
}
//////////////////////////////////////////////////////////////////////////////////////////////