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 LPDIRECTSOUNDBUFFER8 pb8 = NULL;
399 DSBUFFERDESC bufdesc;
404 /* Create the DirectSound object */
405 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
406 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
407 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
411 /* Get the device capabilities */
412 ZeroMemory(&dscaps, sizeof(dscaps));
413 dscaps.dwSize=sizeof(dscaps);
414 rc=IDirectSound8_GetCaps(dso,&dscaps);
415 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
419 /* DSOUND: Error: Invalid buffer description pointer */
420 rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL);
421 ok(rc==DSERR_INVALIDPARAM,
422 "IDirectSound8_CreateSoundBuffer should have returned "
423 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
425 /* DSOUND: Error: Invalid buffer description pointer */
426 rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL);
427 ok(rc==DSERR_INVALIDPARAM && primary==0,
428 "IDirectSound8_CreateSoundBuffer() should have returned "
429 "DSERR_INVALIDPARAM, returned: rc=%s,dsbo=%p\n",
430 DXGetErrorString8(rc),primary);
432 /* DSOUND: Error: Invalid buffer description pointer */
433 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL);
434 ok(rc==DSERR_INVALIDPARAM && primary==0,
435 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s,"
436 "dsbo=%p\n",DXGetErrorString8(rc),primary);
438 ZeroMemory(&bufdesc, sizeof(bufdesc));
440 /* DSOUND: Error: Invalid size */
441 /* DSOUND: Error: Invalid buffer description */
442 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
443 ok(rc==DSERR_INVALIDPARAM && primary==0,
444 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s,"
445 "primary=%p\n",DXGetErrorString8(rc),primary);
447 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
448 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
449 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
450 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
451 DXGetErrorString8(rc));
455 /* Testing the primary buffer */
457 ZeroMemory(&bufdesc, sizeof(bufdesc));
458 bufdesc.dwSize=sizeof(bufdesc);
459 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
460 bufdesc.lpwfxFormat = &wfx;
461 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
462 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
463 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() should have "
464 "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc));
465 if (rc==DS_OK && primary!=NULL)
466 IDirectSoundBuffer_Release(primary);
469 ZeroMemory(&bufdesc, sizeof(bufdesc));
470 bufdesc.dwSize=sizeof(bufdesc);
471 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
472 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
473 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
474 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: "
475 "%s\n",DXGetErrorString8(rc));
476 if (rc==DSERR_CONTROLUNAVAIL)
477 trace(" No Primary\n");
478 else if (rc==DS_OK && primary!=NULL) {
481 /* Try to create a second primary buffer */
482 /* DSOUND: Error: The primary buffer already exists.
483 * Any changes made to the buffer description will be ignored. */
484 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
485 ok(rc==DS_OK && second==primary,
486 "IDirectSound8_CreateSoundBuffer() should have returned original "
487 "primary buffer: %s\n",DXGetErrorString8(rc));
488 ref=IDirectSoundBuffer_Release(second);
489 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
490 "should have 1\n",ref);
492 /* Try to duplicate a primary buffer */
493 /* DSOUND: Error: Can't duplicate primary buffers */
494 rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third);
496 ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer() primary buffer "
497 "should have failed %s\n",DXGetErrorString8(rc));
499 /* Primary buffers don't have an IDirectSoundBuffer8 */
500 rc = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8, (LPVOID*)&pb8);
501 ok(FAILED(rc), "Primary buffer does have an IDirectSoundBuffer8: %s\n", DXGetErrorString8(rc));
503 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
504 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
505 DXGetErrorString8(rc));
507 if (winetest_interactive) {
508 trace("Playing a 5 seconds reference tone at the current volume.\n");
510 trace("(the current volume is %d according to DirectSound)\n",
512 trace("All subsequent tones should be identical to this one.\n");
513 trace("Listen for stutter, changes in pitch, volume, etc.\n");
515 test_buffer8(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
516 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);
518 ref=IDirectSoundBuffer_Release(primary);
519 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
520 "should have 0\n",ref);
523 /* Set the CooperativeLevel back to normal */
524 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
525 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
526 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
527 DXGetErrorString8(rc));
530 ref=IDirectSound8_Release(dso);
531 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
533 return DSERR_GENERIC;
539 * Test the primary buffer at different formats while keeping the
540 * secondary buffer at a constant format.
542 static HRESULT test_primary_secondary8(LPGUID lpGuid)
545 LPDIRECTSOUND8 dso=NULL;
546 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
547 DSBUFFERDESC bufdesc;
549 WAVEFORMATEX wfx, wfx2;
553 /* Create the DirectSound object */
554 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
555 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
556 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
560 /* Get the device capabilities */
561 ZeroMemory(&dscaps, sizeof(dscaps));
562 dscaps.dwSize=sizeof(dscaps);
563 rc=IDirectSound8_GetCaps(dso,&dscaps);
564 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
568 /* We must call SetCooperativeLevel before creating primary buffer */
569 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
570 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
571 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
572 DXGetErrorString8(rc));
576 ZeroMemory(&bufdesc, sizeof(bufdesc));
577 bufdesc.dwSize=sizeof(bufdesc);
578 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
579 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
580 ok(rc==DS_OK && primary!=NULL,
581 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
582 "%s\n",DXGetErrorString8(rc));
584 if (rc==DS_OK && primary!=NULL) {
585 for (f=0;f<NB_FORMATS;f++) {
586 /* We must call SetCooperativeLevel to be allowed to call
588 /* DSOUND: Setting DirectSound cooperative level to
590 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
591 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
592 DXGetErrorString8(rc));
596 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
599 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
600 ok(rc==DS_OK,"IDirectSoundBuffer_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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
627 ok(rc==DS_OK,"IDirectSound8_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_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
652 winetest_interactive,1.0,0,NULL,0,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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
668 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
669 DXGetErrorString8(rc));
672 ref=IDirectSound8_Release(dso);
673 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
675 return DSERR_GENERIC;
680 static HRESULT test_secondary8(LPGUID lpGuid)
683 LPDIRECTSOUND8 dso=NULL;
684 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
685 DSBUFFERDESC bufdesc;
687 WAVEFORMATEX wfx, wfx1;
691 /* Create the DirectSound object */
692 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
693 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
694 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
698 /* Get the device capabilities */
699 ZeroMemory(&dscaps, sizeof(dscaps));
700 dscaps.dwSize=sizeof(dscaps);
701 rc=IDirectSound8_GetCaps(dso,&dscaps);
702 ok(rc==DS_OK,"IDirectSound8_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=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
709 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
710 DXGetErrorString8(rc));
714 ZeroMemory(&bufdesc, sizeof(bufdesc));
715 bufdesc.dwSize=sizeof(bufdesc);
716 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
717 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
718 ok(rc==DS_OK && primary!=NULL,
719 "IDirectSound8_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 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=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
739 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_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 if (winetest_interactive) {
753 trace(" Testing a secondary buffer at %dx%dx%d "
754 "with a primary buffer at %dx%dx%d\n",
755 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
756 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
758 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
759 ok(rc==DS_OK && secondary!=NULL,
760 "IDirectSound8_CreateSoundBuffer() failed to create a secondary "
761 "buffer: %s\n",DXGetErrorString8(rc));
763 if (rc==DS_OK && secondary!=NULL) {
764 test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
765 winetest_interactive,1.0,0,NULL,0,0);
767 ref=IDirectSoundBuffer_Release(secondary);
768 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
769 "should have 0\n",ref);
773 ref=IDirectSoundBuffer_Release(primary);
774 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
775 "should have 0\n",ref);
778 /* Set the CooperativeLevel back to normal */
779 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
780 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
781 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
782 DXGetErrorString8(rc));
785 ref=IDirectSound8_Release(dso);
786 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
788 return DSERR_GENERIC;
793 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
794 LPCSTR lpcstrModule, LPVOID lpContext)
797 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
798 rc = test_dsound8(lpGuid);
799 if (rc == DSERR_NODRIVER)
800 trace(" No Driver\n");
801 else if (rc == DSERR_ALLOCATED)
802 trace(" Already In Use\n");
803 else if (rc == E_FAIL)
804 trace(" No Device\n");
806 test_primary8(lpGuid);
807 test_primary_secondary8(lpGuid);
808 test_secondary8(lpGuid);
814 static void dsound8_tests(void)
817 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
818 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
821 const char * get_file_version(const char * file_name)
823 static char version[32];
824 static char backslash[] = "\\";
828 size = GetFileVersionInfoSizeA("dsound.dll", &handle);
830 char * data = HeapAlloc(GetProcessHeap(), 0, size);
832 if (GetFileVersionInfoA("dsound.dll", handle, size, data)) {
833 VS_FIXEDFILEINFO *pFixedVersionInfo;
835 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
836 sprintf(version, "%d.%d.%d.%d",
837 pFixedVersionInfo->dwFileVersionMS >> 16,
838 pFixedVersionInfo->dwFileVersionMS & 0xffff,
839 pFixedVersionInfo->dwFileVersionLS >> 16,
840 pFixedVersionInfo->dwFileVersionLS & 0xffff);
842 sprintf(version, "not available");
844 sprintf(version, "failed");
846 HeapFree(GetProcessHeap(), 0, data);
848 sprintf(version, "failed");
850 sprintf(version, "not available");
861 hDsound = LoadLibrary("dsound.dll");
864 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
866 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
867 "DirectSoundEnumerateA");
868 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound,
869 "DirectSoundCreate8");
870 if (pDirectSoundCreate8)
872 IDirectSound8_tests();
876 skip("dsound8 test skipped\n");
878 FreeLibrary(hDsound);
881 skip("dsound.dll not found!\n");