2 * Tests basic sound playback in DirectSound.
3 * In particular we test each standard Windows sound format to make sure
4 * we handle the sound card/driver quirks correctly.
6 * Part of this test involves playing test tones. But this only makes
7 * sense if someone is going to carefully listen to it, and would only
8 * bother everyone else.
9 * So this is only done if the test is being run in interactive mode.
11 * Copyright (c) 2002-2004 Francois Gouget
12 * Copyright (c) 2007 Maarten Lankhorst
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
39 #include "dsound_test.h"
41 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
43 static HRESULT (WINAPI
*pDirectSoundEnumerateA
)(LPDSENUMCALLBACKA
,LPVOID
)=NULL
;
44 static HRESULT (WINAPI
*pDirectSoundCreate
)(LPCGUID
,LPDIRECTSOUND
*,
49 static void IDirectSound_test(LPDIRECTSOUND dso
, BOOL initialized
,
58 DWORD speaker_config
, new_speaker_config
, ref_speaker_config
;
60 /* Try to Query for objects */
61 rc
=IDirectSound_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
62 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IUnknown) failed: %08x\n", rc
);
64 IDirectSound_Release(unknown
);
66 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
67 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %08x\n", rc
);
69 IDirectSound_Release(ds
);
71 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
72 ok(rc
==E_NOINTERFACE
,"IDirectSound_QueryInterface(IID_IDirectSound8) "
73 "should have failed: %08x\n",rc
);
75 IDirectSound8_Release(ds8
);
77 if (initialized
== FALSE
) {
78 /* try uninitialized object */
79 rc
=IDirectSound_GetCaps(dso
,0);
80 ok(rc
==DSERR_UNINITIALIZED
,"IDirectSound_GetCaps(NULL) "
81 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc
);
83 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
84 ok(rc
==DSERR_UNINITIALIZED
,"IDirectSound_GetCaps() "
85 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc
);
87 rc
=IDirectSound_Compact(dso
);
88 ok(rc
==DSERR_UNINITIALIZED
,"IDirectSound_Compact() "
89 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc
);
91 rc
=IDirectSound_GetSpeakerConfig(dso
,&speaker_config
);
92 ok(rc
==DSERR_UNINITIALIZED
,"IDirectSound_GetSpeakerConfig() "
93 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc
);
95 rc
=IDirectSound_Initialize(dso
,lpGuid
);
96 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
97 "IDirectSound_Initialize() failed: %08x\n",rc
);
98 if (rc
==DSERR_NODRIVER
) {
99 trace(" No Driver\n");
101 } else if (rc
==E_FAIL
) {
102 trace(" No Device\n");
104 } else if (rc
==DSERR_ALLOCATED
) {
105 trace(" Already In Use\n");
110 rc
=IDirectSound_Initialize(dso
,lpGuid
);
111 ok(rc
==DSERR_ALREADYINITIALIZED
, "IDirectSound_Initialize() "
112 "should have returned DSERR_ALREADYINITIALIZED: %08x\n", rc
);
114 /* DSOUND: Error: Invalid caps buffer */
115 rc
=IDirectSound_GetCaps(dso
,0);
116 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_GetCaps(NULL) "
117 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
119 ZeroMemory(&dscaps
, sizeof(dscaps
));
121 /* DSOUND: Error: Invalid caps buffer */
122 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
123 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_GetCaps() "
124 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
126 dscaps
.dwSize
=sizeof(dscaps
);
128 /* DSOUND: Running on a certified driver */
129 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
130 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
132 rc
=IDirectSound_Compact(dso
);
133 ok(rc
==DSERR_PRIOLEVELNEEDED
,"IDirectSound_Compact() failed: %08x\n", rc
);
135 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
136 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
138 rc
=IDirectSound_Compact(dso
);
139 ok(rc
==DS_OK
,"IDirectSound_Compact() failed: %08x\n",rc
);
141 rc
=IDirectSound_GetSpeakerConfig(dso
,0);
142 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_GetSpeakerConfig(NULL) "
143 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
145 rc
=IDirectSound_GetSpeakerConfig(dso
,&speaker_config
);
146 ok(rc
==DS_OK
,"IDirectSound_GetSpeakerConfig() failed: %08x\n", rc
);
147 ref_speaker_config
= speaker_config
;
149 speaker_config
= DSSPEAKER_COMBINED(DSSPEAKER_STEREO
,
150 DSSPEAKER_GEOMETRY_WIDE
);
151 if (speaker_config
== ref_speaker_config
)
152 speaker_config
= DSSPEAKER_COMBINED(DSSPEAKER_STEREO
,
153 DSSPEAKER_GEOMETRY_NARROW
);
155 rc
=IDirectSound_SetSpeakerConfig(dso
,speaker_config
);
156 ok(rc
==DS_OK
,"IDirectSound_SetSpeakerConfig() failed: %08x\n", rc
);
159 rc
=IDirectSound_GetSpeakerConfig(dso
,&new_speaker_config
);
160 ok(rc
==DS_OK
,"IDirectSound_GetSpeakerConfig() failed: %08x\n", rc
);
161 if (rc
==DS_OK
&& speaker_config
!=new_speaker_config
)
162 trace("IDirectSound_GetSpeakerConfig() failed to set speaker "
163 "config: expected 0x%08x, got 0x%08x\n",
164 speaker_config
,new_speaker_config
);
165 IDirectSound_SetSpeakerConfig(dso
,ref_speaker_config
);
169 ref
=IDirectSound_Release(dso
);
170 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
173 static void IDirectSound_tests(void)
176 LPDIRECTSOUND dso
=NULL
;
177 LPCLASSFACTORY cf
=NULL
;
179 trace("Testing IDirectSound\n");
181 rc
=CoGetClassObject(&CLSID_DirectSound
, CLSCTX_INPROC_SERVER
, NULL
,
182 &IID_IClassFactory
, (void**)&cf
);
183 ok(rc
==S_OK
,"CoGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
184 "failed: %08x\n", rc
);
186 rc
=CoGetClassObject(&CLSID_DirectSound
, CLSCTX_INPROC_SERVER
, NULL
,
187 &IID_IUnknown
, (void**)&cf
);
188 ok(rc
==S_OK
,"CoGetClassObject(CLSID_DirectSound, IID_IUnknown) "
189 "failed: %08x\n", rc
);
191 /* try the COM class factory method of creation with no device specified */
192 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
193 &IID_IDirectSound
, (void**)&dso
);
194 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
196 IDirectSound_test(dso
, FALSE
, NULL
);
198 /* try the COM class factory method of creation with default playback
199 * device specified */
200 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
201 &IID_IDirectSound
, (void**)&dso
);
202 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
204 IDirectSound_test(dso
, FALSE
, &DSDEVID_DefaultPlayback
);
206 /* try the COM class factory method of creation with default voice
207 * playback device specified */
208 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
209 &IID_IDirectSound
, (void**)&dso
);
210 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
212 IDirectSound_test(dso
, FALSE
, &DSDEVID_DefaultVoicePlayback
);
214 /* try the COM class factory method of creation with a bad
216 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
217 &CLSID_DirectSoundPrivate
, (void**)&dso
);
218 ok(rc
==E_NOINTERFACE
,
219 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
220 "should have failed: %08x\n",rc
);
222 /* try the COM class factory method of creation with a bad
223 * GUID and IID specified */
224 rc
=CoCreateInstance(&CLSID_DirectSoundPrivate
, NULL
, CLSCTX_INPROC_SERVER
,
225 &IID_IDirectSound
, (void**)&dso
);
226 ok(rc
==REGDB_E_CLASSNOTREG
,
227 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
228 "should have failed: %08x\n",rc
);
230 /* try with no device specified */
231 rc
=pDirectSoundCreate(NULL
,&dso
,NULL
);
232 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
233 "DirectSoundCreate(NULL) failed: %08x\n",rc
);
235 IDirectSound_test(dso
, TRUE
, NULL
);
237 /* try with default playback device specified */
238 rc
=pDirectSoundCreate(&DSDEVID_DefaultPlayback
,&dso
,NULL
);
239 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
240 "DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %08x\n", rc
);
241 if (rc
==DS_OK
&& dso
)
242 IDirectSound_test(dso
, TRUE
, NULL
);
244 /* try with default voice playback device specified */
245 rc
=pDirectSoundCreate(&DSDEVID_DefaultVoicePlayback
,&dso
,NULL
);
246 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
247 "DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc
);
248 if (rc
==DS_OK
&& dso
)
249 IDirectSound_test(dso
, TRUE
, NULL
);
251 /* try with a bad device specified */
252 rc
=pDirectSoundCreate(&DSDEVID_DefaultVoiceCapture
,&dso
,NULL
);
253 ok(rc
==DSERR_NODRIVER
,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
254 "should have failed: %08x\n",rc
);
255 if (rc
==DS_OK
&& dso
)
256 IDirectSound_Release(dso
);
259 static HRESULT
test_dsound(LPGUID lpGuid
)
262 LPDIRECTSOUND dso
=NULL
;
265 /* DSOUND: Error: Invalid interface buffer */
266 rc
=pDirectSoundCreate(lpGuid
,0,NULL
);
267 ok(rc
==DSERR_INVALIDPARAM
,"DirectSoundCreate() should have returned "
268 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
270 /* Create the DirectSound object */
271 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
272 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
273 "DirectSoundCreate() failed: %08x\n",rc
);
277 /* Try the enumerated device */
278 IDirectSound_test(dso
, TRUE
, lpGuid
);
280 /* Try the COM class factory method of creation with enumerated device */
281 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
282 &IID_IDirectSound
, (void**)&dso
);
283 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
285 IDirectSound_test(dso
, FALSE
, lpGuid
);
287 /* Create a DirectSound object */
288 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
289 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
291 LPDIRECTSOUND dso1
=NULL
;
293 /* Create a second DirectSound object */
294 rc
=pDirectSoundCreate(lpGuid
,&dso1
,NULL
);
295 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
297 /* Release the second DirectSound object */
298 ref
=IDirectSound_Release(dso1
);
299 ok(ref
==0,"IDirectSound_Release() has %d references, should have "
301 ok(dso
!=dso1
,"DirectSound objects should be unique: dso=%p,dso1=%p\n",dso
,dso1
);
304 /* Release the first DirectSound object */
305 ref
=IDirectSound_Release(dso
);
306 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",
309 return DSERR_GENERIC
;
313 /* Create a DirectSound object */
314 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
315 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
317 LPDIRECTSOUNDBUFFER secondary
;
318 DSBUFFERDESC bufdesc
;
321 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,8,1);
322 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
323 bufdesc
.dwSize
=sizeof(bufdesc
);
324 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_CTRL3D
;
325 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
327 bufdesc
.lpwfxFormat
=&wfx
;
328 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
329 ok(rc
==DS_OK
&& secondary
!=NULL
,
330 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
332 if (rc
==DS_OK
&& secondary
!=NULL
) {
333 LPDIRECTSOUND3DBUFFER buffer3d
;
334 rc
=IDirectSound_QueryInterface(secondary
, &IID_IDirectSound3DBuffer
,
336 ok(rc
==DS_OK
&& buffer3d
!=NULL
,"IDirectSound_QueryInterface() "
337 "failed: %08x\n",rc
);
338 if (rc
==DS_OK
&& buffer3d
!=NULL
) {
339 ref
=IDirectSound3DBuffer_AddRef(buffer3d
);
340 ok(ref
==2,"IDirectSound3DBuffer_AddRef() has %d references, "
341 "should have 2\n",ref
);
343 ref
=IDirectSoundBuffer_AddRef(secondary
);
344 ok(ref
==2,"IDirectSoundBuffer_AddRef() has %d references, "
345 "should have 2\n",ref
);
347 /* release with buffer */
348 ref
=IDirectSound_Release(dso
);
349 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",
352 return DSERR_GENERIC
;
359 static HRESULT
test_primary(LPGUID lpGuid
)
362 LPDIRECTSOUND dso
=NULL
;
363 LPDIRECTSOUNDBUFFER primary
=NULL
,second
=NULL
,third
=NULL
;
364 DSBUFFERDESC bufdesc
;
369 /* Create the DirectSound object */
370 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
371 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
372 "DirectSoundCreate() failed: %08x\n",rc
);
376 /* Get the device capabilities */
377 ZeroMemory(&dscaps
, sizeof(dscaps
));
378 dscaps
.dwSize
=sizeof(dscaps
);
379 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
380 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
384 /* DSOUND: Error: Invalid buffer description pointer */
385 rc
=IDirectSound_CreateSoundBuffer(dso
,0,0,NULL
);
386 ok(rc
==DSERR_INVALIDPARAM
,
387 "IDirectSound_CreateSoundBuffer() should have failed: %08x\n", rc
);
389 /* DSOUND: Error: NULL pointer is invalid */
390 /* DSOUND: Error: Invalid buffer description pointer */
391 rc
=IDirectSound_CreateSoundBuffer(dso
,0,&primary
,NULL
);
392 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
393 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
394 "dsbo=%p\n",rc
,primary
);
396 /* DSOUND: Error: Invalid size */
397 /* DSOUND: Error: Invalid buffer description */
399 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
400 bufdesc
.dwSize
=sizeof(bufdesc
)-1;
401 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
402 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
403 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
404 "primary=%p\n",rc
,primary
);
406 /* DSOUND: Error: DSBCAPS_PRIMARYBUFFER flag with non-NULL lpwfxFormat */
407 /* DSOUND: Error: Invalid buffer description pointer */
409 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
410 bufdesc
.dwSize
=sizeof(bufdesc
);
411 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
412 bufdesc
.lpwfxFormat
=&wfx
;
413 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
414 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
415 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
416 "primary=%p\n",rc
,primary
);
418 /* DSOUND: Error: No DSBCAPS_PRIMARYBUFFER flag with NULL lpwfxFormat */
419 /* DSOUND: Error: Invalid buffer description pointer */
421 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
422 bufdesc
.dwSize
=sizeof(bufdesc
);
424 bufdesc
.lpwfxFormat
=NULL
;
425 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
426 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
427 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
428 "primary=%p\n",rc
,primary
);
430 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
431 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
432 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
433 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
437 /* Testing the primary buffer */
439 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
440 bufdesc
.dwSize
=sizeof(bufdesc
);
441 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
;
442 bufdesc
.lpwfxFormat
= &wfx
;
443 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,8,2);
444 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
445 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_CreateSoundBuffer() should have "
446 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
447 if (rc
==DS_OK
&& primary
!=NULL
)
448 IDirectSoundBuffer_Release(primary
);
451 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
452 bufdesc
.dwSize
=sizeof(bufdesc
);
453 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
;
454 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
455 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
==DSERR_CONTROLUNAVAIL
),
456 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc
);
457 if (rc
==DSERR_CONTROLUNAVAIL
)
458 trace(" No Primary\n");
459 else if (rc
==DS_OK
&& primary
!=NULL
) {
462 /* Try to create a second primary buffer */
463 /* DSOUND: Error: The primary buffer already exists.
464 * Any changes made to the buffer description will be ignored. */
465 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&second
,NULL
);
466 ok(rc
==DS_OK
&& second
==primary
,
467 "IDirectSound_CreateSoundBuffer() should have returned original "
468 "primary buffer: %08x\n",rc
);
469 ref
=IDirectSoundBuffer_Release(second
);
470 ok(ref
==1,"IDirectSoundBuffer_Release() primary has %d references, "
471 "should have 1\n",ref
);
473 /* Try to duplicate a primary buffer */
474 /* DSOUND: Error: Can't duplicate primary buffers */
475 rc
=IDirectSound_DuplicateSoundBuffer(dso
,primary
,&third
);
477 ok(rc
!=DS_OK
,"IDirectSound_DuplicateSoundBuffer() primary buffer "
478 "should have failed %08x\n",rc
);
480 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
481 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc
);
483 if (winetest_interactive
) {
484 trace("Playing a 5 seconds reference tone at the current "
487 trace("(the current volume is %d according to DirectSound)\n",
489 trace("All subsequent tones should be identical to this one.\n");
490 trace("Listen for stutter, changes in pitch, volume, etc.\n");
492 test_buffer(dso
,&primary
,1,FALSE
,0,FALSE
,0,winetest_interactive
&&
493 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),5.0,0,0,0,0,FALSE
,0);
495 ref
=IDirectSoundBuffer_Release(primary
);
496 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
497 "should have 0\n",ref
);
500 /* Set the CooperativeLevel back to normal */
501 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
502 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
503 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
506 ref
=IDirectSound_Release(dso
);
507 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
509 return DSERR_GENERIC
;
515 * Test the primary buffer at different formats while keeping the
516 * secondary buffer at a constant format.
518 static HRESULT
test_primary_secondary(LPGUID lpGuid
)
521 LPDIRECTSOUND dso
=NULL
;
522 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
523 DSBUFFERDESC bufdesc
;
525 WAVEFORMATEX wfx
, wfx2
;
528 /* Create the DirectSound object */
529 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
530 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
531 "DirectSoundCreate() failed: %08x\n",rc
);
535 /* Get the device capabilities */
536 ZeroMemory(&dscaps
, sizeof(dscaps
));
537 dscaps
.dwSize
=sizeof(dscaps
);
538 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
539 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
543 /* We must call SetCooperativeLevel before creating primary buffer */
544 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
545 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
546 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
550 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
551 bufdesc
.dwSize
=sizeof(bufdesc
);
552 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
553 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
554 ok(rc
==DS_OK
&& primary
!=NULL
,
555 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
557 if (rc
==DS_OK
&& primary
!=NULL
) {
558 for (f
=0;f
<NB_FORMATS
;f
++) {
559 /* We must call SetCooperativeLevel to be allowed to call
561 /* DSOUND: Setting DirectSound cooperative level to
563 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
564 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
568 init_format(&wfx
,WAVE_FORMAT_PCM
,formats
[f
][0],formats
[f
][1],
571 rc
=IDirectSoundBuffer_SetFormat(primary
,&wfx
);
573 if (wfx
.wBitsPerSample
<= 16)
574 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
575 format_string(&wfx
), rc
);
577 ok(rc
==DS_OK
|| rc
== E_INVALIDARG
, "SetFormat (%s) failed: %08x\n",
578 format_string(&wfx
), rc
);
580 /* There is no guarantee that SetFormat will actually change the
581 * format to what we asked for. It depends on what the soundcard
582 * supports. So we must re-query the format.
584 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx
,sizeof(wfx
),NULL
);
585 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
587 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
588 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
589 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
590 wfx
.nChannels
!=wfx2
.nChannels
)) {
591 trace("Requested primary format tag=0x%04x %dx%dx%d "
592 "avg.B/s=%d align=%d\n",
593 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
594 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
595 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
596 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
597 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
600 /* Set the CooperativeLevel back to normal */
601 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
602 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
603 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
605 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
608 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
609 bufdesc
.dwSize
=sizeof(bufdesc
);
610 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
611 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
613 bufdesc
.lpwfxFormat
=&wfx2
;
614 if (winetest_interactive
) {
615 trace(" Testing a primary buffer at %dx%dx%d with a "
616 "secondary buffer at %dx%dx%d\n",
617 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
618 wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,wfx2
.nChannels
);
620 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
621 ok(rc
==DS_OK
&& secondary
!=NULL
,
622 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
624 if (rc
==DS_OK
&& secondary
!=NULL
) {
625 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
626 winetest_interactive
,1.0,0,NULL
,0,0,FALSE
,0);
628 ref
=IDirectSoundBuffer_Release(secondary
);
629 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
630 "should have 0\n",ref
);
634 ref
=IDirectSoundBuffer_Release(primary
);
635 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
636 "should have 0\n",ref
);
639 /* Set the CooperativeLevel back to normal */
640 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
641 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
642 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
645 ref
=IDirectSound_Release(dso
);
646 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
648 return DSERR_GENERIC
;
653 static HRESULT
test_secondary(LPGUID lpGuid
)
656 LPDIRECTSOUND dso
=NULL
;
657 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
658 DSBUFFERDESC bufdesc
;
660 WAVEFORMATEX wfx
, wfx1
;
664 /* Create the DirectSound object */
665 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
666 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
667 "DirectSoundCreate() failed: %08x\n",rc
);
671 /* Get the device capabilities */
672 ZeroMemory(&dscaps
, sizeof(dscaps
));
673 dscaps
.dwSize
=sizeof(dscaps
);
674 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
675 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
679 /* We must call SetCooperativeLevel before creating primary buffer */
680 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
681 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
682 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
686 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
687 bufdesc
.dwSize
=sizeof(bufdesc
);
688 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
689 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
690 ok(rc
==DS_OK
&& primary
!=NULL
,
691 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
693 if (rc
==DS_OK
&& primary
!=NULL
) {
694 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
695 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
699 for (f
=0;f
<NB_FORMATS
;f
++) {
700 WAVEFORMATEXTENSIBLE wfxe
;
701 init_format(&wfx
,WAVE_FORMAT_PCM
,formats
[f
][0],formats
[f
][1],
704 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
705 bufdesc
.dwSize
=sizeof(bufdesc
);
706 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
707 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
709 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
710 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_CreateSoundBuffer() "
711 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
712 if (rc
==DS_OK
&& secondary
!=NULL
)
713 IDirectSoundBuffer_Release(secondary
);
716 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
717 bufdesc
.dwSize
=sizeof(bufdesc
);
718 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
719 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
721 bufdesc
.lpwfxFormat
=&wfx
;
722 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
723 if (gotdx8
|| wfx
.wBitsPerSample
<= 16)
725 if (wfx
.wBitsPerSample
> 16)
726 ok(((rc
== DSERR_CONTROLUNAVAIL
|| rc
== DSERR_INVALIDCALL
|| rc
== DSERR_INVALIDPARAM
/* 2003 */) && !secondary
)
727 || rc
== DS_OK
, /* driver dependent? */
728 "IDirectSound_CreateSoundBuffer() "
729 "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) "
730 "and NULL, returned: %08x %p\n", rc
, secondary
);
732 ok(rc
==DS_OK
&& secondary
!=NULL
,
733 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
736 ok(rc
==E_INVALIDARG
, "Creating %d bpp buffer on dx < 8 returned: %p %08x\n",
737 wfx
.wBitsPerSample
, secondary
, rc
);
741 skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
742 /* Apparently they succeed with bogus values,
743 * which means that older dsound doesn't look at them
749 IDirectSoundBuffer_Release(secondary
);
752 bufdesc
.lpwfxFormat
=(WAVEFORMATEX
*)&wfxe
;
754 wfxe
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
755 wfxe
.SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
756 wfxe
.Format
.cbSize
= 1;
757 wfxe
.Samples
.wValidBitsPerSample
= wfx
.wBitsPerSample
;
758 wfxe
.dwChannelMask
= (wfx
.nChannels
== 1 ? KSAUDIO_SPEAKER_MONO
: KSAUDIO_SPEAKER_STEREO
);
760 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
761 ok((rc
==DSERR_INVALIDPARAM
|| rc
==DSERR_INVALIDCALL
/* 2003 */) && !secondary
,
762 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
766 IDirectSoundBuffer_Release(secondary
);
770 wfxe
.Format
.cbSize
= sizeof(wfxe
) - sizeof(wfx
) + 1;
772 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
773 ok(((rc
==DSERR_CONTROLUNAVAIL
|| rc
==DSERR_INVALIDCALL
|| rc
==DSERR_INVALIDPARAM
)
775 || rc
==DS_OK
, /* 2003 / 2008 */
776 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
780 IDirectSoundBuffer_Release(secondary
);
784 wfxe
.Format
.cbSize
= sizeof(wfxe
) - sizeof(wfx
);
785 wfxe
.SubFormat
= GUID_NULL
;
786 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
787 ok((rc
==DSERR_INVALIDPARAM
|| rc
==DSERR_INVALIDCALL
) && !secondary
,
788 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
792 IDirectSoundBuffer_Release(secondary
);
795 wfxe
.SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
797 ++wfxe
.Samples
.wValidBitsPerSample
;
798 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
799 ok(rc
==DSERR_INVALIDPARAM
&& !secondary
,
800 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
804 IDirectSoundBuffer_Release(secondary
);
807 --wfxe
.Samples
.wValidBitsPerSample
;
809 wfxe
.Samples
.wValidBitsPerSample
= 0;
810 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
811 ok(rc
==DS_OK
&& secondary
,
812 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
816 IDirectSoundBuffer_Release(secondary
);
819 wfxe
.Samples
.wValidBitsPerSample
= wfxe
.Format
.wBitsPerSample
;
821 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
822 ok(rc
==DS_OK
&& secondary
!=NULL
,
823 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
826 if (rc
==DS_OK
&& secondary
!=NULL
) {
827 if (winetest_interactive
) {
828 trace(" Testing a secondary buffer at %dx%dx%d "
829 "with a primary buffer at %dx%dx%d\n",
830 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
831 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
833 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
834 winetest_interactive
,1.0,0,NULL
,0,0,FALSE
,0);
836 ref
=IDirectSoundBuffer_Release(secondary
);
837 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
838 "should have 0\n",ref
);
842 ref
=IDirectSoundBuffer_Release(primary
);
843 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
844 "should have 0\n",ref
);
847 /* Set the CooperativeLevel back to normal */
848 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
849 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
850 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
853 ref
=IDirectSound_Release(dso
);
854 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
856 return DSERR_GENERIC
;
861 static HRESULT
test_block_align(LPGUID lpGuid
)
864 LPDIRECTSOUND dso
=NULL
;
865 LPDIRECTSOUNDBUFFER secondary
=NULL
;
866 DSBUFFERDESC bufdesc
;
872 /* Create the DirectSound object */
873 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
874 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
875 "DirectSoundCreate() failed: %08x\n",rc
);
879 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,16,2);
880 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
881 bufdesc
.dwSize
=sizeof(bufdesc
);
882 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
883 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
+ 1;
884 bufdesc
.lpwfxFormat
=&wfx
;
885 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
886 ok(rc
==DS_OK
,"IDirectSound_CreateSoundBuffer() "
887 "should have returned DS_OK, returned: %08x\n", rc
);
889 if (rc
==DS_OK
&& secondary
!=NULL
) {
890 ZeroMemory(&dsbcaps
, sizeof(dsbcaps
));
891 dsbcaps
.dwSize
= sizeof(dsbcaps
);
892 rc
=IDirectSoundBuffer_GetCaps(secondary
,&dsbcaps
);
893 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
894 "returned: %08x\n", rc
);
895 if (rc
==DS_OK
&& wfx
.nBlockAlign
> 1)
897 ok(dsbcaps
.dwBufferBytes
==(wfx
.nAvgBytesPerSec
+ wfx
.nBlockAlign
),
898 "Buffer size not a multiple of nBlockAlign: requested %d, "
899 "got %d, should be %d\n", bufdesc
.dwBufferBytes
,
900 dsbcaps
.dwBufferBytes
, wfx
.nAvgBytesPerSec
+ wfx
.nBlockAlign
);
902 rc
= IDirectSoundBuffer_SetCurrentPosition(secondary
, 0);
903 ok(rc
== DS_OK
, "Could not set position to 0: %08x\n", rc
);
904 rc
= IDirectSoundBuffer_GetCurrentPosition(secondary
, &pos
, NULL
);
905 ok(rc
== DS_OK
, "Could not get position: %08x\n", rc
);
906 rc
= IDirectSoundBuffer_SetCurrentPosition(secondary
, 1);
907 ok(rc
== DS_OK
, "Could not set position to 1: %08x\n", rc
);
908 rc
= IDirectSoundBuffer_GetCurrentPosition(secondary
, &pos2
, NULL
);
909 ok(rc
== DS_OK
, "Could not get new position: %08x\n", rc
);
910 ok(pos
== pos2
, "Positions not the same! Old position: %d, new position: %d\n", pos
, pos2
);
912 ref
=IDirectSoundBuffer_Release(secondary
);
913 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d references, "
914 "should have 0\n",ref
);
917 ref
=IDirectSound_Release(dso
);
918 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
920 return DSERR_GENERIC
;
928 } fmts
[] = { { 8, 1 }, { 8, 2 }, { 16, 1 }, {16, 2 } };
930 static HRESULT
test_frequency(LPGUID lpGuid
)
933 LPDIRECTSOUND dso
=NULL
;
934 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
935 DSBUFFERDESC bufdesc
;
937 WAVEFORMATEX wfx
, wfx1
;
940 int rates
[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
943 /* Create the DirectSound object */
944 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
945 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
946 "DirectSoundCreate() failed: %08x\n",rc
);
950 /* Get the device capabilities */
951 ZeroMemory(&dscaps
, sizeof(dscaps
));
952 dscaps
.dwSize
=sizeof(dscaps
);
953 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
954 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
958 /* We must call SetCooperativeLevel before creating primary buffer */
959 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
960 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
961 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
965 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
966 bufdesc
.dwSize
=sizeof(bufdesc
);
967 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
968 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
969 ok(rc
==DS_OK
&& primary
!=NULL
,
970 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
972 if (rc
==DS_OK
&& primary
!=NULL
) {
973 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
974 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
978 for (f
=0;f
<sizeof(fmts
)/sizeof(fmts
[0]);f
++) {
979 for (r
=0;r
<sizeof(rates
)/sizeof(rates
[0]);r
++) {
980 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,fmts
[f
].bits
,
983 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
984 bufdesc
.dwSize
=sizeof(bufdesc
);
985 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
|DSBCAPS_CTRLFREQUENCY
;
986 bufdesc
.dwBufferBytes
=align((wfx
.nAvgBytesPerSec
*rates
[r
]/11025)*
987 BUFFER_LEN
/1000,wfx
.nBlockAlign
);
988 bufdesc
.lpwfxFormat
=&wfx
;
989 if (winetest_interactive
) {
990 trace(" Testing a secondary buffer at %dx%dx%d "
991 "with a primary buffer at %dx%dx%d\n",
992 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
993 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
995 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
996 ok(rc
==DS_OK
&& secondary
!=NULL
,
997 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
999 if (rc
==DS_OK
&& secondary
!=NULL
) {
1000 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
1001 winetest_interactive
,1.0,0,NULL
,0,0,TRUE
,rates
[r
]);
1003 ref
=IDirectSoundBuffer_Release(secondary
);
1004 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
1005 "should have 0\n",ref
);
1010 ref
=IDirectSoundBuffer_Release(primary
);
1011 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1012 "should have 0\n",ref
);
1015 /* Set the CooperativeLevel back to normal */
1016 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1017 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
1018 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
1021 ref
=IDirectSound_Release(dso
);
1022 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1024 return DSERR_GENERIC
;
1029 static unsigned int number
;
1031 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1032 LPCSTR lpcstrModule
, LPVOID lpContext
)
1035 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1037 /* Don't test the primary device */
1040 ok (!lpcstrModule
[0], "lpcstrModule(%s) != NULL\n", lpcstrModule
);
1044 rc
= test_dsound(lpGuid
);
1045 if (rc
== DSERR_NODRIVER
)
1046 trace(" No Driver\n");
1047 else if (rc
== DSERR_ALLOCATED
)
1048 trace(" Already In Use\n");
1049 else if (rc
== E_FAIL
)
1050 trace(" No Device\n");
1052 test_block_align(lpGuid
);
1053 test_primary(lpGuid
);
1054 test_primary_secondary(lpGuid
);
1055 test_secondary(lpGuid
);
1056 test_frequency(lpGuid
);
1062 static void dsound_tests(void)
1065 rc
=pDirectSoundEnumerateA(&dsenum_callback
,NULL
);
1066 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %08x\n",rc
);
1075 hDsound
= LoadLibrary("dsound.dll");
1080 ok( FreeLibrary(hDsound
), "FreeLibrary(1) returned %d\n", GetLastError());
1081 SetLastError(0xdeadbeef);
1082 ret
= FreeLibrary(hDsound
);
1084 broken(!ret
&& GetLastError() == ERROR_MOD_NOT_FOUND
) || /* NT4 */
1085 broken(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
), /* Win9x */
1086 "FreeLibrary(2) returned %d\n", GetLastError());
1087 ok(!FreeLibrary(hDsound
), "DirectSound DLL still loaded\n");
1090 hDsound
= LoadLibrary("dsound.dll");
1094 pDirectSoundEnumerateA
= (void*)GetProcAddress(hDsound
,
1095 "DirectSoundEnumerateA");
1096 pDirectSoundCreate
= (void*)GetProcAddress(hDsound
,
1097 "DirectSoundCreate");
1099 gotdx8
= !!GetProcAddress(hDsound
, "DirectSoundCreate8");
1101 IDirectSound_tests();
1104 FreeLibrary(hDsound
);
1107 skip("dsound.dll not found!\n");