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"
40 #include "dsound_test.h"
42 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
44 static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
45 static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID,LPDIRECTSOUND*,
50 static void IDirectSound_test(LPDIRECTSOUND dso, BOOL initialized,
59 DWORD speaker_config, new_speaker_config;
61 /* Try to Query for objects */
62 rc=IDirectSound_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
63 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",
64 DXGetErrorString8(rc));
66 IDirectSound_Release(unknown);
68 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
69 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",
70 DXGetErrorString8(rc));
72 IDirectSound_Release(ds);
74 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
75 ok(rc==E_NOINTERFACE,"IDirectSound_QueryInterface(IID_IDirectSound8) "
76 "should have failed: %s\n",DXGetErrorString8(rc));
78 IDirectSound8_Release(ds8);
80 if (initialized == FALSE) {
81 /* try uninitialized object */
82 rc=IDirectSound_GetCaps(dso,0);
83 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps(NULL) "
84 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
85 DXGetErrorString8(rc));
87 rc=IDirectSound_GetCaps(dso,&dscaps);
88 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps() "
89 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
90 DXGetErrorString8(rc));
92 rc=IDirectSound_Compact(dso);
93 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_Compact() "
94 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
95 DXGetErrorString8(rc));
97 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
98 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetSpeakerConfig() "
99 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
100 DXGetErrorString8(rc));
102 rc=IDirectSound_Initialize(dso,lpGuid);
103 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
104 "IDirectSound_Initialize() failed: %s\n",DXGetErrorString8(rc));
105 if (rc==DSERR_NODRIVER) {
106 trace(" No Driver\n");
108 } else if (rc==E_FAIL) {
109 trace(" No Device\n");
111 } else if (rc==DSERR_ALLOCATED) {
112 trace(" Already In Use\n");
117 rc=IDirectSound_Initialize(dso,lpGuid);
118 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound_Initialize() "
119 "should have returned DSERR_ALREADYINITIALIZED: %s\n",
120 DXGetErrorString8(rc));
122 /* DSOUND: Error: Invalid caps buffer */
123 rc=IDirectSound_GetCaps(dso,0);
124 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps(NULL) "
125 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
126 DXGetErrorString8(rc));
128 ZeroMemory(&dscaps, sizeof(dscaps));
130 /* DSOUND: Error: Invalid caps buffer */
131 rc=IDirectSound_GetCaps(dso,&dscaps);
132 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
133 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
134 DXGetErrorString8(rc));
136 dscaps.dwSize=sizeof(dscaps);
138 /* DSOUND: Running on a certified driver */
139 rc=IDirectSound_GetCaps(dso,&dscaps);
140 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
142 rc=IDirectSound_Compact(dso);
143 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %s\n",
144 DXGetErrorString8(rc));
146 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
147 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
148 DXGetErrorString8(rc));
150 rc=IDirectSound_Compact(dso);
151 ok(rc==DS_OK,"IDirectSound_Compact() failed: %s\n",DXGetErrorString8(rc));
153 rc=IDirectSound_GetSpeakerConfig(dso,0);
154 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
155 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
156 DXGetErrorString8(rc));
158 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
159 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
160 DXGetErrorString8(rc));
162 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
163 DSSPEAKER_GEOMETRY_WIDE);
164 rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
165 ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %s\n",
166 DXGetErrorString8(rc));
168 rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
169 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
170 DXGetErrorString8(rc));
171 if (rc==DS_OK && speaker_config!=new_speaker_config)
172 trace("IDirectSound_GetSpeakerConfig() failed to set speaker "
173 "config: expected 0x%08x, got 0x%08x\n",
174 speaker_config,new_speaker_config);
178 ref=IDirectSound_Release(dso);
179 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
182 static void IDirectSound_tests(void)
185 LPDIRECTSOUND dso=NULL;
186 LPCLASSFACTORY cf=NULL;
188 trace("Testing IDirectSound\n");
190 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
191 &IID_IClassFactory, (void**)&cf);
192 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
193 "failed: %s\n", DXGetErrorString8(rc));
195 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
196 &IID_IUnknown, (void**)&cf);
197 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IUnknown) "
198 "failed: %s\n", DXGetErrorString8(rc));
200 /* try the COM class factory method of creation with no device specified */
201 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
202 &IID_IDirectSound, (void**)&dso);
203 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
204 DXGetErrorString8(rc));
206 IDirectSound_test(dso, FALSE, NULL);
208 /* try the COM class factory method of creation with default playback
209 * device specified */
210 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
211 &IID_IDirectSound, (void**)&dso);
212 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
213 DXGetErrorString8(rc));
215 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
217 /* try the COM class factory method of creation with default voice
218 * playback device specified */
219 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
220 &IID_IDirectSound, (void**)&dso);
221 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
222 DXGetErrorString8(rc));
224 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
226 /* try the COM class factory method of creation with a bad
228 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
229 &CLSID_DirectSoundPrivate, (void**)&dso);
230 ok(rc==E_NOINTERFACE,
231 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
232 "should have failed: %s\n",DXGetErrorString8(rc));
234 /* try the COM class factory method of creation with a bad
235 * GUID and IID specified */
236 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
237 &IID_IDirectSound, (void**)&dso);
238 ok(rc==REGDB_E_CLASSNOTREG,
239 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
240 "should have failed: %s\n",DXGetErrorString8(rc));
242 /* try with no device specified */
243 rc=pDirectSoundCreate(NULL,&dso,NULL);
244 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
245 "DirectSoundCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
247 IDirectSound_test(dso, TRUE, NULL);
249 /* try with default playback device specified */
250 rc=pDirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
251 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
252 "DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %s\n",
253 DXGetErrorString8(rc));
254 if (rc==DS_OK && dso)
255 IDirectSound_test(dso, TRUE, NULL);
257 /* try with default voice playback device specified */
258 rc=pDirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
259 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
260 "DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %s\n",
261 DXGetErrorString8(rc));
262 if (rc==DS_OK && dso)
263 IDirectSound_test(dso, TRUE, NULL);
265 /* try with a bad device specified */
266 rc=pDirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
267 ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
268 "should have failed: %s\n",DXGetErrorString8(rc));
269 if (rc==DS_OK && dso)
270 IDirectSound_Release(dso);
273 static HRESULT test_dsound(LPGUID lpGuid)
276 LPDIRECTSOUND dso=NULL;
279 /* DSOUND: Error: Invalid interface buffer */
280 rc=pDirectSoundCreate(lpGuid,0,NULL);
281 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate() should have returned "
282 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
284 /* Create the DirectSound object */
285 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
286 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
287 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
291 /* Try the enumerated device */
292 IDirectSound_test(dso, TRUE, lpGuid);
294 /* Try the COM class factory method of creation with enumerated device */
295 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
296 &IID_IDirectSound, (void**)&dso);
297 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
298 DXGetErrorString8(rc));
300 IDirectSound_test(dso, FALSE, lpGuid);
302 /* Create a DirectSound object */
303 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
304 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
306 LPDIRECTSOUND dso1=NULL;
308 /* Create a second DirectSound object */
309 rc=pDirectSoundCreate(lpGuid,&dso1,NULL);
310 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
312 /* Release the second DirectSound object */
313 ref=IDirectSound_Release(dso1);
314 ok(ref==0,"IDirectSound_Release() has %d references, should have "
316 ok(dso!=dso1,"DirectSound objects should be unique: dso=%p,dso1=%p\n",dso,dso1);
319 /* Release the first DirectSound object */
320 ref=IDirectSound_Release(dso);
321 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
324 return DSERR_GENERIC;
328 /* Create a DirectSound object */
329 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
330 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
332 LPDIRECTSOUNDBUFFER secondary;
333 DSBUFFERDESC bufdesc;
336 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
337 ZeroMemory(&bufdesc, sizeof(bufdesc));
338 bufdesc.dwSize=sizeof(bufdesc);
339 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
340 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
342 bufdesc.lpwfxFormat=&wfx;
343 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
344 ok(rc==DS_OK && secondary!=NULL,
345 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
346 "buffer %s\n",DXGetErrorString8(rc));
347 if (rc==DS_OK && secondary!=NULL) {
348 LPDIRECTSOUND3DBUFFER buffer3d;
349 rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
351 ok(rc==DS_OK && buffer3d!=NULL,"IDirectSound_QueryInterface() "
352 "failed: %s\n",DXGetErrorString8(rc));
353 if (rc==DS_OK && buffer3d!=NULL) {
354 ref=IDirectSound3DBuffer_AddRef(buffer3d);
355 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
356 "should have 2\n",ref);
358 ref=IDirectSoundBuffer_AddRef(secondary);
359 ok(ref==2,"IDirectSoundBuffer_AddRef() has %d references, "
360 "should have 2\n",ref);
362 /* release with buffer */
363 ref=IDirectSound_Release(dso);
364 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
367 return DSERR_GENERIC;
374 static HRESULT test_primary(LPGUID lpGuid)
377 LPDIRECTSOUND dso=NULL;
378 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
379 DSBUFFERDESC bufdesc;
384 /* Create the DirectSound object */
385 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
386 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
387 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
391 /* Get the device capabilities */
392 ZeroMemory(&dscaps, sizeof(dscaps));
393 dscaps.dwSize=sizeof(dscaps);
394 rc=IDirectSound_GetCaps(dso,&dscaps);
395 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
399 /* DSOUND: Error: Invalid buffer description pointer */
400 rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
401 ok(rc==DSERR_INVALIDPARAM,
402 "IDirectSound_CreateSoundBuffer() should have failed: %s\n",
403 DXGetErrorString8(rc));
405 /* DSOUND: Error: NULL pointer is invalid */
406 /* DSOUND: Error: Invalid buffer description pointer */
407 rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
408 ok(rc==DSERR_INVALIDPARAM && primary==0,
409 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
410 "dsbo=%p\n",DXGetErrorString8(rc),primary);
412 /* DSOUND: Error: Invalid size */
413 /* DSOUND: Error: Invalid buffer description */
415 ZeroMemory(&bufdesc, sizeof(bufdesc));
416 bufdesc.dwSize=sizeof(bufdesc)-1;
417 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
418 ok(rc==DSERR_INVALIDPARAM && primary==0,
419 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
420 "primary=%p\n",DXGetErrorString8(rc),primary);
422 /* DSOUND: Error: DSBCAPS_PRIMARYBUFFER flag with non-NULL lpwfxFormat */
423 /* DSOUND: Error: Invalid buffer description pointer */
425 ZeroMemory(&bufdesc, sizeof(bufdesc));
426 bufdesc.dwSize=sizeof(bufdesc);
427 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
428 bufdesc.lpwfxFormat=&wfx;
429 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
430 ok(rc==DSERR_INVALIDPARAM && primary==0,
431 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
432 "primary=%p\n",DXGetErrorString8(rc),primary);
434 /* DSOUND: Error: No DSBCAPS_PRIMARYBUFFER flag with NULL lpwfxFormat */
435 /* DSOUND: Error: Invalid buffer description pointer */
437 ZeroMemory(&bufdesc, sizeof(bufdesc));
438 bufdesc.dwSize=sizeof(bufdesc);
440 bufdesc.lpwfxFormat=NULL;
441 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
442 ok(rc==DSERR_INVALIDPARAM && primary==0,
443 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
444 "primary=%p\n",DXGetErrorString8(rc),primary);
446 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
447 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
448 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
449 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
450 DXGetErrorString8(rc));
454 /* Testing the primary buffer */
456 ZeroMemory(&bufdesc, sizeof(bufdesc));
457 bufdesc.dwSize=sizeof(bufdesc);
458 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
459 bufdesc.lpwfxFormat = &wfx;
460 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
461 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
462 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() should have "
463 "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc));
464 if (rc==DS_OK && primary!=NULL)
465 IDirectSoundBuffer_Release(primary);
468 ZeroMemory(&bufdesc, sizeof(bufdesc));
469 bufdesc.dwSize=sizeof(bufdesc);
470 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
471 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
472 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
473 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "
474 "%s\n",DXGetErrorString8(rc));
475 if (rc==DSERR_CONTROLUNAVAIL)
476 trace(" No Primary\n");
477 else if (rc==DS_OK && primary!=NULL) {
480 /* Try to create a second primary buffer */
481 /* DSOUND: Error: The primary buffer already exists.
482 * Any changes made to the buffer description will be ignored. */
483 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
484 ok(rc==DS_OK && second==primary,
485 "IDirectSound_CreateSoundBuffer() should have returned original "
486 "primary buffer: %s\n",DXGetErrorString8(rc));
487 ref=IDirectSoundBuffer_Release(second);
488 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
489 "should have 1\n",ref);
491 /* Try to duplicate a primary buffer */
492 /* DSOUND: Error: Can't duplicate primary buffers */
493 rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
495 ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer() primary buffer "
496 "should have failed %s\n",DXGetErrorString8(rc));
498 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
499 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
500 DXGetErrorString8(rc));
502 if (winetest_interactive) {
503 trace("Playing a 5 seconds reference tone at the current "
506 trace("(the current volume is %d according to DirectSound)\n",
508 trace("All subsequent tones should be identical to this one.\n");
509 trace("Listen for stutter, changes in pitch, volume, etc.\n");
511 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
512 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0,FALSE,0);
514 ref=IDirectSoundBuffer_Release(primary);
515 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
516 "should have 0\n",ref);
519 /* Set the CooperativeLevel back to normal */
520 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
521 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
522 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
523 DXGetErrorString8(rc));
526 ref=IDirectSound_Release(dso);
527 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
529 return DSERR_GENERIC;
535 * Test the primary buffer at different formats while keeping the
536 * secondary buffer at a constant format.
538 static HRESULT test_primary_secondary(LPGUID lpGuid)
541 LPDIRECTSOUND dso=NULL;
542 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
543 DSBUFFERDESC bufdesc;
545 WAVEFORMATEX wfx, wfx2;
548 /* Create the DirectSound object */
549 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
550 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
551 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
555 /* Get the device capabilities */
556 ZeroMemory(&dscaps, sizeof(dscaps));
557 dscaps.dwSize=sizeof(dscaps);
558 rc=IDirectSound_GetCaps(dso,&dscaps);
559 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
563 /* We must call SetCooperativeLevel before creating primary buffer */
564 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
565 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
566 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
567 DXGetErrorString8(rc));
571 ZeroMemory(&bufdesc, sizeof(bufdesc));
572 bufdesc.dwSize=sizeof(bufdesc);
573 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
574 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
575 ok(rc==DS_OK && primary!=NULL,
576 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
577 "%s\n",DXGetErrorString8(rc));
579 if (rc==DS_OK && primary!=NULL) {
580 for (f=0;f<NB_FORMATS;f++) {
581 /* We must call SetCooperativeLevel to be allowed to call
583 /* DSOUND: Setting DirectSound cooperative level to
585 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
586 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
587 DXGetErrorString8(rc));
591 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
594 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
596 if (wfx.wBitsPerSample <= 16)
597 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %s\n",
598 format_string(&wfx), DXGetErrorString8(rc));
600 ok(rc==DS_OK || rc == E_INVALIDARG, "SetFormat (%s) failed: %s\n",
601 format_string(&wfx), DXGetErrorString8(rc));
603 /* There is no guarantee that SetFormat will actually change the
604 * format to what we asked for. It depends on what the soundcard
605 * supports. So we must re-query the format.
607 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
608 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
609 DXGetErrorString8(rc));
611 (wfx.wFormatTag!=wfx2.wFormatTag ||
612 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
613 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
614 wfx.nChannels!=wfx2.nChannels)) {
615 trace("Requested primary format tag=0x%04x %dx%dx%d "
616 "avg.B/s=%d align=%d\n",
617 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
618 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
619 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
620 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
621 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
624 /* Set the CooperativeLevel back to normal */
625 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
626 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
627 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
628 DXGetErrorString8(rc));
630 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
633 ZeroMemory(&bufdesc, sizeof(bufdesc));
634 bufdesc.dwSize=sizeof(bufdesc);
635 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
636 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
638 bufdesc.lpwfxFormat=&wfx2;
639 if (winetest_interactive) {
640 trace(" Testing a primary buffer at %dx%dx%d with a "
641 "secondary buffer at %dx%dx%d\n",
642 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
643 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
645 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
646 ok(rc==DS_OK && secondary!=NULL,
647 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
648 "buffer %s\n",DXGetErrorString8(rc));
650 if (rc==DS_OK && secondary!=NULL) {
651 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
652 winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
654 ref=IDirectSoundBuffer_Release(secondary);
655 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
656 "should have 0\n",ref);
660 ref=IDirectSoundBuffer_Release(primary);
661 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
662 "should have 0\n",ref);
665 /* Set the CooperativeLevel back to normal */
666 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
667 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
668 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
669 DXGetErrorString8(rc));
672 ref=IDirectSound_Release(dso);
673 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
675 return DSERR_GENERIC;
680 static HRESULT test_secondary(LPGUID lpGuid)
683 LPDIRECTSOUND dso=NULL;
684 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
685 DSBUFFERDESC bufdesc;
687 WAVEFORMATEX wfx, wfx1;
691 /* Create the DirectSound object */
692 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
693 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
694 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
698 /* Get the device capabilities */
699 ZeroMemory(&dscaps, sizeof(dscaps));
700 dscaps.dwSize=sizeof(dscaps);
701 rc=IDirectSound_GetCaps(dso,&dscaps);
702 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
706 /* We must call SetCooperativeLevel before creating primary buffer */
707 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
708 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
709 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
710 DXGetErrorString8(rc));
714 ZeroMemory(&bufdesc, sizeof(bufdesc));
715 bufdesc.dwSize=sizeof(bufdesc);
716 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
717 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
718 ok(rc==DS_OK && primary!=NULL,
719 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
720 "%s\n",DXGetErrorString8(rc));
722 if (rc==DS_OK && primary!=NULL) {
723 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
724 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
725 DXGetErrorString8(rc));
729 for (f=0;f<NB_FORMATS;f++) {
730 WAVEFORMATEXTENSIBLE wfxe;
731 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
734 ZeroMemory(&bufdesc, sizeof(bufdesc));
735 bufdesc.dwSize=sizeof(bufdesc);
736 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
737 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
739 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
740 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() "
741 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
742 DXGetErrorString8(rc));
743 if (rc==DS_OK && secondary!=NULL)
744 IDirectSoundBuffer_Release(secondary);
747 ZeroMemory(&bufdesc, sizeof(bufdesc));
748 bufdesc.dwSize=sizeof(bufdesc);
749 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
750 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
752 bufdesc.lpwfxFormat=&wfx;
753 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
754 if (gotdx8 || wfx.wBitsPerSample <= 16)
756 if (wfx.wBitsPerSample > 16)
757 ok(rc == DSERR_CONTROLUNAVAIL && !secondary, "IDirectSound_CreateSoundBuffer() "
758 "should have returned DSERR_CONTROLUNAVAIL and NULL, returned: %s %p\n",
759 DXGetErrorString8(rc), secondary);
761 ok(rc==DS_OK && secondary!=NULL,
762 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
763 "buffer %s\n",DXGetErrorString8(rc));
766 ok(rc==E_INVALIDARG, "Creating %d bpp buffer on dx < 8 returned: %p %s\n",
767 wfx.wBitsPerSample, secondary, DXGetErrorString8(rc));
771 skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
772 /* Apparently they succeed with bogus values,
773 * which means that older dsound doesn't look at them
779 IDirectSoundBuffer_Release(secondary);
782 bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
784 wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
785 wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
786 wfxe.Format.cbSize = 1;
787 wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
788 wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);
790 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
791 ok(rc==DSERR_INVALIDPARAM && !secondary,
792 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
793 DXGetErrorString8(rc), secondary);
795 IDirectSoundBuffer_Release(secondary);
797 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1;
799 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
800 ok(DSERR_CONTROLUNAVAIL && !secondary,
801 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
802 DXGetErrorString8(rc), secondary);
804 IDirectSoundBuffer_Release(secondary);
806 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
807 wfxe.SubFormat = GUID_NULL;
808 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
809 ok(rc==DSERR_INVALIDPARAM && !secondary,
810 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
811 DXGetErrorString8(rc), secondary);
813 IDirectSoundBuffer_Release(secondary);
814 wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
816 ++wfxe.Samples.wValidBitsPerSample;
817 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
818 ok(rc==DSERR_INVALIDPARAM && !secondary,
819 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
820 DXGetErrorString8(rc), secondary);
822 IDirectSoundBuffer_Release(secondary);
823 --wfxe.Samples.wValidBitsPerSample;
825 wfxe.Samples.wValidBitsPerSample = 0;
826 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
827 ok(rc==DS_OK && secondary,
828 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
829 DXGetErrorString8(rc), secondary);
831 IDirectSoundBuffer_Release(secondary);
832 wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample;
834 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
835 ok(rc==DS_OK && secondary!=NULL,
836 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
837 "buffer %s\n",DXGetErrorString8(rc));
840 if (rc==DS_OK && secondary!=NULL) {
841 if (winetest_interactive) {
842 trace(" Testing a secondary buffer at %dx%dx%d "
843 "with a primary buffer at %dx%dx%d\n",
844 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
845 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
847 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
848 winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
850 ref=IDirectSoundBuffer_Release(secondary);
851 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
852 "should have 0\n",ref);
856 ref=IDirectSoundBuffer_Release(primary);
857 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
858 "should have 0\n",ref);
861 /* Set the CooperativeLevel back to normal */
862 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
863 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
864 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
865 DXGetErrorString8(rc));
868 ref=IDirectSound_Release(dso);
869 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
871 return DSERR_GENERIC;
876 static HRESULT test_block_align(LPGUID lpGuid)
879 LPDIRECTSOUND dso=NULL;
880 LPDIRECTSOUNDBUFFER secondary=NULL;
881 DSBUFFERDESC bufdesc;
887 /* Create the DirectSound object */
888 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
889 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
890 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
894 init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
895 ZeroMemory(&bufdesc, sizeof(bufdesc));
896 bufdesc.dwSize=sizeof(bufdesc);
897 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
898 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec + 1;
899 bufdesc.lpwfxFormat=&wfx;
900 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
901 ok(rc==DS_OK,"IDirectSound_CreateSoundBuffer() "
902 "should have returned DS_OK, returned: %s\n",
903 DXGetErrorString8(rc));
905 if (rc==DS_OK && secondary!=NULL) {
906 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
907 dsbcaps.dwSize = sizeof(dsbcaps);
908 rc=IDirectSoundBuffer_GetCaps(secondary,&dsbcaps);
909 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
910 "returned: %s\n", DXGetErrorString8(rc));
911 if (rc==DS_OK && wfx.nBlockAlign > 1)
913 ok(dsbcaps.dwBufferBytes==(wfx.nAvgBytesPerSec + wfx.nBlockAlign),
914 "Buffer size not a multiple of nBlockAlign: requested %d, "
915 "got %d, should be %d\n", bufdesc.dwBufferBytes,
916 dsbcaps.dwBufferBytes, wfx.nAvgBytesPerSec + wfx.nBlockAlign);
918 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 0);
919 ok(rc == DS_OK, "Could not set position to 0: %s\n", DXGetErrorString8(rc));
920 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos, NULL);
921 ok(rc == DS_OK, "Could not get position: %s\n", DXGetErrorString8(rc));
922 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 1);
923 ok(rc == DS_OK, "Could not set position to 1: %s\n", DXGetErrorString8(rc));
924 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos2, NULL);
925 ok(rc == DS_OK, "Could not get new position: %s\n", DXGetErrorString8(rc));
926 ok(pos == pos2, "Positions not the same! Old position: %d, new position: %d\n", pos, pos2);
928 ref=IDirectSoundBuffer_Release(secondary);
929 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, "
930 "should have 0\n",ref);
933 ref=IDirectSound_Release(dso);
934 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
936 return DSERR_GENERIC;
944 } fmts[] = { { 8, 1 }, { 8, 2 }, { 16, 1 }, {16, 2 } };
946 static HRESULT test_frequency(LPGUID lpGuid)
949 LPDIRECTSOUND dso=NULL;
950 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
951 DSBUFFERDESC bufdesc;
953 WAVEFORMATEX wfx, wfx1;
956 int rates[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
959 /* Create the DirectSound object */
960 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
961 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
962 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
966 /* Get the device capabilities */
967 ZeroMemory(&dscaps, sizeof(dscaps));
968 dscaps.dwSize=sizeof(dscaps);
969 rc=IDirectSound_GetCaps(dso,&dscaps);
970 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
974 /* We must call SetCooperativeLevel before creating primary buffer */
975 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
976 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
977 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
978 DXGetErrorString8(rc));
982 ZeroMemory(&bufdesc, sizeof(bufdesc));
983 bufdesc.dwSize=sizeof(bufdesc);
984 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
985 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
986 ok(rc==DS_OK && primary!=NULL,
987 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
988 "%s\n",DXGetErrorString8(rc));
990 if (rc==DS_OK && primary!=NULL) {
991 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
992 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
993 DXGetErrorString8(rc));
997 for (f=0;f<sizeof(fmts)/sizeof(fmts[0]);f++) {
998 for (r=0;r<sizeof(rates)/sizeof(rates[0]);r++) {
999 init_format(&wfx,WAVE_FORMAT_PCM,11025,fmts[f].bits,
1002 ZeroMemory(&bufdesc, sizeof(bufdesc));
1003 bufdesc.dwSize=sizeof(bufdesc);
1004 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLFREQUENCY;
1005 bufdesc.dwBufferBytes=align((wfx.nAvgBytesPerSec*rates[r]/11025)*
1006 BUFFER_LEN/1000,wfx.nBlockAlign);
1007 bufdesc.lpwfxFormat=&wfx;
1008 if (winetest_interactive) {
1009 trace(" Testing a secondary buffer at %dx%dx%d "
1010 "with a primary buffer at %dx%dx%d\n",
1011 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
1012 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
1014 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
1015 ok(rc==DS_OK && secondary!=NULL,
1016 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
1017 "buffer %s\n",DXGetErrorString8(rc));
1019 if (rc==DS_OK && secondary!=NULL) {
1020 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
1021 winetest_interactive,1.0,0,NULL,0,0,TRUE,rates[r]);
1023 ref=IDirectSoundBuffer_Release(secondary);
1024 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1025 "should have 0\n",ref);
1030 ref=IDirectSoundBuffer_Release(primary);
1031 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1032 "should have 0\n",ref);
1035 /* Set the CooperativeLevel back to normal */
1036 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1037 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1038 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
1039 DXGetErrorString8(rc));
1042 ref=IDirectSound_Release(dso);
1043 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1045 return DSERR_GENERIC;
1050 static unsigned int number;
1052 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1053 LPCSTR lpcstrModule, LPVOID lpContext)
1056 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1058 /* Don't test the primary device */
1061 ok (!lpcstrModule[0], "lpcstrModule(%s) != NULL\n", lpcstrModule);
1065 rc = test_dsound(lpGuid);
1066 if (rc == DSERR_NODRIVER)
1067 trace(" No Driver\n");
1068 else if (rc == DSERR_ALLOCATED)
1069 trace(" Already In Use\n");
1070 else if (rc == E_FAIL)
1071 trace(" No Device\n");
1073 test_block_align(lpGuid);
1074 test_primary(lpGuid);
1075 test_primary_secondary(lpGuid);
1076 test_secondary(lpGuid);
1077 test_frequency(lpGuid);
1083 static void dsound_tests(void)
1086 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
1087 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1096 hDsound = LoadLibrary("dsound.dll");
1099 ok( FreeLibrary(hDsound), "FreeLibrary(1) returned %d\n", GetLastError());
1100 ok( FreeLibrary(hDsound), "FreeLibrary(2) returned %d\n", GetLastError());
1101 ok(!FreeLibrary(hDsound), "DirectSound DLL still loaded\n");
1104 hDsound = LoadLibrary("dsound.dll");
1107 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
1109 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
1110 "DirectSoundEnumerateA");
1111 pDirectSoundCreate = (void*)GetProcAddress(hDsound,
1112 "DirectSoundCreate");
1114 gotdx8 = !!GetProcAddress(hDsound, "DirectSoundCreate8");
1116 IDirectSound_tests();
1119 FreeLibrary(hDsound);
1122 skip("dsound.dll not found!\n");