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 IDirectSound_test(LPDIRECTSOUND dso, BOOL initialized,
53 DWORD speaker_config, new_speaker_config;
55 /* Try to Query for objects */
56 rc=IDirectSound_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
57 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",
58 DXGetErrorString8(rc));
60 IDirectSound_Release(unknown);
62 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
63 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",
64 DXGetErrorString8(rc));
66 IDirectSound_Release(ds);
68 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
69 ok(rc==E_NOINTERFACE,"IDirectSound_QueryInterface(IID_IDirectSound8) "
70 "should have failed: %s\n",DXGetErrorString8(rc));
72 IDirectSound8_Release(ds8);
74 if (initialized == FALSE) {
75 /* try unitialized object */
76 rc=IDirectSound_GetCaps(dso,0);
77 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps(NULL) "
78 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
79 DXGetErrorString8(rc));
81 rc=IDirectSound_GetCaps(dso,&dscaps);
82 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps() "
83 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
84 DXGetErrorString8(rc));
86 rc=IDirectSound_Compact(dso);
87 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_Compact() "
88 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
89 DXGetErrorString8(rc));
91 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
92 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetSpeakerConfig() "
93 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
94 DXGetErrorString8(rc));
96 rc=IDirectSound_Initialize(dso,lpGuid);
97 ok(rc==DS_OK,"IDirectSound_Initialize() failed: %s\n",
98 DXGetErrorString8(rc));
101 /* DSOUND: Error: Invalid caps buffer */
102 rc=IDirectSound_GetCaps(dso,0);
103 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps(NULL) "
104 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
105 DXGetErrorString8(rc));
107 ZeroMemory(&dscaps, sizeof(dscaps));
109 /* DSOUND: Error: Invalid caps buffer */
110 rc=IDirectSound_GetCaps(dso,&dscaps);
111 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
112 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
113 DXGetErrorString8(rc));
115 dscaps.dwSize=sizeof(dscaps);
117 /* DSOUND: Running on a certified driver */
118 rc=IDirectSound_GetCaps(dso,&dscaps);
119 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
121 rc=IDirectSound_Compact(dso);
122 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %s\n",
123 DXGetErrorString8(rc));
125 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
126 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
127 DXGetErrorString8(rc));
129 rc=IDirectSound_Compact(dso);
130 ok(rc==DS_OK,"IDirectSound_Compact() failed: %s\n",DXGetErrorString8(rc));
132 rc=IDirectSound_GetSpeakerConfig(dso,0);
133 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
134 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
135 DXGetErrorString8(rc));
137 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
138 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
139 DXGetErrorString8(rc));
141 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
142 DSSPEAKER_GEOMETRY_WIDE);
143 rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
144 ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %s\n",
145 DXGetErrorString8(rc));
147 rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
148 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
149 DXGetErrorString8(rc));
151 ok(speaker_config==new_speaker_config,
152 "IDirectSound_GetSpeakerConfig() failed to set speaker config: "
153 "expected 0x%08lx, got 0x%08lx\n",
154 speaker_config,new_speaker_config);
157 ref=IDirectSound_Release(dso);
158 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
161 static void IDirectSound_tests()
164 LPDIRECTSOUND dso=NULL;
166 trace("Testing IDirectSound\n");
168 /* try the COM class factory method of creation with no device specified */
169 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
170 &IID_IDirectSound, (void**)&dso);
171 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
172 DXGetErrorString8(rc));
174 IDirectSound_test(dso, FALSE, NULL);
176 /* try the COM class factory method of creation with default playback
177 * device specified */
178 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
179 &IID_IDirectSound, (void**)&dso);
180 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
181 DXGetErrorString8(rc));
183 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
185 /* try the COM class factory method of creation with default voice
186 * playback device specified */
187 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
188 &IID_IDirectSound, (void**)&dso);
189 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
190 DXGetErrorString8(rc));
192 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
194 /* try the COM class factory method of creation with a bad
196 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
197 &CLSID_DirectSoundPrivate, (void**)&dso);
198 ok(rc==E_NOINTERFACE,
199 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
200 "should have failed: %s\n",DXGetErrorString8(rc));
202 /* try the COM class factory method of creation with a bad
203 * GUID and IID specified */
204 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
205 &IID_IDirectSound, (void**)&dso);
206 ok(rc==REGDB_E_CLASSNOTREG,
207 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
208 "should have failed: %s\n",DXGetErrorString8(rc));
210 /* try with no device specified */
211 rc=DirectSoundCreate(NULL,&dso,NULL);
212 ok(rc==S_OK,"DirectSoundCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
214 IDirectSound_test(dso, TRUE, NULL);
216 /* try with default playback device specified */
217 rc=DirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
218 ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %s\n",
219 DXGetErrorString8(rc));
221 IDirectSound_test(dso, TRUE, NULL);
223 /* try with default voice playback device specified */
224 rc=DirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
225 ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %s\n",
226 DXGetErrorString8(rc));
228 IDirectSound_test(dso, TRUE, NULL);
230 /* try with a bad device specified */
231 rc=DirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
232 ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
233 "should have failed: %s\n",DXGetErrorString8(rc));
236 static HRESULT test_dsound(LPGUID lpGuid)
239 LPDIRECTSOUND dso=NULL;
242 /* DSOUND: Error: Invalid interface buffer */
243 rc=DirectSoundCreate(lpGuid,0,NULL);
244 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate() should have returned "
245 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
247 /* Create the DirectSound object */
248 rc=DirectSoundCreate(lpGuid,&dso,NULL);
249 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
253 /* Try the enumerated device */
254 IDirectSound_test(dso, TRUE, lpGuid);
256 /* Try the COM class factory method of creation with enumerated device */
257 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
258 &IID_IDirectSound, (void**)&dso);
259 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
260 DXGetErrorString8(rc));
262 IDirectSound_test(dso, FALSE, lpGuid);
264 /* Create a DirectSound object */
265 rc=DirectSoundCreate(lpGuid,&dso,NULL);
266 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
268 LPDIRECTSOUND dso1=NULL;
270 /* Create a second DirectSound object */
271 rc=DirectSoundCreate(lpGuid,&dso1,NULL);
272 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
274 /* Release the second DirectSound object */
275 ref=IDirectSound_Release(dso1);
276 ok(ref==0,"IDirectSound_Release() has %d references, should have "
278 ok(dso!=dso1,"DirectSound objects should be unique: "
279 "dso=0x%08lx,dso1=0x%08lx\n",(DWORD)dso,(DWORD)dso1);
282 /* Release the first DirectSound object */
283 ref=IDirectSound_Release(dso);
284 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
287 return DSERR_GENERIC;
291 /* Create a DirectSound object */
292 rc=DirectSoundCreate(lpGuid,&dso,NULL);
293 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
295 LPDIRECTSOUNDBUFFER secondary;
296 DSBUFFERDESC bufdesc;
299 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
300 ZeroMemory(&bufdesc, sizeof(bufdesc));
301 bufdesc.dwSize=sizeof(bufdesc);
302 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
303 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
304 bufdesc.lpwfxFormat=&wfx;
305 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
306 ok(rc==DS_OK && secondary!=NULL,
307 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
308 "buffer %s\n",DXGetErrorString8(rc));
309 if (rc==DS_OK && secondary!=NULL) {
310 LPDIRECTSOUND3DBUFFER buffer3d;
311 rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
313 ok(rc==DS_OK && buffer3d!=NULL,"IDirectSound_QueryInterface() "
314 "failed: %s\n",DXGetErrorString8(rc));
315 if (rc==DS_OK && buffer3d!=NULL) {
316 ref=IDirectSound3DBuffer_AddRef(buffer3d);
317 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
318 "should have 2\n",ref);
320 ref=IDirectSoundBuffer_AddRef(secondary);
321 ok(ref==2,"IDirectSoundBuffer_AddRef() has %d references, "
322 "should have 2\n",ref);
324 /* release with buffer */
325 ref=IDirectSound_Release(dso);
326 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
329 return DSERR_GENERIC;
336 static HRESULT test_primary(LPGUID lpGuid)
339 LPDIRECTSOUND dso=NULL;
340 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
341 DSBUFFERDESC bufdesc;
345 /* Create the DirectSound object */
346 rc=DirectSoundCreate(lpGuid,&dso,NULL);
347 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
351 /* Get the device capabilities */
352 ZeroMemory(&dscaps, sizeof(dscaps));
353 dscaps.dwSize=sizeof(dscaps);
354 rc=IDirectSound_GetCaps(dso,&dscaps);
355 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
359 /* DSOUND: Error: Invalid buffer description pointer */
360 rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
361 ok(rc==DSERR_INVALIDPARAM,
362 "IDirectSound_CreateSoundBuffer() should have failed: %s\n",
363 DXGetErrorString8(rc));
365 /* DSOUND: Error: Invalid buffer description pointer */
366 rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
367 ok(rc==DSERR_INVALIDPARAM && primary==0,
368 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
369 "dsbo=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
371 /* DSOUND: Error: Invalid buffer description pointer */
372 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,0,NULL);
373 ok(rc==DSERR_INVALIDPARAM && primary==0,
374 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
375 "dsbo=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
377 ZeroMemory(&bufdesc, sizeof(bufdesc));
379 /* DSOUND: Error: Invalid size */
380 /* DSOUND: Error: Invalid buffer description */
381 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
382 ok(rc==DSERR_INVALIDPARAM && primary==0,
383 "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"
384 "primary=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
386 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
387 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
388 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
389 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
390 DXGetErrorString8(rc));
394 /* Testing the primary buffer */
396 ZeroMemory(&bufdesc, sizeof(bufdesc));
397 bufdesc.dwSize=sizeof(bufdesc);
398 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
399 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
400 ok(rc==DS_OK && primary!=NULL,
401 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "
402 "%s\n",DXGetErrorString8(rc));
403 if (rc==DS_OK && primary!=NULL) {
406 /* Try to create a second primary buffer */
407 /* DSOUND: Error: The primary buffer already exists.
408 * Any changes made to the buffer description will be ignored. */
409 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
410 ok(rc==DS_OK && second==primary,
411 "IDirectSound_CreateSoundBuffer() should have returned original "
412 "primary buffer: %s\n",DXGetErrorString8(rc));
413 ref=IDirectSoundBuffer_Release(second);
414 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
415 "should have 1\n",ref);
417 /* Try to duplicate a primary buffer */
418 /* DSOUND: Error: Can't duplicate primary buffers */
419 rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
421 ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer() primary buffer "
422 "should have failed %s\n",DXGetErrorString8(rc));
424 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
425 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
426 DXGetErrorString8(rc));
428 if (winetest_interactive) {
429 trace("Playing a 5 seconds reference tone at the current volume.\n");
431 trace("(the current volume is %ld according to DirectSound)\n",
433 trace("All subsequent tones should be identical to this one.\n");
434 trace("Listen for stutter, changes in pitch, volume, etc.\n");
436 test_buffer(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive &&
437 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);
439 ref=IDirectSoundBuffer_Release(primary);
440 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
441 "should have 0\n",ref);
444 /* Set the CooperativeLevel back to normal */
445 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
446 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
447 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
448 DXGetErrorString8(rc));
451 ref=IDirectSound_Release(dso);
452 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
454 return DSERR_GENERIC;
460 * Test the primary buffer at different formats while keeping the
461 * secondary buffer at a constant format.
463 static HRESULT test_primary_secondary(LPGUID lpGuid)
466 LPDIRECTSOUND dso=NULL;
467 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
468 DSBUFFERDESC bufdesc;
470 WAVEFORMATEX wfx, wfx2;
473 /* Create the DirectSound object */
474 rc=DirectSoundCreate(lpGuid,&dso,NULL);
475 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
479 /* Get the device capabilities */
480 ZeroMemory(&dscaps, sizeof(dscaps));
481 dscaps.dwSize=sizeof(dscaps);
482 rc=IDirectSound_GetCaps(dso,&dscaps);
483 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
487 /* We must call SetCooperativeLevel before creating primary buffer */
488 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
489 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
490 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
491 DXGetErrorString8(rc));
495 ZeroMemory(&bufdesc, sizeof(bufdesc));
496 bufdesc.dwSize=sizeof(bufdesc);
497 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
498 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
499 ok(rc==DS_OK && primary!=NULL,
500 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
501 "%s\n",DXGetErrorString8(rc));
503 if (rc==DS_OK && primary!=NULL) {
504 for (f=0;f<NB_FORMATS;f++) {
505 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
506 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
507 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
508 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
509 DXGetErrorString8(rc));
513 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
516 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
517 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n",
518 DXGetErrorString8(rc));
520 /* There is no garantee that SetFormat will actually change the
521 * format to what we asked for. It depends on what the soundcard
522 * supports. So we must re-query the format.
524 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
525 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
526 DXGetErrorString8(rc));
528 (wfx.wFormatTag!=wfx2.wFormatTag ||
529 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
530 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
531 wfx.nChannels!=wfx2.nChannels)) {
532 trace("Requested primary format tag=0x%04x %ldx%dx%d "
533 "avg.B/s=%ld align=%d\n",
534 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
535 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
536 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
537 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
538 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
541 /* Set the CooperativeLevel back to normal */
542 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
543 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
544 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
545 DXGetErrorString8(rc));
547 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
550 ZeroMemory(&bufdesc, sizeof(bufdesc));
551 bufdesc.dwSize=sizeof(bufdesc);
552 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
553 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
554 bufdesc.lpwfxFormat=&wfx2;
555 if (winetest_interactive) {
556 trace(" Testing a primary buffer at %ldx%dx%d with a "
557 "secondary buffer at %ldx%dx%d\n",
558 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
559 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
561 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
562 ok(rc==DS_OK && secondary!=NULL,
563 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
564 "buffer %s\n",DXGetErrorString8(rc));
566 if (rc==DS_OK && secondary!=NULL) {
567 test_buffer(dso,secondary,0,FALSE,0,FALSE,0,
568 winetest_interactive,1.0,0,NULL,0,0);
570 ref=IDirectSoundBuffer_Release(secondary);
571 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
572 "should have 0\n",ref);
576 ref=IDirectSoundBuffer_Release(primary);
577 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
578 "should have 0\n",ref);
581 /* Set the CooperativeLevel back to normal */
582 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
583 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
584 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
585 DXGetErrorString8(rc));
588 ref=IDirectSound_Release(dso);
589 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
591 return DSERR_GENERIC;
596 static HRESULT test_secondary(LPGUID lpGuid)
599 LPDIRECTSOUND dso=NULL;
600 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
601 DSBUFFERDESC bufdesc;
607 /* Create the DirectSound object */
608 rc=DirectSoundCreate(lpGuid,&dso,NULL);
609 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
613 /* Get the device capabilities */
614 ZeroMemory(&dscaps, sizeof(dscaps));
615 dscaps.dwSize=sizeof(dscaps);
616 rc=IDirectSound_GetCaps(dso,&dscaps);
617 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
621 /* We must call SetCooperativeLevel before creating primary buffer */
622 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
623 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
624 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
625 DXGetErrorString8(rc));
629 ZeroMemory(&bufdesc, sizeof(bufdesc));
630 bufdesc.dwSize=sizeof(bufdesc);
631 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
632 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
633 ok(rc==DS_OK && primary!=NULL,
634 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "
635 "%s\n",DXGetErrorString8(rc));
637 if (rc==DS_OK && primary!=NULL) {
638 for (f=0;f<NB_FORMATS;f++) {
639 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
642 ZeroMemory(&bufdesc, sizeof(bufdesc));
643 bufdesc.dwSize=sizeof(bufdesc);
644 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
645 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
646 bufdesc.lpwfxFormat=&wfx;
647 if (winetest_interactive) {
648 trace(" Testing a secondary buffer at %ldx%dx%d\n",
649 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
651 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
652 ok(rc==DS_OK && secondary!=NULL,
653 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
654 "buffer %s\n",DXGetErrorString8(rc));
656 if (rc==DS_OK && secondary!=NULL) {
657 test_buffer(dso,secondary,0,FALSE,0,FALSE,0,
658 winetest_interactive,1.0,0,NULL,0,0);
660 ref=IDirectSoundBuffer_Release(secondary);
661 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
662 "should have 0\n",ref);
666 ref=IDirectSoundBuffer_Release(primary);
667 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
668 "should have 0\n",ref);
671 /* Set the CooperativeLevel back to normal */
672 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
673 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
674 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
675 DXGetErrorString8(rc));
678 ref=IDirectSound_Release(dso);
679 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
681 return DSERR_GENERIC;
686 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
687 LPCSTR lpcstrModule, LPVOID lpContext)
689 trace("*** Testing %s - %s\n",lpcstrDescription,lpcstrModule);
691 test_primary(lpGuid);
692 test_primary_secondary(lpGuid);
693 test_secondary(lpGuid);
698 static void dsound_tests()
701 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
702 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
709 IDirectSound_tests();