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 IDirectSound
*dso
=(IDirectSound
*)0xdeadbeef;
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 /* COM aggregation */
192 rc
=CoCreateInstance(&CLSID_DirectSound
, (IUnknown
*)&dso
, CLSCTX_INPROC_SERVER
,
193 &IID_IDirectSound
, (void**)&dso
);
194 ok(rc
==CLASS_E_NOAGGREGATION
|| broken(rc
==DSERR_INVALIDPARAM
),
195 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", rc
);
197 /* try the COM class factory method of creation with no device specified */
198 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
199 &IID_IDirectSound
, (void**)&dso
);
200 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
202 IDirectSound_test(dso
, FALSE
, NULL
);
204 /* try the COM class factory method of creation with default playback
205 * device specified */
206 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
207 &IID_IDirectSound
, (void**)&dso
);
208 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
210 IDirectSound_test(dso
, FALSE
, &DSDEVID_DefaultPlayback
);
212 /* try the COM class factory method of creation with default voice
213 * playback device specified */
214 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
215 &IID_IDirectSound
, (void**)&dso
);
216 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
218 IDirectSound_test(dso
, FALSE
, &DSDEVID_DefaultVoicePlayback
);
220 /* try the COM class factory method of creation with a bad
222 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
223 &CLSID_DirectSoundPrivate
, (void**)&dso
);
224 ok(rc
==E_NOINTERFACE
,
225 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
226 "should have failed: %08x\n",rc
);
228 /* try the COM class factory method of creation with a bad
229 * GUID and IID specified */
230 rc
=CoCreateInstance(&CLSID_DirectSoundPrivate
, NULL
, CLSCTX_INPROC_SERVER
,
231 &IID_IDirectSound
, (void**)&dso
);
232 ok(rc
==REGDB_E_CLASSNOTREG
,
233 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
234 "should have failed: %08x\n",rc
);
236 /* try with no device specified */
237 rc
=pDirectSoundCreate(NULL
,&dso
,NULL
);
238 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
239 "DirectSoundCreate(NULL) failed: %08x\n",rc
);
241 IDirectSound_test(dso
, TRUE
, NULL
);
243 /* try with default playback device specified */
244 rc
=pDirectSoundCreate(&DSDEVID_DefaultPlayback
,&dso
,NULL
);
245 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
246 "DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %08x\n", rc
);
247 if (rc
==DS_OK
&& dso
)
248 IDirectSound_test(dso
, TRUE
, NULL
);
250 /* try with default voice playback device specified */
251 rc
=pDirectSoundCreate(&DSDEVID_DefaultVoicePlayback
,&dso
,NULL
);
252 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
253 "DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc
);
254 if (rc
==DS_OK
&& dso
)
255 IDirectSound_test(dso
, TRUE
, NULL
);
257 /* try with a bad device specified */
258 rc
=pDirectSoundCreate(&DSDEVID_DefaultVoiceCapture
,&dso
,NULL
);
259 ok(rc
==DSERR_NODRIVER
,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
260 "should have failed: %08x\n",rc
);
261 if (rc
==DS_OK
&& dso
)
262 IDirectSound_Release(dso
);
265 static HRESULT
test_dsound(LPGUID lpGuid
)
268 LPDIRECTSOUND dso
=NULL
;
271 /* DSOUND: Error: Invalid interface buffer */
272 rc
=pDirectSoundCreate(lpGuid
,0,NULL
);
273 ok(rc
==DSERR_INVALIDPARAM
,"DirectSoundCreate() should have returned "
274 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
276 /* Create the DirectSound object */
277 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
278 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
279 "DirectSoundCreate() failed: %08x\n",rc
);
283 /* Try the enumerated device */
284 IDirectSound_test(dso
, TRUE
, lpGuid
);
286 /* Try the COM class factory method of creation with enumerated device */
287 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
,
288 &IID_IDirectSound
, (void**)&dso
);
289 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc
);
291 IDirectSound_test(dso
, FALSE
, lpGuid
);
293 /* Create a DirectSound object */
294 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
295 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
297 LPDIRECTSOUND dso1
=NULL
;
299 /* Create a second DirectSound object */
300 rc
=pDirectSoundCreate(lpGuid
,&dso1
,NULL
);
301 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
303 /* Release the second DirectSound object */
304 ref
=IDirectSound_Release(dso1
);
305 ok(ref
==0,"IDirectSound_Release() has %d references, should have "
307 ok(dso
!=dso1
,"DirectSound objects should be unique: dso=%p,dso1=%p\n",dso
,dso1
);
310 /* Release the first DirectSound object */
311 ref
=IDirectSound_Release(dso
);
312 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",
315 return DSERR_GENERIC
;
319 /* Create a DirectSound object */
320 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
321 ok(rc
==DS_OK
,"DirectSoundCreate() failed: %08x\n",rc
);
323 LPDIRECTSOUNDBUFFER secondary
;
324 DSBUFFERDESC bufdesc
;
327 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,8,1);
328 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
329 bufdesc
.dwSize
=sizeof(bufdesc
);
330 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_CTRL3D
;
331 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
333 bufdesc
.lpwfxFormat
=&wfx
;
334 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
335 ok((rc
==DS_OK
&& secondary
!=NULL
) || broken(rc
== DSERR_CONTROLUNAVAIL
), /* vmware drivers on w2k */
336 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
338 if (rc
==DS_OK
&& secondary
!=NULL
) {
339 LPDIRECTSOUND3DBUFFER buffer3d
;
340 rc
=IDirectSound_QueryInterface(secondary
, &IID_IDirectSound3DBuffer
,
342 ok(rc
==DS_OK
&& buffer3d
!=NULL
,"IDirectSound_QueryInterface() "
343 "failed: %08x\n",rc
);
344 if (rc
==DS_OK
&& buffer3d
!=NULL
) {
345 ref
=IDirectSound3DBuffer_AddRef(buffer3d
);
346 ok(ref
==2,"IDirectSound3DBuffer_AddRef() has %d references, "
347 "should have 2\n",ref
);
349 ref
=IDirectSoundBuffer_AddRef(secondary
);
350 ok(ref
==2,"IDirectSoundBuffer_AddRef() has %d references, "
351 "should have 2\n",ref
);
353 /* release with buffer */
354 ref
=IDirectSound_Release(dso
);
355 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",
358 return DSERR_GENERIC
;
365 static HRESULT
test_primary(LPGUID lpGuid
)
368 LPDIRECTSOUND dso
=NULL
;
369 LPDIRECTSOUNDBUFFER primary
=NULL
,second
=NULL
,third
=NULL
;
370 DSBUFFERDESC bufdesc
;
375 /* Create the DirectSound object */
376 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
377 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
378 "DirectSoundCreate() failed: %08x\n",rc
);
382 /* Get the device capabilities */
383 ZeroMemory(&dscaps
, sizeof(dscaps
));
384 dscaps
.dwSize
=sizeof(dscaps
);
385 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
386 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
390 /* DSOUND: Error: Invalid buffer description pointer */
391 rc
=IDirectSound_CreateSoundBuffer(dso
,0,0,NULL
);
392 ok(rc
==DSERR_INVALIDPARAM
,
393 "IDirectSound_CreateSoundBuffer() should have failed: %08x\n", rc
);
395 /* DSOUND: Error: NULL pointer is invalid */
396 /* DSOUND: Error: Invalid buffer description pointer */
397 rc
=IDirectSound_CreateSoundBuffer(dso
,0,&primary
,NULL
);
398 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
399 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
400 "dsbo=%p\n",rc
,primary
);
402 /* DSOUND: Error: Invalid size */
403 /* DSOUND: Error: Invalid buffer description */
405 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
406 bufdesc
.dwSize
=sizeof(bufdesc
)-1;
407 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
408 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
409 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
410 "primary=%p\n",rc
,primary
);
412 /* DSOUND: Error: DSBCAPS_PRIMARYBUFFER flag with non-NULL lpwfxFormat */
413 /* DSOUND: Error: Invalid buffer description pointer */
415 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
416 bufdesc
.dwSize
=sizeof(bufdesc
);
417 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
418 bufdesc
.lpwfxFormat
=&wfx
;
419 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
420 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
421 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
422 "primary=%p\n",rc
,primary
);
424 /* DSOUND: Error: No DSBCAPS_PRIMARYBUFFER flag with NULL lpwfxFormat */
425 /* DSOUND: Error: Invalid buffer description pointer */
427 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
428 bufdesc
.dwSize
=sizeof(bufdesc
);
430 bufdesc
.lpwfxFormat
=NULL
;
431 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
432 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,
433 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
434 "primary=%p\n",rc
,primary
);
436 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
437 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
438 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
439 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
443 /* Testing the primary buffer */
445 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
446 bufdesc
.dwSize
=sizeof(bufdesc
);
447 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
;
448 bufdesc
.lpwfxFormat
= &wfx
;
449 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,8,2);
450 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
451 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_CreateSoundBuffer() should have "
452 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
453 if (rc
==DS_OK
&& primary
!=NULL
)
454 IDirectSoundBuffer_Release(primary
);
457 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
458 bufdesc
.dwSize
=sizeof(bufdesc
);
459 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
;
460 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
461 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
==DSERR_CONTROLUNAVAIL
),
462 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc
);
463 if (rc
==DSERR_CONTROLUNAVAIL
)
464 trace(" No Primary\n");
465 else if (rc
==DS_OK
&& primary
!=NULL
) {
468 /* Try to create a second primary buffer */
469 /* DSOUND: Error: The primary buffer already exists.
470 * Any changes made to the buffer description will be ignored. */
471 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&second
,NULL
);
472 ok(rc
==DS_OK
&& second
==primary
,
473 "IDirectSound_CreateSoundBuffer() should have returned original "
474 "primary buffer: %08x\n",rc
);
475 ref
=IDirectSoundBuffer_Release(second
);
476 ok(ref
==1,"IDirectSoundBuffer_Release() primary has %d references, "
477 "should have 1\n",ref
);
479 /* Try to duplicate a primary buffer */
480 /* DSOUND: Error: Can't duplicate primary buffers */
481 rc
=IDirectSound_DuplicateSoundBuffer(dso
,primary
,&third
);
483 ok(rc
!=DS_OK
,"IDirectSound_DuplicateSoundBuffer() primary buffer "
484 "should have failed %08x\n",rc
);
486 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
487 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc
);
489 if (winetest_interactive
) {
490 trace("Playing a 5 seconds reference tone at the current "
493 trace("(the current volume is %d according to DirectSound)\n",
495 trace("All subsequent tones should be identical to this one.\n");
496 trace("Listen for stutter, changes in pitch, volume, etc.\n");
498 test_buffer(dso
,&primary
,1,FALSE
,0,FALSE
,0,winetest_interactive
&&
499 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),5.0,0,0,0,0,FALSE
,0);
501 ref
=IDirectSoundBuffer_Release(primary
);
502 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references\n",ref
);
504 ref
=IDirectSoundBuffer_AddRef(primary
);
505 ok(ref
==1,"IDirectSoundBuffer_AddRef() primary has %d references\n",ref
);
507 ref
=IDirectSoundBuffer_Release(primary
);
508 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references\n",ref
);
510 ref
=IDirectSoundBuffer_Release(primary
);
511 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
512 "should have 0\n",ref
);
515 /* Set the CooperativeLevel back to normal */
516 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
517 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
518 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
521 ref
=IDirectSound_Release(dso
);
522 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
524 return DSERR_GENERIC
;
530 * Test the primary buffer at different formats while keeping the
531 * secondary buffer at a constant format.
533 static HRESULT
test_primary_secondary(LPGUID lpGuid
)
536 LPDIRECTSOUND dso
=NULL
;
537 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
538 DSBUFFERDESC bufdesc
;
540 WAVEFORMATEX wfx
, wfx2
;
543 /* Create the DirectSound object */
544 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
545 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
546 "DirectSoundCreate() failed: %08x\n",rc
);
550 /* Get the device capabilities */
551 ZeroMemory(&dscaps
, sizeof(dscaps
));
552 dscaps
.dwSize
=sizeof(dscaps
);
553 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
554 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
558 /* We must call SetCooperativeLevel before creating primary buffer */
559 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
560 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
561 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
565 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
566 bufdesc
.dwSize
=sizeof(bufdesc
);
567 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
568 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
569 ok(rc
==DS_OK
&& primary
!=NULL
,
570 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
572 if (rc
==DS_OK
&& primary
!=NULL
) {
573 for (f
=0;f
<NB_FORMATS
;f
++) {
574 for (tag
=0;tag
<NB_TAGS
;tag
++) {
575 /* if float, we only want to test 32-bit */
576 if ((format_tags
[tag
] == WAVE_FORMAT_IEEE_FLOAT
) && (formats
[f
][1] != 32))
579 /* We must call SetCooperativeLevel to be allowed to call
581 /* DSOUND: Setting DirectSound cooperative level to
583 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
584 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
588 init_format(&wfx
,format_tags
[tag
],formats
[f
][0],formats
[f
][1],
591 rc
=IDirectSoundBuffer_SetFormat(primary
,&wfx
);
593 if (wfx
.wBitsPerSample
<= 16)
594 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
595 format_string(&wfx
), rc
);
597 ok(rc
==DS_OK
|| rc
== E_INVALIDARG
, "SetFormat (%s) failed: %08x\n",
598 format_string(&wfx
), rc
);
600 /* There is no guarantee that SetFormat will actually change the
601 * format to what we asked for. It depends on what the soundcard
602 * supports. So we must re-query the format.
604 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx
,sizeof(wfx
),NULL
);
605 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
607 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
608 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
609 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
610 wfx
.nChannels
!=wfx2
.nChannels
)) {
611 trace("Requested primary format tag=0x%04x %dx%dx%d "
612 "avg.B/s=%d align=%d\n",
613 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
614 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
615 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
616 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
617 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
620 /* Set the CooperativeLevel back to normal */
621 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
622 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
623 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
625 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
628 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
629 bufdesc
.dwSize
=sizeof(bufdesc
);
630 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
631 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
633 bufdesc
.lpwfxFormat
=&wfx2
;
634 if (winetest_interactive
) {
635 trace(" Testing a primary buffer at %dx%dx%d (fmt=%d) with a "
636 "secondary buffer at %dx%dx%d\n",
637 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,format_tags
[tag
],
638 wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,wfx2
.nChannels
);
640 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
641 ok((rc
==DS_OK
&& secondary
!=NULL
) || broken(rc
== DSERR_CONTROLUNAVAIL
), /* vmware drivers on w2k */
642 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
644 if (rc
==DS_OK
&& secondary
!=NULL
) {
645 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
646 winetest_interactive
,1.0,0,NULL
,0,0,FALSE
,0);
648 ref
=IDirectSoundBuffer_Release(secondary
);
649 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
650 "should have 0\n",ref
);
655 ref
=IDirectSoundBuffer_Release(primary
);
656 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
657 "should have 0\n",ref
);
660 /* Set the CooperativeLevel back to normal */
661 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
662 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
663 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
666 ref
=IDirectSound_Release(dso
);
667 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
669 return DSERR_GENERIC
;
674 static HRESULT
test_secondary(LPGUID lpGuid
)
677 LPDIRECTSOUND dso
=NULL
;
678 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
679 DSBUFFERDESC bufdesc
;
681 WAVEFORMATEX wfx
, wfx1
;
685 /* Create the DirectSound object */
686 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
687 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
688 "DirectSoundCreate() failed: %08x\n",rc
);
692 /* Get the device capabilities */
693 ZeroMemory(&dscaps
, sizeof(dscaps
));
694 dscaps
.dwSize
=sizeof(dscaps
);
695 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
696 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
700 /* We must call SetCooperativeLevel before creating primary buffer */
701 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
702 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
703 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
707 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
708 bufdesc
.dwSize
=sizeof(bufdesc
);
709 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
710 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
711 ok(rc
==DS_OK
&& primary
!=NULL
,
712 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
714 if (rc
==DS_OK
&& primary
!=NULL
) {
715 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
716 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
720 for (f
=0;f
<NB_FORMATS
;f
++) {
721 for (tag
=0;tag
<NB_TAGS
;tag
++) {
722 WAVEFORMATEXTENSIBLE wfxe
;
724 /* if float, we only want to test 32-bit */
725 if ((format_tags
[tag
] == WAVE_FORMAT_IEEE_FLOAT
) && (formats
[f
][1] != 32))
728 init_format(&wfx
,format_tags
[tag
],formats
[f
][0],formats
[f
][1],
731 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
732 bufdesc
.dwSize
=sizeof(bufdesc
);
733 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
734 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
736 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
737 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound_CreateSoundBuffer() "
738 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
739 if (rc
==DS_OK
&& secondary
!=NULL
)
740 IDirectSoundBuffer_Release(secondary
);
743 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
744 bufdesc
.dwSize
=sizeof(bufdesc
);
745 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
746 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
748 bufdesc
.lpwfxFormat
=&wfx
;
749 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
750 if (gotdx8
|| wfx
.wBitsPerSample
<= 16 || wfx
.wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
)
752 if (wfx
.wBitsPerSample
> 16)
753 ok(broken((rc
== DSERR_CONTROLUNAVAIL
|| rc
== DSERR_INVALIDCALL
|| rc
== DSERR_INVALIDPARAM
/* 2003 */) && !secondary
)
754 || rc
== DS_OK
, /* driver dependent? */
755 "IDirectSound_CreateSoundBuffer() "
756 "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) "
757 "and NULL, returned: %08x %p\n", rc
, secondary
);
759 ok((rc
==DS_OK
&& secondary
!=NULL
) || broken(rc
== DSERR_CONTROLUNAVAIL
), /* vmware drivers on w2k */
760 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
763 ok(rc
==E_INVALIDARG
, "Creating %d bpp buffer on dx < 8 returned: %p %08x\n",
764 wfx
.wBitsPerSample
, secondary
, rc
);
768 win_skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
769 /* Apparently they succeed with bogus values,
770 * which means that older dsound doesn't look at them
776 IDirectSoundBuffer_Release(secondary
);
779 bufdesc
.lpwfxFormat
=(WAVEFORMATEX
*)&wfxe
;
781 wfxe
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
782 wfxe
.SubFormat
= (format_tags
[tag
] == WAVE_FORMAT_PCM
? KSDATAFORMAT_SUBTYPE_PCM
: KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
);
783 wfxe
.Format
.cbSize
= 1;
784 wfxe
.Samples
.wValidBitsPerSample
= wfx
.wBitsPerSample
;
785 wfxe
.dwChannelMask
= (wfx
.nChannels
== 1 ? KSAUDIO_SPEAKER_MONO
: KSAUDIO_SPEAKER_STEREO
);
787 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
788 ok((rc
==DSERR_INVALIDPARAM
|| rc
==DSERR_INVALIDCALL
/* 2003 */) && !secondary
,
789 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
793 IDirectSoundBuffer_Release(secondary
);
797 wfxe
.Format
.cbSize
= sizeof(wfxe
) - sizeof(wfx
) + 1;
799 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
800 ok(((rc
==DSERR_CONTROLUNAVAIL
|| rc
==DSERR_INVALIDCALL
|| rc
==DSERR_INVALIDPARAM
)
802 || rc
==DS_OK
, /* 2003 / 2008 */
803 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
807 IDirectSoundBuffer_Release(secondary
);
811 wfxe
.Format
.cbSize
= sizeof(wfxe
) - sizeof(wfx
);
812 wfxe
.SubFormat
= GUID_NULL
;
813 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
814 ok((rc
==DSERR_INVALIDPARAM
|| rc
==DSERR_INVALIDCALL
) && !secondary
,
815 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
819 IDirectSoundBuffer_Release(secondary
);
822 wfxe
.SubFormat
= (format_tags
[tag
] == WAVE_FORMAT_PCM
? KSDATAFORMAT_SUBTYPE_PCM
: KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
);
824 ++wfxe
.Samples
.wValidBitsPerSample
;
825 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
826 ok(rc
==DSERR_INVALIDPARAM
&& !secondary
,
827 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
831 IDirectSoundBuffer_Release(secondary
);
834 --wfxe
.Samples
.wValidBitsPerSample
;
836 wfxe
.Samples
.wValidBitsPerSample
= 0;
837 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
838 ok(rc
==DS_OK
&& secondary
,
839 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
843 IDirectSoundBuffer_Release(secondary
);
846 wfxe
.Samples
.wValidBitsPerSample
= wfxe
.Format
.wBitsPerSample
;
848 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
849 ok(rc
==DS_OK
&& secondary
!=NULL
,
850 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
853 if (rc
==DS_OK
&& secondary
!=NULL
) {
854 if (winetest_interactive
) {
855 trace(" Testing a secondary buffer at %dx%dx%d (fmt=%d) "
856 "with a primary buffer at %dx%dx%d\n",
857 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,format_tags
[tag
],
858 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
860 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
861 winetest_interactive
,1.0,0,NULL
,0,0,FALSE
,0);
863 ref
=IDirectSoundBuffer_Release(secondary
);
864 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
865 "should have 0\n",ref
);
870 ref
=IDirectSoundBuffer_Release(primary
);
871 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
872 "should have 0\n",ref
);
875 /* Set the CooperativeLevel back to normal */
876 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
877 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
878 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
881 ref
=IDirectSound_Release(dso
);
882 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
884 return DSERR_GENERIC
;
889 static HRESULT
test_block_align(LPGUID lpGuid
)
892 LPDIRECTSOUND dso
=NULL
;
893 LPDIRECTSOUNDBUFFER secondary
=NULL
;
894 DSBUFFERDESC bufdesc
;
900 /* Create the DirectSound object */
901 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
902 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
903 "DirectSoundCreate() failed: %08x\n",rc
);
907 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,16,2);
908 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
909 bufdesc
.dwSize
=sizeof(bufdesc
);
910 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
911 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
+ 1;
912 bufdesc
.lpwfxFormat
=&wfx
;
913 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
914 ok(rc
== DS_OK
|| broken(rc
== DSERR_CONTROLUNAVAIL
), /* vmware drivers on w2k */
915 "IDirectSound_CreateSoundBuffer() should have returned DS_OK, returned: %08x\n", rc
);
917 if (rc
==DS_OK
&& secondary
!=NULL
) {
918 ZeroMemory(&dsbcaps
, sizeof(dsbcaps
));
919 dsbcaps
.dwSize
= sizeof(dsbcaps
);
920 rc
=IDirectSoundBuffer_GetCaps(secondary
,&dsbcaps
);
921 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
922 "returned: %08x\n", rc
);
923 if (rc
==DS_OK
&& wfx
.nBlockAlign
> 1)
925 ok(dsbcaps
.dwBufferBytes
==(wfx
.nAvgBytesPerSec
+ wfx
.nBlockAlign
),
926 "Buffer size not a multiple of nBlockAlign: requested %d, "
927 "got %d, should be %d\n", bufdesc
.dwBufferBytes
,
928 dsbcaps
.dwBufferBytes
, wfx
.nAvgBytesPerSec
+ wfx
.nBlockAlign
);
930 rc
= IDirectSoundBuffer_SetCurrentPosition(secondary
, 0);
931 ok(rc
== DS_OK
, "Could not set position to 0: %08x\n", rc
);
932 rc
= IDirectSoundBuffer_GetCurrentPosition(secondary
, &pos
, NULL
);
933 ok(rc
== DS_OK
, "Could not get position: %08x\n", rc
);
934 rc
= IDirectSoundBuffer_SetCurrentPosition(secondary
, 1);
935 ok(rc
== DS_OK
, "Could not set position to 1: %08x\n", rc
);
936 rc
= IDirectSoundBuffer_GetCurrentPosition(secondary
, &pos2
, NULL
);
937 ok(rc
== DS_OK
, "Could not get new position: %08x\n", rc
);
938 ok(pos
== pos2
, "Positions not the same! Old position: %d, new position: %d\n", pos
, pos2
);
940 ref
=IDirectSoundBuffer_Release(secondary
);
941 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d references, "
942 "should have 0\n",ref
);
945 ref
=IDirectSound_Release(dso
);
946 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
948 return DSERR_GENERIC
;
956 } fmts
[] = { { 8, 1 }, { 8, 2 }, { 16, 1 }, {16, 2 } };
958 static HRESULT
test_frequency(LPGUID lpGuid
)
961 LPDIRECTSOUND dso
=NULL
;
962 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
963 DSBUFFERDESC bufdesc
;
965 WAVEFORMATEX wfx
, wfx1
;
968 int rates
[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
971 /* Create the DirectSound object */
972 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
973 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
974 "DirectSoundCreate() failed: %08x\n",rc
);
978 /* Get the device capabilities */
979 ZeroMemory(&dscaps
, sizeof(dscaps
));
980 dscaps
.dwSize
=sizeof(dscaps
);
981 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
982 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %08x\n",rc
);
986 /* We must call SetCooperativeLevel before creating primary buffer */
987 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
988 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
989 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
993 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
994 bufdesc
.dwSize
=sizeof(bufdesc
);
995 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
996 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
997 ok(rc
==DS_OK
&& primary
!=NULL
,
998 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc
);
1000 if (rc
==DS_OK
&& primary
!=NULL
) {
1001 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
1002 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
1006 for (f
=0;f
<sizeof(fmts
)/sizeof(fmts
[0]);f
++) {
1007 for (r
=0;r
<sizeof(rates
)/sizeof(rates
[0]);r
++) {
1008 init_format(&wfx
,WAVE_FORMAT_PCM
,11025,fmts
[f
].bits
,
1011 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1012 bufdesc
.dwSize
=sizeof(bufdesc
);
1013 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
|DSBCAPS_CTRLFREQUENCY
;
1014 bufdesc
.dwBufferBytes
=align((wfx
.nAvgBytesPerSec
*rates
[r
]/11025)*
1015 BUFFER_LEN
/1000,wfx
.nBlockAlign
);
1016 bufdesc
.lpwfxFormat
=&wfx
;
1017 if (winetest_interactive
) {
1018 trace(" Testing a secondary buffer at %dx%dx%d "
1019 "with a primary buffer at %dx%dx%d\n",
1020 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
1021 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
1023 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
1024 ok((rc
==DS_OK
&& secondary
!=NULL
) || broken(rc
== DSERR_CONTROLUNAVAIL
), /* vmware drivers on w2k */
1025 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc
);
1027 if (rc
==DS_OK
&& secondary
!=NULL
) {
1028 test_buffer(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
1029 winetest_interactive
,1.0,0,NULL
,0,0,TRUE
,rates
[r
]);
1031 ref
=IDirectSoundBuffer_Release(secondary
);
1032 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
1033 "should have 0\n",ref
);
1038 ref
=IDirectSoundBuffer_Release(primary
);
1039 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1040 "should have 0\n",ref
);
1043 /* Set the CooperativeLevel back to normal */
1044 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1045 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
1046 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
1049 ref
=IDirectSound_Release(dso
);
1050 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1052 return DSERR_GENERIC
;
1057 static HRESULT
test_notify(LPDIRECTSOUNDBUFFER dsb
,
1058 DWORD count
, LPHANDLE event
,
1064 rc
=IDirectSoundBuffer_SetCurrentPosition(dsb
,0);
1066 "IDirectSoundBuffer_SetCurrentPosition failed %08x\n",rc
);
1070 rc
=IDirectSoundBuffer_Play(dsb
,0,0,0);
1071 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play failed %08x\n",rc
);
1075 rc
=IDirectSoundBuffer_Stop(dsb
);
1076 ok(rc
==DS_OK
,"IDirectSoundBuffer_Stop failed %08x\n",rc
);
1080 ret
=WaitForMultipleObjects(count
,event
,FALSE
,0);
1081 ok(ret
==expected
,"expected %d. got %d\n",expected
,ret
);
1085 static HRESULT
test_duplicate(LPGUID lpGuid
)
1088 LPDIRECTSOUND dso
=NULL
;
1089 LPDIRECTSOUNDBUFFER primary
=NULL
;
1090 DSBUFFERDESC bufdesc
;
1093 /* Create the DirectSound object */
1094 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
1095 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
1096 "DirectSoundCreate() failed: %08x\n",rc
);
1100 /* We must call SetCooperativeLevel before creating primary buffer */
1101 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1102 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1103 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
1107 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1108 bufdesc
.dwSize
=sizeof(bufdesc
);
1109 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
1110 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1111 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound_CreateSoundBuffer() failed "
1112 "to create a primary buffer %08x\n",rc
);
1114 if (rc
==DS_OK
&& primary
!=NULL
) {
1115 LPDIRECTSOUNDBUFFER original
=NULL
;
1118 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,1);
1119 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1120 bufdesc
.dwSize
=sizeof(bufdesc
);
1121 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
|DSBCAPS_CTRLPOSITIONNOTIFY
;
1122 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
/100; /* very short buffer */
1123 bufdesc
.lpwfxFormat
=&wfx
;
1124 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&original
,NULL
);
1125 ok(rc
==DS_OK
&& original
!=NULL
,
1126 "IDirectSound_CreateSoundBuffer() failed to create a original "
1127 "buffer %08x\n",rc
);
1128 if (rc
==DS_OK
&& original
!=NULL
) {
1129 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
1130 LPDIRECTSOUNDNOTIFY notify
=NULL
;
1136 /* Prepare notify events */
1137 for (i
=0;i
<sizeof(event
)/sizeof(event
[0]);i
++) {
1138 event
[i
] = CreateEvent(NULL
,FALSE
,FALSE
,NULL
);
1141 /* Make silent buffer */
1142 rc
=IDirectSoundBuffer_Lock(original
,0,0,&buf
,&bufsize
,
1143 NULL
,NULL
,DSBLOCK_ENTIREBUFFER
);
1144 ok(rc
==DS_OK
&& buf
!=NULL
,
1145 "IDirectSoundBuffer_Lock failed to lock the buffer %08x\n",rc
);
1146 if (rc
==DS_OK
&& buf
!=NULL
) {
1147 ZeroMemory(buf
,bufsize
);
1148 rc
=IDirectSoundBuffer_Unlock(original
,buf
,bufsize
,
1150 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock failed to unlock "
1154 rc
=IDirectSoundBuffer_QueryInterface(original
,
1155 &IID_IDirectSoundNotify
,
1157 ok(rc
==DS_OK
&& notify
!=NULL
,
1158 "IDirectSoundBuffer_QueryInterface() failed to create a "
1159 "notification %08x\n",rc
);
1160 if (rc
==DS_OK
&& notify
!=NULL
) {
1161 DSBPOSITIONNOTIFY dsbpn
;
1162 LPDIRECTSOUNDNOTIFY dup_notify
=NULL
;
1164 dsbpn
.dwOffset
=DSBPN_OFFSETSTOP
;
1165 dsbpn
.hEventNotify
=event
[0];
1166 rc
=IDirectSoundNotify_SetNotificationPositions(notify
,
1168 ok(rc
==DS_OK
,"IDirectSoundNotify_SetNotificationPositions "
1169 "failed %08x\n",rc
);
1171 rc
=IDirectSound_DuplicateSoundBuffer(dso
,original
,&duplicated
);
1172 ok(rc
==DS_OK
&& duplicated
!=NULL
,
1173 "IDirectSound_DuplicateSoundBuffer failed %08x\n",rc
);
1175 trace("testing duplicated buffer without notifications.\n");
1176 test_notify(duplicated
,sizeof(event
)/sizeof(event
[0]),
1177 event
,WAIT_TIMEOUT
);
1179 rc
=IDirectSoundBuffer_QueryInterface(duplicated
,
1180 &IID_IDirectSoundNotify
,
1181 (void**)&dup_notify
);
1182 ok(rc
==DS_OK
&&dup_notify
!=NULL
,
1183 "IDirectSoundBuffer_QueryInterface() failed to create a "
1184 "notification %08x\n",rc
);
1185 if(rc
==DS_OK
&&dup_notify
!=NULL
) {
1186 dsbpn
.dwOffset
=DSBPN_OFFSETSTOP
;
1187 dsbpn
.hEventNotify
=event
[1];
1188 rc
=IDirectSoundNotify_SetNotificationPositions(dup_notify
,
1190 ok(rc
==DS_OK
,"IDirectSoundNotify_SetNotificationPositions "
1191 "failed %08x\n",rc
);
1193 trace("testing duplicated buffer with a notification.\n");
1194 test_notify(duplicated
,sizeof(event
)/sizeof(event
[0]),
1195 event
,WAIT_OBJECT_0
+1);
1197 ref
=IDirectSoundNotify_Release(dup_notify
);
1198 ok(ref
==0,"IDirectSoundNotify_Release() has %d references, "
1199 "should have 0\n",ref
);
1201 ref
=IDirectSoundNotify_Release(notify
);
1202 ok(ref
==0,"IDirectSoundNotify_Release() has %d references, "
1203 "should have 0\n",ref
);
1205 trace("testing original buffer with a notification.\n");
1206 test_notify(original
,sizeof(event
)/sizeof(event
[0]),
1207 event
,WAIT_OBJECT_0
);
1209 ref
=IDirectSoundBuffer_Release(duplicated
);
1210 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
1211 "should have 0\n",ref
);
1213 ref
=IDirectSoundBuffer_Release(original
);
1214 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
1215 "should have 0\n",ref
);
1217 ref
=IDirectSoundBuffer_Release(primary
);
1218 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
1219 "should have 0\n",ref
);
1222 /* Set the CooperativeLevel back to normal */
1223 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1224 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
1225 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
1228 ref
=IDirectSound_Release(dso
);
1229 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1231 return DSERR_GENERIC
;
1236 static HRESULT
test_invalid_fmts(LPGUID lpGuid
)
1239 LPDIRECTSOUND dso
=NULL
;
1240 LPDIRECTSOUNDBUFFER primary
=NULL
;
1241 DSBUFFERDESC bufdesc
;
1243 /* Create the DirectSound object */
1244 rc
=pDirectSoundCreate(lpGuid
,&dso
,NULL
);
1245 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
,
1246 "DirectSoundCreate() failed: %08x\n",rc
);
1250 /* We must call SetCooperativeLevel before creating primary buffer */
1251 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1252 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1253 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc
);
1255 IDirectSound_Release(dso
);
1259 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1260 bufdesc
.dwSize
=sizeof(bufdesc
);
1261 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
1262 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1263 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound_CreateSoundBuffer() failed "
1264 "to create a primary buffer %08x\n",rc
);
1266 if (rc
==DS_OK
&& primary
!=NULL
) {
1268 WAVEFORMATEXTENSIBLE fmtex
;
1270 wfx
.wFormatTag
= WAVE_FORMAT_PCM
;
1272 wfx
.nSamplesPerSec
= 44100;
1273 wfx
.wBitsPerSample
= 16;
1274 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1275 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1276 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1277 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1280 wfx
.nSamplesPerSec
= 44100;
1281 wfx
.wBitsPerSample
= 0;
1282 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1283 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1284 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1285 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1288 wfx
.nSamplesPerSec
= 44100;
1289 wfx
.wBitsPerSample
= 2;
1290 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1291 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1292 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1293 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1296 wfx
.nSamplesPerSec
= 44100;
1297 wfx
.wBitsPerSample
= 12;
1298 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1299 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1300 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1301 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1304 wfx
.nSamplesPerSec
= 0;
1305 wfx
.wBitsPerSample
= 16;
1306 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1307 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1308 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1309 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1312 wfx
.nSamplesPerSec
= 44100;
1313 wfx
.wBitsPerSample
= 16;
1314 wfx
.nBlockAlign
= 0;
1315 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1316 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1317 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1320 wfx
.nSamplesPerSec
= 44100;
1321 wfx
.wBitsPerSample
= 16;
1322 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1323 wfx
.nAvgBytesPerSec
= 0;
1324 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1325 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1328 wfx
.nSamplesPerSec
= 44100;
1329 wfx
.wBitsPerSample
= 16;
1330 wfx
.nBlockAlign
= (wfx
.nChannels
* wfx
.wBitsPerSample
/ 8) - 1;
1331 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1332 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1333 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1336 wfx
.nSamplesPerSec
= 44100;
1337 wfx
.wBitsPerSample
= 16;
1338 wfx
.nBlockAlign
= (wfx
.nChannels
* wfx
.wBitsPerSample
/ 8) + 1;
1339 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
1340 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1341 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1344 wfx
.nSamplesPerSec
= 44100;
1345 wfx
.wBitsPerSample
= 16;
1346 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1347 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
+ 1;
1348 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1349 ok(rc
== S_OK
, "SetFormat: %08x\n", rc
);
1352 wfx
.nSamplesPerSec
= 44100;
1353 wfx
.wBitsPerSample
= 16;
1354 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1355 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
- 1;
1356 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1357 ok(rc
== S_OK
, "SetFormat: %08x\n", rc
);
1360 wfx
.nSamplesPerSec
= 44100;
1361 wfx
.wBitsPerSample
= 16;
1362 wfx
.nBlockAlign
= wfx
.nChannels
* wfx
.wBitsPerSample
/ 8;
1363 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
+ 1;
1364 rc
= IDirectSoundBuffer_SetFormat(primary
, &wfx
);
1365 ok(rc
== S_OK
, "SetFormat: %08x\n", rc
);
1367 fmtex
.Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1368 fmtex
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1369 fmtex
.Format
.nChannels
= 2;
1370 fmtex
.Format
.nSamplesPerSec
= 44100;
1371 fmtex
.Format
.wBitsPerSample
= 16;
1372 fmtex
.Format
.nBlockAlign
= fmtex
.Format
.nChannels
* fmtex
.Format
.wBitsPerSample
/ 8;
1373 fmtex
.Format
.nAvgBytesPerSec
= fmtex
.Format
.nSamplesPerSec
* fmtex
.Format
.nBlockAlign
;
1374 fmtex
.Samples
.wValidBitsPerSample
= 0;
1375 fmtex
.dwChannelMask
= SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
;
1376 fmtex
.SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1377 rc
= IDirectSoundBuffer_SetFormat(primary
, (WAVEFORMATEX
*)&fmtex
);
1378 ok(rc
== S_OK
, "SetFormat: %08x\n", rc
);
1380 fmtex
.Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1381 fmtex
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1382 fmtex
.Format
.nChannels
= 2;
1383 fmtex
.Format
.nSamplesPerSec
= 44100;
1384 fmtex
.Format
.wBitsPerSample
= 24;
1385 fmtex
.Format
.nBlockAlign
= fmtex
.Format
.nChannels
* fmtex
.Format
.wBitsPerSample
/ 8;
1386 fmtex
.Format
.nAvgBytesPerSec
= fmtex
.Format
.nSamplesPerSec
* fmtex
.Format
.nBlockAlign
;
1387 fmtex
.Samples
.wValidBitsPerSample
= 20;
1388 fmtex
.dwChannelMask
= SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
;
1389 fmtex
.SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1390 rc
= IDirectSoundBuffer_SetFormat(primary
, (WAVEFORMATEX
*)&fmtex
);
1391 ok(rc
== S_OK
, "SetFormat: %08x\n", rc
);
1393 fmtex
.Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1394 fmtex
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1395 fmtex
.Format
.nChannels
= 2;
1396 fmtex
.Format
.nSamplesPerSec
= 44100;
1397 fmtex
.Format
.wBitsPerSample
= 24;
1398 fmtex
.Format
.nBlockAlign
= fmtex
.Format
.nChannels
* fmtex
.Format
.wBitsPerSample
/ 8;
1399 fmtex
.Format
.nAvgBytesPerSec
= fmtex
.Format
.nSamplesPerSec
* fmtex
.Format
.nBlockAlign
;
1400 fmtex
.Samples
.wValidBitsPerSample
= 32;
1401 fmtex
.dwChannelMask
= SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
;
1402 fmtex
.SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1403 rc
= IDirectSoundBuffer_SetFormat(primary
, (WAVEFORMATEX
*)&fmtex
);
1404 ok(rc
== E_INVALIDARG
, "SetFormat: %08x\n", rc
);
1406 IDirectSoundBuffer_Release(primary
);
1409 IDirectSound_Release(dso
);
1414 static unsigned int number
;
1416 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1417 LPCSTR lpcstrModule
, LPVOID lpContext
)
1420 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1422 /* Don't test the primary device */
1425 ok (!lpcstrModule
[0], "lpcstrModule(%s) != NULL\n", lpcstrModule
);
1429 rc
= test_dsound(lpGuid
);
1430 if (rc
== DSERR_NODRIVER
)
1431 trace(" No Driver\n");
1432 else if (rc
== DSERR_ALLOCATED
)
1433 trace(" Already In Use\n");
1434 else if (rc
== E_FAIL
)
1435 trace(" No Device\n");
1437 test_block_align(lpGuid
);
1438 test_primary(lpGuid
);
1439 test_primary_secondary(lpGuid
);
1440 test_secondary(lpGuid
);
1441 test_frequency(lpGuid
);
1442 test_duplicate(lpGuid
);
1443 test_invalid_fmts(lpGuid
);
1449 static void dsound_tests(void)
1452 rc
=pDirectSoundEnumerateA(&dsenum_callback
,NULL
);
1453 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %08x\n",rc
);
1456 static void test_hw_buffers(void)
1459 IDirectSoundBuffer
*primary
, *primary2
, **secondaries
, *secondary
;
1460 IDirectSoundBuffer8
*buf8
;
1463 DSBUFFERDESC bufdesc
;
1468 hr
= pDirectSoundCreate(NULL
, &ds
, NULL
);
1469 ok(hr
== S_OK
|| hr
== DSERR_NODRIVER
|| hr
== DSERR_ALLOCATED
|| hr
== E_FAIL
,
1470 "DirectSoundCreate failed: %08x\n", hr
);
1474 caps
.dwSize
= sizeof(caps
);
1476 hr
= IDirectSound_GetCaps(ds
, &caps
);
1477 ok(hr
== S_OK
, "GetCaps failed: %08x\n", hr
);
1479 ok(caps
.dwPrimaryBuffers
== 1, "Got wrong number of primary buffers: %u\n",
1480 caps
.dwPrimaryBuffers
);
1482 /* DSBCAPS_LOC* is ignored for primary buffers */
1483 bufdesc
.dwSize
= sizeof(bufdesc
);
1484 bufdesc
.dwFlags
= DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_LOCHARDWARE
|
1485 DSBCAPS_PRIMARYBUFFER
;
1486 bufdesc
.dwBufferBytes
= 0;
1487 bufdesc
.dwReserved
= 0;
1488 bufdesc
.lpwfxFormat
= NULL
;
1489 bufdesc
.guid3DAlgorithm
= GUID_NULL
;
1491 hr
= IDirectSound_CreateSoundBuffer(ds
, &bufdesc
, &primary
, NULL
);
1492 ok(hr
== S_OK
, "CreateSoundBuffer failed: %08x\n", hr
);
1494 IDirectSound_Release(ds
);
1498 bufdesc
.dwFlags
= DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_LOCSOFTWARE
|
1499 DSBCAPS_PRIMARYBUFFER
;
1501 hr
= IDirectSound_CreateSoundBuffer(ds
, &bufdesc
, &primary2
, NULL
);
1502 ok(hr
== S_OK
, "CreateSoundBuffer failed: %08x\n", hr
);
1503 ok(primary
== primary2
, "Got different primary buffers: %p, %p\n", primary
, primary2
);
1505 IDirectSoundBuffer_Release(primary2
);
1507 buf8
= (IDirectSoundBuffer8
*)0xDEADBEEF;
1508 hr
= IDirectSoundBuffer_QueryInterface(primary
, &IID_IDirectSoundBuffer8
,
1510 ok(hr
== E_NOINTERFACE
, "QueryInterface gave wrong failure: %08x\n", hr
);
1511 ok(buf8
== NULL
, "Pointer didn't get set to NULL\n");
1513 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
1515 fmt
.nSamplesPerSec
= 48000;
1516 fmt
.wBitsPerSample
= 16;
1517 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/ 8;
1518 fmt
.nAvgBytesPerSec
= fmt
.nBlockAlign
* fmt
.nSamplesPerSec
;
1521 bufdesc
.lpwfxFormat
= &fmt
;
1522 bufdesc
.dwBufferBytes
= fmt
.nSamplesPerSec
* fmt
.nBlockAlign
/ 10;
1523 bufdesc
.dwFlags
= DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_LOCHARDWARE
|
1526 secondaries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1527 sizeof(IDirectSoundBuffer
*) * caps
.dwMaxHwMixingAllBuffers
);
1529 /* try to fill all of the hw buffers */
1530 trace("dwMaxHwMixingAllBuffers: %u\n", caps
.dwMaxHwMixingAllBuffers
);
1531 trace("dwMaxHwMixingStaticBuffers: %u\n", caps
.dwMaxHwMixingStaticBuffers
);
1532 trace("dwMaxHwMixingStreamingBuffers: %u\n", caps
.dwMaxHwMixingStreamingBuffers
);
1533 for(i
= 0; i
< caps
.dwMaxHwMixingAllBuffers
; ++i
){
1534 hr
= IDirectSound_CreateSoundBuffer(ds
, &bufdesc
, &secondaries
[i
], NULL
);
1535 ok(hr
== S_OK
|| hr
== E_NOTIMPL
|| broken(hr
== DSERR_CONTROLUNAVAIL
) || broken(hr
== E_FAIL
),
1536 "CreateSoundBuffer(%u) failed: %08x\n", i
, hr
);
1540 bufcaps
.dwSize
= sizeof(bufcaps
);
1541 hr
= IDirectSoundBuffer_GetCaps(secondaries
[i
], &bufcaps
);
1542 ok(hr
== S_OK
, "GetCaps failed: %08x\n", hr
);
1543 ok((bufcaps
.dwFlags
& DSBCAPS_LOCHARDWARE
) != 0,
1544 "Buffer wasn't allocated in hardware, dwFlags: %x\n", bufcaps
.dwFlags
);
1547 /* see if we can create one more */
1548 hr
= IDirectSound_CreateSoundBuffer(ds
, &bufdesc
, &secondary
, NULL
);
1549 ok((i
== caps
.dwMaxHwMixingAllBuffers
&& hr
== DSERR_ALLOCATED
) || /* out of hw buffers */
1550 (caps
.dwMaxHwMixingAllBuffers
== 0 && hr
== DSERR_INVALIDCALL
) || /* no hw buffers at all */
1551 hr
== E_NOTIMPL
|| /* don't support hw buffers */
1552 broken(hr
== DSERR_CONTROLUNAVAIL
) || /* vmware winxp, others? */
1553 broken(hr
== E_FAIL
) || /* broken AC97 driver */
1554 broken(hr
== S_OK
) /* broken driver allows more hw bufs than dscaps claims */,
1555 "CreateSoundBuffer(%u) gave wrong error: %08x\n", i
, hr
);
1557 IDirectSoundBuffer_Release(secondary
);
1559 for(i
= 0; i
< caps
.dwMaxHwMixingAllBuffers
; ++i
)
1561 IDirectSoundBuffer_Release(secondaries
[i
]);
1562 HeapFree(GetProcessHeap(), 0, secondaries
);
1564 IDirectSoundBuffer_Release(primary
);
1565 IDirectSound_Release(ds
);
1574 hDsound
= LoadLibrary("dsound.dll");
1579 ret
= FreeLibrary(hDsound
);
1580 ok( ret
, "FreeLibrary(1) returned %d\n", GetLastError());
1581 SetLastError(0xdeadbeef);
1582 ret
= FreeLibrary(hDsound
);
1584 broken(!ret
&& GetLastError() == ERROR_MOD_NOT_FOUND
), /* NT4 */
1585 "FreeLibrary(2) returned %d\n", GetLastError());
1586 ok(!FreeLibrary(hDsound
), "DirectSound DLL still loaded\n");
1589 hDsound
= LoadLibrary("dsound.dll");
1593 pDirectSoundEnumerateA
= (void*)GetProcAddress(hDsound
,
1594 "DirectSoundEnumerateA");
1595 pDirectSoundCreate
= (void*)GetProcAddress(hDsound
,
1596 "DirectSoundCreate");
1598 gotdx8
= !!GetProcAddress(hDsound
, "DirectSoundCreate8");
1600 IDirectSound_tests();
1604 FreeLibrary(hDsound
);
1607 win_skip("dsound.dll not found - skipping all tests\n");