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"
36 /* MinGW doesn't have ksguid, needed for make crosstest to work. */
41 #include "dsound_test.h"
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;
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: %s\n",
63 DXGetErrorString8(rc));
65 IDirectSound_Release(unknown);
67 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
68 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",
69 DXGetErrorString8(rc));
71 IDirectSound_Release(ds);
73 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
74 ok(rc==E_NOINTERFACE,"IDirectSound_QueryInterface(IID_IDirectSound8) "
75 "should have failed: %s\n",DXGetErrorString8(rc));
77 IDirectSound8_Release(ds8);
79 if (initialized == FALSE) {
80 /* try uninitialized object */
81 rc=IDirectSound_GetCaps(dso,0);
82 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps(NULL) "
83 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
84 DXGetErrorString8(rc));
86 rc=IDirectSound_GetCaps(dso,&dscaps);
87 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps() "
88 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
89 DXGetErrorString8(rc));
91 rc=IDirectSound_Compact(dso);
92 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_Compact() "
93 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
94 DXGetErrorString8(rc));
96 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
97 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetSpeakerConfig() "
98 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
99 DXGetErrorString8(rc));
101 rc=IDirectSound_Initialize(dso,lpGuid);
102 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
103 "IDirectSound_Initialize() failed: %s\n",DXGetErrorString8(rc));
104 if (rc==DSERR_NODRIVER) {
105 trace(" No Driver\n");
107 } else if (rc==E_FAIL) {
108 trace(" No Device\n");
110 } else if (rc==DSERR_ALLOCATED) {
111 trace(" Already In Use\n");
116 rc=IDirectSound_Initialize(dso,lpGuid);
117 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound_Initialize() "
118 "should have returned DSERR_ALREADYINITIALIZED: %s\n",
119 DXGetErrorString8(rc));
121 /* DSOUND: Error: Invalid caps buffer */
122 rc=IDirectSound_GetCaps(dso,0);
123 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps(NULL) "
124 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
125 DXGetErrorString8(rc));
127 ZeroMemory(&dscaps, sizeof(dscaps));
129 /* DSOUND: Error: Invalid caps buffer */
130 rc=IDirectSound_GetCaps(dso,&dscaps);
131 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
132 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
133 DXGetErrorString8(rc));
135 dscaps.dwSize=sizeof(dscaps);
137 /* DSOUND: Running on a certified driver */
138 rc=IDirectSound_GetCaps(dso,&dscaps);
139 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
141 rc=IDirectSound_Compact(dso);
142 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %s\n",
143 DXGetErrorString8(rc));
145 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
146 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
147 DXGetErrorString8(rc));
149 rc=IDirectSound_Compact(dso);
150 ok(rc==DS_OK,"IDirectSound_Compact() failed: %s\n",DXGetErrorString8(rc));
152 rc=IDirectSound_GetSpeakerConfig(dso,0);
153 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
154 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
155 DXGetErrorString8(rc));
157 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
158 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
159 DXGetErrorString8(rc));
161 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
162 DSSPEAKER_GEOMETRY_WIDE);
163 rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
164 ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %s\n",
165 DXGetErrorString8(rc));
167 rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
168 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
169 DXGetErrorString8(rc));
170 if (rc==DS_OK && speaker_config!=new_speaker_config)
171 trace("IDirectSound_GetSpeakerConfig() failed to set speaker "
172 "config: expected 0x%08x, got 0x%08x\n",
173 speaker_config,new_speaker_config);
177 ref=IDirectSound_Release(dso);
178 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
181 static void IDirectSound_tests(void)
184 LPDIRECTSOUND dso=NULL;
185 LPCLASSFACTORY cf=NULL;
187 trace("Testing IDirectSound\n");
189 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
190 &IID_IClassFactory, (void**)&cf);
191 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
192 "failed: %s\n", DXGetErrorString8(rc));
194 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
195 &IID_IUnknown, (void**)&cf);
196 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IUnknown) "
197 "failed: %s\n", DXGetErrorString8(rc));
199 /* try the COM class factory method of creation with no device specified */
200 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
201 &IID_IDirectSound, (void**)&dso);
202 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
203 DXGetErrorString8(rc));
205 IDirectSound_test(dso, FALSE, NULL);
207 /* try the COM class factory method of creation with default playback
208 * device specified */
209 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
210 &IID_IDirectSound, (void**)&dso);
211 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
212 DXGetErrorString8(rc));
214 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
216 /* try the COM class factory method of creation with default voice
217 * playback device specified */
218 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
219 &IID_IDirectSound, (void**)&dso);
220 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
221 DXGetErrorString8(rc));
223 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
225 /* try the COM class factory method of creation with a bad
227 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
228 &CLSID_DirectSoundPrivate, (void**)&dso);
229 ok(rc==E_NOINTERFACE,
230 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
231 "should have failed: %s\n",DXGetErrorString8(rc));
233 /* try the COM class factory method of creation with a bad
234 * GUID and IID specified */
235 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
236 &IID_IDirectSound, (void**)&dso);
237 ok(rc==REGDB_E_CLASSNOTREG,
238 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
239 "should have failed: %s\n",DXGetErrorString8(rc));
241 /* try with no device specified */
242 rc=pDirectSoundCreate(NULL,&dso,NULL);
243 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
244 "DirectSoundCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
246 IDirectSound_test(dso, TRUE, NULL);
248 /* try with default playback device specified */
249 rc=pDirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
250 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
251 "DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %s\n",
252 DXGetErrorString8(rc));
253 if (rc==DS_OK && dso)
254 IDirectSound_test(dso, TRUE, NULL);
256 /* try with default voice playback device specified */
257 rc=pDirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
258 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
259 "DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %s\n",
260 DXGetErrorString8(rc));
261 if (rc==DS_OK && dso)
262 IDirectSound_test(dso, TRUE, NULL);
264 /* try with a bad device specified */
265 rc=pDirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
266 ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
267 "should have failed: %s\n",DXGetErrorString8(rc));
268 if (rc==DS_OK && dso)
269 IDirectSound_Release(dso);
272 static HRESULT test_dsound(LPGUID lpGuid)
275 LPDIRECTSOUND dso=NULL;
278 /* DSOUND: Error: Invalid interface buffer */
279 rc=pDirectSoundCreate(lpGuid,0,NULL);
280 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate() should have returned "
281 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
283 /* Create the DirectSound object */
284 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
285 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
286 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
290 /* Try the enumerated device */
291 IDirectSound_test(dso, TRUE, lpGuid);
293 /* Try the COM class factory method of creation with enumerated device */
294 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
295 &IID_IDirectSound, (void**)&dso);
296 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
297 DXGetErrorString8(rc));
299 IDirectSound_test(dso, FALSE, lpGuid);
301 /* Create a DirectSound object */
302 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
303 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
305 LPDIRECTSOUND dso1=NULL;
307 /* Create a second DirectSound object */
308 rc=pDirectSoundCreate(lpGuid,&dso1,NULL);
309 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
311 /* Release the second DirectSound object */
312 ref=IDirectSound_Release(dso1);
313 ok(ref==0,"IDirectSound_Release() has %d references, should have "
315 ok(dso!=dso1,"DirectSound objects should be unique: dso=%p,dso1=%p\n",dso,dso1);
318 /* Release the first DirectSound object */
319 ref=IDirectSound_Release(dso);
320 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
323 return DSERR_GENERIC;
327 /* Create a DirectSound object */
328 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
329 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
331 LPDIRECTSOUNDBUFFER secondary;
332 DSBUFFERDESC bufdesc;
335 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
336 ZeroMemory(&bufdesc, sizeof(bufdesc));
337 bufdesc.dwSize=sizeof(bufdesc);
338 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
339 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
341 bufdesc.lpwfxFormat=&wfx;
342 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
343 ok(rc==DS_OK && secondary!=NULL,
344 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
345 "buffer %s\n",DXGetErrorString8(rc));
346 if (rc==DS_OK && secondary!=NULL) {
347 LPDIRECTSOUND3DBUFFER buffer3d;
348 rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
350 ok(rc==DS_OK && buffer3d!=NULL,"IDirectSound_QueryInterface() "
351 "failed: %s\n",DXGetErrorString8(rc));
352 if (rc==DS_OK && buffer3d!=NULL) {
353 ref=IDirectSound3DBuffer_AddRef(buffer3d);
354 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
355 "should have 2\n",ref);
357 ref=IDirectSoundBuffer_AddRef(secondary);
358 ok(ref==2,"IDirectSoundBuffer_AddRef() has %d references, "
359 "should have 2\n",ref);
361 /* release with buffer */
362 ref=IDirectSound_Release(dso);
363 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
366 return DSERR_GENERIC;
373 static HRESULT test_primary(LPGUID lpGuid)
376 LPDIRECTSOUND dso=NULL;
377 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
378 DSBUFFERDESC bufdesc;
383 /* Create the DirectSound object */
384 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
385 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
386 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
390 /* Get the device capabilities */
391 ZeroMemory(&dscaps, sizeof(dscaps));
392 dscaps.dwSize=sizeof(dscaps);
393 rc=IDirectSound_GetCaps(dso,&dscaps);
394 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
398 /* DSOUND: Error: Invalid buffer description pointer */
399 rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
400 ok(rc==DSERR_INVALIDPARAM,
401 "IDirectSound_CreateSoundBuffer() should have failed: %s\n",
402 DXGetErrorString8(rc));
404 /* DSOUND: Error: NULL pointer is invalid */
405 /* DSOUND: Error: Invalid buffer description pointer */
406 rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
407 ok(rc==DSERR_INVALIDPARAM && primary==0,
408 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
409 "dsbo=%p\n",DXGetErrorString8(rc),primary);
411 /* DSOUND: Error: Invalid size */
412 /* DSOUND: Error: Invalid buffer description */
414 ZeroMemory(&bufdesc, sizeof(bufdesc));
415 bufdesc.dwSize=sizeof(bufdesc)-1;
416 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
417 ok(rc==DSERR_INVALIDPARAM && primary==0,
418 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
419 "primary=%p\n",DXGetErrorString8(rc),primary);
421 /* DSOUND: Error: DSBCAPS_PRIMARYBUFFER flag with non-NULL lpwfxFormat */
422 /* DSOUND: Error: Invalid buffer description pointer */
424 ZeroMemory(&bufdesc, sizeof(bufdesc));
425 bufdesc.dwSize=sizeof(bufdesc);
426 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
427 bufdesc.lpwfxFormat=&wfx;
428 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
429 ok(rc==DSERR_INVALIDPARAM && primary==0,
430 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
431 "primary=%p\n",DXGetErrorString8(rc),primary);
433 /* DSOUND: Error: No DSBCAPS_PRIMARYBUFFER flag with NULL lpwfxFormat */
434 /* DSOUND: Error: Invalid buffer description pointer */
436 ZeroMemory(&bufdesc, sizeof(bufdesc));
437 bufdesc.dwSize=sizeof(bufdesc);
439 bufdesc.lpwfxFormat=NULL;
440 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
441 ok(rc==DSERR_INVALIDPARAM && primary==0,
442 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
443 "primary=%p\n",DXGetErrorString8(rc),primary);
445 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
446 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
447 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
448 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
449 DXGetErrorString8(rc));
453 /* Testing the primary buffer */
455 ZeroMemory(&bufdesc, sizeof(bufdesc));
456 bufdesc.dwSize=sizeof(bufdesc);
457 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
458 bufdesc.lpwfxFormat = &wfx;
459 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
460 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
461 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() should have "
462 "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc));
463 if (rc==DS_OK && primary!=NULL)
464 IDirectSoundBuffer_Release(primary);
467 ZeroMemory(&bufdesc, sizeof(bufdesc));
468 bufdesc.dwSize=sizeof(bufdesc);
469 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
470 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
471 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
472 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "
473 "%s\n",DXGetErrorString8(rc));
474 if (rc==DSERR_CONTROLUNAVAIL)
475 trace(" No Primary\n");
476 else if (rc==DS_OK && primary!=NULL) {
479 /* Try to create a second primary buffer */
480 /* DSOUND: Error: The primary buffer already exists.
481 * Any changes made to the buffer description will be ignored. */
482 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
483 ok(rc==DS_OK && second==primary,
484 "IDirectSound_CreateSoundBuffer() should have returned original "
485 "primary buffer: %s\n",DXGetErrorString8(rc));
486 ref=IDirectSoundBuffer_Release(second);
487 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
488 "should have 1\n",ref);
490 /* Try to duplicate a primary buffer */
491 /* DSOUND: Error: Can't duplicate primary buffers */
492 rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
494 ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer() primary buffer "
495 "should have failed %s\n",DXGetErrorString8(rc));
497 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
498 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
499 DXGetErrorString8(rc));
501 if (winetest_interactive) {
502 trace("Playing a 5 seconds reference tone at the current "
505 trace("(the current volume is %d according to DirectSound)\n",
507 trace("All subsequent tones should be identical to this one.\n");
508 trace("Listen for stutter, changes in pitch, volume, etc.\n");
510 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
511 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0,FALSE,0);
513 ref=IDirectSoundBuffer_Release(primary);
514 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
515 "should have 0\n",ref);
518 /* Set the CooperativeLevel back to normal */
519 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
520 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
521 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
522 DXGetErrorString8(rc));
525 ref=IDirectSound_Release(dso);
526 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
528 return DSERR_GENERIC;
534 * Test the primary buffer at different formats while keeping the
535 * secondary buffer at a constant format.
537 static HRESULT test_primary_secondary(LPGUID lpGuid)
540 LPDIRECTSOUND dso=NULL;
541 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
542 DSBUFFERDESC bufdesc;
544 WAVEFORMATEX wfx, wfx2;
547 /* Create the DirectSound object */
548 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
549 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
550 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
554 /* Get the device capabilities */
555 ZeroMemory(&dscaps, sizeof(dscaps));
556 dscaps.dwSize=sizeof(dscaps);
557 rc=IDirectSound_GetCaps(dso,&dscaps);
558 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
562 /* We must call SetCooperativeLevel before creating primary buffer */
563 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
564 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
565 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
566 DXGetErrorString8(rc));
570 ZeroMemory(&bufdesc, sizeof(bufdesc));
571 bufdesc.dwSize=sizeof(bufdesc);
572 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
573 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
574 ok(rc==DS_OK && primary!=NULL,
575 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
576 "%s\n",DXGetErrorString8(rc));
578 if (rc==DS_OK && primary!=NULL) {
579 for (f=0;f<NB_FORMATS;f++) {
580 /* We must call SetCooperativeLevel to be allowed to call
582 /* DSOUND: Setting DirectSound cooperative level to
584 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
585 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
586 DXGetErrorString8(rc));
590 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
593 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
595 if (wfx.wBitsPerSample <= 16)
596 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %s\n",
597 format_string(&wfx), DXGetErrorString8(rc));
599 ok(rc==DS_OK || rc == E_INVALIDARG, "SetFormat (%s) failed: %s\n",
600 format_string(&wfx), DXGetErrorString8(rc));
602 /* There is no guarantee that SetFormat will actually change the
603 * format to what we asked for. It depends on what the soundcard
604 * supports. So we must re-query the format.
606 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
607 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
608 DXGetErrorString8(rc));
610 (wfx.wFormatTag!=wfx2.wFormatTag ||
611 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
612 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
613 wfx.nChannels!=wfx2.nChannels)) {
614 trace("Requested primary format tag=0x%04x %dx%dx%d "
615 "avg.B/s=%d align=%d\n",
616 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
617 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
618 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
619 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
620 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
623 /* Set the CooperativeLevel back to normal */
624 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
625 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
626 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
627 DXGetErrorString8(rc));
629 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
632 ZeroMemory(&bufdesc, sizeof(bufdesc));
633 bufdesc.dwSize=sizeof(bufdesc);
634 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
635 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
637 bufdesc.lpwfxFormat=&wfx2;
638 if (winetest_interactive) {
639 trace(" Testing a primary buffer at %dx%dx%d with a "
640 "secondary buffer at %dx%dx%d\n",
641 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
642 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
644 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
645 ok(rc==DS_OK && secondary!=NULL,
646 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
647 "buffer %s\n",DXGetErrorString8(rc));
649 if (rc==DS_OK && secondary!=NULL) {
650 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
651 winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
653 ref=IDirectSoundBuffer_Release(secondary);
654 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
655 "should have 0\n",ref);
659 ref=IDirectSoundBuffer_Release(primary);
660 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
661 "should have 0\n",ref);
664 /* Set the CooperativeLevel back to normal */
665 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
666 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
667 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
668 DXGetErrorString8(rc));
671 ref=IDirectSound_Release(dso);
672 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
674 return DSERR_GENERIC;
679 static HRESULT test_secondary(LPGUID lpGuid)
682 LPDIRECTSOUND dso=NULL;
683 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
684 DSBUFFERDESC bufdesc;
686 WAVEFORMATEX wfx, wfx1;
690 /* Create the DirectSound object */
691 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
692 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
693 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
697 /* Get the device capabilities */
698 ZeroMemory(&dscaps, sizeof(dscaps));
699 dscaps.dwSize=sizeof(dscaps);
700 rc=IDirectSound_GetCaps(dso,&dscaps);
701 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
705 /* We must call SetCooperativeLevel before creating primary buffer */
706 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
707 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
708 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
709 DXGetErrorString8(rc));
713 ZeroMemory(&bufdesc, sizeof(bufdesc));
714 bufdesc.dwSize=sizeof(bufdesc);
715 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
716 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
717 ok(rc==DS_OK && primary!=NULL,
718 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
719 "%s\n",DXGetErrorString8(rc));
721 if (rc==DS_OK && primary!=NULL) {
722 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
723 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
724 DXGetErrorString8(rc));
728 for (f=0;f<NB_FORMATS;f++) {
729 WAVEFORMATEXTENSIBLE wfxe;
730 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
733 ZeroMemory(&bufdesc, sizeof(bufdesc));
734 bufdesc.dwSize=sizeof(bufdesc);
735 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
736 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
738 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
739 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() "
740 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
741 DXGetErrorString8(rc));
742 if (rc==DS_OK && secondary!=NULL)
743 IDirectSoundBuffer_Release(secondary);
746 ZeroMemory(&bufdesc, sizeof(bufdesc));
747 bufdesc.dwSize=sizeof(bufdesc);
748 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
749 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
751 bufdesc.lpwfxFormat=&wfx;
752 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
753 if (gotdx8 || wfx.wBitsPerSample <= 16)
755 if (wfx.wBitsPerSample > 16)
756 ok(rc == DSERR_CONTROLUNAVAIL && !secondary, "IDirectSound_CreateSoundBuffer() "
757 "should have returned DSERR_CONTROLUNAVAIL and NULL, returned: %s %p\n",
758 DXGetErrorString8(rc), secondary);
760 ok(rc==DS_OK && secondary!=NULL,
761 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
762 "buffer %s\n",DXGetErrorString8(rc));
765 ok(rc==E_INVALIDARG, "Creating %d bpp buffer on dx < 8 returned: %p %s\n",
766 wfx.wBitsPerSample, secondary, DXGetErrorString8(rc));
770 skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
771 /* Apparently they succeed with bogus values,
772 * which means that older dsound doesn't look at them
778 IDirectSoundBuffer_Release(secondary);
781 bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
783 wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
784 wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
785 wfxe.Format.cbSize = 1;
786 wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
787 wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);
789 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
790 ok(rc==DSERR_INVALIDPARAM && !secondary,
791 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
792 DXGetErrorString8(rc), secondary);
794 IDirectSoundBuffer_Release(secondary);
796 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1;
798 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
799 ok(DSERR_CONTROLUNAVAIL && !secondary,
800 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
801 DXGetErrorString8(rc), secondary);
803 IDirectSoundBuffer_Release(secondary);
805 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
806 wfxe.SubFormat = GUID_NULL;
807 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
808 ok(rc==DSERR_INVALIDPARAM && !secondary,
809 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
810 DXGetErrorString8(rc), secondary);
812 IDirectSoundBuffer_Release(secondary);
813 wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
815 ++wfxe.Samples.wValidBitsPerSample;
816 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
817 ok(rc==DSERR_INVALIDPARAM && !secondary,
818 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
819 DXGetErrorString8(rc), secondary);
821 IDirectSoundBuffer_Release(secondary);
822 --wfxe.Samples.wValidBitsPerSample;
824 wfxe.Samples.wValidBitsPerSample = 0;
825 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
826 ok(rc==DS_OK && secondary,
827 "IDirectSound_CreateSoundBuffer() returned: %s %p\n",
828 DXGetErrorString8(rc), secondary);
830 IDirectSoundBuffer_Release(secondary);
831 wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample;
833 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
834 ok(rc==DS_OK && secondary!=NULL,
835 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
836 "buffer %s\n",DXGetErrorString8(rc));
839 if (rc==DS_OK && secondary!=NULL) {
840 if (winetest_interactive) {
841 trace(" Testing a secondary buffer at %dx%dx%d "
842 "with a primary buffer at %dx%dx%d\n",
843 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
844 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
846 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
847 winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
849 ref=IDirectSoundBuffer_Release(secondary);
850 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
851 "should have 0\n",ref);
855 ref=IDirectSoundBuffer_Release(primary);
856 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
857 "should have 0\n",ref);
860 /* Set the CooperativeLevel back to normal */
861 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
862 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
863 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
864 DXGetErrorString8(rc));
867 ref=IDirectSound_Release(dso);
868 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
870 return DSERR_GENERIC;
875 static HRESULT test_block_align(LPGUID lpGuid)
878 LPDIRECTSOUND dso=NULL;
879 LPDIRECTSOUNDBUFFER secondary=NULL;
880 DSBUFFERDESC bufdesc;
886 /* Create the DirectSound object */
887 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
888 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
889 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
893 init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
894 ZeroMemory(&bufdesc, sizeof(bufdesc));
895 bufdesc.dwSize=sizeof(bufdesc);
896 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
897 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec + 1;
898 bufdesc.lpwfxFormat=&wfx;
899 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
900 ok(rc==DS_OK,"IDirectSound_CreateSoundBuffer() "
901 "should have returned DS_OK, returned: %s\n",
902 DXGetErrorString8(rc));
904 if (rc==DS_OK && secondary!=NULL) {
905 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
906 dsbcaps.dwSize = sizeof(dsbcaps);
907 rc=IDirectSoundBuffer_GetCaps(secondary,&dsbcaps);
908 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
909 "returned: %s\n", DXGetErrorString8(rc));
910 if (rc==DS_OK && wfx.nBlockAlign > 1)
912 ok(dsbcaps.dwBufferBytes==(wfx.nAvgBytesPerSec + wfx.nBlockAlign),
913 "Buffer size not a multiple of nBlockAlign: requested %d, "
914 "got %d, should be %d\n", bufdesc.dwBufferBytes,
915 dsbcaps.dwBufferBytes, wfx.nAvgBytesPerSec + wfx.nBlockAlign);
917 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 0);
918 ok(rc == DS_OK, "Could not set position to 0: %s\n", DXGetErrorString8(rc));
919 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos, NULL);
920 ok(rc == DS_OK, "Could not get position: %s\n", DXGetErrorString8(rc));
921 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 1);
922 ok(rc == DS_OK, "Could not set position to 1: %s\n", DXGetErrorString8(rc));
923 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos2, NULL);
924 ok(rc == DS_OK, "Could not get new position: %s\n", DXGetErrorString8(rc));
925 ok(pos == pos2, "Positions not the same! Old position: %d, new position: %d\n", pos, pos2);
927 ref=IDirectSoundBuffer_Release(secondary);
928 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, "
929 "should have 0\n",ref);
932 ref=IDirectSound_Release(dso);
933 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
935 return DSERR_GENERIC;
943 } fmts[] = { { 8, 1 }, { 8, 2 }, { 16, 1 }, {16, 2 } };
945 static HRESULT test_frequency(LPGUID lpGuid)
948 LPDIRECTSOUND dso=NULL;
949 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
950 DSBUFFERDESC bufdesc;
952 WAVEFORMATEX wfx, wfx1;
955 int rates[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
958 /* Create the DirectSound object */
959 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
960 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
961 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
965 /* Get the device capabilities */
966 ZeroMemory(&dscaps, sizeof(dscaps));
967 dscaps.dwSize=sizeof(dscaps);
968 rc=IDirectSound_GetCaps(dso,&dscaps);
969 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
973 /* We must call SetCooperativeLevel before creating primary buffer */
974 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
975 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
976 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
977 DXGetErrorString8(rc));
981 ZeroMemory(&bufdesc, sizeof(bufdesc));
982 bufdesc.dwSize=sizeof(bufdesc);
983 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
984 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
985 ok(rc==DS_OK && primary!=NULL,
986 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
987 "%s\n",DXGetErrorString8(rc));
989 if (rc==DS_OK && primary!=NULL) {
990 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
991 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
992 DXGetErrorString8(rc));
996 for (f=0;f<sizeof(fmts)/sizeof(fmts[0]);f++) {
997 for (r=0;r<sizeof(rates)/sizeof(rates[0]);r++) {
998 init_format(&wfx,WAVE_FORMAT_PCM,11025,fmts[f].bits,
1001 ZeroMemory(&bufdesc, sizeof(bufdesc));
1002 bufdesc.dwSize=sizeof(bufdesc);
1003 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLFREQUENCY;
1004 bufdesc.dwBufferBytes=align((wfx.nAvgBytesPerSec*rates[r]/11025)*
1005 BUFFER_LEN/1000,wfx.nBlockAlign);
1006 bufdesc.lpwfxFormat=&wfx;
1007 if (winetest_interactive) {
1008 trace(" Testing a secondary buffer at %dx%dx%d "
1009 "with a primary buffer at %dx%dx%d\n",
1010 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
1011 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
1013 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
1014 ok(rc==DS_OK && secondary!=NULL,
1015 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
1016 "buffer %s\n",DXGetErrorString8(rc));
1018 if (rc==DS_OK && secondary!=NULL) {
1019 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
1020 winetest_interactive,1.0,0,NULL,0,0,TRUE,rates[r]);
1022 ref=IDirectSoundBuffer_Release(secondary);
1023 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1024 "should have 0\n",ref);
1029 ref=IDirectSoundBuffer_Release(primary);
1030 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1031 "should have 0\n",ref);
1034 /* Set the CooperativeLevel back to normal */
1035 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1036 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1037 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
1038 DXGetErrorString8(rc));
1041 ref=IDirectSound_Release(dso);
1042 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1044 return DSERR_GENERIC;
1049 static unsigned int number;
1051 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1052 LPCSTR lpcstrModule, LPVOID lpContext)
1055 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1057 /* Don't test the primary device */
1060 ok (!lpcstrModule[0], "lpcstrModule(%s) != NULL\n", lpcstrModule);
1064 rc = test_dsound(lpGuid);
1065 if (rc == DSERR_NODRIVER)
1066 trace(" No Driver\n");
1067 else if (rc == DSERR_ALLOCATED)
1068 trace(" Already In Use\n");
1069 else if (rc == E_FAIL)
1070 trace(" No Device\n");
1072 test_block_align(lpGuid);
1073 test_primary(lpGuid);
1074 test_primary_secondary(lpGuid);
1075 test_secondary(lpGuid);
1076 test_frequency(lpGuid);
1082 static void dsound_tests(void)
1085 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
1086 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1095 hDsound = LoadLibrary("dsound.dll");
1098 ok( FreeLibrary(hDsound), "FreeLibrary(1) returned %d\n", GetLastError());
1099 ok( FreeLibrary(hDsound), "FreeLibrary(2) returned %d\n", GetLastError());
1100 ok(!FreeLibrary(hDsound), "DirectSound DLL still loaded\n");
1103 hDsound = LoadLibrary("dsound.dll");
1106 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
1108 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
1109 "DirectSoundEnumerateA");
1110 pDirectSoundCreate = (void*)GetProcAddress(hDsound,
1111 "DirectSoundCreate");
1113 gotdx8 = !!GetProcAddress(hDsound, "DirectSoundCreate8");
1115 IDirectSound_tests();
1118 FreeLibrary(hDsound);
1121 skip("dsound.dll not found!\n");