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 failed: %s\n",DXGetErrorString8(rc));
106 ZeroMemory(&dscaps, sizeof(dscaps));
108 /* DSOUND: Error: Invalid caps buffer */
109 rc=IDirectSound_GetCaps(dso,&dscaps);
110 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
111 "should have failed: %s\n",DXGetErrorString8(rc));
113 dscaps.dwSize=sizeof(dscaps);
115 /* DSOUND: Running on a certified driver */
116 rc=IDirectSound_GetCaps(dso,&dscaps);
117 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
119 rc=IDirectSound_Compact(dso);
120 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %s\n",
121 DXGetErrorString8(rc));
123 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
124 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
125 DXGetErrorString8(rc));
127 rc=IDirectSound_Compact(dso);
128 ok(rc==DS_OK,"IDirectSound_Compact() failed: %s\n",DXGetErrorString8(rc));
130 rc=IDirectSound_GetSpeakerConfig(dso,0);
131 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
132 "should have failed: %s\n",DXGetErrorString8(rc));
134 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
135 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
136 DXGetErrorString8(rc));
138 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
139 DSSPEAKER_GEOMETRY_WIDE);
140 rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
141 ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %s\n",
142 DXGetErrorString8(rc));
144 rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
145 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
146 DXGetErrorString8(rc));
148 ok(speaker_config==new_speaker_config,
149 "IDirectSound_GetSpeakerConfig() failed to set speaker config: "
150 "expected 0x%08lx, got 0x%08lx\n",
151 speaker_config,new_speaker_config);
154 ref=IDirectSound_Release(dso);
155 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
158 static void IDirectSound_tests()
161 LPDIRECTSOUND dso=NULL;
163 trace("Testing IDirectSound\n");
165 /* try the COM class factory method of creation with no device specified */
166 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
167 &IID_IDirectSound, (void**)&dso);
168 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
169 DXGetErrorString8(rc));
171 IDirectSound_test(dso, FALSE, NULL);
173 /* try the COM class factory method of creation with default playback
174 * device specified */
175 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
176 &IID_IDirectSound, (void**)&dso);
177 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
178 DXGetErrorString8(rc));
180 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
182 /* try the COM class factory method of creation with default voice
183 * playback device specified */
184 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
185 &IID_IDirectSound, (void**)&dso);
186 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
187 DXGetErrorString8(rc));
189 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
191 /* try the COM class factory method of creation with a bad
193 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
194 &CLSID_DirectSoundPrivate, (void**)&dso);
195 ok(rc==E_NOINTERFACE,
196 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
197 "should have failed: %s\n",DXGetErrorString8(rc));
199 /* try the COM class factory method of creation with a bad
200 * GUID and IID specified */
201 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
202 &IID_IDirectSound, (void**)&dso);
203 ok(rc==REGDB_E_CLASSNOTREG,
204 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
205 "should have failed: %s\n",DXGetErrorString8(rc));
207 /* try with no device specified */
208 rc=DirectSoundCreate(NULL,&dso,NULL);
209 ok(rc==S_OK,"DirectSoundCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
211 IDirectSound_test(dso, TRUE, NULL);
213 /* try with default playback device specified */
214 rc=DirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
215 ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %s\n",
216 DXGetErrorString8(rc));
218 IDirectSound_test(dso, TRUE, NULL);
220 /* try with default voice playback device specified */
221 rc=DirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
222 ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %s\n",
223 DXGetErrorString8(rc));
225 IDirectSound_test(dso, TRUE, NULL);
227 /* try with a bad device specified */
228 rc=DirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
229 ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
230 "should have failed: %s\n",DXGetErrorString8(rc));
233 static HRESULT test_dsound(LPGUID lpGuid)
236 LPDIRECTSOUND dso=NULL;
239 /* DSOUND: Error: Invalid interface buffer */
240 rc=DirectSoundCreate(lpGuid,0,NULL);
241 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate should have failed: %s\n",
242 DXGetErrorString8(rc));
244 /* Create the DirectSound object */
245 rc=DirectSoundCreate(lpGuid,&dso,NULL);
246 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
250 /* Try the enumerated device */
251 IDirectSound_test(dso, TRUE, lpGuid);
253 /* Try the COM class factory method of creation with enumerated device */
254 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
255 &IID_IDirectSound, (void**)&dso);
256 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
257 DXGetErrorString8(rc));
259 IDirectSound_test(dso, FALSE, lpGuid);
261 /* Create a DirectSound object */
262 rc=DirectSoundCreate(lpGuid,&dso,NULL);
263 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
265 LPDIRECTSOUND dso1=NULL;
267 /* Create a second DirectSound object */
268 rc=DirectSoundCreate(lpGuid,&dso1,NULL);
269 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
271 /* Release the second DirectSound object */
272 ref=IDirectSound_Release(dso1);
273 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
275 ok(dso!=dso1,"DirectSound objects should be unique: "
276 "dso=0x%08lx,dso1=0x%08lx\n",(DWORD)dso,(DWORD)dso1);
279 /* Release the first DirectSound object */
280 ref=IDirectSound_Release(dso);
281 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
284 return DSERR_GENERIC;
288 /* Create a DirectSound object */
289 rc=DirectSoundCreate(lpGuid,&dso,NULL);
290 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
292 LPDIRECTSOUNDBUFFER secondary;
293 DSBUFFERDESC bufdesc;
296 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
297 ZeroMemory(&bufdesc, sizeof(bufdesc));
298 bufdesc.dwSize=sizeof(bufdesc);
299 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
300 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
301 bufdesc.lpwfxFormat=&wfx;
302 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
303 ok(rc==DS_OK && secondary!=NULL,
304 "IDirectSound_CreateSoundBuffer failed to create a secondary buffer "
305 "%s\n",DXGetErrorString8(rc));
306 if (rc==DS_OK && secondary!=NULL) {
307 LPDIRECTSOUND3DBUFFER buffer3d;
308 rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
310 ok(rc==DS_OK && buffer3d!=NULL,"QueryInterface failed: %s\n",
311 DXGetErrorString8(rc));
312 if (rc==DS_OK && buffer3d!=NULL) {
313 ref=IDirectSound3DBuffer_AddRef(buffer3d);
314 ok(ref==2,"IDirectSound3DBuffer_AddRef has %d references, "
315 "should have 2\n",ref);
317 ref=IDirectSoundBuffer_AddRef(secondary);
318 ok(ref==2,"IDirectSoundBuffer_AddRef has %d references, "
319 "should have 2\n",ref);
321 /* release with buffer */
322 ref=IDirectSound_Release(dso);
323 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
326 return DSERR_GENERIC;
333 static HRESULT test_primary(LPGUID lpGuid)
336 LPDIRECTSOUND dso=NULL;
337 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
338 DSBUFFERDESC bufdesc;
342 /* Create the DirectSound object */
343 rc=DirectSoundCreate(lpGuid,&dso,NULL);
344 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
348 /* Get the device capabilities */
349 ZeroMemory(&dscaps, sizeof(dscaps));
350 dscaps.dwSize=sizeof(dscaps);
351 rc=IDirectSound_GetCaps(dso,&dscaps);
352 ok(rc==DS_OK,"IDirectSound_GetCaps failed: %s\n",DXGetErrorString8(rc));
356 /* DSOUND: Error: Invalid buffer description pointer */
357 rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
358 ok(rc==DSERR_INVALIDPARAM,
359 "IDirectSound_CreateSoundBuffer should have failed: %s\n",
360 DXGetErrorString8(rc));
362 /* DSOUND: Error: Invalid buffer description pointer */
363 rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
364 ok(rc==DSERR_INVALIDPARAM && primary==0,
365 "IDirectSound_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
366 DXGetErrorString8(rc),(DWORD)primary);
368 /* DSOUND: Error: Invalid buffer description pointer */
369 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,0,NULL);
370 ok(rc==DSERR_INVALIDPARAM && primary==0,
371 "IDirectSound_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
372 DXGetErrorString8(rc),(DWORD)primary);
374 ZeroMemory(&bufdesc, sizeof(bufdesc));
376 /* DSOUND: Error: Invalid size */
377 /* DSOUND: Error: Invalid buffer description */
378 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
379 ok(rc==DSERR_INVALIDPARAM && primary==0,
380 "IDirectSound_CreateSoundBuffer should have failed: rc=%s,"
381 "primary=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
383 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
384 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
385 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
386 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
387 DXGetErrorString8(rc));
391 /* Testing the primary buffer */
393 ZeroMemory(&bufdesc, sizeof(bufdesc));
394 bufdesc.dwSize=sizeof(bufdesc);
395 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
396 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
397 ok(rc==DS_OK && primary!=NULL,
398 "IDirectSound_CreateSoundBuffer failed to create a primary buffer: %s\n",
399 DXGetErrorString8(rc));
400 if (rc==DS_OK && primary!=NULL) {
403 /* Try to create a second primary buffer */
404 /* DSOUND: Error: The primary buffer already exists.
405 * Any changes made to the buffer description will be ignored. */
406 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
407 ok(rc==DS_OK && second==primary,
408 "IDirectSound_CreateSoundBuffer should have returned original "
409 "primary buffer: %s\n",DXGetErrorString8(rc));
410 ref=IDirectSoundBuffer_Release(second);
411 ok(ref==1,"IDirectSoundBuffer_Release primary has %d references, "
412 "should have 1\n",ref);
414 /* Try to duplicate a primary buffer */
415 /* DSOUND: Error: Can't duplicate primary buffers */
416 rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
418 ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer primary buffer should "
419 "have failed %s\n",DXGetErrorString8(rc));
421 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
422 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume failed: %s\n",
423 DXGetErrorString8(rc));
425 if (winetest_interactive) {
426 trace("Playing a 5 seconds reference tone at the current volume.\n");
428 trace("(the current volume is %ld according to DirectSound)\n",
430 trace("All subsequent tones should be identical to this one.\n");
431 trace("Listen for stutter, changes in pitch, volume, etc.\n");
433 test_buffer(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive &&
434 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);
436 ref=IDirectSoundBuffer_Release(primary);
437 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
438 "should have 0\n",ref);
441 /* Set the CooperativeLevel back to normal */
442 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
443 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
444 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
445 DXGetErrorString8(rc));
448 ref=IDirectSound_Release(dso);
449 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
451 return DSERR_GENERIC;
457 * Test the primary buffer at different formats while keeping the
458 * secondary buffer at a constant format.
460 static HRESULT test_primary_secondary(LPGUID lpGuid)
463 LPDIRECTSOUND dso=NULL;
464 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
465 DSBUFFERDESC bufdesc;
467 WAVEFORMATEX wfx, wfx2;
470 /* Create the DirectSound object */
471 rc=DirectSoundCreate(lpGuid,&dso,NULL);
472 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
476 /* Get the device capabilities */
477 ZeroMemory(&dscaps, sizeof(dscaps));
478 dscaps.dwSize=sizeof(dscaps);
479 rc=IDirectSound_GetCaps(dso,&dscaps);
480 ok(rc==DS_OK,"IDirectSound_GetCaps failed: %s\n",DXGetErrorString8(rc));
484 /* We must call SetCooperativeLevel before creating primary buffer */
485 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
486 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
487 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
488 DXGetErrorString8(rc));
492 ZeroMemory(&bufdesc, sizeof(bufdesc));
493 bufdesc.dwSize=sizeof(bufdesc);
494 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
495 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
496 ok(rc==DS_OK && primary!=NULL,
497 "IDirectSound_CreateSoundBuffer failed to create a primary buffer %s\n",
498 DXGetErrorString8(rc));
500 if (rc==DS_OK && primary!=NULL) {
501 for (f=0;f<NB_FORMATS;f++) {
502 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
503 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
504 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
505 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
509 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
512 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
513 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat failed: %s\n",
514 DXGetErrorString8(rc));
516 /* There is no garantee that SetFormat will actually change the
517 * format to what we asked for. It depends on what the soundcard
518 * supports. So we must re-query the format.
520 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
521 ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
523 (wfx.wFormatTag!=wfx2.wFormatTag ||
524 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
525 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
526 wfx.nChannels!=wfx2.nChannels)) {
527 trace("Requested primary format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
528 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
529 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
530 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
531 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
532 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
535 /* Set the CooperativeLevel back to normal */
536 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
537 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
538 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
540 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
543 ZeroMemory(&bufdesc, sizeof(bufdesc));
544 bufdesc.dwSize=sizeof(bufdesc);
545 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
546 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
547 bufdesc.lpwfxFormat=&wfx2;
548 trace(" Testing a primary buffer at %ldx%dx%d with a secondary buffer at %ldx%dx%d\n",
549 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
550 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
551 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
552 ok(rc==DS_OK && secondary!=NULL,
553 "IDirectSound_CreateSoundBuffer failed to create a secondary "
554 "buffer %s\n",DXGetErrorString8(rc));
556 if (rc==DS_OK && secondary!=NULL) {
557 test_buffer(dso,secondary,0,FALSE,0,FALSE,0,
558 winetest_interactive,1.0,0,NULL,0,0);
560 ref=IDirectSoundBuffer_Release(secondary);
561 ok(ref==0,"IDirectSoundBuffer_Release has %d references, "
562 "should have 0\n",ref);
566 ref=IDirectSoundBuffer_Release(primary);
567 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
568 "should have 0\n",ref);
571 /* Set the CooperativeLevel back to normal */
572 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
573 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
574 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
575 DXGetErrorString8(rc));
578 ref=IDirectSound_Release(dso);
579 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
581 return DSERR_GENERIC;
586 static HRESULT test_secondary(LPGUID lpGuid)
589 LPDIRECTSOUND dso=NULL;
590 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
591 DSBUFFERDESC bufdesc;
597 /* Create the DirectSound object */
598 rc=DirectSoundCreate(lpGuid,&dso,NULL);
599 ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
603 /* Get the device capabilities */
604 ZeroMemory(&dscaps, sizeof(dscaps));
605 dscaps.dwSize=sizeof(dscaps);
606 rc=IDirectSound_GetCaps(dso,&dscaps);
607 ok(rc==DS_OK,"IDirectSound_GetCaps failed: %s\n",DXGetErrorString8(rc));
611 /* We must call SetCooperativeLevel before creating primary buffer */
612 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
613 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
614 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
615 DXGetErrorString8(rc));
619 ZeroMemory(&bufdesc, sizeof(bufdesc));
620 bufdesc.dwSize=sizeof(bufdesc);
621 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
622 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
623 ok(rc==DS_OK && primary!=NULL,
624 "IDirectSound_CreateSoundBuffer failed to create a primary buffer %s\n",
625 DXGetErrorString8(rc));
627 if (rc==DS_OK && primary!=NULL) {
628 for (f=0;f<NB_FORMATS;f++) {
629 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
632 ZeroMemory(&bufdesc, sizeof(bufdesc));
633 bufdesc.dwSize=sizeof(bufdesc);
634 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
635 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
636 bufdesc.lpwfxFormat=&wfx;
637 trace(" Testing a secondary buffer at %ldx%dx%d\n",
638 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
639 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
640 ok(rc==DS_OK && secondary!=NULL,
641 "IDirectSound_CreateSoundBuffer failed to create a secondary "
642 "buffer %s\n",DXGetErrorString8(rc));
644 if (rc==DS_OK && secondary!=NULL) {
645 test_buffer(dso,secondary,0,FALSE,0,FALSE,0,
646 winetest_interactive,1.0,0,NULL,0,0);
648 ref=IDirectSoundBuffer_Release(secondary);
649 ok(ref==0,"IDirectSoundBuffer_Release has %d references, "
650 "should have 0\n",ref);
654 ref=IDirectSoundBuffer_Release(primary);
655 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
656 "should have 0\n",ref);
659 /* Set the CooperativeLevel back to normal */
660 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
661 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
662 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
663 DXGetErrorString8(rc));
666 ref=IDirectSound_Release(dso);
667 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
669 return DSERR_GENERIC;
674 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
675 LPCSTR lpcstrModule, LPVOID lpContext)
677 trace("*** Testing %s - %s\n",lpcstrDescription,lpcstrModule);
679 test_primary(lpGuid);
680 test_primary_secondary(lpGuid);
681 test_secondary(lpGuid);
686 static void dsound_tests()
689 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
690 ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
697 IDirectSound_tests();