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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
35 #include "wine/test.h"
42 #include "dsound_test.h"
44 static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized,
53 DWORD speaker_config, new_speaker_config;
56 /* Try to Query for objects */
57 rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
58 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n",
59 DXGetErrorString8(rc));
61 IDirectSound8_Release(unknown);
63 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
64 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n",
65 DXGetErrorString8(rc));
67 IDirectSound_Release(ds);
69 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
70 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) "
71 "should have failed: %s\n",DXGetErrorString8(rc));
73 IDirectSound8_Release(ds8);
75 if (initialized == FALSE) {
76 /* try unitialized object */
77 rc=IDirectSound8_GetCaps(dso,0);
78 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) "
79 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
80 DXGetErrorString8(rc));
82 rc=IDirectSound8_GetCaps(dso,&dscaps);
83 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() "
84 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
85 DXGetErrorString8(rc));
87 rc=IDirectSound8_Compact(dso);
88 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() "
89 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
90 DXGetErrorString8(rc));
92 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
93 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() "
94 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
95 DXGetErrorString8(rc));
97 rc=IDirectSound8_VerifyCertification(dso, &certified);
98 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() "
99 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
100 DXGetErrorString8(rc));
102 rc=IDirectSound8_Initialize(dso,lpGuid);
103 ok(rc==DS_OK,"IDirectSound8_Initialize() failed: %s\n",
104 DXGetErrorString8(rc));
107 /* DSOUND: Error: Invalid caps buffer */
108 rc=IDirectSound8_GetCaps(dso,0);
109 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
110 "should have failed: %s\n",DXGetErrorString8(rc));
112 ZeroMemory(&dscaps, sizeof(dscaps));
114 /* DSOUND: Error: Invalid caps buffer */
115 rc=IDirectSound8_GetCaps(dso,&dscaps);
116 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
117 "should have failed: %s\n",DXGetErrorString8(rc));
119 dscaps.dwSize=sizeof(dscaps);
121 /* DSOUND: Running on a certified driver */
122 rc=IDirectSound8_GetCaps(dso,&dscaps);
123 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
125 rc=IDirectSound8_Compact(dso);
126 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %s\n",
127 DXGetErrorString8(rc));
129 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
130 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n",
131 DXGetErrorString8(rc));
133 rc=IDirectSound8_Compact(dso);
134 ok(rc==DS_OK,"IDirectSound8_Compact() failed: %s\n",DXGetErrorString8(rc));
136 rc=IDirectSound8_GetSpeakerConfig(dso,0);
137 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) "
138 "should have failed: %s\n",DXGetErrorString8(rc));
140 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
141 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n",
142 DXGetErrorString8(rc));
144 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
145 DSSPEAKER_GEOMETRY_WIDE);
146 rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config);
147 ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %s\n",
148 DXGetErrorString8(rc));
150 rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config);
151 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n",
152 DXGetErrorString8(rc));
154 ok(speaker_config==new_speaker_config,
155 "IDirectSound8_GetSpeakerConfig() failed to set speaker config: "
156 "expected 0x%08lx, got 0x%08lx\n",
157 speaker_config,new_speaker_config);
160 rc=IDirectSound8_VerifyCertification(dso, &certified);
161 ok(rc==DS_OK,"IDirectSound8_VerifyCertification() failed: %s\n",
162 DXGetErrorString8(rc));
164 ref=IDirectSound8_Release(dso);
165 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
168 static void IDirectSound8_tests()
171 LPDIRECTSOUND8 dso=NULL;
173 trace("Testing IDirectSound8\n");
175 /* try the COM class factory method of creation with no device specified */
176 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
177 &IID_IDirectSound8, (void**)&dso);
178 ok(rc==S_OK,"CoCreateInstance failed: %s\n",DXGetErrorString8(rc));
180 IDirectSound8_test(dso, FALSE, NULL);
182 /* try the COM class factory method of creation with default playback
183 * device specified */
184 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
185 &IID_IDirectSound8, (void**)&dso);
186 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n",
187 DXGetErrorString8(rc));
189 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultPlayback);
191 /* try the COM class factory method of creation with default voice
192 * playback device specified */
193 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
194 &IID_IDirectSound8, (void**)&dso);
195 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n",
196 DXGetErrorString8(rc));
198 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
200 /* try the COM class factory method of creation with a bad
202 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
203 &CLSID_DirectSoundPrivate, (void**)&dso);
204 ok(rc==E_NOINTERFACE,
205 "CoCreateInstance(CLSID_DirectSound8,CLSID_DirectSoundPrivate) "
206 "should have failed: %s\n",DXGetErrorString8(rc));
208 /* try the COM class factory method of creation with a bad
209 * GUID and IID specified */
210 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
211 &IID_IDirectSound8, (void**)&dso);
212 ok(rc==REGDB_E_CLASSNOTREG,
213 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound8) "
214 "should have failed: %s\n",DXGetErrorString8(rc));
216 /* try with no device specified */
217 rc=DirectSoundCreate8(NULL,&dso,NULL);
218 ok(rc==S_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
220 IDirectSound8_test(dso, TRUE, NULL);
222 /* try with default playback device specified */
223 rc=DirectSoundCreate8(&DSDEVID_DefaultPlayback,&dso,NULL);
224 ok(rc==S_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
226 IDirectSound8_test(dso, TRUE, NULL);
228 /* try with default voice playback device specified */
229 rc=DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
230 ok(rc==S_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
232 IDirectSound8_test(dso, TRUE, NULL);
234 /* try with a bad device specified */
235 rc=DirectSoundCreate8(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
236 ok(rc==DSERR_NODRIVER,"DirectSoundCreate8(DSDEVID_DefaultVoiceCapture) "
237 "should have failed: %s\n",DXGetErrorString8(rc));
240 static HRESULT test_dsound8(LPGUID lpGuid)
243 LPDIRECTSOUND8 dso=NULL;
246 /* DSOUND: Error: Invalid interface buffer */
247 rc=DirectSoundCreate8(lpGuid,0,NULL);
248 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8 should have failed: %s\n",
249 DXGetErrorString8(rc));
251 /* Create the DirectSound8 object */
252 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
253 ok(rc==DS_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
257 /* Try the enumerated device */
258 IDirectSound8_test(dso, TRUE, lpGuid);
260 /* Try the COM class factory method of creation with enumerated device */
261 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
262 &IID_IDirectSound8, (void**)&dso);
263 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
264 DXGetErrorString8(rc));
266 IDirectSound8_test(dso, FALSE, lpGuid);
268 /* Create a DirectSound8 object */
269 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
270 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
272 LPDIRECTSOUND8 dso1=NULL;
274 /* Create a second DirectSound8 object */
275 rc=DirectSoundCreate8(lpGuid,&dso1,NULL);
276 ok(rc==DS_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
278 /* Release the second DirectSound8 object */
279 ref=IDirectSound8_Release(dso1);
280 ok(ref==0,"IDirectSound8_Release has %d references, "
281 "should have 0\n",ref);
282 ok(dso!=dso1,"DirectSound8 objects should be unique: "
283 "dso=0x%08lx,dso1=0x%08lx\n",(DWORD)dso,(DWORD)dso1);
286 /* Release the first DirectSound8 object */
287 ref=IDirectSound8_Release(dso);
288 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",
291 return DSERR_GENERIC;
295 /* Create a DirectSound8 object */
296 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
297 ok(rc==DS_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
299 LPDIRECTSOUNDBUFFER secondary;
300 DSBUFFERDESC bufdesc;
303 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
304 ZeroMemory(&bufdesc, sizeof(bufdesc));
305 bufdesc.dwSize=sizeof(bufdesc);
306 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
307 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
308 bufdesc.lpwfxFormat=&wfx;
309 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
310 ok(rc==DS_OK && secondary!=NULL,
311 "IDirectSound8_CreateSoundBuffer failed to create a secondary "
312 "buffer %s\n",DXGetErrorString8(rc));
313 if (rc==DS_OK && secondary!=NULL) {
314 LPDIRECTSOUND3DBUFFER buffer3d;
315 LPDIRECTSOUNDBUFFER8 buffer8;
316 rc=IDirectSound8_QueryInterface(secondary,
317 &IID_IDirectSound3DBuffer,
319 ok(rc==DS_OK && buffer3d!=NULL,
320 "IDirectSound8_QueryInterface failed: %s\n",
321 DXGetErrorString8(rc));
322 if (rc==DS_OK && buffer3d!=NULL) {
323 ref=IDirectSound3DBuffer_AddRef(buffer3d);
324 ok(ref==2,"IDirectSound3DBuffer_AddRef has %d references, "
325 "should have 2\n",ref);
327 rc=IDirectSound8_QueryInterface(secondary,
328 &IID_IDirectSoundBuffer8,
330 if (rc==DS_OK && buffer8!=NULL) {
331 ref=IDirectSoundBuffer8_AddRef(buffer8);
332 ok(ref==3,"IDirectSoundBuffer8_AddRef has %d references, "
333 "should have 3\n",ref);
335 ref=IDirectSoundBuffer_AddRef(secondary);
336 ok(ref==4,"IDirectSoundBuffer_AddRef has %d references, "
337 "should have 4\n",ref);
339 /* release with buffer */
340 ref=IDirectSound8_Release(dso);
341 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",
344 return DSERR_GENERIC;
351 static HRESULT test_primary8(LPGUID lpGuid)
354 LPDIRECTSOUND8 dso=NULL;
355 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
356 DSBUFFERDESC bufdesc;
360 /* Create the DirectSound object */
361 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
362 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
366 /* Get the device capabilities */
367 ZeroMemory(&dscaps, sizeof(dscaps));
368 dscaps.dwSize=sizeof(dscaps);
369 rc=IDirectSound8_GetCaps(dso,&dscaps);
370 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
374 /* DSOUND: Error: Invalid buffer description pointer */
375 rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL);
376 ok(rc==DSERR_INVALIDPARAM,
377 "IDirectSound8_CreateSoundBuffer should have failed: %s\n",
378 DXGetErrorString8(rc));
380 /* DSOUND: Error: Invalid buffer description pointer */
381 rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL);
382 ok(rc==DSERR_INVALIDPARAM && primary==0,
383 "IDirectSound8_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
384 DXGetErrorString8(rc),(DWORD)primary);
386 /* DSOUND: Error: Invalid buffer description pointer */
387 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL);
388 ok(rc==DSERR_INVALIDPARAM && primary==0,
389 "IDirectSound8_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
390 DXGetErrorString8(rc),(DWORD)primary);
392 ZeroMemory(&bufdesc, sizeof(bufdesc));
394 /* DSOUND: Error: Invalid size */
395 /* DSOUND: Error: Invalid buffer description */
396 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
397 ok(rc==DSERR_INVALIDPARAM && primary==0,
398 "IDirectSound8_CreateSoundBuffer should have failed: rc=%s,"
399 "primary=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
401 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
402 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
403 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
404 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
405 DXGetErrorString8(rc));
409 /* Testing the primary buffer */
411 ZeroMemory(&bufdesc, sizeof(bufdesc));
412 bufdesc.dwSize=sizeof(bufdesc);
413 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
414 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
415 ok(rc==DS_OK && primary!=NULL,
416 "IDirectSound8_CreateSoundBuffer failed to create a primary buffer: "
417 "%s\n",DXGetErrorString8(rc));
418 if (rc==DS_OK && primary!=NULL) {
421 /* Try to create a second primary buffer */
422 /* DSOUND: Error: The primary buffer already exists.
423 * Any changes made to the buffer description will be ignored. */
424 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
425 ok(rc==DS_OK && second==primary,
426 "IDirectSound8_CreateSoundBuffer should have returned original "
427 "primary buffer: %s\n",DXGetErrorString8(rc));
428 ref=IDirectSoundBuffer_Release(second);
429 ok(ref==1,"IDirectSoundBuffer_Release primary has %d references, "
430 "should have 1\n",ref);
432 /* Try to duplicate a primary buffer */
433 /* DSOUND: Error: Can't duplicate primary buffers */
434 rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third);
436 ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer primary buffer should "
437 "have failed %s\n",DXGetErrorString8(rc));
439 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
440 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume failed: %s\n",
441 DXGetErrorString8(rc));
443 if (winetest_interactive) {
444 trace("Playing a 5 seconds reference tone at the current volume.\n");
446 trace("(the current volume is %ld according to DirectSound)\n",
448 trace("All subsequent tones should be identical to this one.\n");
449 trace("Listen for stutter, changes in pitch, volume, etc.\n");
451 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive &&
452 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);
454 ref=IDirectSoundBuffer_Release(primary);
455 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
456 "should have 0\n",ref);
459 /* Set the CooperativeLevel back to normal */
460 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
461 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
462 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
463 DXGetErrorString8(rc));
466 ref=IDirectSound8_Release(dso);
467 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
469 return DSERR_GENERIC;
475 * Test the primary buffer at different formats while keeping the
476 * secondary buffer at a constant format.
478 static HRESULT test_primary_secondary8(LPGUID lpGuid)
481 LPDIRECTSOUND8 dso=NULL;
482 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
483 DSBUFFERDESC bufdesc;
485 WAVEFORMATEX wfx, wfx2;
488 /* Create the DirectSound object */
489 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
490 ok(rc==DS_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
494 /* Get the device capabilities */
495 ZeroMemory(&dscaps, sizeof(dscaps));
496 dscaps.dwSize=sizeof(dscaps);
497 rc=IDirectSound8_GetCaps(dso,&dscaps);
498 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc));
502 /* We must call SetCooperativeLevel before creating primary buffer */
503 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
504 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
505 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
506 DXGetErrorString8(rc));
510 ZeroMemory(&bufdesc, sizeof(bufdesc));
511 bufdesc.dwSize=sizeof(bufdesc);
512 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
513 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
514 ok(rc==DS_OK && primary!=NULL,
515 "IDirectSound8_CreateSoundBuffer failed to create a primary buffer %s\n",
516 DXGetErrorString8(rc));
518 if (rc==DS_OK && primary!=NULL) {
519 for (f=0;f<NB_FORMATS;f++) {
520 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
521 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
522 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
523 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
524 DXGetErrorString8(rc));
528 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
531 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
532 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat failed: %s\n",
533 DXGetErrorString8(rc));
535 /* There is no garantee that SetFormat will actually change the
536 * format to what we asked for. It depends on what the soundcard
537 * supports. So we must re-query the format.
539 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
540 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat failed: %s\n",
541 DXGetErrorString8(rc));
543 (wfx.wFormatTag!=wfx2.wFormatTag ||
544 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
545 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
546 wfx.nChannels!=wfx2.nChannels)) {
547 trace("Requested primary format tag=0x%04x %ldx%dx%d "
548 "avg.B/s=%ld align=%d\n",
549 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
550 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
551 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
552 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
553 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
556 /* Set the CooperativeLevel back to normal */
557 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
558 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
559 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
560 DXGetErrorString8(rc));
562 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
565 ZeroMemory(&bufdesc, sizeof(bufdesc));
566 bufdesc.dwSize=sizeof(bufdesc);
567 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
568 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
569 bufdesc.lpwfxFormat=&wfx2;
570 trace(" Testing a primary buffer at %ldx%dx%d with a "
571 "secondary buffer at %ldx%dx%d\n",
572 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
573 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
574 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
575 ok(rc==DS_OK && secondary!=NULL,
576 "IDirectSound_CreateSoundBuffer failed to create a secondary "
577 "buffer %s\n",DXGetErrorString8(rc));
579 if (rc==DS_OK && secondary!=NULL) {
580 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,
581 winetest_interactive,1.0,0,NULL,0,0);
583 ref=IDirectSoundBuffer_Release(secondary);
584 ok(ref==0,"IDirectSoundBuffer_Release has %d references, "
585 "should have 0\n",ref);
589 ref=IDirectSoundBuffer_Release(primary);
590 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
591 "should have 0\n",ref);
594 /* Set the CooperativeLevel back to normal */
595 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
596 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
597 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
598 DXGetErrorString8(rc));
601 ref=IDirectSound8_Release(dso);
602 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
604 return DSERR_GENERIC;
609 static HRESULT test_secondary8(LPGUID lpGuid)
612 LPDIRECTSOUND8 dso=NULL;
613 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
614 DSBUFFERDESC bufdesc;
620 /* Create the DirectSound object */
621 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
622 ok(rc==DS_OK,"DirectSoundCreate8 failed: %s\n",DXGetErrorString8(rc));
626 /* Get the device capabilities */
627 ZeroMemory(&dscaps, sizeof(dscaps));
628 dscaps.dwSize=sizeof(dscaps);
629 rc=IDirectSound8_GetCaps(dso,&dscaps);
630 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc));
634 /* We must call SetCooperativeLevel before creating primary buffer */
635 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
636 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
637 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
638 DXGetErrorString8(rc));
642 ZeroMemory(&bufdesc, sizeof(bufdesc));
643 bufdesc.dwSize=sizeof(bufdesc);
644 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
645 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
646 ok(rc==DS_OK && primary!=NULL,
647 "IDirectSound8_CreateSoundBuffer failed to create a primary buffer %s\n",
648 DXGetErrorString8(rc));
650 if (rc==DS_OK && primary!=NULL) {
651 for (f=0;f<NB_FORMATS;f++) {
652 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
655 ZeroMemory(&bufdesc, sizeof(bufdesc));
656 bufdesc.dwSize=sizeof(bufdesc);
657 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
658 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
659 bufdesc.lpwfxFormat=&wfx;
660 trace(" Testing a secondary buffer at %ldx%dx%d\n",
661 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
662 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
663 ok(rc==DS_OK && secondary!=NULL,
664 "IDirectSound8_CreateSoundBuffer failed to create a secondary "
665 "buffer %s\n",DXGetErrorString8(rc));
667 if (rc==DS_OK && secondary!=NULL) {
668 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,
669 winetest_interactive,1.0,0,NULL,0,0);
671 ref=IDirectSoundBuffer_Release(secondary);
672 ok(ref==0,"IDirectSoundBuffer_Release has %d references, "
673 "should have 0\n",ref);
677 ref=IDirectSoundBuffer_Release(primary);
678 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
679 "should have 0\n",ref);
682 /* Set the CooperativeLevel back to normal */
683 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
684 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
685 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel failed: %s\n",
686 DXGetErrorString8(rc));
689 ref=IDirectSound8_Release(dso);
690 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
692 return DSERR_GENERIC;
697 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
698 LPCSTR lpcstrModule, LPVOID lpContext)
700 trace("*** Testing %s - %s\n",lpcstrDescription,lpcstrModule);
701 test_dsound8(lpGuid);
702 test_primary8(lpGuid);
703 test_primary_secondary8(lpGuid);
704 test_secondary8(lpGuid);
709 static void dsound8_tests()
712 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
713 ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
723 hDsound = LoadLibraryA("dsound.dll");
725 trace("dsound.dll not found\n");
729 pFunc = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
731 trace("dsound8 test skipped\n");
735 IDirectSound8_tests();