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
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
36 #include "dsound_test.h"
38 static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
39 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL;
41 int align(int length, int align)
43 return (length / align) * align;
46 static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized,
55 DWORD speaker_config, new_speaker_config;
58 /* Try to Query for objects */
59 rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
60 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n",
61 DXGetErrorString8(rc));
63 IDirectSound8_Release(unknown);
65 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
66 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n",
67 DXGetErrorString8(rc));
69 IDirectSound_Release(ds);
71 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
72 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) "
73 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
74 DXGetErrorString8(rc));
76 IDirectSound8_Release(ds8);
78 if (initialized == FALSE) {
79 /* try uninitialized object */
80 rc=IDirectSound8_GetCaps(dso,0);
81 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) "
82 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
83 DXGetErrorString8(rc));
85 rc=IDirectSound8_GetCaps(dso,&dscaps);
86 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() "
87 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
88 DXGetErrorString8(rc));
90 rc=IDirectSound8_Compact(dso);
91 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() "
92 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
93 DXGetErrorString8(rc));
95 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
96 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() "
97 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
98 DXGetErrorString8(rc));
100 rc=IDirectSound8_VerifyCertification(dso, &certified);
101 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() "
102 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
103 DXGetErrorString8(rc));
105 rc=IDirectSound8_Initialize(dso,lpGuid);
106 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
107 "IDirectSound8_Initialize() failed: %s\n",DXGetErrorString8(rc));
108 if (rc==DSERR_NODRIVER) {
109 trace(" No Driver\n");
111 } else if (rc==E_FAIL) {
112 trace(" No Device\n");
114 } else if (rc==DSERR_ALLOCATED) {
115 trace(" Already In Use\n");
120 rc=IDirectSound8_Initialize(dso,lpGuid);
121 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound8_Initialize() "
122 "should have returned DSERR_ALREADYINITIALIZED: %s\n",
123 DXGetErrorString8(rc));
125 /* DSOUND: Error: Invalid caps buffer */
126 rc=IDirectSound8_GetCaps(dso,0);
127 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
128 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
129 DXGetErrorString8(rc));
131 ZeroMemory(&dscaps, sizeof(dscaps));
133 /* DSOUND: Error: Invalid caps buffer */
134 rc=IDirectSound8_GetCaps(dso,&dscaps);
135 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
136 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
137 DXGetErrorString8(rc));
139 dscaps.dwSize=sizeof(dscaps);
141 /* DSOUND: Running on a certified driver */
142 rc=IDirectSound8_GetCaps(dso,&dscaps);
143 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
145 rc=IDirectSound8_Compact(dso);
146 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %s\n",
147 DXGetErrorString8(rc));
149 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
150 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
151 DXGetErrorString8(rc));
153 rc=IDirectSound8_Compact(dso);
154 ok(rc==DS_OK,"IDirectSound8_Compact() failed: %s\n",DXGetErrorString8(rc));
156 rc=IDirectSound8_GetSpeakerConfig(dso,0);
157 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) "
158 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
159 DXGetErrorString8(rc));
161 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
162 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n",
163 DXGetErrorString8(rc));
165 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
166 DSSPEAKER_GEOMETRY_WIDE);
167 rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config);
168 ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %s\n",
169 DXGetErrorString8(rc));
171 rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config);
172 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n",
173 DXGetErrorString8(rc));
174 if (rc==DS_OK && speaker_config!=new_speaker_config)
175 trace("IDirectSound8_GetSpeakerConfig() failed to set speaker "
176 "config: expected 0x%08x, got 0x%08x\n",
177 speaker_config,new_speaker_config);
180 rc=IDirectSound8_VerifyCertification(dso, &certified);
181 ok(rc==DS_OK||rc==E_NOTIMPL,"IDirectSound8_VerifyCertification() failed: %s\n",
182 DXGetErrorString8(rc));
185 ref=IDirectSound8_Release(dso);
186 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
189 static void IDirectSound8_tests(void)
192 LPDIRECTSOUND8 dso=NULL;
193 LPCLASSFACTORY cf=NULL;
195 trace("Testing IDirectSound8\n");
197 rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
198 &IID_IClassFactory, (void**)&cf);
199 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IClassFactory) "
200 "failed: %s\n", DXGetErrorString8(rc));
202 rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
203 &IID_IUnknown, (void**)&cf);
204 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IUnknown) "
205 "failed: %s\n", DXGetErrorString8(rc));
207 /* try the COM class factory method of creation with no device specified */
208 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
209 &IID_IDirectSound8, (void**)&dso);
210 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance() failed: %s\n",
211 DXGetErrorString8(rc));
212 if (rc==REGDB_E_CLASSNOTREG) {
213 trace(" Class Not Registered\n");
217 IDirectSound8_test(dso, FALSE, NULL);
219 /* try the COM class factory method of creation with default playback
220 * device specified */
221 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
222 &IID_IDirectSound8, (void**)&dso);
223 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n",
224 DXGetErrorString8(rc));
226 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultPlayback);
228 /* try the COM class factory method of creation with default voice
229 * playback device specified */
230 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
231 &IID_IDirectSound8, (void**)&dso);
232 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n",
233 DXGetErrorString8(rc));
235 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
237 /* try the COM class factory method of creation with a bad
239 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
240 &CLSID_DirectSoundPrivate, (void**)&dso);
241 ok(rc==E_NOINTERFACE,
242 "CoCreateInstance(CLSID_DirectSound8,CLSID_DirectSoundPrivate) "
243 "should have failed: %s\n",DXGetErrorString8(rc));
245 /* try the COM class factory method of creation with a bad
246 * GUID and IID specified */
247 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
248 &IID_IDirectSound8, (void**)&dso);
249 ok(rc==REGDB_E_CLASSNOTREG,
250 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound8) "
251 "should have failed: %s\n",DXGetErrorString8(rc));
253 /* try with no device specified */
254 rc=pDirectSoundCreate8(NULL,&dso,NULL);
255 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
256 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
257 if (rc==DS_OK && dso)
258 IDirectSound8_test(dso, TRUE, NULL);
260 /* try with default playback device specified */
261 rc=pDirectSoundCreate8(&DSDEVID_DefaultPlayback,&dso,NULL);
262 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
263 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
264 if (rc==DS_OK && dso)
265 IDirectSound8_test(dso, TRUE, NULL);
267 /* try with default voice playback device specified */
268 rc=pDirectSoundCreate8(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
269 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
270 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
271 if (rc==DS_OK && dso)
272 IDirectSound8_test(dso, TRUE, NULL);
274 /* try with a bad device specified */
275 rc=pDirectSoundCreate8(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
276 ok(rc==DSERR_NODRIVER,"DirectSoundCreate8(DSDEVID_DefaultVoiceCapture) "
277 "should have failed: %s\n",DXGetErrorString8(rc));
280 static HRESULT test_dsound8(LPGUID lpGuid)
283 LPDIRECTSOUND8 dso=NULL;
286 /* DSOUND: Error: Invalid interface buffer */
287 rc=pDirectSoundCreate8(lpGuid,0,NULL);
288 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned "
289 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
291 /* Create the DirectSound8 object */
292 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
293 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
294 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
298 /* Try the enumerated device */
299 IDirectSound8_test(dso, TRUE, lpGuid);
301 /* Try the COM class factory method of creation with enumerated device */
302 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
303 &IID_IDirectSound8, (void**)&dso);
304 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
305 DXGetErrorString8(rc));
307 IDirectSound8_test(dso, FALSE, lpGuid);
309 /* Create a DirectSound8 object */
310 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
311 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
313 LPDIRECTSOUND8 dso1=NULL;
315 /* Create a second DirectSound8 object */
316 rc=pDirectSoundCreate8(lpGuid,&dso1,NULL);
317 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
319 /* Release the second DirectSound8 object */
320 ref=IDirectSound8_Release(dso1);
321 ok(ref==0,"IDirectSound8_Release() has %d references, "
322 "should have 0\n",ref);
323 ok(dso!=dso1,"DirectSound8 objects should be unique: "
324 "dso=%p,dso1=%p\n",dso,dso1);
327 /* Release the first DirectSound8 object */
328 ref=IDirectSound8_Release(dso);
329 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
332 return DSERR_GENERIC;
336 /* Create a DirectSound8 object */
337 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
338 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
340 LPDIRECTSOUNDBUFFER secondary;
341 DSBUFFERDESC bufdesc;
344 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
345 ZeroMemory(&bufdesc, sizeof(bufdesc));
346 bufdesc.dwSize=sizeof(bufdesc);
347 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
348 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
350 bufdesc.lpwfxFormat=&wfx;
351 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
352 ok(rc==DS_OK && secondary!=NULL,
353 "IDirectSound8_CreateSoundBuffer() failed to create a secondary "
354 "buffer: %s\n",DXGetErrorString8(rc));
355 if (rc==DS_OK && secondary!=NULL) {
356 LPDIRECTSOUND3DBUFFER buffer3d;
357 LPDIRECTSOUNDBUFFER8 buffer8;
358 rc=IDirectSound8_QueryInterface(secondary,
359 &IID_IDirectSound3DBuffer,
361 ok(rc==DS_OK && buffer3d!=NULL,
362 "IDirectSound8_QueryInterface() failed: %s\n",
363 DXGetErrorString8(rc));
364 if (rc==DS_OK && buffer3d!=NULL) {
365 ref=IDirectSound3DBuffer_AddRef(buffer3d);
366 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
367 "should have 2\n",ref);
369 rc=IDirectSound8_QueryInterface(secondary,
370 &IID_IDirectSoundBuffer8,
372 if (rc==DS_OK && buffer8!=NULL) {
373 ref=IDirectSoundBuffer8_AddRef(buffer8);
374 ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, "
375 "should have 3\n",ref);
377 ref=IDirectSoundBuffer_AddRef(secondary);
378 ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, "
379 "should have 4\n",ref);
381 /* release with buffer */
382 ref=IDirectSound8_Release(dso);
383 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
386 return DSERR_GENERIC;
393 static HRESULT test_primary8(LPGUID lpGuid)
396 LPDIRECTSOUND8 dso=NULL;
397 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
398 DSBUFFERDESC bufdesc;
403 /* Create the DirectSound object */
404 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
405 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
406 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
410 /* Get the device capabilities */
411 ZeroMemory(&dscaps, sizeof(dscaps));
412 dscaps.dwSize=sizeof(dscaps);
413 rc=IDirectSound8_GetCaps(dso,&dscaps);
414 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
418 /* DSOUND: Error: Invalid buffer description pointer */
419 rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL);
420 ok(rc==DSERR_INVALIDPARAM,
421 "IDirectSound8_CreateSoundBuffer should have returned "
422 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
424 /* DSOUND: Error: Invalid buffer description pointer */
425 rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL);
426 ok(rc==DSERR_INVALIDPARAM && primary==0,
427 "IDirectSound8_CreateSoundBuffer() should have returned "
428 "DSERR_INVALIDPARAM, returned: rc=%s,dsbo=%p\n",
429 DXGetErrorString8(rc),primary);
431 /* DSOUND: Error: Invalid buffer description pointer */
432 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL);
433 ok(rc==DSERR_INVALIDPARAM && primary==0,
434 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s,"
435 "dsbo=%p\n",DXGetErrorString8(rc),primary);
437 ZeroMemory(&bufdesc, sizeof(bufdesc));
439 /* DSOUND: Error: Invalid size */
440 /* DSOUND: Error: Invalid buffer description */
441 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
442 ok(rc==DSERR_INVALIDPARAM && primary==0,
443 "IDirectSound8_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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
449 ok(rc==DS_OK,"IDirectSound8_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=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
462 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_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=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
472 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
473 "IDirectSound8_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=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
484 ok(rc==DS_OK && second==primary,
485 "IDirectSound8_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=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third);
495 ok(rc!=DS_OK,"IDirectSound8_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 volume.\n");
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_buffer8(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
511 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
521 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
522 DXGetErrorString8(rc));
525 ref=IDirectSound8_Release(dso);
526 ok(ref==0,"IDirectSound8_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_secondary8(LPGUID lpGuid)
540 LPDIRECTSOUND8 dso=NULL;
541 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
542 DSBUFFERDESC bufdesc;
544 WAVEFORMATEX wfx, wfx2;
548 /* Create the DirectSound object */
549 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
550 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
551 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
555 /* Get the device capabilities */
556 ZeroMemory(&dscaps, sizeof(dscaps));
557 dscaps.dwSize=sizeof(dscaps);
558 rc=IDirectSound8_GetCaps(dso,&dscaps);
559 ok(rc==DS_OK,"IDirectSound8_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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
566 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
567 DXGetErrorString8(rc));
571 ZeroMemory(&bufdesc, sizeof(bufdesc));
572 bufdesc.dwSize=sizeof(bufdesc);
573 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
574 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
575 ok(rc==DS_OK && primary!=NULL,
576 "IDirectSound8_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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
586 ok(rc==DS_OK,"IDirectSound8_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);
595 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %s\n",
596 format_string(&wfx), DXGetErrorString8(rc));
598 /* There is no guarantee that SetFormat will actually change the
599 * format to what we asked for. It depends on what the soundcard
600 * supports. So we must re-query the format.
602 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
603 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
604 DXGetErrorString8(rc));
606 (wfx.wFormatTag!=wfx2.wFormatTag ||
607 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
608 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
609 wfx.nChannels!=wfx2.nChannels)) {
610 trace("Requested primary format tag=0x%04x %dx%dx%d "
611 "avg.B/s=%d align=%d\n",
612 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
613 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
614 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
615 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
616 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
619 /* Set the CooperativeLevel back to normal */
620 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
621 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
622 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
623 DXGetErrorString8(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 with a "
636 "secondary buffer at %dx%dx%d\n",
637 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
638 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
640 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
641 ok(rc==DS_OK && secondary!=NULL,
642 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
643 "buffer %s\n",DXGetErrorString8(rc));
645 if (rc==DS_OK && secondary!=NULL) {
646 test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
647 winetest_interactive,1.0,0,NULL,0,0);
649 ref=IDirectSoundBuffer_Release(secondary);
650 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
651 "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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
663 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
664 DXGetErrorString8(rc));
667 ref=IDirectSound8_Release(dso);
668 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
670 return DSERR_GENERIC;
675 static HRESULT test_secondary8(LPGUID lpGuid)
678 LPDIRECTSOUND8 dso=NULL;
679 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
680 DSBUFFERDESC bufdesc;
682 WAVEFORMATEX wfx, wfx1;
686 /* Create the DirectSound object */
687 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
688 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
689 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
693 /* Get the device capabilities */
694 ZeroMemory(&dscaps, sizeof(dscaps));
695 dscaps.dwSize=sizeof(dscaps);
696 rc=IDirectSound8_GetCaps(dso,&dscaps);
697 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
701 /* We must call SetCooperativeLevel before creating primary buffer */
702 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
703 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
704 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
705 DXGetErrorString8(rc));
709 ZeroMemory(&bufdesc, sizeof(bufdesc));
710 bufdesc.dwSize=sizeof(bufdesc);
711 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
712 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
713 ok(rc==DS_OK && primary!=NULL,
714 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
715 "%s\n",DXGetErrorString8(rc));
717 if (rc==DS_OK && primary!=NULL) {
718 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
719 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
720 DXGetErrorString8(rc));
724 for (f=0;f<NB_FORMATS;f++) {
725 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
728 ZeroMemory(&bufdesc, sizeof(bufdesc));
729 bufdesc.dwSize=sizeof(bufdesc);
730 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
731 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
733 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
734 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() "
735 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
736 DXGetErrorString8(rc));
737 if (rc==DS_OK && secondary!=NULL)
738 IDirectSoundBuffer_Release(secondary);
741 ZeroMemory(&bufdesc, sizeof(bufdesc));
742 bufdesc.dwSize=sizeof(bufdesc);
743 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
744 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
746 bufdesc.lpwfxFormat=&wfx;
747 if (winetest_interactive) {
748 trace(" Testing a secondary buffer at %dx%dx%d "
749 "with a primary buffer at %dx%dx%d\n",
750 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
751 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
753 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
754 ok(rc==DS_OK && secondary!=NULL,
755 "IDirectSound8_CreateSoundBuffer() failed to create a secondary "
756 "buffer: %s\n",DXGetErrorString8(rc));
758 if (rc==DS_OK && secondary!=NULL) {
759 test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
760 winetest_interactive,1.0,0,NULL,0,0);
762 ref=IDirectSoundBuffer_Release(secondary);
763 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
764 "should have 0\n",ref);
768 ref=IDirectSoundBuffer_Release(primary);
769 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
770 "should have 0\n",ref);
773 /* Set the CooperativeLevel back to normal */
774 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
775 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
776 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
777 DXGetErrorString8(rc));
780 ref=IDirectSound8_Release(dso);
781 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
783 return DSERR_GENERIC;
788 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
789 LPCSTR lpcstrModule, LPVOID lpContext)
792 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
793 rc = test_dsound8(lpGuid);
794 if (rc == DSERR_NODRIVER)
795 trace(" No Driver\n");
796 else if (rc == DSERR_ALLOCATED)
797 trace(" Already In Use\n");
798 else if (rc == E_FAIL)
799 trace(" No Device\n");
801 test_primary8(lpGuid);
802 test_primary_secondary8(lpGuid);
803 test_secondary8(lpGuid);
809 static void dsound8_tests(void)
812 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
813 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
816 const char * get_file_version(const char * file_name)
818 static char version[32];
819 static char backslash[] = "\\";
823 size = GetFileVersionInfoSizeA("dsound.dll", &handle);
825 char * data = HeapAlloc(GetProcessHeap(), 0, size);
827 if (GetFileVersionInfoA("dsound.dll", handle, size, data)) {
828 VS_FIXEDFILEINFO *pFixedVersionInfo;
830 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
831 sprintf(version, "%d.%d.%d.%d",
832 pFixedVersionInfo->dwFileVersionMS >> 16,
833 pFixedVersionInfo->dwFileVersionMS & 0xffff,
834 pFixedVersionInfo->dwFileVersionLS >> 16,
835 pFixedVersionInfo->dwFileVersionLS & 0xffff);
837 sprintf(version, "not available");
839 sprintf(version, "failed");
841 HeapFree(GetProcessHeap(), 0, data);
843 sprintf(version, "failed");
845 sprintf(version, "not available");
856 hDsound = LoadLibrary("dsound.dll");
859 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
861 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
862 "DirectSoundEnumerateA");
863 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound,
864 "DirectSoundCreate8");
865 if (pDirectSoundCreate8)
867 IDirectSound8_tests();
871 skip("dsound8 test skipped\n");
873 FreeLibrary(hDsound);
876 skip("dsound.dll not found!\n");