2 * Tests the panning and 3D functions of DirectSound
4 * Part of this test involves playing test tones. But this only makes
5 * sense if someone is going to carefully listen to it, and would only
6 * bother everyone else.
7 * So this is only done if the test is being run in interactive mode.
9 * Copyright (c) 2002-2004 Francois Gouget
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
35 #include "dsound_test.h"
37 static HRESULT (WINAPI
*pDirectSoundEnumerateA
)(LPDSENUMCALLBACKA
,LPVOID
)=NULL
;
38 static HRESULT (WINAPI
*pDirectSoundCreate8
)(LPCGUID
,LPDIRECTSOUND8
*,LPUNKNOWN
)=NULL
;
44 LPDIRECTSOUNDBUFFER dsbo
;
52 static int buffer_refill8(play_state_t
* state
, DWORD size
)
58 if (size
>state
->wave_len
-state
->written
)
59 size
=state
->wave_len
-state
->written
;
61 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
62 &ptr1
,&len1
,&ptr2
,&len2
,0);
63 ok(rc
==DS_OK
,"IDirectSoundBuffer_Lock() failed: %08x\n", rc
);
67 memcpy(ptr1
,state
->wave
+state
->written
,len1
);
70 memcpy(ptr2
,state
->wave
+state
->written
,len2
);
73 state
->offset
=state
->written
% state
->buffer_size
;
74 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
75 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc
);
81 static int buffer_silence8(play_state_t
* state
, DWORD size
)
88 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
89 &ptr1
,&len1
,&ptr2
,&len2
,0);
90 ok(rc
==DS_OK
,"IDirectSoundBuffer_Lock() failed: %08x\n", rc
);
94 s
=(state
->wfx
->wBitsPerSample
==8?0x80:0);
99 state
->offset
=(state
->offset
+size
) % state
->buffer_size
;
100 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
101 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc
);
107 static BOOL
buffer_service8(play_state_t
* state
)
109 DWORD last_play_pos
,play_pos
,buf_free
;
112 rc
=IDirectSoundBuffer_GetCurrentPosition(state
->dsbo
,&play_pos
,NULL
);
113 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCurrentPosition() failed: %08x\n", rc
);
118 /* Update the amount played */
119 last_play_pos
=state
->played
% state
->buffer_size
;
120 if (play_pos
<last_play_pos
)
121 state
->played
+=state
->buffer_size
-last_play_pos
+play_pos
;
123 state
->played
+=play_pos
-last_play_pos
;
125 if (winetest_debug
> 1)
126 trace("buf size=%d last_play_pos=%d play_pos=%d played=%d / %d\n",
127 state
->buffer_size
,last_play_pos
,play_pos
,state
->played
,
130 if (state
->played
>state
->wave_len
)
132 /* Everything has been played */
136 /* Refill the buffer */
137 if (state
->offset
<=play_pos
)
138 buf_free
=play_pos
-state
->offset
;
140 buf_free
=state
->buffer_size
-state
->offset
+play_pos
;
142 if (winetest_debug
> 1)
143 trace("offset=%d free=%d written=%d / %d\n",
144 state
->offset
,buf_free
,state
->written
,state
->wave_len
);
148 if (state
->written
<state
->wave_len
)
150 int w
=buffer_refill8(state
,buf_free
);
154 if (state
->written
==state
->wave_len
&& winetest_debug
> 1)
155 trace("last sound byte at %d\n",
156 (state
->written
% state
->buffer_size
));
160 /* Fill with silence */
161 if (winetest_debug
> 1)
162 trace("writing %d bytes of silence\n",buf_free
);
163 if (buffer_silence8(state
,buf_free
)==-1)
169 if (winetest_debug
> 1)
170 trace("stopping playback\n");
171 rc
=IDirectSoundBuffer_Stop(state
->dsbo
);
172 ok(rc
==DS_OK
,"IDirectSoundBuffer_Stop() failed: %08x\n", rc
);
176 void test_buffer8(LPDIRECTSOUND8 dso
, LPDIRECTSOUNDBUFFER
* dsbo
,
177 BOOL is_primary
, BOOL set_volume
, LONG volume
,
178 BOOL set_pan
, LONG pan
, BOOL play
, double duration
,
179 BOOL buffer3d
, LPDIRECTSOUND3DLISTENER listener
,
180 BOOL move_listener
, BOOL move_sound
)
184 WAVEFORMATEX wfx
,wfx2
;
185 DWORD size
,status
,freq
;
189 /* DSOUND: Error: Invalid caps pointer */
190 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,0);
191 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
192 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
194 ZeroMemory(&dsbcaps
, sizeof(dsbcaps
));
196 /* DSOUND: Error: Invalid caps pointer */
197 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&dsbcaps
);
198 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
199 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
201 dsbcaps
.dwSize
=sizeof(dsbcaps
);
202 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&dsbcaps
);
203 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc
);
204 if (rc
==DS_OK
&& winetest_debug
> 1) {
205 trace(" Caps: flags=0x%08x size=%d\n",dsbcaps
.dwFlags
,
206 dsbcaps
.dwBufferBytes
);
209 /* Query the format size. */
211 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,NULL
,0,&size
);
212 ok(rc
==DS_OK
&& size
!=0,"IDirectSoundBuffer_GetFormat() should have "
213 "returned the needed size: rc=%08x size=%d\n",rc
,size
);
215 ok(size
== sizeof(WAVEFORMATEX
) || size
== sizeof(WAVEFORMATEXTENSIBLE
),
216 "Expected a correct structure size, got %d\n", size
);
218 if (size
== sizeof(WAVEFORMATEX
)) {
219 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,&wfx
,size
,NULL
);
220 ieee
= (wfx
.wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
);
221 } else if (size
== sizeof(WAVEFORMATEXTENSIBLE
)) {
222 WAVEFORMATEXTENSIBLE wfxe
;
223 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,(WAVEFORMATEX
*)&wfxe
,size
,NULL
);
225 ieee
= IsEqualGUID(&wfxe
.SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
);
229 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
230 if (rc
==DS_OK
&& winetest_debug
> 1) {
231 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
232 is_primary
? "Primary" : "Secondary",
233 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
234 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
237 /* DSOUND: Error: Invalid frequency buffer */
238 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,0);
239 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetFrequency() should have "
240 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
242 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
243 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,&freq
);
244 ok((rc
==DS_OK
&& !is_primary
) || (rc
==DSERR_CONTROLUNAVAIL
&&is_primary
) ||
245 (rc
==DSERR_CONTROLUNAVAIL
&&!(dsbcaps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
)),
246 "IDirectSoundBuffer_GetFrequency() failed: %08x\n",rc
);
248 ok(freq
==wfx
.nSamplesPerSec
,"The frequency returned by GetFrequency "
249 "%d does not match the format %d\n",freq
,wfx
.nSamplesPerSec
);
252 /* DSOUND: Error: Invalid status pointer */
253 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,0);
254 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetStatus() should have "
255 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
257 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
258 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc
);
259 ok(status
==0,"status=0x%x instead of 0\n",status
);
263 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
264 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
265 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
266 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
267 "failed: %08x\n",rc
);
271 /* DSOUND: Error: Invalid format pointer */
272 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,0);
273 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_SetFormat() should have "
274 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
276 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
277 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,&wfx2
);
278 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
279 format_string(&wfx2
), rc
);
281 /* There is no guarantee that SetFormat will actually change the
282 * format to what we asked for. It depends on what the soundcard
283 * supports. So we must re-query the format.
285 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,&wfx
,sizeof(wfx
),NULL
);
286 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
288 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
289 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
290 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
291 wfx
.nChannels
!=wfx2
.nChannels
)) {
292 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
293 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
294 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
295 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
296 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
297 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
300 ZeroMemory(&new_dsbcaps
, sizeof(new_dsbcaps
));
301 new_dsbcaps
.dwSize
= sizeof(new_dsbcaps
);
302 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&new_dsbcaps
);
303 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc
);
304 if (rc
==DS_OK
&& winetest_debug
> 1) {
305 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps
.dwFlags
,
306 new_dsbcaps
.dwBufferBytes
);
309 /* Check for primary buffer size change */
310 ok(new_dsbcaps
.dwBufferBytes
== dsbcaps
.dwBufferBytes
,
311 " buffer size changed after SetFormat() - "
312 "previous size was %u, current size is %u\n",
313 dsbcaps
.dwBufferBytes
, new_dsbcaps
.dwBufferBytes
);
314 dsbcaps
.dwBufferBytes
= new_dsbcaps
.dwBufferBytes
;
316 /* Check for primary buffer flags change */
317 ok(new_dsbcaps
.dwFlags
== dsbcaps
.dwFlags
,
318 " flags changed after SetFormat() - "
319 "previous flags were %08x, current flags are %08x\n",
320 dsbcaps
.dwFlags
, new_dsbcaps
.dwFlags
);
322 /* Set the CooperativeLevel back to normal */
323 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
324 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
325 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
326 "failed: %08x\n",rc
);
331 DS3DLISTENER listener_param
;
332 LPDIRECTSOUND3DBUFFER buffer
=NULL
;
333 DS3DBUFFER buffer_param
;
334 DWORD start_time
,now
;
338 if (winetest_interactive
) {
339 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration
,
340 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
,wfx
.nChannels
);
344 /* We must call SetCooperativeLevel to be allowed to call Lock */
345 /* DSOUND: Setting DirectSound cooperative level to
346 * DSSCL_WRITEPRIMARY */
347 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),
350 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: %08x\n",rc
);
355 LPDIRECTSOUNDBUFFER temp_buffer
;
357 rc
=IDirectSoundBuffer_QueryInterface(*dsbo
,&IID_IDirectSound3DBuffer
,
359 ok(rc
==DS_OK
,"IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
363 /* check the COM interface */
364 rc
=IDirectSoundBuffer_QueryInterface(*dsbo
, &IID_IDirectSoundBuffer
,
365 (LPVOID
*)&temp_buffer
);
366 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
367 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
368 ok(temp_buffer
==*dsbo
,"COM interface broken: %p != %p\n",
370 ref
=IDirectSoundBuffer_Release(temp_buffer
);
371 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
372 "should have 1\n",ref
);
375 rc
=IDirectSound3DBuffer_QueryInterface(*dsbo
, &IID_IDirectSoundBuffer
,
376 (LPVOID
*)&temp_buffer
);
377 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
378 "IDirectSound3DBuffer_QueryInterface() failed: %08x\n", rc
);
379 ok(temp_buffer
==*dsbo
,"COM interface broken: %p != %p\n",
381 ref
=IDirectSoundBuffer_Release(temp_buffer
);
382 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
383 "should have 1\n",ref
);
385 ref
=IDirectSoundBuffer_Release(*dsbo
);
386 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
387 "should have 0\n",ref
);
389 rc
=IDirectSound3DBuffer_QueryInterface(buffer
,
390 &IID_IDirectSoundBuffer
,
392 ok(rc
==DS_OK
&& *dsbo
!=NULL
,"IDirectSound3DBuffer_QueryInterface() "
393 "failed: %08x\n",rc
);
395 /* DSOUND: Error: Invalid buffer */
396 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,0);
397 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
398 "failed: %08x\n",rc
);
400 ZeroMemory(&buffer_param
, sizeof(buffer_param
));
402 /* DSOUND: Error: Invalid buffer */
403 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
404 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
405 "failed: %08x\n",rc
);
407 buffer_param
.dwSize
=sizeof(buffer_param
);
408 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
409 ok(rc
==DS_OK
,"IDirectSound3DBuffer_GetAllParameters() failed: %08x\n", rc
);
412 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
414 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&val
);
415 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc
);
417 rc
=IDirectSoundBuffer_SetVolume(*dsbo
,volume
);
418 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume() failed: %08x\n", rc
);
420 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
421 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&volume
);
422 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetVolume() "
423 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
428 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLPAN
) {
430 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&val
);
431 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan() failed: %08x\n", rc
);
433 rc
=IDirectSoundBuffer_SetPan(*dsbo
,pan
);
434 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan() failed: %08x\n", rc
);
436 /* DSOUND: Error: Buffer does not have CTRLPAN */
437 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&pan
);
438 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
439 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
443 /* try an offset past the end of the buffer */
444 rc
= IDirectSoundBuffer_Lock(*dsbo
, dsbcaps
.dwBufferBytes
, 0, &buffer1
,
445 &length1
, NULL
, NULL
,
446 DSBLOCK_ENTIREBUFFER
);
447 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
448 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
450 /* try a size larger than the buffer */
451 rc
= IDirectSoundBuffer_Lock(*dsbo
, 0, dsbcaps
.dwBufferBytes
+ 1,
452 &buffer1
, &length1
, NULL
, NULL
,
453 DSBLOCK_FROMWRITECURSOR
);
454 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
455 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
457 state
.wave
=wave_generate_la(&wfx
,duration
,&state
.wave_len
,ieee
);
461 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
462 state
.played
=state
.written
=state
.offset
=0;
463 buffer_refill8(&state
,state
.buffer_size
);
465 rc
=IDirectSoundBuffer_Play(*dsbo
,0,0,DSBPLAY_LOOPING
);
466 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play() failed: %08x\n", rc
);
468 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
469 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc
);
470 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
471 "GetStatus: bad status: %x\n",status
);
474 ZeroMemory(&listener_param
,sizeof(listener_param
));
475 listener_param
.dwSize
=sizeof(listener_param
);
476 rc
=IDirectSound3DListener_GetAllParameters(listener
,&listener_param
);
477 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
478 "failed: %08x\n",rc
);
480 listener_param
.vPosition
.x
= -5.0f
;
481 listener_param
.vVelocity
.x
= (float)(10.0/duration
);
483 rc
=IDirectSound3DListener_SetAllParameters(listener
,
486 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n", rc
);
490 buffer_param
.vPosition
.x
= 100.0f
;
491 buffer_param
.vVelocity
.x
= (float)(-200.0/duration
);
493 buffer_param
.flMinDistance
= 10;
494 rc
=IDirectSound3DBuffer_SetAllParameters(buffer
,&buffer_param
,
496 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
499 start_time
=GetTickCount();
500 while (buffer_service8(&state
)) {
501 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
);
503 if (listener
&& move_listener
) {
504 listener_param
.vPosition
.x
= (float)(-5.0+10.0*(now
-start_time
)/1000/duration
);
505 if (winetest_debug
>2)
506 trace("listener position=%g\n",listener_param
.vPosition
.x
);
507 rc
=IDirectSound3DListener_SetPosition(listener
,
508 listener_param
.vPosition
.x
,listener_param
.vPosition
.y
,
509 listener_param
.vPosition
.z
,DS3D_IMMEDIATE
);
510 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n",rc
);
512 if (buffer3d
&& move_sound
) {
513 buffer_param
.vPosition
.x
= (float)(100-200.0*(now
-start_time
)/1000/duration
);
514 if (winetest_debug
>2)
515 trace("sound position=%g\n",buffer_param
.vPosition
.x
);
516 rc
=IDirectSound3DBuffer_SetPosition(buffer
,
517 buffer_param
.vPosition
.x
,buffer_param
.vPosition
.y
,
518 buffer_param
.vPosition
.z
,DS3D_IMMEDIATE
);
519 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
522 /* Check the sound duration was within 10% of the expected value */
524 ok(fabs(1000*duration
-now
+start_time
)<=100*duration
,
525 "The sound played for %d ms instead of %g ms\n",
526 now
-start_time
,1000*duration
);
528 HeapFree(GetProcessHeap(), 0, state
.wave
);
530 /* Set the CooperativeLevel back to normal */
531 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
532 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
533 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
534 "failed: %08x\n",rc
);
537 ref
=IDirectSound3DBuffer_Release(buffer
);
538 ok(ref
==0,"IDirectSound3DBuffer_Release() has %d references, "
539 "should have 0\n",ref
);
544 static HRESULT
test_secondary8(LPGUID lpGuid
, BOOL play
,
545 BOOL has_3d
, BOOL has_3dbuffer
,
546 BOOL has_listener
, BOOL has_duplicate
,
547 BOOL move_listener
, BOOL move_sound
)
550 LPDIRECTSOUND8 dso
=NULL
;
551 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
552 LPDIRECTSOUND3DLISTENER listener
=NULL
;
553 DSBUFFERDESC bufdesc
;
554 WAVEFORMATEX wfx
, wfx1
;
557 /* Create the DirectSound object */
558 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
559 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
563 /* We must call SetCooperativeLevel before creating primary buffer */
564 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
565 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
566 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
570 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
571 bufdesc
.dwSize
=sizeof(bufdesc
);
572 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
574 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
576 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
577 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
578 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
579 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: %08x\n",has_3d
?"3D ":"", rc
);
580 if (rc
== DSERR_CONTROLUNAVAIL
)
581 trace(" No Primary\n");
582 else if (rc
==DS_OK
&& primary
!=NULL
) {
583 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
584 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
589 rc
=IDirectSoundBuffer_QueryInterface(primary
,
590 &IID_IDirectSound3DListener
,
592 ok(rc
==DS_OK
&& listener
!=NULL
,
593 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
594 "listener %08x\n",rc
);
595 ref
=IDirectSoundBuffer_Release(primary
);
596 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
597 "should have 0\n",ref
);
598 if (rc
==DS_OK
&& listener
!=NULL
) {
599 DS3DLISTENER listener_param
;
600 ZeroMemory(&listener_param
,sizeof(listener_param
));
601 /* DSOUND: Error: Invalid buffer */
602 rc
=IDirectSound3DListener_GetAllParameters(listener
,0);
603 ok(rc
==DSERR_INVALIDPARAM
,
604 "IDirectSound3dListener_GetAllParameters() should have "
605 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
607 /* DSOUND: Error: Invalid buffer */
608 rc
=IDirectSound3DListener_GetAllParameters(listener
,
610 ok(rc
==DSERR_INVALIDPARAM
,
611 "IDirectSound3dListener_GetAllParameters() should have "
612 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
614 listener_param
.dwSize
=sizeof(listener_param
);
615 rc
=IDirectSound3DListener_GetAllParameters(listener
,
617 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
618 "failed: %08x\n",rc
);
620 ok(listener
==NULL
, "IDirectSoundBuffer_QueryInterface() "
621 "failed but returned a listener anyway\n");
622 ok(rc
!=DS_OK
, "IDirectSoundBuffer_QueryInterface() succeeded "
623 "but returned a NULL listener\n");
625 ref
=IDirectSound3DListener_Release(listener
);
626 ok(ref
==0,"IDirectSound3dListener_Release() listener has "
627 "%d references, should have 0\n",ref
);
633 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,2);
635 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
636 bufdesc
.dwSize
=sizeof(bufdesc
);
637 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
639 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
642 (DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
643 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
645 bufdesc
.lpwfxFormat
=&wfx
;
647 /* a stereo 3D buffer should fail */
648 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
649 ok(rc
==DSERR_INVALIDPARAM
,
650 "IDirectSound8_CreateSoundBuffer(secondary) should have "
651 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
654 ref
=IDirectSoundBuffer_Release(secondary
);
655 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, should have 0\n",ref
);
657 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,1);
660 if (winetest_interactive
) {
661 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
662 "with a primary buffer at %dx%dx%d\n",
663 has_3dbuffer
?"3D ":"",
664 has_duplicate
?"duplicated ":"",
665 listener
!=NULL
||move_sound
?"with ":"",
666 move_listener
?"moving ":"",
667 listener
!=NULL
?"listener ":"",
668 listener
&&move_sound
?"and moving sound ":move_sound
?
670 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
671 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
673 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
674 ok(rc
==DS_OK
&& secondary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
675 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %08x\n",
676 has_3dbuffer
?"3D ":"", has_duplicate
?"duplicated ":"",
677 listener
!=NULL
||move_sound
?"with ":"", move_listener
?"moving ":"",
678 listener
!=NULL
?"listener ":"",
679 listener
&&move_sound
?"and moving sound ":move_sound
?
681 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
682 getDSBCAPS(bufdesc
.dwFlags
),rc
);
683 if (rc
==DS_OK
&& secondary
!=NULL
) {
685 LONG refvol
,vol
,refpan
,pan
;
687 /* Check the initial secondary buffer's volume and pan */
688 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
689 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(secondary) failed: %08x\n",rc
);
690 ok(vol
==0,"wrong volume for a new secondary buffer: %d\n",vol
);
691 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
692 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc
);
693 ok(pan
==0,"wrong pan for a new secondary buffer: %d\n",pan
);
695 /* Check that changing the secondary buffer's volume and pan
696 * does not impact the primary buffer's volume and pan
698 rc
=IDirectSoundBuffer_GetVolume(primary
,&refvol
);
699 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc
);
700 rc
=IDirectSoundBuffer_GetPan(primary
,&refpan
);
701 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
703 rc
=IDirectSoundBuffer_SetVolume(secondary
,-1000);
704 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
705 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
706 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
707 ok(vol
==-1000,"secondary: wrong volume %d instead of -1000\n",
709 rc
=IDirectSoundBuffer_SetPan(secondary
,-1000);
710 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
711 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
712 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc
);
713 ok(pan
==-1000,"secondary: wrong pan %d instead of -1000\n",
716 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
717 ok(rc
==DS_OK
,"IDirectSoundBuffer_`GetVolume(primary) failed: i%08x\n",rc
);
718 ok(vol
==refvol
,"The primary volume changed from %d to %d\n",
720 rc
=IDirectSoundBuffer_GetPan(primary
,&pan
);
721 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
722 ok(pan
==refpan
,"The primary pan changed from %d to %d\n",
725 rc
=IDirectSoundBuffer_SetVolume(secondary
,0);
726 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
727 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
728 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
731 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
733 /* DSOUND: Error: Invalid source buffer */
734 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,0);
735 ok(rc
==DSERR_INVALIDPARAM
,
736 "IDirectSound8_DuplicateSoundBuffer() should have returned "
737 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
739 /* DSOUND: Error: Invalid dest buffer */
740 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,0);
741 ok(rc
==DSERR_INVALIDPARAM
,
742 "IDirectSound8_DuplicateSoundBuffer() should have returned "
743 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
745 /* DSOUND: Error: Invalid source buffer */
746 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,&duplicated
);
747 ok(rc
==DSERR_INVALIDPARAM
,
748 "IDirectSound8_DuplicateSoundBuffer() should have returned "
749 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
752 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,
754 ok(rc
==DS_OK
&& duplicated
!=NULL
,
755 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
756 "a secondary buffer: %08x\n",rc
);
758 if (rc
==DS_OK
&& duplicated
!=NULL
) {
759 ref
=IDirectSoundBuffer_Release(secondary
);
760 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d "
761 "references, should have 0\n",ref
);
762 secondary
=duplicated
;
766 if (rc
==DS_OK
&& secondary
!=NULL
) {
768 duration
=(move_listener
|| move_sound
?4.0:1.0);
769 test_buffer8(dso
,&secondary
,FALSE
,FALSE
,0,FALSE
,0,
770 winetest_interactive
,duration
,has_3dbuffer
,
771 listener
,move_listener
,move_sound
);
772 ref
=IDirectSoundBuffer_Release(secondary
);
773 ok(ref
==0,"IDirectSoundBuffer_Release() %s has %d references, "
774 "should have 0\n",has_duplicate
?"duplicated":"secondary",
781 ref
=IDirectSound3DListener_Release(listener
);
782 ok(ref
==0,"IDirectSound3dListener_Release() listener has %d "
783 "references, should have 0\n",ref
);
786 ref
=IDirectSoundBuffer_Release(primary
);
787 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
788 "should have 0\n",ref
);
791 ok(primary
==NULL
,"IDirectSound8_CreateSoundBuffer(primary) failed "
792 "but primary created anyway\n");
793 ok(rc
!=DS_OK
,"IDirectSound8_CreateSoundBuffer(primary) succeeded "
794 "but primary not created\n");
796 ref
=IDirectSoundBuffer_Release(primary
);
797 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
798 "should have 0\n",ref
);
802 /* Set the CooperativeLevel back to normal */
803 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
804 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
805 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
808 ref
=IDirectSound8_Release(dso
);
809 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
811 return DSERR_GENERIC
;
816 static HRESULT
test_for_driver8(LPGUID lpGuid
)
819 LPDIRECTSOUND8 dso
=NULL
;
822 /* Create the DirectSound object */
823 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
824 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
825 "DirectSoundCreate8() failed: %08x\n",rc
);
829 ref
=IDirectSound8_Release(dso
);
830 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
832 return DSERR_GENERIC
;
837 static HRESULT
test_primary8(LPGUID lpGuid
)
840 LPDIRECTSOUND8 dso
=NULL
;
841 LPDIRECTSOUNDBUFFER primary
=NULL
;
842 DSBUFFERDESC bufdesc
;
846 /* Create the DirectSound object */
847 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
848 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
852 /* Get the device capabilities */
853 ZeroMemory(&dscaps
, sizeof(dscaps
));
854 dscaps
.dwSize
=sizeof(dscaps
);
855 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
856 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
860 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
861 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
862 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
863 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
867 /* Testing the primary buffer */
869 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
870 bufdesc
.dwSize
=sizeof(bufdesc
);
871 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
;
872 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
873 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
874 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc
);
875 if (rc
== DSERR_CONTROLUNAVAIL
)
876 trace(" No Primary\n");
877 else if (rc
==DS_OK
&& primary
!=NULL
) {
878 test_buffer8(dso
,&primary
,TRUE
,TRUE
,0,TRUE
,0,
879 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
880 1.0,FALSE
,NULL
,FALSE
,FALSE
);
881 if (winetest_interactive
) {
884 volume
= DSBVOLUME_MAX
;
885 for (i
= 0; i
< 6; i
++) {
886 test_buffer8(dso
,&primary
,TRUE
,TRUE
,volume
,TRUE
,0,
887 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
888 1.0,FALSE
,NULL
,FALSE
,FALSE
);
889 volume
-= ((DSBVOLUME_MAX
-DSBVOLUME_MIN
) / 40);
893 for (i
= 0; i
< 7; i
++) {
894 test_buffer8(dso
,&primary
,TRUE
,TRUE
,0,TRUE
,pan
,
895 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
896 1.0,FALSE
,NULL
,FALSE
,FALSE
);
897 pan
+= ((DSBPAN_RIGHT
-DSBPAN_LEFT
) / 6);
900 ref
=IDirectSoundBuffer_Release(primary
);
901 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
902 "should have 0\n",ref
);
905 /* Set the CooperativeLevel back to normal */
906 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
907 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
908 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
911 ref
=IDirectSound8_Release(dso
);
912 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
914 return DSERR_GENERIC
;
919 static HRESULT
test_primary_3d8(LPGUID lpGuid
)
922 LPDIRECTSOUND8 dso
=NULL
;
923 LPDIRECTSOUNDBUFFER primary
=NULL
;
924 DSBUFFERDESC bufdesc
;
928 /* Create the DirectSound object */
929 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
930 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
934 /* Get the device capabilities */
935 ZeroMemory(&dscaps
, sizeof(dscaps
));
936 dscaps
.dwSize
=sizeof(dscaps
);
937 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
938 ok(rc
==DS_OK
,"IDirectSound8_GetCaps failed: %08x\n",rc
);
942 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
943 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
944 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
945 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
950 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
951 bufdesc
.dwSize
=sizeof(bufdesc
);
952 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
953 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
954 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
955 "to create a primary buffer: %08x\n",rc
);
956 if (rc
==DS_OK
&& primary
!=NULL
) {
957 ref
=IDirectSoundBuffer_Release(primary
);
958 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
959 "should have 0\n",ref
);
961 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
962 bufdesc
.dwSize
=sizeof(bufdesc
);
963 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
964 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
965 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
966 "failed to create a 3D primary buffer: %08x\n",rc
);
967 if (rc
==DS_OK
&& primary
!=NULL
) {
968 test_buffer8(dso
,&primary
,TRUE
,FALSE
,0,FALSE
,0,
969 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
970 1.0,FALSE
,NULL
,FALSE
,FALSE
);
971 ref
=IDirectSoundBuffer_Release(primary
);
972 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
973 "should have 0\n",ref
);
976 /* Set the CooperativeLevel back to normal */
977 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
978 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
979 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
982 ref
=IDirectSound8_Release(dso
);
983 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
985 return DSERR_GENERIC
;
990 static HRESULT
test_primary_3d_with_listener8(LPGUID lpGuid
)
993 LPDIRECTSOUND8 dso
=NULL
;
994 LPDIRECTSOUNDBUFFER primary
=NULL
;
995 DSBUFFERDESC bufdesc
;
999 /* Create the DirectSound object */
1000 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
1001 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
1005 /* Get the device capabilities */
1006 ZeroMemory(&dscaps
, sizeof(dscaps
));
1007 dscaps
.dwSize
=sizeof(dscaps
);
1008 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
1009 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
1013 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1014 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1015 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1016 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
1020 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1021 bufdesc
.dwSize
=sizeof(bufdesc
);
1022 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1023 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1024 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
1025 "to create a 3D primary buffer %08x\n",rc
);
1026 if (rc
==DS_OK
&& primary
!=NULL
) {
1027 LPDIRECTSOUND3DLISTENER listener
=NULL
;
1028 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1029 &IID_IDirectSound3DListener
,
1030 (void **)&listener
);
1031 ok(rc
==DS_OK
&& listener
!=NULL
,"IDirectSoundBuffer_QueryInterface() "
1032 "failed to get a 3D listener: %08x\n",rc
);
1033 if (rc
==DS_OK
&& listener
!=NULL
) {
1034 LPDIRECTSOUNDBUFFER temp_buffer
=NULL
;
1036 /* Checking the COM interface */
1037 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1038 &IID_IDirectSoundBuffer
,
1039 (LPVOID
*)&temp_buffer
);
1040 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1041 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1042 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1043 if (rc
==DS_OK
&& temp_buffer
!=NULL
) {
1044 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1045 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1046 "should have 1\n",ref
);
1049 rc
=IDirectSound3DListener_QueryInterface(listener
,
1050 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1051 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1052 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1053 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1054 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1055 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1056 "should have 1\n",ref
);
1058 /* Testing the buffer */
1059 test_buffer8(dso
,&primary
,TRUE
,FALSE
,0,FALSE
,0,
1060 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
1061 1.0,FALSE
,listener
,FALSE
,FALSE
);
1064 /* Testing the reference counting */
1065 ref
=IDirectSound3DListener_Release(listener
);
1066 ok(ref
==0,"IDirectSound3DListener_Release() listener has %d "
1067 "references, should have 0\n",ref
);
1070 /* Testing the reference counting */
1071 ref
=IDirectSoundBuffer_Release(primary
);
1072 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1073 "should have 0\n",ref
);
1077 ref
=IDirectSound8_Release(dso
);
1078 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
1080 return DSERR_GENERIC
;
1085 static unsigned driver_count
= 0;
1087 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1088 LPCSTR lpcstrModule
, LPVOID lpContext
)
1091 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1094 rc
= test_for_driver8(lpGuid
);
1095 if (rc
== DSERR_NODRIVER
) {
1096 trace(" No Driver\n");
1098 } else if (rc
== DSERR_ALLOCATED
) {
1099 trace(" Already In Use\n");
1101 } else if (rc
== E_FAIL
) {
1102 trace(" No Device\n");
1106 trace(" Testing the primary buffer\n");
1107 test_primary8(lpGuid
);
1109 trace(" Testing 3D primary buffer\n");
1110 test_primary_3d8(lpGuid
);
1112 trace(" Testing 3D primary buffer with listener\n");
1113 test_primary_3d_with_listener8(lpGuid
);
1115 /* Testing secondary buffers */
1116 test_secondary8(lpGuid
,winetest_interactive
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
);
1117 test_secondary8(lpGuid
,winetest_interactive
,FALSE
,FALSE
,FALSE
,TRUE
, FALSE
,FALSE
);
1119 /* Testing 3D secondary buffers */
1120 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,FALSE
,FALSE
,FALSE
,FALSE
);
1121 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, FALSE
,FALSE
,FALSE
,FALSE
);
1122 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, FALSE
,TRUE
, FALSE
,FALSE
);
1123 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,TRUE
, FALSE
,FALSE
,FALSE
);
1124 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,TRUE
, TRUE
, FALSE
,FALSE
);
1125 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,FALSE
,FALSE
);
1126 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, TRUE
, FALSE
,FALSE
);
1127 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,TRUE
, FALSE
);
1128 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,FALSE
,TRUE
);
1129 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,TRUE
, TRUE
);
1134 static void ds3d8_tests(void)
1137 rc
=pDirectSoundEnumerateA(&dsenum_callback
,NULL
);
1138 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %08x\n",rc
);
1139 trace("tested %u DirectSound drivers\n", driver_count
);
1148 hDsound
= LoadLibraryA("dsound.dll");
1152 pDirectSoundEnumerateA
= (void*)GetProcAddress(hDsound
,
1153 "DirectSoundEnumerateA");
1154 pDirectSoundCreate8
= (void*)GetProcAddress(hDsound
,
1155 "DirectSoundCreate8");
1156 if (pDirectSoundCreate8
)
1159 skip("DirectSoundCreate8 missing - skipping all tests\n");
1161 FreeLibrary(hDsound
);
1164 skip("dsound.dll not found - skipping all tests\n");