TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / dsound / tests / dsound.c
blob78364ede7b6d811fe8adb84abda9acb350acbd6f
1 /*
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
12 * Copyright (c) 2007 Maarten Lankhorst
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include <windows.h>
31 #include "wine/test.h"
32 #include "mmsystem.h"
33 #include "dsound.h"
34 #include "dsconf.h"
35 #include "initguid.h"
36 #include "ks.h"
37 #include "ksmedia.h"
39 #include "dsound_test.h"
41 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
43 static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
44 static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID,LPDIRECTSOUND*,
45 LPUNKNOWN)=NULL;
47 static BOOL gotdx8;
49 static void IDirectSound_test(LPDIRECTSOUND dso, BOOL initialized,
50 LPCGUID lpGuid)
52 HRESULT rc;
53 DSCAPS dscaps;
54 int ref;
55 IUnknown * unknown;
56 IDirectSound * ds;
57 IDirectSound8 * ds8;
58 DWORD speaker_config, new_speaker_config, ref_speaker_config;
60 /* Try to Query for objects */
61 rc=IDirectSound_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
62 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
63 if (rc==DS_OK)
64 IDirectSound_Release(unknown);
66 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
67 ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %08x\n", rc);
68 if (rc==DS_OK)
69 IDirectSound_Release(ds);
71 rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
72 ok(rc==E_NOINTERFACE,"IDirectSound_QueryInterface(IID_IDirectSound8) "
73 "should have failed: %08x\n",rc);
74 if (rc==DS_OK)
75 IDirectSound8_Release(ds8);
77 if (initialized == FALSE) {
78 /* try uninitialized object */
79 rc=IDirectSound_GetCaps(dso,0);
80 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps(NULL) "
81 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
83 rc=IDirectSound_GetCaps(dso,&dscaps);
84 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps() "
85 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
87 rc=IDirectSound_Compact(dso);
88 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_Compact() "
89 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
91 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
92 ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetSpeakerConfig() "
93 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
95 rc=IDirectSound_Initialize(dso,lpGuid);
96 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
97 "IDirectSound_Initialize() failed: %08x\n",rc);
98 if (rc==DSERR_NODRIVER) {
99 trace(" No Driver\n");
100 goto EXIT;
101 } else if (rc==E_FAIL) {
102 trace(" No Device\n");
103 goto EXIT;
104 } else if (rc==DSERR_ALLOCATED) {
105 trace(" Already In Use\n");
106 goto EXIT;
110 rc=IDirectSound_Initialize(dso,lpGuid);
111 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound_Initialize() "
112 "should have returned DSERR_ALREADYINITIALIZED: %08x\n", rc);
114 /* DSOUND: Error: Invalid caps buffer */
115 rc=IDirectSound_GetCaps(dso,0);
116 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps(NULL) "
117 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
119 ZeroMemory(&dscaps, sizeof(dscaps));
121 /* DSOUND: Error: Invalid caps buffer */
122 rc=IDirectSound_GetCaps(dso,&dscaps);
123 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
124 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
126 dscaps.dwSize=sizeof(dscaps);
128 /* DSOUND: Running on a certified driver */
129 rc=IDirectSound_GetCaps(dso,&dscaps);
130 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
132 rc=IDirectSound_Compact(dso);
133 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %08x\n", rc);
135 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
136 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
138 rc=IDirectSound_Compact(dso);
139 ok(rc==DS_OK,"IDirectSound_Compact() failed: %08x\n",rc);
141 rc=IDirectSound_GetSpeakerConfig(dso,0);
142 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
143 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
145 rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
146 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %08x\n", rc);
147 ref_speaker_config = speaker_config;
149 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
150 DSSPEAKER_GEOMETRY_WIDE);
151 if (speaker_config == ref_speaker_config)
152 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
153 DSSPEAKER_GEOMETRY_NARROW);
154 if(rc==DS_OK) {
155 rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
156 ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %08x\n", rc);
158 if (rc==DS_OK) {
159 rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
160 ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %08x\n", rc);
161 if (rc==DS_OK && speaker_config!=new_speaker_config && ref_speaker_config!=new_speaker_config)
162 trace("IDirectSound_GetSpeakerConfig() failed to set speaker "
163 "config: expected 0x%08x or 0x%08x, got 0x%08x\n",
164 speaker_config,ref_speaker_config,new_speaker_config);
165 IDirectSound_SetSpeakerConfig(dso,ref_speaker_config);
168 EXIT:
169 ref=IDirectSound_Release(dso);
170 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
173 static void IDirectSound_tests(void)
175 HRESULT rc;
176 IDirectSound *dso=(IDirectSound*)0xdeadbeef;
177 LPCLASSFACTORY cf=NULL;
179 trace("Testing IDirectSound\n");
181 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
182 &IID_IClassFactory, (void**)&cf);
183 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
184 "failed: %08x\n", rc);
186 rc=CoGetClassObject(&CLSID_DirectSound, CLSCTX_INPROC_SERVER, NULL,
187 &IID_IUnknown, (void**)&cf);
188 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound, IID_IUnknown) "
189 "failed: %08x\n", rc);
191 /* COM aggregation */
192 rc=CoCreateInstance(&CLSID_DirectSound, (IUnknown*)&dso, CLSCTX_INPROC_SERVER,
193 &IID_IDirectSound, (void**)&dso);
194 ok(rc==CLASS_E_NOAGGREGATION || broken(rc==DSERR_INVALIDPARAM),
195 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", rc);
197 /* try the COM class factory method of creation with no device specified */
198 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
199 &IID_IDirectSound, (void**)&dso);
200 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc);
201 if (dso)
202 IDirectSound_test(dso, FALSE, NULL);
204 /* try the COM class factory method of creation with default playback
205 * device specified */
206 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
207 &IID_IDirectSound, (void**)&dso);
208 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc);
209 if (dso)
210 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
212 /* try the COM class factory method of creation with default voice
213 * playback device specified */
214 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
215 &IID_IDirectSound, (void**)&dso);
216 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc);
217 if (dso)
218 IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
220 /* try the COM class factory method of creation with a bad
221 * IID specified */
222 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
223 &CLSID_DirectSoundPrivate, (void**)&dso);
224 ok(rc==E_NOINTERFACE,
225 "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
226 "should have failed: %08x\n",rc);
228 /* try the COM class factory method of creation with a bad
229 * GUID and IID specified */
230 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
231 &IID_IDirectSound, (void**)&dso);
232 ok(rc==REGDB_E_CLASSNOTREG,
233 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
234 "should have failed: %08x\n",rc);
236 /* try with no device specified */
237 rc=pDirectSoundCreate(NULL,&dso,NULL);
238 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
239 "DirectSoundCreate(NULL) failed: %08x\n",rc);
240 if (rc==S_OK && dso)
241 IDirectSound_test(dso, TRUE, NULL);
243 /* try with default playback device specified */
244 rc=pDirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
245 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
246 "DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %08x\n", rc);
247 if (rc==DS_OK && dso)
248 IDirectSound_test(dso, TRUE, NULL);
250 /* try with default voice playback device specified */
251 rc=pDirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
252 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
253 "DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc);
254 if (rc==DS_OK && dso)
255 IDirectSound_test(dso, TRUE, NULL);
257 /* try with a bad device specified */
258 rc=pDirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
259 ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
260 "should have failed: %08x\n",rc);
261 if (rc==DS_OK && dso)
262 IDirectSound_Release(dso);
265 static HRESULT test_dsound(LPGUID lpGuid)
267 HRESULT rc;
268 LPDIRECTSOUND dso=NULL;
269 int ref;
271 /* DSOUND: Error: Invalid interface buffer */
272 rc=pDirectSoundCreate(lpGuid,0,NULL);
273 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate() should have returned "
274 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
276 /* Create the DirectSound object */
277 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
278 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
279 "DirectSoundCreate() failed: %08x\n",rc);
280 if (rc!=DS_OK)
281 return rc;
283 /* Try the enumerated device */
284 IDirectSound_test(dso, TRUE, lpGuid);
286 /* Try the COM class factory method of creation with enumerated device */
287 rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
288 &IID_IDirectSound, (void**)&dso);
289 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc);
290 if (dso)
291 IDirectSound_test(dso, FALSE, lpGuid);
293 /* Create a DirectSound object */
294 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
295 ok(rc==DS_OK,"DirectSoundCreate() failed: %08x\n",rc);
296 if (rc==DS_OK) {
297 LPDIRECTSOUND dso1=NULL;
299 /* Create a second DirectSound object */
300 rc=pDirectSoundCreate(lpGuid,&dso1,NULL);
301 ok(rc==DS_OK,"DirectSoundCreate() failed: %08x\n",rc);
302 if (rc==DS_OK) {
303 /* Release the second DirectSound object */
304 ref=IDirectSound_Release(dso1);
305 ok(ref==0,"IDirectSound_Release() has %d references, should have "
306 "0\n",ref);
307 ok(dso!=dso1,"DirectSound objects should be unique: dso=%p,dso1=%p\n",dso,dso1);
310 /* Release the first DirectSound object */
311 ref=IDirectSound_Release(dso);
312 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
313 ref);
314 if (ref!=0)
315 return DSERR_GENERIC;
316 } else
317 return rc;
319 /* Create a DirectSound object */
320 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
321 ok(rc==DS_OK,"DirectSoundCreate() failed: %08x\n",rc);
322 if (rc==DS_OK) {
323 LPDIRECTSOUNDBUFFER secondary;
324 DSBUFFERDESC bufdesc;
325 WAVEFORMATEX wfx;
327 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
328 ZeroMemory(&bufdesc, sizeof(bufdesc));
329 bufdesc.dwSize=sizeof(bufdesc);
330 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
331 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
332 wfx.nBlockAlign);
333 bufdesc.lpwfxFormat=&wfx;
334 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
335 ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
336 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
337 "buffer %08x\n",rc);
338 if (rc==DS_OK && secondary!=NULL) {
339 LPDIRECTSOUND3DBUFFER buffer3d;
340 rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
341 (void **)&buffer3d);
342 ok(rc==DS_OK && buffer3d!=NULL,"IDirectSound_QueryInterface() "
343 "failed: %08x\n",rc);
344 if (rc==DS_OK && buffer3d!=NULL) {
345 ref=IDirectSound3DBuffer_AddRef(buffer3d);
346 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
347 "should have 2\n",ref);
349 ref=IDirectSoundBuffer_AddRef(secondary);
350 ok(ref==2,"IDirectSoundBuffer_AddRef() has %d references, "
351 "should have 2\n",ref);
353 /* release with buffer */
354 ref=IDirectSound_Release(dso);
355 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
356 ref);
357 if (ref!=0)
358 return DSERR_GENERIC;
359 } else
360 return rc;
362 return DS_OK;
365 static HRESULT test_primary(LPGUID lpGuid)
367 HRESULT rc;
368 LPDIRECTSOUND dso=NULL;
369 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
370 DSBUFFERDESC bufdesc;
371 DSCAPS dscaps;
372 WAVEFORMATEX wfx;
373 int ref;
375 /* Create the DirectSound object */
376 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
377 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
378 "DirectSoundCreate() failed: %08x\n",rc);
379 if (rc!=DS_OK)
380 return rc;
382 /* Get the device capabilities */
383 ZeroMemory(&dscaps, sizeof(dscaps));
384 dscaps.dwSize=sizeof(dscaps);
385 rc=IDirectSound_GetCaps(dso,&dscaps);
386 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
387 if (rc!=DS_OK)
388 goto EXIT;
390 /* DSOUND: Error: Invalid buffer description pointer */
391 rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
392 ok(rc==DSERR_INVALIDPARAM,
393 "IDirectSound_CreateSoundBuffer() should have failed: %08x\n", rc);
395 /* DSOUND: Error: NULL pointer is invalid */
396 /* DSOUND: Error: Invalid buffer description pointer */
397 rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
398 ok(rc==DSERR_INVALIDPARAM && primary==0,
399 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
400 "dsbo=%p\n",rc,primary);
402 /* DSOUND: Error: Invalid size */
403 /* DSOUND: Error: Invalid buffer description */
404 primary=NULL;
405 ZeroMemory(&bufdesc, sizeof(bufdesc));
406 bufdesc.dwSize=sizeof(bufdesc)-1;
407 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
408 ok(rc==DSERR_INVALIDPARAM && primary==0,
409 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
410 "primary=%p\n",rc,primary);
412 /* DSOUND: Error: DSBCAPS_PRIMARYBUFFER flag with non-NULL lpwfxFormat */
413 /* DSOUND: Error: Invalid buffer description pointer */
414 primary=NULL;
415 ZeroMemory(&bufdesc, sizeof(bufdesc));
416 bufdesc.dwSize=sizeof(bufdesc);
417 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
418 bufdesc.lpwfxFormat=&wfx;
419 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
420 ok(rc==DSERR_INVALIDPARAM && primary==0,
421 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
422 "primary=%p\n",rc,primary);
424 /* DSOUND: Error: No DSBCAPS_PRIMARYBUFFER flag with NULL lpwfxFormat */
425 /* DSOUND: Error: Invalid buffer description pointer */
426 primary=NULL;
427 ZeroMemory(&bufdesc, sizeof(bufdesc));
428 bufdesc.dwSize=sizeof(bufdesc);
429 bufdesc.dwFlags=0;
430 bufdesc.lpwfxFormat=NULL;
431 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
432 ok(rc==DSERR_INVALIDPARAM && primary==0,
433 "IDirectSound_CreateSoundBuffer() should have failed: rc=%08x,"
434 "primary=%p\n",rc,primary);
436 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
437 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
438 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
439 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
440 if (rc!=DS_OK)
441 goto EXIT;
443 /* Testing the primary buffer */
444 primary=NULL;
445 ZeroMemory(&bufdesc, sizeof(bufdesc));
446 bufdesc.dwSize=sizeof(bufdesc);
447 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
448 bufdesc.lpwfxFormat = &wfx;
449 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
450 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
451 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() should have "
452 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
453 if (rc==DS_OK && primary!=NULL)
454 IDirectSoundBuffer_Release(primary);
456 primary=NULL;
457 ZeroMemory(&bufdesc, sizeof(bufdesc));
458 bufdesc.dwSize=sizeof(bufdesc);
459 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
460 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
461 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
462 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc);
463 if (rc==DSERR_CONTROLUNAVAIL)
464 trace(" No Primary\n");
465 else if (rc==DS_OK && primary!=NULL) {
466 LONG vol;
468 /* Try to create a second primary buffer */
469 /* DSOUND: Error: The primary buffer already exists.
470 * Any changes made to the buffer description will be ignored. */
471 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
472 ok(rc==DS_OK && second==primary,
473 "IDirectSound_CreateSoundBuffer() should have returned original "
474 "primary buffer: %08x\n",rc);
475 ref=IDirectSoundBuffer_Release(second);
476 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
477 "should have 1\n",ref);
479 /* Try to duplicate a primary buffer */
480 /* DSOUND: Error: Can't duplicate primary buffers */
481 rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
482 /* rc=0x88780032 */
483 ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer() primary buffer "
484 "should have failed %08x\n",rc);
486 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
487 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc);
489 if (winetest_interactive) {
490 trace("Playing a 5 seconds reference tone at the current "
491 "volume.\n");
492 if (rc==DS_OK)
493 trace("(the current volume is %d according to DirectSound)\n",
494 vol);
495 trace("All subsequent tones should be identical to this one.\n");
496 trace("Listen for stutter, changes in pitch, volume, etc.\n");
498 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
499 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0,FALSE,0);
501 ref=IDirectSoundBuffer_Release(primary);
502 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references\n",ref);
504 ref=IDirectSoundBuffer_AddRef(primary);
505 ok(ref==1,"IDirectSoundBuffer_AddRef() primary has %d references\n",ref);
507 ref=IDirectSoundBuffer_Release(primary);
508 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references\n",ref);
510 ref=IDirectSoundBuffer_Release(primary);
511 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
512 "should have 0\n",ref);
515 /* Set the CooperativeLevel back to normal */
516 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
517 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
518 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
520 EXIT:
521 ref=IDirectSound_Release(dso);
522 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
523 if (ref!=0)
524 return DSERR_GENERIC;
526 return rc;
530 * Test the primary buffer at different formats while keeping the
531 * secondary buffer at a constant format.
533 static HRESULT test_primary_secondary(LPGUID lpGuid)
535 HRESULT rc;
536 LPDIRECTSOUND dso=NULL;
537 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
538 DSBUFFERDESC bufdesc;
539 DSCAPS dscaps;
540 WAVEFORMATEX wfx, wfx2;
541 int f,ref,tag;
543 /* Create the DirectSound object */
544 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
545 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
546 "DirectSoundCreate() failed: %08x\n",rc);
547 if (rc!=DS_OK)
548 return rc;
550 /* Get the device capabilities */
551 ZeroMemory(&dscaps, sizeof(dscaps));
552 dscaps.dwSize=sizeof(dscaps);
553 rc=IDirectSound_GetCaps(dso,&dscaps);
554 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
555 if (rc!=DS_OK)
556 goto EXIT;
558 /* We must call SetCooperativeLevel before creating primary buffer */
559 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
560 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
561 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
562 if (rc!=DS_OK)
563 goto EXIT;
565 ZeroMemory(&bufdesc, sizeof(bufdesc));
566 bufdesc.dwSize=sizeof(bufdesc);
567 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
568 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
569 ok(rc==DS_OK && primary!=NULL,
570 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc);
572 if (rc==DS_OK && primary!=NULL) {
573 for (f=0;f<NB_FORMATS;f++) {
574 for (tag=0;tag<NB_TAGS;tag++) {
575 /* if float, we only want to test 32-bit */
576 if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
577 continue;
579 /* We must call SetCooperativeLevel to be allowed to call
580 * SetFormat */
581 /* DSOUND: Setting DirectSound cooperative level to
582 * DSSCL_PRIORITY */
583 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
584 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
585 if (rc!=DS_OK)
586 goto EXIT;
588 init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
589 formats[f][2]);
590 wfx2=wfx;
591 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
593 if (wfx.wBitsPerSample <= 16)
594 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
595 format_string(&wfx), rc);
596 else
597 ok(rc==DS_OK || rc == E_INVALIDARG, "SetFormat (%s) failed: %08x\n",
598 format_string(&wfx), rc);
600 /* There is no guarantee that SetFormat will actually change the
601 * format to what we asked for. It depends on what the soundcard
602 * supports. So we must re-query the format.
604 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
605 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
606 if (rc==DS_OK &&
607 (wfx.wFormatTag!=wfx2.wFormatTag ||
608 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
609 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
610 wfx.nChannels!=wfx2.nChannels)) {
611 trace("Requested primary format tag=0x%04x %dx%dx%d "
612 "avg.B/s=%d align=%d\n",
613 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
614 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
615 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
616 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
617 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
620 /* Set the CooperativeLevel back to normal */
621 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
622 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
623 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
625 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
627 secondary=NULL;
628 ZeroMemory(&bufdesc, sizeof(bufdesc));
629 bufdesc.dwSize=sizeof(bufdesc);
630 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
631 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
632 wfx.nBlockAlign);
633 bufdesc.lpwfxFormat=&wfx2;
634 if (winetest_interactive) {
635 trace(" Testing a primary buffer at %dx%dx%d (fmt=%d) with a "
636 "secondary buffer at %dx%dx%d\n",
637 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
638 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
640 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
641 ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
642 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",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,FALSE,0);
648 ref=IDirectSoundBuffer_Release(secondary);
649 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
650 "should have 0\n",ref);
655 ref=IDirectSoundBuffer_Release(primary);
656 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
657 "should have 0\n",ref);
660 /* Set the CooperativeLevel back to normal */
661 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
662 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
663 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
665 EXIT:
666 ref=IDirectSound_Release(dso);
667 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
668 if (ref!=0)
669 return DSERR_GENERIC;
671 return rc;
674 static HRESULT test_secondary(LPGUID lpGuid)
676 HRESULT rc;
677 LPDIRECTSOUND dso=NULL;
678 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
679 DSBUFFERDESC bufdesc;
680 DSCAPS dscaps;
681 WAVEFORMATEX wfx, wfx1;
682 DWORD f, tag;
683 int ref;
685 /* Create the DirectSound object */
686 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
687 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
688 "DirectSoundCreate() failed: %08x\n",rc);
689 if (rc!=DS_OK)
690 return rc;
692 /* Get the device capabilities */
693 ZeroMemory(&dscaps, sizeof(dscaps));
694 dscaps.dwSize=sizeof(dscaps);
695 rc=IDirectSound_GetCaps(dso,&dscaps);
696 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
697 if (rc!=DS_OK)
698 goto EXIT;
700 /* We must call SetCooperativeLevel before creating primary buffer */
701 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
702 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
703 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
704 if (rc!=DS_OK)
705 goto EXIT;
707 ZeroMemory(&bufdesc, sizeof(bufdesc));
708 bufdesc.dwSize=sizeof(bufdesc);
709 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
710 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
711 ok(rc==DS_OK && primary!=NULL,
712 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc);
714 if (rc==DS_OK && primary!=NULL) {
715 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
716 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
717 if (rc!=DS_OK)
718 goto EXIT1;
720 for (f=0;f<NB_FORMATS;f++) {
721 for (tag=0;tag<NB_TAGS;tag++) {
722 WAVEFORMATEXTENSIBLE wfxe;
724 /* if float, we only want to test 32-bit */
725 if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
726 continue;
728 init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
729 formats[f][2]);
730 secondary=NULL;
731 ZeroMemory(&bufdesc, sizeof(bufdesc));
732 bufdesc.dwSize=sizeof(bufdesc);
733 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
734 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
735 wfx.nBlockAlign);
736 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
737 ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() "
738 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
739 if (rc==DS_OK && secondary!=NULL)
740 IDirectSoundBuffer_Release(secondary);
742 secondary=NULL;
743 ZeroMemory(&bufdesc, sizeof(bufdesc));
744 bufdesc.dwSize=sizeof(bufdesc);
745 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
746 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
747 wfx.nBlockAlign);
748 bufdesc.lpwfxFormat=&wfx;
749 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
750 if (gotdx8 || wfx.wBitsPerSample <= 16 || wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
752 if (wfx.wBitsPerSample > 16)
753 ok(broken((rc == DSERR_CONTROLUNAVAIL || rc == DSERR_INVALIDCALL || rc == DSERR_INVALIDPARAM /* 2003 */) && !secondary)
754 || rc == DS_OK, /* driver dependent? */
755 "IDirectSound_CreateSoundBuffer() "
756 "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) "
757 "and NULL, returned: %08x %p\n", rc, secondary);
758 else
759 ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
760 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc);
762 else
763 ok(rc==E_INVALIDARG, "Creating %d bpp buffer on dx < 8 returned: %p %08x\n",
764 wfx.wBitsPerSample, secondary, rc);
766 if (!gotdx8)
768 win_skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
769 /* Apparently they succeed with bogus values,
770 * which means that older dsound doesn't look at them
772 goto no_wfe;
775 if (secondary)
776 IDirectSoundBuffer_Release(secondary);
777 secondary = NULL;
779 bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
780 wfxe.Format = wfx;
781 wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
782 wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
783 wfxe.Format.cbSize = 1;
784 wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
785 wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);
787 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
788 ok((rc==DSERR_INVALIDPARAM || rc==DSERR_INVALIDCALL /* 2003 */) && !secondary,
789 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
790 rc, secondary);
791 if (secondary)
793 IDirectSoundBuffer_Release(secondary);
794 secondary=NULL;
797 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1;
799 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
800 ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL || rc==DSERR_INVALIDPARAM)
801 && !secondary)
802 || rc==DS_OK, /* 2003 / 2008 */
803 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
804 rc, secondary);
805 if (secondary)
807 IDirectSoundBuffer_Release(secondary);
808 secondary=NULL;
811 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
812 wfxe.SubFormat = GUID_NULL;
813 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
814 ok((rc==DSERR_INVALIDPARAM || rc==DSERR_INVALIDCALL) && !secondary,
815 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
816 rc, secondary);
817 if (secondary)
819 IDirectSoundBuffer_Release(secondary);
820 secondary=NULL;
822 wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
824 ++wfxe.Samples.wValidBitsPerSample;
825 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
826 ok(rc==DSERR_INVALIDPARAM && !secondary,
827 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
828 rc, secondary);
829 if (secondary)
831 IDirectSoundBuffer_Release(secondary);
832 secondary=NULL;
834 --wfxe.Samples.wValidBitsPerSample;
836 wfxe.Samples.wValidBitsPerSample = 0;
837 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
838 ok(rc==DS_OK && secondary,
839 "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
840 rc, secondary);
841 if (secondary)
843 IDirectSoundBuffer_Release(secondary);
844 secondary=NULL;
846 wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample;
848 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
849 ok(rc==DS_OK && secondary!=NULL,
850 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc);
852 no_wfe:
853 if (rc==DS_OK && secondary!=NULL) {
854 if (winetest_interactive) {
855 trace(" Testing a secondary buffer at %dx%dx%d (fmt=%d) "
856 "with a primary buffer at %dx%dx%d\n",
857 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
858 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
860 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
861 winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
863 ref=IDirectSoundBuffer_Release(secondary);
864 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
865 "should have 0\n",ref);
869 EXIT1:
870 ref=IDirectSoundBuffer_Release(primary);
871 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
872 "should have 0\n",ref);
875 /* Set the CooperativeLevel back to normal */
876 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
877 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
878 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
880 EXIT:
881 ref=IDirectSound_Release(dso);
882 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
883 if (ref!=0)
884 return DSERR_GENERIC;
886 return rc;
889 static HRESULT test_block_align(LPGUID lpGuid)
891 HRESULT rc;
892 LPDIRECTSOUND dso=NULL;
893 LPDIRECTSOUNDBUFFER secondary=NULL;
894 DSBUFFERDESC bufdesc;
895 DSBCAPS dsbcaps;
896 WAVEFORMATEX wfx;
897 DWORD pos, pos2;
898 int ref;
900 /* Create the DirectSound object */
901 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
902 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
903 "DirectSoundCreate() failed: %08x\n",rc);
904 if (rc!=DS_OK)
905 return rc;
907 init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
908 ZeroMemory(&bufdesc, sizeof(bufdesc));
909 bufdesc.dwSize=sizeof(bufdesc);
910 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
911 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec + 1;
912 bufdesc.lpwfxFormat=&wfx;
913 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
914 ok(rc == DS_OK || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
915 "IDirectSound_CreateSoundBuffer() should have returned DS_OK, returned: %08x\n", rc);
917 if (rc==DS_OK && secondary!=NULL) {
918 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
919 dsbcaps.dwSize = sizeof(dsbcaps);
920 rc=IDirectSoundBuffer_GetCaps(secondary,&dsbcaps);
921 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
922 "returned: %08x\n", rc);
923 if (rc==DS_OK && wfx.nBlockAlign > 1)
925 ok(dsbcaps.dwBufferBytes==(wfx.nAvgBytesPerSec + wfx.nBlockAlign),
926 "Buffer size not a multiple of nBlockAlign: requested %d, "
927 "got %d, should be %d\n", bufdesc.dwBufferBytes,
928 dsbcaps.dwBufferBytes, wfx.nAvgBytesPerSec + wfx.nBlockAlign);
930 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 0);
931 ok(rc == DS_OK, "Could not set position to 0: %08x\n", rc);
932 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos, NULL);
933 ok(rc == DS_OK, "Could not get position: %08x\n", rc);
934 rc = IDirectSoundBuffer_SetCurrentPosition(secondary, 1);
935 ok(rc == DS_OK, "Could not set position to 1: %08x\n", rc);
936 rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos2, NULL);
937 ok(rc == DS_OK, "Could not get new position: %08x\n", rc);
938 ok(pos == pos2, "Positions not the same! Old position: %d, new position: %d\n", pos, pos2);
940 ref=IDirectSoundBuffer_Release(secondary);
941 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, "
942 "should have 0\n",ref);
945 ref=IDirectSound_Release(dso);
946 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
947 if (ref!=0)
948 return DSERR_GENERIC;
950 return rc;
953 static struct fmt {
954 int bits;
955 int channels;
956 } fmts[] = { { 8, 1 }, { 8, 2 }, { 16, 1 }, {16, 2 } };
958 static HRESULT test_frequency(LPGUID lpGuid)
960 HRESULT rc;
961 LPDIRECTSOUND dso=NULL;
962 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
963 DSBUFFERDESC bufdesc;
964 DSCAPS dscaps;
965 WAVEFORMATEX wfx, wfx1;
966 DWORD f, r;
967 int ref;
968 int rates[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
969 48000, 96000 };
971 /* Create the DirectSound object */
972 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
973 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
974 "DirectSoundCreate() failed: %08x\n",rc);
975 if (rc!=DS_OK)
976 return rc;
978 /* Get the device capabilities */
979 ZeroMemory(&dscaps, sizeof(dscaps));
980 dscaps.dwSize=sizeof(dscaps);
981 rc=IDirectSound_GetCaps(dso,&dscaps);
982 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
983 if (rc!=DS_OK)
984 goto EXIT;
986 /* We must call SetCooperativeLevel before creating primary buffer */
987 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
988 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
989 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
990 if (rc!=DS_OK)
991 goto EXIT;
993 ZeroMemory(&bufdesc, sizeof(bufdesc));
994 bufdesc.dwSize=sizeof(bufdesc);
995 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
996 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
997 ok(rc==DS_OK && primary!=NULL,
998 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc);
1000 if (rc==DS_OK && primary!=NULL) {
1001 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
1002 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
1003 if (rc!=DS_OK)
1004 goto EXIT1;
1006 for (f=0;f<sizeof(fmts)/sizeof(fmts[0]);f++) {
1007 for (r=0;r<sizeof(rates)/sizeof(rates[0]);r++) {
1008 init_format(&wfx,WAVE_FORMAT_PCM,11025,fmts[f].bits,
1009 fmts[f].channels);
1010 secondary=NULL;
1011 ZeroMemory(&bufdesc, sizeof(bufdesc));
1012 bufdesc.dwSize=sizeof(bufdesc);
1013 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLFREQUENCY;
1014 bufdesc.dwBufferBytes=align((wfx.nAvgBytesPerSec*rates[r]/11025)*
1015 BUFFER_LEN/1000,wfx.nBlockAlign);
1016 bufdesc.lpwfxFormat=&wfx;
1017 if (winetest_interactive) {
1018 trace(" Testing a secondary buffer at %dx%dx%d "
1019 "with a primary buffer at %dx%dx%d\n",
1020 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
1021 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
1023 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
1024 ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
1025 "IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %08x\n",rc);
1027 if (rc==DS_OK && secondary!=NULL) {
1028 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
1029 winetest_interactive,1.0,0,NULL,0,0,TRUE,rates[r]);
1031 ref=IDirectSoundBuffer_Release(secondary);
1032 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1033 "should have 0\n",ref);
1037 EXIT1:
1038 ref=IDirectSoundBuffer_Release(primary);
1039 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1040 "should have 0\n",ref);
1043 /* Set the CooperativeLevel back to normal */
1044 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1045 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1046 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
1048 EXIT:
1049 ref=IDirectSound_Release(dso);
1050 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1051 if (ref!=0)
1052 return DSERR_GENERIC;
1054 return rc;
1057 static HRESULT test_notify(LPDIRECTSOUNDBUFFER dsb,
1058 DWORD count, LPHANDLE event,
1059 DWORD expected)
1061 HRESULT rc;
1062 DWORD ret;
1064 rc=IDirectSoundBuffer_SetCurrentPosition(dsb,0);
1065 ok(rc==DS_OK,
1066 "IDirectSoundBuffer_SetCurrentPosition failed %08x\n",rc);
1067 if(rc!=DS_OK)
1068 return rc;
1070 rc=IDirectSoundBuffer_Play(dsb,0,0,0);
1071 ok(rc==DS_OK,"IDirectSoundBuffer_Play failed %08x\n",rc);
1072 if(rc!=DS_OK)
1073 return rc;
1075 rc=IDirectSoundBuffer_Stop(dsb);
1076 ok(rc==DS_OK,"IDirectSoundBuffer_Stop failed %08x\n",rc);
1077 if(rc!=DS_OK)
1078 return rc;
1080 ret=WaitForMultipleObjects(count,event,FALSE,0);
1081 ok(ret==expected,"expected %d. got %d\n",expected,ret);
1082 return rc;
1085 static HRESULT test_duplicate(LPGUID lpGuid)
1087 HRESULT rc;
1088 LPDIRECTSOUND dso=NULL;
1089 LPDIRECTSOUNDBUFFER primary=NULL;
1090 DSBUFFERDESC bufdesc;
1091 int ref;
1093 /* Create the DirectSound object */
1094 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
1095 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
1096 "DirectSoundCreate() failed: %08x\n",rc);
1097 if (rc!=DS_OK)
1098 return rc;
1100 /* We must call SetCooperativeLevel before creating primary buffer */
1101 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1102 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1103 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
1104 if (rc!=DS_OK)
1105 goto EXIT;
1107 ZeroMemory(&bufdesc, sizeof(bufdesc));
1108 bufdesc.dwSize=sizeof(bufdesc);
1109 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
1110 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1111 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1112 "to create a primary buffer %08x\n",rc);
1114 if (rc==DS_OK && primary!=NULL) {
1115 LPDIRECTSOUNDBUFFER original=NULL;
1116 WAVEFORMATEX wfx;
1118 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
1119 ZeroMemory(&bufdesc, sizeof(bufdesc));
1120 bufdesc.dwSize=sizeof(bufdesc);
1121 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY;
1122 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec/100; /* very short buffer */
1123 bufdesc.lpwfxFormat=&wfx;
1124 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&original,NULL);
1125 ok(rc==DS_OK && original!=NULL,
1126 "IDirectSound_CreateSoundBuffer() failed to create an original "
1127 "buffer %08x\n",rc);
1128 if (rc==DS_OK && original!=NULL) {
1129 LPDIRECTSOUNDBUFFER duplicated=NULL;
1130 LPDIRECTSOUNDNOTIFY notify=NULL;
1131 HANDLE event[2];
1132 LPVOID buf=NULL;
1133 DWORD bufsize;
1134 int i;
1136 /* Prepare notify events */
1137 for (i=0;i<sizeof(event)/sizeof(event[0]);i++) {
1138 event[i] = CreateEventW(NULL, FALSE, FALSE, NULL);
1141 /* Make silent buffer */
1142 rc=IDirectSoundBuffer_Lock(original,0,0,&buf,&bufsize,
1143 NULL,NULL,DSBLOCK_ENTIREBUFFER);
1144 ok(rc==DS_OK && buf!=NULL,
1145 "IDirectSoundBuffer_Lock failed to lock the buffer %08x\n",rc);
1146 if (rc==DS_OK && buf!=NULL) {
1147 ZeroMemory(buf,bufsize);
1148 rc=IDirectSoundBuffer_Unlock(original,buf,bufsize,
1149 NULL,0);
1150 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock failed to unlock "
1151 "%08x\n",rc);
1154 rc=IDirectSoundBuffer_QueryInterface(original,
1155 &IID_IDirectSoundNotify,
1156 (void**)&notify);
1157 ok(rc==DS_OK && notify!=NULL,
1158 "IDirectSoundBuffer_QueryInterface() failed to create a "
1159 "notification %08x\n",rc);
1160 if (rc==DS_OK && notify!=NULL) {
1161 DSBPOSITIONNOTIFY dsbpn;
1162 LPDIRECTSOUNDNOTIFY dup_notify=NULL;
1164 dsbpn.dwOffset=DSBPN_OFFSETSTOP;
1165 dsbpn.hEventNotify=event[0];
1166 rc=IDirectSoundNotify_SetNotificationPositions(notify,
1167 1,&dsbpn);
1168 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions "
1169 "failed %08x\n",rc);
1171 rc=IDirectSound_DuplicateSoundBuffer(dso,original,&duplicated);
1172 ok(rc==DS_OK && duplicated!=NULL,
1173 "IDirectSound_DuplicateSoundBuffer failed %08x\n",rc);
1175 trace("testing duplicated buffer without notifications.\n");
1176 test_notify(duplicated,sizeof(event)/sizeof(event[0]),
1177 event,WAIT_TIMEOUT);
1179 rc=IDirectSoundBuffer_QueryInterface(duplicated,
1180 &IID_IDirectSoundNotify,
1181 (void**)&dup_notify);
1182 ok(rc==DS_OK&&dup_notify!=NULL,
1183 "IDirectSoundBuffer_QueryInterface() failed to create a "
1184 "notification %08x\n",rc);
1185 if(rc==DS_OK&&dup_notify!=NULL) {
1186 dsbpn.dwOffset=DSBPN_OFFSETSTOP;
1187 dsbpn.hEventNotify=event[1];
1188 rc=IDirectSoundNotify_SetNotificationPositions(dup_notify,
1189 1,&dsbpn);
1190 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions "
1191 "failed %08x\n",rc);
1193 trace("testing duplicated buffer with a notification.\n");
1194 test_notify(duplicated,sizeof(event)/sizeof(event[0]),
1195 event,WAIT_OBJECT_0+1);
1197 ref=IDirectSoundNotify_Release(dup_notify);
1198 ok(ref==0,"IDirectSoundNotify_Release() has %d references, "
1199 "should have 0\n",ref);
1201 ref=IDirectSoundNotify_Release(notify);
1202 ok(ref==0,"IDirectSoundNotify_Release() has %d references, "
1203 "should have 0\n",ref);
1205 trace("testing original buffer with a notification.\n");
1206 test_notify(original,sizeof(event)/sizeof(event[0]),
1207 event,WAIT_OBJECT_0);
1209 ref=IDirectSoundBuffer_Release(duplicated);
1210 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1211 "should have 0\n",ref);
1213 ref=IDirectSoundBuffer_Release(original);
1214 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1215 "should have 0\n",ref);
1217 ref=IDirectSoundBuffer_Release(primary);
1218 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
1219 "should have 0\n",ref);
1222 /* Set the CooperativeLevel back to normal */
1223 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1224 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1225 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
1227 EXIT:
1228 ref=IDirectSound_Release(dso);
1229 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1230 if (ref!=0)
1231 return DSERR_GENERIC;
1233 return rc;
1236 static HRESULT do_invalid_fmt_test(IDirectSound *dso,
1237 IDirectSoundBuffer *buf, WAVEFORMATEX *wfx, IDirectSoundBuffer **out_buf)
1239 HRESULT rc;
1240 *out_buf = NULL;
1241 if(!buf){
1242 DSBUFFERDESC bufdesc;
1243 ZeroMemory(&bufdesc, sizeof(bufdesc));
1244 bufdesc.dwSize = sizeof(bufdesc);
1245 bufdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY;
1246 bufdesc.dwBufferBytes = 4096;
1247 bufdesc.lpwfxFormat = wfx;
1248 rc = IDirectSound_CreateSoundBuffer(dso, &bufdesc, out_buf, NULL);
1249 }else{
1250 rc = IDirectSoundBuffer_SetFormat(buf, wfx);
1251 if(SUCCEEDED(rc)){
1252 IDirectSoundBuffer_AddRef(buf);
1253 *out_buf = buf;
1256 return rc;
1259 /* if no buffer is given, use CreateSoundBuffer instead of SetFormat */
1260 static void perform_invalid_fmt_tests(const char *testname, IDirectSound *dso, IDirectSoundBuffer *buf)
1262 WAVEFORMATEX wfx;
1263 WAVEFORMATEXTENSIBLE fmtex;
1264 HRESULT rc;
1265 IDirectSoundBuffer *got_buf;
1267 wfx.wFormatTag = WAVE_FORMAT_PCM;
1268 wfx.nChannels = 0;
1269 wfx.nSamplesPerSec = 44100;
1270 wfx.wBitsPerSample = 16;
1271 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1272 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1273 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1274 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1276 wfx.nChannels = 2;
1277 wfx.nSamplesPerSec = 44100;
1278 wfx.wBitsPerSample = 0;
1279 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1280 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1281 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1282 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1284 wfx.nChannels = 2;
1285 wfx.nSamplesPerSec = 44100;
1286 wfx.wBitsPerSample = 2;
1287 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1288 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1289 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1290 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1292 wfx.nChannels = 2;
1293 wfx.nSamplesPerSec = 44100;
1294 wfx.wBitsPerSample = 12;
1295 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1296 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1297 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1298 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1300 wfx.nChannels = 2;
1301 wfx.nSamplesPerSec = 0;
1302 wfx.wBitsPerSample = 16;
1303 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1304 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1305 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1306 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1308 wfx.nChannels = 2;
1309 wfx.nSamplesPerSec = 44100;
1310 wfx.wBitsPerSample = 16;
1311 wfx.nBlockAlign = 0;
1312 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1313 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1314 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1316 wfx.nChannels = 2;
1317 wfx.nSamplesPerSec = 44100;
1318 wfx.wBitsPerSample = 16;
1319 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1320 wfx.nAvgBytesPerSec = 0;
1321 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1322 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1324 wfx.nChannels = 2;
1325 wfx.nSamplesPerSec = 44100;
1326 wfx.wBitsPerSample = 16;
1327 wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) - 1;
1328 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1329 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1330 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1332 wfx.nChannels = 2;
1333 wfx.nSamplesPerSec = 44100;
1334 wfx.wBitsPerSample = 16;
1335 wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) + 1;
1336 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1337 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1338 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1340 wfx.nChannels = 2;
1341 wfx.nSamplesPerSec = 44100;
1342 wfx.wBitsPerSample = 16;
1343 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1344 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
1345 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1346 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1348 rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
1349 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1350 ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
1351 ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
1352 ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
1353 ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
1354 ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
1355 ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
1356 IDirectSoundBuffer_Release(got_buf);
1358 wfx.nChannels = 2;
1359 wfx.nSamplesPerSec = 44100;
1360 wfx.wBitsPerSample = 16;
1361 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1362 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign - 1;
1363 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1364 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1366 rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
1367 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1368 ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
1369 ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
1370 ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
1371 ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
1372 ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
1373 ok(wfx.nAvgBytesPerSec == 44100 * 4 - 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
1374 IDirectSoundBuffer_Release(got_buf);
1376 wfx.nChannels = 2;
1377 wfx.nSamplesPerSec = 44100;
1378 wfx.wBitsPerSample = 16;
1379 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1380 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
1381 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1382 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1384 rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
1385 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1386 ok(wfx.wFormatTag == WAVE_FORMAT_PCM, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
1387 ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
1388 ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
1389 ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
1390 ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
1391 ok(wfx.nAvgBytesPerSec == 44100 * 4 + 1, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
1392 IDirectSoundBuffer_Release(got_buf);
1394 if(buf){
1395 wfx.wFormatTag = WAVE_FORMAT_ALAW;
1396 wfx.nChannels = 2;
1397 wfx.nSamplesPerSec = 44100;
1398 wfx.wBitsPerSample = 16;
1399 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1400 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1401 rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
1402 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1404 if(got_buf){
1405 rc = IDirectSoundBuffer_GetFormat(got_buf, &wfx, sizeof(wfx), NULL);
1406 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1407 ok(wfx.wFormatTag == WAVE_FORMAT_ALAW, "%s: format: 0x%x\n", testname, wfx.wFormatTag);
1408 ok(wfx.nChannels == 2, "%s: channels: %u\n", testname, wfx.nChannels);
1409 ok(wfx.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, wfx.nSamplesPerSec);
1410 ok(wfx.wBitsPerSample == 16, "%s: bps: %u\n", testname, wfx.wBitsPerSample);
1411 ok(wfx.nBlockAlign == 4, "%s: blockalign: %u\n", testname, wfx.nBlockAlign);
1412 ok(wfx.nAvgBytesPerSec == 44100 * 4, "%s: avgbytes: %u\n", testname, wfx.nAvgBytesPerSec);
1413 IDirectSoundBuffer_Release(got_buf);
1417 if(!gotdx8){
1418 win_skip("Not doing the WAVE_FORMAT_EXTENSIBLE tests\n");
1419 return;
1422 fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
1423 fmtex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
1424 fmtex.Format.nChannels = 2;
1425 fmtex.Format.nSamplesPerSec = 44100;
1426 fmtex.Format.wBitsPerSample = 16;
1427 fmtex.Format.nBlockAlign = fmtex.Format.nChannels * fmtex.Format.wBitsPerSample / 8;
1428 fmtex.Format.nAvgBytesPerSec = fmtex.Format.nSamplesPerSec * fmtex.Format.nBlockAlign;
1429 fmtex.Samples.wValidBitsPerSample = 0;
1430 fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
1431 fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1432 rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
1433 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1435 rc = IDirectSoundBuffer_GetFormat(got_buf, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
1436 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1437 ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "%s: format: 0x%x\n", testname, fmtex.Format.wFormatTag);
1438 ok(fmtex.Format.nChannels == 2, "%s: channels: %u\n", testname, fmtex.Format.nChannels);
1439 ok(fmtex.Format.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, fmtex.Format.nSamplesPerSec);
1440 ok(fmtex.Format.wBitsPerSample == 16, "%s: bps: %u\n", testname, fmtex.Format.wBitsPerSample);
1441 ok(fmtex.Format.nBlockAlign == 4, "%s: blockalign: %u\n", testname, fmtex.Format.nBlockAlign);
1442 ok(fmtex.Format.nAvgBytesPerSec == 44100 * 4, "%s: avgbytes: %u\n", testname, fmtex.Format.nAvgBytesPerSec);
1443 ok(fmtex.Samples.wValidBitsPerSample == 0 || /* <= XP */
1444 fmtex.Samples.wValidBitsPerSample == 16, /* >= Vista */
1445 "%s: validbits: %u\n", testname, fmtex.Samples.wValidBitsPerSample);
1446 ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "%s: subtype incorrect\n", testname);
1447 IDirectSoundBuffer_Release(got_buf);
1449 fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
1450 fmtex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
1451 fmtex.Format.nChannels = 2;
1452 fmtex.Format.nSamplesPerSec = 44100;
1453 fmtex.Format.wBitsPerSample = 24;
1454 fmtex.Format.nBlockAlign = fmtex.Format.nChannels * fmtex.Format.wBitsPerSample / 8;
1455 fmtex.Format.nAvgBytesPerSec = fmtex.Format.nSamplesPerSec * fmtex.Format.nBlockAlign;
1456 fmtex.Samples.wValidBitsPerSample = 20;
1457 fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
1458 fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1459 rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
1460 ok(rc == S_OK, "%s: SetFormat: %08x\n", testname, rc);
1462 rc = IDirectSoundBuffer_GetFormat(got_buf, (WAVEFORMATEX*)&fmtex, sizeof(fmtex), NULL);
1463 ok(rc == S_OK, "%s: GetFormat: %08x\n", testname, rc);
1464 ok(fmtex.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "%s: format: 0x%x\n", testname, fmtex.Format.wFormatTag);
1465 ok(fmtex.Format.nChannels == 2, "%s: channels: %u\n", testname, fmtex.Format.nChannels);
1466 ok(fmtex.Format.nSamplesPerSec == 44100, "%s: rate: %u\n", testname, fmtex.Format.nSamplesPerSec);
1467 ok(fmtex.Format.wBitsPerSample == 24, "%s: bps: %u\n", testname, fmtex.Format.wBitsPerSample);
1468 ok(fmtex.Format.nBlockAlign == 6, "%s: blockalign: %u\n", testname, fmtex.Format.nBlockAlign);
1469 ok(fmtex.Format.nAvgBytesPerSec == 44100 * 6, "%s: avgbytes: %u\n", testname, fmtex.Format.nAvgBytesPerSec);
1470 ok(fmtex.Samples.wValidBitsPerSample == 20, "%s: validbits: %u\n", testname, fmtex.Samples.wValidBitsPerSample);
1471 ok(IsEqualGUID(&fmtex.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM), "%s: subtype incorrect\n", testname);
1472 IDirectSoundBuffer_Release(got_buf);
1474 fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
1475 fmtex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
1476 fmtex.Format.nChannels = 2;
1477 fmtex.Format.nSamplesPerSec = 44100;
1478 fmtex.Format.wBitsPerSample = 24;
1479 fmtex.Format.nBlockAlign = fmtex.Format.nChannels * fmtex.Format.wBitsPerSample / 8;
1480 fmtex.Format.nAvgBytesPerSec = fmtex.Format.nSamplesPerSec * fmtex.Format.nBlockAlign;
1481 fmtex.Samples.wValidBitsPerSample = 32;
1482 fmtex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
1483 fmtex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
1484 rc = do_invalid_fmt_test(dso, buf, (WAVEFORMATEX*)&fmtex, &got_buf);
1485 ok(rc == E_INVALIDARG, "%s: SetFormat: %08x\n", testname, rc);
1488 static HRESULT test_invalid_fmts(LPGUID lpGuid)
1490 HRESULT rc;
1491 LPDIRECTSOUND dso=NULL;
1492 LPDIRECTSOUNDBUFFER buffer=NULL;
1493 DSBUFFERDESC bufdesc;
1495 /* Create the DirectSound object */
1496 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
1497 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
1498 "DirectSoundCreate() failed: %08x\n",rc);
1499 if (rc!=DS_OK)
1500 return rc;
1502 /* We must call SetCooperativeLevel before creating primary buffer */
1503 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1504 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1505 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
1506 if (rc!=DS_OK){
1507 IDirectSound_Release(dso);
1508 return rc;
1511 ZeroMemory(&bufdesc, sizeof(bufdesc));
1512 bufdesc.dwSize=sizeof(bufdesc);
1513 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
1514 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&buffer,NULL);
1515 ok(rc==DS_OK && buffer!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1516 "to create a primary buffer %08x\n",rc);
1517 if (rc==DS_OK && buffer!=NULL) {
1518 perform_invalid_fmt_tests("primary", dso, buffer);
1519 IDirectSoundBuffer_Release(buffer);
1522 perform_invalid_fmt_tests("secondary", dso, NULL);
1524 IDirectSound_Release(dso);
1526 return S_OK;
1529 static void test_notifications(LPGUID lpGuid)
1531 HRESULT rc;
1532 IDirectSound *dso;
1533 IDirectSoundBuffer *buf;
1534 IDirectSoundNotify *buf_notif;
1535 DSBUFFERDESC bufdesc;
1536 WAVEFORMATEX wfx;
1537 DSBPOSITIONNOTIFY notifies[2];
1538 HANDLE handles[2];
1539 DWORD expect;
1540 int cycles;
1542 rc = pDirectSoundCreate(lpGuid, &dso, NULL);
1543 ok(rc == DS_OK || rc == DSERR_NODRIVER || rc == DSERR_ALLOCATED,
1544 "DirectSoundCreate() failed: %08x\n", rc);
1545 if(rc != DS_OK)
1546 return;
1548 rc = IDirectSound_SetCooperativeLevel(dso, get_hwnd(), DSSCL_PRIORITY);
1549 ok(rc == DS_OK, "IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
1550 if(rc != DS_OK){
1551 IDirectSound_Release(dso);
1552 return;
1555 wfx.wFormatTag = WAVE_FORMAT_PCM;
1556 wfx.nChannels = 1;
1557 wfx.nSamplesPerSec = 44100;
1558 wfx.wBitsPerSample = 16;
1559 wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
1560 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
1561 wfx.cbSize = 0;
1563 ZeroMemory(&bufdesc, sizeof(bufdesc));
1564 bufdesc.dwSize = sizeof(bufdesc);
1565 bufdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY;
1566 bufdesc.dwBufferBytes = wfx.nSamplesPerSec * wfx.nBlockAlign / 2; /* 0.5s */
1567 bufdesc.lpwfxFormat = &wfx;
1568 rc = IDirectSound_CreateSoundBuffer(dso, &bufdesc, &buf, NULL);
1569 ok(rc == DS_OK && buf != NULL, "IDirectSound_CreateSoundBuffer() failed "
1570 "to create a buffer %08x\n", rc);
1572 rc = IDirectSoundBuffer_QueryInterface(buf, &IID_IDirectSoundNotify, (void**)&buf_notif);
1573 ok(rc == DS_OK, "QueryInterface(IID_IDirectSoundNotify): %08x\n", rc);
1575 notifies[0].dwOffset = 0;
1576 handles[0] = notifies[0].hEventNotify = CreateEventW(NULL, FALSE, FALSE, NULL);
1577 notifies[1].dwOffset = bufdesc.dwBufferBytes / 2;
1578 handles[1] = notifies[1].hEventNotify = CreateEventW(NULL, FALSE, FALSE, NULL);
1580 rc = IDirectSoundNotify_SetNotificationPositions(buf_notif, 2, notifies);
1581 ok(rc == DS_OK, "SetNotificationPositions: %08x\n", rc);
1583 IDirectSoundNotify_Release(buf_notif);
1585 rc = IDirectSoundBuffer_Play(buf, 0, 0, DSBPLAY_LOOPING);
1586 ok(rc == DS_OK, "Play: %08x\n", rc);
1588 expect = 0;
1589 for(cycles = 0; cycles < 6 /* 1.5s */; ++cycles){
1590 DWORD wait;
1592 wait = WaitForMultipleObjects(2, handles, FALSE, 1000);
1593 ok(wait <= WAIT_OBJECT_0 + 1 && wait - WAIT_OBJECT_0 == expect,
1594 "Got unexpected notification order or timeout: %u\n", wait);
1596 expect = !expect;
1599 rc = IDirectSoundBuffer_Stop(buf);
1600 ok(rc == DS_OK, "Stop: %08x\n", rc);
1602 CloseHandle(notifies[0].hEventNotify);
1603 CloseHandle(notifies[1].hEventNotify);
1605 IDirectSoundBuffer_Release(buf);
1606 IDirectSound_Release(dso);
1609 static unsigned int number;
1611 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1612 LPCSTR lpcstrModule, LPVOID lpContext)
1614 HRESULT rc;
1615 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1617 /* Don't test the primary device */
1618 if (!number++)
1620 ok (!lpcstrModule[0], "lpcstrModule(%s) != NULL\n", lpcstrModule);
1621 return TRUE;
1624 rc = test_dsound(lpGuid);
1625 if (rc == DSERR_NODRIVER)
1626 trace(" No Driver\n");
1627 else if (rc == DSERR_ALLOCATED)
1628 trace(" Already In Use\n");
1629 else if (rc == E_FAIL)
1630 trace(" No Device\n");
1631 else {
1632 test_block_align(lpGuid);
1633 test_primary(lpGuid);
1634 test_primary_secondary(lpGuid);
1635 test_secondary(lpGuid);
1636 test_frequency(lpGuid);
1637 test_duplicate(lpGuid);
1638 test_invalid_fmts(lpGuid);
1639 test_notifications(lpGuid);
1642 return TRUE;
1645 static void dsound_tests(void)
1647 HRESULT rc;
1648 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
1649 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %08x\n",rc);
1652 static void test_hw_buffers(void)
1654 IDirectSound *ds;
1655 IDirectSoundBuffer *primary, *primary2, **secondaries, *secondary;
1656 IDirectSoundBuffer8 *buf8;
1657 DSCAPS caps;
1658 DSBCAPS bufcaps;
1659 DSBUFFERDESC bufdesc;
1660 WAVEFORMATEX fmt;
1661 UINT i;
1662 HRESULT hr;
1664 hr = pDirectSoundCreate(NULL, &ds, NULL);
1665 ok(hr == S_OK || hr == DSERR_NODRIVER || hr == DSERR_ALLOCATED || hr == E_FAIL,
1666 "DirectSoundCreate failed: %08x\n", hr);
1667 if(hr != S_OK)
1668 return;
1670 caps.dwSize = sizeof(caps);
1672 hr = IDirectSound_GetCaps(ds, &caps);
1673 ok(hr == S_OK, "GetCaps failed: %08x\n", hr);
1675 ok(caps.dwPrimaryBuffers == 1, "Got wrong number of primary buffers: %u\n",
1676 caps.dwPrimaryBuffers);
1678 /* DSBCAPS_LOC* is ignored for primary buffers */
1679 bufdesc.dwSize = sizeof(bufdesc);
1680 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE |
1681 DSBCAPS_PRIMARYBUFFER;
1682 bufdesc.dwBufferBytes = 0;
1683 bufdesc.dwReserved = 0;
1684 bufdesc.lpwfxFormat = NULL;
1685 bufdesc.guid3DAlgorithm = GUID_NULL;
1687 hr = IDirectSound_CreateSoundBuffer(ds, &bufdesc, &primary, NULL);
1688 ok(hr == S_OK, "CreateSoundBuffer failed: %08x\n", hr);
1689 if(hr != S_OK){
1690 IDirectSound_Release(ds);
1691 return;
1694 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCSOFTWARE |
1695 DSBCAPS_PRIMARYBUFFER;
1697 hr = IDirectSound_CreateSoundBuffer(ds, &bufdesc, &primary2, NULL);
1698 ok(hr == S_OK, "CreateSoundBuffer failed: %08x\n", hr);
1699 ok(primary == primary2, "Got different primary buffers: %p, %p\n", primary, primary2);
1700 if(hr == S_OK)
1701 IDirectSoundBuffer_Release(primary2);
1703 buf8 = (IDirectSoundBuffer8 *)0xDEADBEEF;
1704 hr = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8,
1705 (void**)&buf8);
1706 ok(hr == E_NOINTERFACE, "QueryInterface gave wrong failure: %08x\n", hr);
1707 ok(buf8 == NULL, "Pointer didn't get set to NULL\n");
1709 fmt.wFormatTag = WAVE_FORMAT_PCM;
1710 fmt.nChannels = 2;
1711 fmt.nSamplesPerSec = 48000;
1712 fmt.wBitsPerSample = 16;
1713 fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
1714 fmt.nAvgBytesPerSec = fmt.nBlockAlign * fmt.nSamplesPerSec;
1715 fmt.cbSize = 0;
1717 bufdesc.lpwfxFormat = &fmt;
1718 bufdesc.dwBufferBytes = fmt.nSamplesPerSec * fmt.nBlockAlign / 10;
1719 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE |
1720 DSBCAPS_CTRLVOLUME;
1722 secondaries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1723 sizeof(IDirectSoundBuffer *) * caps.dwMaxHwMixingAllBuffers);
1725 /* try to fill all of the hw buffers */
1726 trace("dwMaxHwMixingAllBuffers: %u\n", caps.dwMaxHwMixingAllBuffers);
1727 trace("dwMaxHwMixingStaticBuffers: %u\n", caps.dwMaxHwMixingStaticBuffers);
1728 trace("dwMaxHwMixingStreamingBuffers: %u\n", caps.dwMaxHwMixingStreamingBuffers);
1729 for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i){
1730 hr = IDirectSound_CreateSoundBuffer(ds, &bufdesc, &secondaries[i], NULL);
1731 ok(hr == S_OK || hr == E_NOTIMPL || broken(hr == DSERR_CONTROLUNAVAIL) || broken(hr == E_FAIL),
1732 "CreateSoundBuffer(%u) failed: %08x\n", i, hr);
1733 if(hr != S_OK)
1734 break;
1736 bufcaps.dwSize = sizeof(bufcaps);
1737 hr = IDirectSoundBuffer_GetCaps(secondaries[i], &bufcaps);
1738 ok(hr == S_OK, "GetCaps failed: %08x\n", hr);
1739 ok((bufcaps.dwFlags & DSBCAPS_LOCHARDWARE) != 0,
1740 "Buffer wasn't allocated in hardware, dwFlags: %x\n", bufcaps.dwFlags);
1743 /* see if we can create one more */
1744 hr = IDirectSound_CreateSoundBuffer(ds, &bufdesc, &secondary, NULL);
1745 ok((i == caps.dwMaxHwMixingAllBuffers && hr == DSERR_ALLOCATED) || /* out of hw buffers */
1746 (caps.dwMaxHwMixingAllBuffers == 0 && hr == DSERR_INVALIDCALL) || /* no hw buffers at all */
1747 hr == E_NOTIMPL || /* don't support hw buffers */
1748 broken(hr == DSERR_CONTROLUNAVAIL) || /* vmware winxp, others? */
1749 broken(hr == E_FAIL) || /* broken AC97 driver */
1750 broken(hr == S_OK) /* broken driver allows more hw bufs than dscaps claims */,
1751 "CreateSoundBuffer(%u) gave wrong error: %08x\n", i, hr);
1752 if(hr == S_OK)
1753 IDirectSoundBuffer_Release(secondary);
1755 for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i)
1756 if(secondaries[i])
1757 IDirectSoundBuffer_Release(secondaries[i]);
1758 HeapFree(GetProcessHeap(), 0, secondaries);
1760 IDirectSoundBuffer_Release(primary);
1761 IDirectSound_Release(ds);
1764 START_TEST(dsound)
1766 HMODULE hDsound;
1768 CoInitialize(NULL);
1770 hDsound = LoadLibraryA("dsound.dll");
1771 if (hDsound)
1773 BOOL ret;
1775 ret = FreeLibrary(hDsound);
1776 ok( ret, "FreeLibrary(1) returned %d\n", GetLastError());
1779 hDsound = LoadLibraryA("dsound.dll");
1780 if (hDsound)
1783 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
1784 "DirectSoundEnumerateA");
1785 pDirectSoundCreate = (void*)GetProcAddress(hDsound,
1786 "DirectSoundCreate");
1788 gotdx8 = !!GetProcAddress(hDsound, "DirectSoundCreate8");
1790 IDirectSound_tests();
1791 dsound_tests();
1792 test_hw_buffers();
1794 FreeLibrary(hDsound);
1796 else
1797 win_skip("dsound.dll not found - skipping all tests\n");
1799 CoUninitialize();