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 int 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
);
227 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
228 if (rc
==DS_OK
&& winetest_debug
> 1) {
229 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
230 is_primary
? "Primary" : "Secondary",
231 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
232 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
235 /* DSOUND: Error: Invalid frequency buffer */
236 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,0);
237 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetFrequency() should have "
238 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
240 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
241 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,&freq
);
242 ok((rc
==DS_OK
&& !is_primary
) || (rc
==DSERR_CONTROLUNAVAIL
&&is_primary
) ||
243 (rc
==DSERR_CONTROLUNAVAIL
&&!(dsbcaps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
)),
244 "IDirectSoundBuffer_GetFrequency() failed: %08x\n",rc
);
246 ok(freq
==wfx
.nSamplesPerSec
,"The frequency returned by GetFrequency "
247 "%d does not match the format %d\n",freq
,wfx
.nSamplesPerSec
);
250 /* DSOUND: Error: Invalid status pointer */
251 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,0);
252 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetStatus() should have "
253 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
255 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
256 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc
);
257 ok(status
==0,"status=0x%x instead of 0\n",status
);
261 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
262 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
263 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
264 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
265 "failed: %08x\n",rc
);
269 /* DSOUND: Error: Invalid format pointer */
270 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,0);
271 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_SetFormat() should have "
272 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc
);
274 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
275 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,&wfx2
);
276 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
277 format_string(&wfx2
), rc
);
279 /* There is no guarantee that SetFormat will actually change the
280 * format to what we asked for. It depends on what the soundcard
281 * supports. So we must re-query the format.
283 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,&wfx
,sizeof(wfx
),NULL
);
284 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc
);
286 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
287 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
288 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
289 wfx
.nChannels
!=wfx2
.nChannels
)) {
290 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
291 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
292 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
293 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
294 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
295 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
298 ZeroMemory(&new_dsbcaps
, sizeof(new_dsbcaps
));
299 new_dsbcaps
.dwSize
= sizeof(new_dsbcaps
);
300 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&new_dsbcaps
);
301 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc
);
302 if (rc
==DS_OK
&& winetest_debug
> 1) {
303 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps
.dwFlags
,
304 new_dsbcaps
.dwBufferBytes
);
307 /* Check for primary buffer size change */
308 ok(new_dsbcaps
.dwBufferBytes
== dsbcaps
.dwBufferBytes
,
309 " buffer size changed after SetFormat() - "
310 "previous size was %u, current size is %u\n",
311 dsbcaps
.dwBufferBytes
, new_dsbcaps
.dwBufferBytes
);
312 dsbcaps
.dwBufferBytes
= new_dsbcaps
.dwBufferBytes
;
314 /* Check for primary buffer flags change */
315 ok(new_dsbcaps
.dwFlags
== dsbcaps
.dwFlags
,
316 " flags changed after SetFormat() - "
317 "previous flags were %08x, current flags are %08x\n",
318 dsbcaps
.dwFlags
, new_dsbcaps
.dwFlags
);
320 /* Set the CooperativeLevel back to normal */
321 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
322 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
323 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
324 "failed: %08x\n",rc
);
329 DS3DLISTENER listener_param
;
330 LPDIRECTSOUND3DBUFFER buffer
=NULL
;
331 DS3DBUFFER buffer_param
;
332 DWORD start_time
,now
;
336 if (winetest_interactive
) {
337 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration
,
338 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
,wfx
.nChannels
);
342 /* We must call SetCooperativeLevel to be allowed to call Lock */
343 /* DSOUND: Setting DirectSound cooperative level to
344 * DSSCL_WRITEPRIMARY */
345 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),
348 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: %08x\n",rc
);
353 LPDIRECTSOUNDBUFFER temp_buffer
;
355 rc
=IDirectSoundBuffer_QueryInterface(*dsbo
,&IID_IDirectSound3DBuffer
,
357 ok(rc
==DS_OK
,"IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
361 /* check the COM interface */
362 rc
=IDirectSoundBuffer_QueryInterface(*dsbo
, &IID_IDirectSoundBuffer
,
363 (LPVOID
*)&temp_buffer
);
364 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
365 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
366 ok(temp_buffer
==*dsbo
,"COM interface broken: %p != %p\n",
368 ref
=IDirectSoundBuffer_Release(temp_buffer
);
369 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
370 "should have 1\n",ref
);
373 rc
=IDirectSound3DBuffer_QueryInterface(*dsbo
, &IID_IDirectSoundBuffer
,
374 (LPVOID
*)&temp_buffer
);
375 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
376 "IDirectSound3DBuffer_QueryInterface() failed: %08x\n", rc
);
377 ok(temp_buffer
==*dsbo
,"COM interface broken: %p != %p\n",
379 ref
=IDirectSoundBuffer_Release(temp_buffer
);
380 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
381 "should have 1\n",ref
);
383 ref
=IDirectSoundBuffer_Release(*dsbo
);
384 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
385 "should have 0\n",ref
);
387 rc
=IDirectSound3DBuffer_QueryInterface(buffer
,
388 &IID_IDirectSoundBuffer
,
390 ok(rc
==DS_OK
&& *dsbo
!=NULL
,"IDirectSound3DBuffer_QueryInterface() "
391 "failed: %08x\n",rc
);
393 /* DSOUND: Error: Invalid buffer */
394 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,0);
395 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
396 "failed: %08x\n",rc
);
398 ZeroMemory(&buffer_param
, sizeof(buffer_param
));
400 /* DSOUND: Error: Invalid buffer */
401 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
402 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
403 "failed: %08x\n",rc
);
405 buffer_param
.dwSize
=sizeof(buffer_param
);
406 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
407 ok(rc
==DS_OK
,"IDirectSound3DBuffer_GetAllParameters() failed: %08x\n", rc
);
410 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
412 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&val
);
413 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc
);
415 rc
=IDirectSoundBuffer_SetVolume(*dsbo
,volume
);
416 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume() failed: %08x\n", rc
);
418 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
419 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&volume
);
420 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetVolume() "
421 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
426 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLPAN
) {
428 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&val
);
429 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan() failed: %08x\n", rc
);
431 rc
=IDirectSoundBuffer_SetPan(*dsbo
,pan
);
432 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan() failed: %08x\n", rc
);
434 /* DSOUND: Error: Buffer does not have CTRLPAN */
435 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&pan
);
436 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
437 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
441 /* try an offset past the end of the buffer */
442 rc
= IDirectSoundBuffer_Lock(*dsbo
, dsbcaps
.dwBufferBytes
, 0, &buffer1
,
443 &length1
, NULL
, NULL
,
444 DSBLOCK_ENTIREBUFFER
);
445 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
446 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
448 /* try a size larger than the buffer */
449 rc
= IDirectSoundBuffer_Lock(*dsbo
, 0, dsbcaps
.dwBufferBytes
+ 1,
450 &buffer1
, &length1
, NULL
, NULL
,
451 DSBLOCK_FROMWRITECURSOR
);
452 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
453 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
455 state
.wave
=wave_generate_la(&wfx
,duration
,&state
.wave_len
,ieee
);
459 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
460 state
.played
=state
.written
=state
.offset
=0;
461 buffer_refill8(&state
,state
.buffer_size
);
463 rc
=IDirectSoundBuffer_Play(*dsbo
,0,0,DSBPLAY_LOOPING
);
464 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play() failed: %08x\n", rc
);
466 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
467 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc
);
468 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
469 "GetStatus: bad status: %x\n",status
);
472 ZeroMemory(&listener_param
,sizeof(listener_param
));
473 listener_param
.dwSize
=sizeof(listener_param
);
474 rc
=IDirectSound3DListener_GetAllParameters(listener
,&listener_param
);
475 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
476 "failed: %08x\n",rc
);
478 listener_param
.vPosition
.x
= -5.0f
;
479 listener_param
.vVelocity
.x
= (float)(10.0/duration
);
481 rc
=IDirectSound3DListener_SetAllParameters(listener
,
484 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n", rc
);
488 buffer_param
.vPosition
.x
= 100.0f
;
489 buffer_param
.vVelocity
.x
= (float)(-200.0/duration
);
491 buffer_param
.flMinDistance
= 10;
492 rc
=IDirectSound3DBuffer_SetAllParameters(buffer
,&buffer_param
,
494 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
497 start_time
=GetTickCount();
498 while (buffer_service8(&state
)) {
499 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
);
501 if (listener
&& move_listener
) {
502 listener_param
.vPosition
.x
= (float)(-5.0+10.0*(now
-start_time
)/1000/duration
);
503 if (winetest_debug
>2)
504 trace("listener position=%g\n",listener_param
.vPosition
.x
);
505 rc
=IDirectSound3DListener_SetPosition(listener
,
506 listener_param
.vPosition
.x
,listener_param
.vPosition
.y
,
507 listener_param
.vPosition
.z
,DS3D_IMMEDIATE
);
508 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n",rc
);
510 if (buffer3d
&& move_sound
) {
511 buffer_param
.vPosition
.x
= (float)(100-200.0*(now
-start_time
)/1000/duration
);
512 if (winetest_debug
>2)
513 trace("sound position=%g\n",buffer_param
.vPosition
.x
);
514 rc
=IDirectSound3DBuffer_SetPosition(buffer
,
515 buffer_param
.vPosition
.x
,buffer_param
.vPosition
.y
,
516 buffer_param
.vPosition
.z
,DS3D_IMMEDIATE
);
517 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
520 /* Check the sound duration was within 10% of the expected value */
522 ok(fabs(1000*duration
-now
+start_time
)<=100*duration
,
523 "The sound played for %d ms instead of %g ms\n",
524 now
-start_time
,1000*duration
);
526 HeapFree(GetProcessHeap(), 0, state
.wave
);
528 /* Set the CooperativeLevel back to normal */
529 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
530 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
531 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
532 "failed: %08x\n",rc
);
535 ref
=IDirectSound3DBuffer_Release(buffer
);
536 ok(ref
==0,"IDirectSound3DBuffer_Release() has %d references, "
537 "should have 0\n",ref
);
542 static HRESULT
test_secondary8(LPGUID lpGuid
, int play
,
543 int has_3d
, int has_3dbuffer
,
544 int has_listener
, int has_duplicate
,
545 int move_listener
, int move_sound
)
548 LPDIRECTSOUND8 dso
=NULL
;
549 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
550 LPDIRECTSOUND3DLISTENER listener
=NULL
;
551 DSBUFFERDESC bufdesc
;
552 WAVEFORMATEX wfx
, wfx1
;
555 /* Create the DirectSound object */
556 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
557 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
561 /* We must call SetCooperativeLevel before creating primary buffer */
562 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
563 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
564 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
568 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
569 bufdesc
.dwSize
=sizeof(bufdesc
);
570 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
572 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
574 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
575 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
576 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
577 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: %08x\n",has_3d
?"3D ":"", rc
);
578 if (rc
== DSERR_CONTROLUNAVAIL
)
579 trace(" No Primary\n");
580 else if (rc
==DS_OK
&& primary
!=NULL
) {
581 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
582 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
587 rc
=IDirectSoundBuffer_QueryInterface(primary
,
588 &IID_IDirectSound3DListener
,
590 ok(rc
==DS_OK
&& listener
!=NULL
,
591 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
592 "listener %08x\n",rc
);
593 ref
=IDirectSoundBuffer_Release(primary
);
594 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
595 "should have 0\n",ref
);
596 if (rc
==DS_OK
&& listener
!=NULL
) {
597 DS3DLISTENER listener_param
;
598 ZeroMemory(&listener_param
,sizeof(listener_param
));
599 /* DSOUND: Error: Invalid buffer */
600 rc
=IDirectSound3DListener_GetAllParameters(listener
,0);
601 ok(rc
==DSERR_INVALIDPARAM
,
602 "IDirectSound3dListener_GetAllParameters() should have "
603 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
605 /* DSOUND: Error: Invalid buffer */
606 rc
=IDirectSound3DListener_GetAllParameters(listener
,
608 ok(rc
==DSERR_INVALIDPARAM
,
609 "IDirectSound3dListener_GetAllParameters() should have "
610 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
612 listener_param
.dwSize
=sizeof(listener_param
);
613 rc
=IDirectSound3DListener_GetAllParameters(listener
,
615 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
616 "failed: %08x\n",rc
);
618 ok(listener
==NULL
, "IDirectSoundBuffer_QueryInterface() "
619 "failed but returned a listener anyway\n");
620 ok(rc
!=DS_OK
, "IDirectSoundBuffer_QueryInterface() succeeded "
621 "but returned a NULL listener\n");
623 ref
=IDirectSound3DListener_Release(listener
);
624 ok(ref
==0,"IDirectSound3dListener_Release() listener has "
625 "%d references, should have 0\n",ref
);
631 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,2);
633 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
634 bufdesc
.dwSize
=sizeof(bufdesc
);
635 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
637 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
640 (DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
641 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
643 bufdesc
.lpwfxFormat
=&wfx
;
645 /* a stereo 3D buffer should fail */
646 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
647 ok(rc
==DSERR_INVALIDPARAM
,
648 "IDirectSound8_CreateSoundBuffer(secondary) should have "
649 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
652 ref
=IDirectSoundBuffer_Release(secondary
);
653 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, should have 0\n",ref
);
655 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,1);
658 if (winetest_interactive
) {
659 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
660 "with a primary buffer at %dx%dx%d\n",
661 has_3dbuffer
?"3D ":"",
662 has_duplicate
?"duplicated ":"",
663 listener
!=NULL
||move_sound
?"with ":"",
664 move_listener
?"moving ":"",
665 listener
!=NULL
?"listener ":"",
666 listener
&&move_sound
?"and moving sound ":move_sound
?
668 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
669 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
671 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
672 ok(rc
==DS_OK
&& secondary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
673 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %08x\n",
674 has_3dbuffer
?"3D ":"", has_duplicate
?"duplicated ":"",
675 listener
!=NULL
||move_sound
?"with ":"", move_listener
?"moving ":"",
676 listener
!=NULL
?"listener ":"",
677 listener
&&move_sound
?"and moving sound ":move_sound
?
679 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
680 getDSBCAPS(bufdesc
.dwFlags
),rc
);
681 if (rc
==DS_OK
&& secondary
!=NULL
) {
683 LONG refvol
,vol
,refpan
,pan
;
685 /* Check the initial secondary buffer's volume and pan */
686 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
687 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(secondary) failed: %08x\n",rc
);
688 ok(vol
==0,"wrong volume for a new secondary buffer: %d\n",vol
);
689 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
690 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc
);
691 ok(pan
==0,"wrong pan for a new secondary buffer: %d\n",pan
);
693 /* Check that changing the secondary buffer's volume and pan
694 * does not impact the primary buffer's volume and pan
696 rc
=IDirectSoundBuffer_GetVolume(primary
,&refvol
);
697 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc
);
698 rc
=IDirectSoundBuffer_GetPan(primary
,&refpan
);
699 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
701 rc
=IDirectSoundBuffer_SetVolume(secondary
,-1000);
702 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
703 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
704 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
705 ok(vol
==-1000,"secondary: wrong volume %d instead of -1000\n",
707 rc
=IDirectSoundBuffer_SetPan(secondary
,-1000);
708 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
709 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
710 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
711 ok(pan
==-1000,"secondary: wrong pan %d instead of -1000\n",
714 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
715 ok(rc
==DS_OK
,"IDirectSoundBuffer_`GetVolume(primary) failed: i%08x\n",rc
);
716 ok(vol
==refvol
,"The primary volume changed from %d to %d\n",
718 rc
=IDirectSoundBuffer_GetPan(primary
,&pan
);
719 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
720 ok(pan
==refpan
,"The primary pan changed from %d to %d\n",
723 rc
=IDirectSoundBuffer_SetVolume(secondary
,0);
724 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
725 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
726 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
729 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
731 /* DSOUND: Error: Invalid source buffer */
732 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,0);
733 ok(rc
==DSERR_INVALIDPARAM
,
734 "IDirectSound8_DuplicateSoundBuffer() should have returned "
735 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
737 /* DSOUND: Error: Invalid dest buffer */
738 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,0);
739 ok(rc
==DSERR_INVALIDPARAM
,
740 "IDirectSound8_DuplicateSoundBuffer() should have returned "
741 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
743 /* DSOUND: Error: Invalid source buffer */
744 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,&duplicated
);
745 ok(rc
==DSERR_INVALIDPARAM
,
746 "IDirectSound8_DuplicateSoundBuffer() should have returned "
747 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
750 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,
752 ok(rc
==DS_OK
&& duplicated
!=NULL
,
753 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
754 "a secondary buffer: %08x\n",rc
);
756 if (rc
==DS_OK
&& duplicated
!=NULL
) {
757 ref
=IDirectSoundBuffer_Release(secondary
);
758 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d "
759 "references, should have 0\n",ref
);
760 secondary
=duplicated
;
764 if (rc
==DS_OK
&& secondary
!=NULL
) {
766 duration
=(move_listener
|| move_sound
?4.0:1.0);
767 test_buffer8(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
768 winetest_interactive
,duration
,has_3dbuffer
,
769 listener
,move_listener
,move_sound
);
770 ref
=IDirectSoundBuffer_Release(secondary
);
771 ok(ref
==0,"IDirectSoundBuffer_Release() %s has %d references, "
772 "should have 0\n",has_duplicate
?"duplicated":"secondary",
779 ref
=IDirectSound3DListener_Release(listener
);
780 ok(ref
==0,"IDirectSound3dListener_Release() listener has %d "
781 "references, should have 0\n",ref
);
784 ref
=IDirectSoundBuffer_Release(primary
);
785 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
786 "should have 0\n",ref
);
789 ok(primary
==NULL
,"IDirectSound8_CreateSoundBuffer(primary) failed "
790 "but primary created anyway\n");
791 ok(rc
!=DS_OK
,"IDirectSound8_CreateSoundBuffer(primary) succeeded "
792 "but primary not created\n");
794 ref
=IDirectSoundBuffer_Release(primary
);
795 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
796 "should have 0\n",ref
);
800 /* Set the CooperativeLevel back to normal */
801 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
802 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
803 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
806 ref
=IDirectSound8_Release(dso
);
807 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
809 return DSERR_GENERIC
;
814 static HRESULT
test_for_driver8(LPGUID lpGuid
)
817 LPDIRECTSOUND8 dso
=NULL
;
820 /* Create the DirectSound object */
821 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
822 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
823 "DirectSoundCreate8() failed: %08x\n",rc
);
827 ref
=IDirectSound8_Release(dso
);
828 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
830 return DSERR_GENERIC
;
835 static HRESULT
test_primary8(LPGUID lpGuid
)
838 LPDIRECTSOUND8 dso
=NULL
;
839 LPDIRECTSOUNDBUFFER primary
=NULL
;
840 DSBUFFERDESC bufdesc
;
844 /* Create the DirectSound object */
845 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
846 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
850 /* Get the device capabilities */
851 ZeroMemory(&dscaps
, sizeof(dscaps
));
852 dscaps
.dwSize
=sizeof(dscaps
);
853 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
854 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
858 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
859 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
860 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
861 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
865 /* Testing the primary buffer */
867 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
868 bufdesc
.dwSize
=sizeof(bufdesc
);
869 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
;
870 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
871 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
872 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc
);
873 if (rc
== DSERR_CONTROLUNAVAIL
)
874 trace(" No Primary\n");
875 else if (rc
==DS_OK
&& primary
!=NULL
) {
876 test_buffer8(dso
,&primary
,1,TRUE
,0,TRUE
,0,winetest_interactive
&&
877 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,NULL
,0,0);
878 if (winetest_interactive
) {
881 volume
= DSBVOLUME_MAX
;
882 for (i
= 0; i
< 6; i
++) {
883 test_buffer8(dso
,&primary
,1,TRUE
,volume
,TRUE
,0,
884 winetest_interactive
&&
885 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
887 volume
-= ((DSBVOLUME_MAX
-DSBVOLUME_MIN
) / 40);
891 for (i
= 0; i
< 7; i
++) {
892 test_buffer8(dso
,&primary
,1,TRUE
,0,TRUE
,pan
,
893 winetest_interactive
&&
894 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0);
895 pan
+= ((DSBPAN_RIGHT
-DSBPAN_LEFT
) / 6);
898 ref
=IDirectSoundBuffer_Release(primary
);
899 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
900 "should have 0\n",ref
);
903 /* Set the CooperativeLevel back to normal */
904 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
905 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
906 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
909 ref
=IDirectSound8_Release(dso
);
910 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
912 return DSERR_GENERIC
;
917 static HRESULT
test_primary_3d8(LPGUID lpGuid
)
920 LPDIRECTSOUND8 dso
=NULL
;
921 LPDIRECTSOUNDBUFFER primary
=NULL
;
922 DSBUFFERDESC bufdesc
;
926 /* Create the DirectSound object */
927 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
928 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
932 /* Get the device capabilities */
933 ZeroMemory(&dscaps
, sizeof(dscaps
));
934 dscaps
.dwSize
=sizeof(dscaps
);
935 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
936 ok(rc
==DS_OK
,"IDirectSound8_GetCaps failed: %08x\n",rc
);
940 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
941 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
942 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
943 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
948 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
949 bufdesc
.dwSize
=sizeof(bufdesc
);
950 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
951 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
952 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
953 "to create a primary buffer: %08x\n",rc
);
954 if (rc
==DS_OK
&& primary
!=NULL
) {
955 ref
=IDirectSoundBuffer_Release(primary
);
956 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
957 "should have 0\n",ref
);
959 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
960 bufdesc
.dwSize
=sizeof(bufdesc
);
961 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
962 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
963 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
964 "failed to create a 3D primary buffer: %08x\n",rc
);
965 if (rc
==DS_OK
&& primary
!=NULL
) {
966 test_buffer8(dso
,&primary
,1,FALSE
,0,FALSE
,0,
967 winetest_interactive
&&
968 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0);
969 ref
=IDirectSoundBuffer_Release(primary
);
970 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
971 "should have 0\n",ref
);
974 /* Set the CooperativeLevel back to normal */
975 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
976 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
977 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
980 ref
=IDirectSound8_Release(dso
);
981 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
983 return DSERR_GENERIC
;
988 static HRESULT
test_primary_3d_with_listener8(LPGUID lpGuid
)
991 LPDIRECTSOUND8 dso
=NULL
;
992 LPDIRECTSOUNDBUFFER primary
=NULL
;
993 DSBUFFERDESC bufdesc
;
997 /* Create the DirectSound object */
998 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
999 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
1003 /* Get the device capabilities */
1004 ZeroMemory(&dscaps
, sizeof(dscaps
));
1005 dscaps
.dwSize
=sizeof(dscaps
);
1006 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
1007 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
1011 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1012 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1013 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1014 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
1018 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1019 bufdesc
.dwSize
=sizeof(bufdesc
);
1020 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1021 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1022 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
1023 "to create a 3D primary buffer %08x\n",rc
);
1024 if (rc
==DS_OK
&& primary
!=NULL
) {
1025 LPDIRECTSOUND3DLISTENER listener
=NULL
;
1026 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1027 &IID_IDirectSound3DListener
,
1028 (void **)&listener
);
1029 ok(rc
==DS_OK
&& listener
!=NULL
,"IDirectSoundBuffer_QueryInterface() "
1030 "failed to get a 3D listener: %08x\n",rc
);
1031 if (rc
==DS_OK
&& listener
!=NULL
) {
1032 LPDIRECTSOUNDBUFFER temp_buffer
=NULL
;
1034 /* Checking the COM interface */
1035 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1036 &IID_IDirectSoundBuffer
,
1037 (LPVOID
*)&temp_buffer
);
1038 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1039 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1040 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1041 if (rc
==DS_OK
&& temp_buffer
!=NULL
) {
1042 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1043 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1044 "should have 1\n",ref
);
1047 rc
=IDirectSound3DListener_QueryInterface(listener
,
1048 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1049 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1050 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1051 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1052 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1053 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1054 "should have 1\n",ref
);
1056 /* Testing the buffer */
1057 test_buffer8(dso
,&primary
,1,FALSE
,0,FALSE
,0,
1058 winetest_interactive
&&
1059 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
1060 1.0,0,listener
,0,0);
1063 /* Testing the reference counting */
1064 ref
=IDirectSound3DListener_Release(listener
);
1065 ok(ref
==0,"IDirectSound3DListener_Release() listener has %d "
1066 "references, should have 0\n",ref
);
1069 /* Testing the reference counting */
1070 ref
=IDirectSoundBuffer_Release(primary
);
1071 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1072 "should have 0\n",ref
);
1076 ref
=IDirectSound8_Release(dso
);
1077 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
1079 return DSERR_GENERIC
;
1084 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1085 LPCSTR lpcstrModule
, LPVOID lpContext
)
1088 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1090 rc
= test_for_driver8(lpGuid
);
1091 if (rc
== DSERR_NODRIVER
) {
1092 trace(" No Driver\n");
1094 } else if (rc
== DSERR_ALLOCATED
) {
1095 trace(" Already In Use\n");
1097 } else if (rc
== E_FAIL
) {
1098 trace(" No Device\n");
1102 trace(" Testing the primary buffer\n");
1103 test_primary8(lpGuid
);
1105 trace(" Testing 3D primary buffer\n");
1106 test_primary_3d8(lpGuid
);
1108 trace(" Testing 3D primary buffer with listener\n");
1109 test_primary_3d_with_listener8(lpGuid
);
1111 /* Testing secondary buffers */
1112 test_secondary8(lpGuid
,winetest_interactive
,0,0,0,0,0,0);
1113 test_secondary8(lpGuid
,winetest_interactive
,0,0,0,1,0,0);
1115 /* Testing 3D secondary buffers */
1116 test_secondary8(lpGuid
,winetest_interactive
,1,0,0,0,0,0);
1117 test_secondary8(lpGuid
,winetest_interactive
,1,1,0,0,0,0);
1118 test_secondary8(lpGuid
,winetest_interactive
,1,1,0,1,0,0);
1119 test_secondary8(lpGuid
,winetest_interactive
,1,0,1,0,0,0);
1120 test_secondary8(lpGuid
,winetest_interactive
,1,0,1,1,0,0);
1121 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,0,0);
1122 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,1,0,0);
1123 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,1,0);
1124 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,0,1);
1125 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,1,1);
1130 static void ds3d8_tests(void)
1133 rc
=pDirectSoundEnumerateA(&dsenum_callback
,NULL
);
1134 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %08x\n",rc
);
1143 hDsound
= LoadLibrary("dsound.dll");
1147 pDirectSoundEnumerateA
= (void*)GetProcAddress(hDsound
,
1148 "DirectSoundEnumerateA");
1149 pDirectSoundCreate8
= (void*)GetProcAddress(hDsound
,
1150 "DirectSoundCreate8");
1151 if (pDirectSoundCreate8
)
1154 skip("ds3d8 test skipped\n");
1156 FreeLibrary(hDsound
);
1159 skip("dsound.dll not found!\n");