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
);
374 ref
=IDirectSoundBuffer_Release(*dsbo
);
375 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
376 "should have 0\n",ref
);
378 rc
=IDirectSound3DBuffer_QueryInterface(buffer
,
379 &IID_IDirectSoundBuffer
,
381 ok(rc
==DS_OK
&& *dsbo
!=NULL
,"IDirectSound3DBuffer_QueryInterface() "
382 "failed: %08x\n",rc
);
384 /* DSOUND: Error: Invalid buffer */
385 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,0);
386 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
387 "failed: %08x\n",rc
);
389 ZeroMemory(&buffer_param
, sizeof(buffer_param
));
391 /* DSOUND: Error: Invalid buffer */
392 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
393 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
394 "failed: %08x\n",rc
);
396 buffer_param
.dwSize
=sizeof(buffer_param
);
397 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
398 ok(rc
==DS_OK
,"IDirectSound3DBuffer_GetAllParameters() failed: %08x\n", rc
);
401 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
403 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&val
);
404 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc
);
406 rc
=IDirectSoundBuffer_SetVolume(*dsbo
,volume
);
407 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume() failed: %08x\n", rc
);
409 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
410 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&volume
);
411 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetVolume() "
412 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
417 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLPAN
) {
419 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&val
);
420 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan() failed: %08x\n", rc
);
422 rc
=IDirectSoundBuffer_SetPan(*dsbo
,pan
);
423 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan() failed: %08x\n", rc
);
425 /* DSOUND: Error: Buffer does not have CTRLPAN */
426 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&pan
);
427 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
428 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
432 /* try an offset past the end of the buffer */
433 rc
= IDirectSoundBuffer_Lock(*dsbo
, dsbcaps
.dwBufferBytes
, 0, &buffer1
,
434 &length1
, NULL
, NULL
,
435 DSBLOCK_ENTIREBUFFER
);
436 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
437 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
439 /* try a size larger than the buffer */
440 rc
= IDirectSoundBuffer_Lock(*dsbo
, 0, dsbcaps
.dwBufferBytes
+ 1,
441 &buffer1
, &length1
, NULL
, NULL
,
442 DSBLOCK_FROMWRITECURSOR
);
443 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
444 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
446 state
.wave
=wave_generate_la(&wfx
,duration
,&state
.wave_len
,ieee
);
450 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
451 state
.played
=state
.written
=state
.offset
=0;
452 buffer_refill8(&state
,state
.buffer_size
);
454 rc
=IDirectSoundBuffer_Play(*dsbo
,0,0,DSBPLAY_LOOPING
);
455 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play() failed: %08x\n", rc
);
457 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
458 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc
);
459 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
460 "GetStatus: bad status: %x\n",status
);
463 ZeroMemory(&listener_param
,sizeof(listener_param
));
464 listener_param
.dwSize
=sizeof(listener_param
);
465 rc
=IDirectSound3DListener_GetAllParameters(listener
,&listener_param
);
466 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
467 "failed: %08x\n",rc
);
469 listener_param
.vPosition
.x
= -5.0f
;
470 listener_param
.vVelocity
.x
= (float)(10.0/duration
);
472 rc
=IDirectSound3DListener_SetAllParameters(listener
,
475 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n", rc
);
479 buffer_param
.vPosition
.x
= 100.0f
;
480 buffer_param
.vVelocity
.x
= (float)(-200.0/duration
);
482 buffer_param
.flMinDistance
= 10;
483 rc
=IDirectSound3DBuffer_SetAllParameters(buffer
,&buffer_param
,
485 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
488 start_time
=GetTickCount();
489 while (buffer_service8(&state
)) {
490 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
);
492 if (listener
&& move_listener
) {
493 listener_param
.vPosition
.x
= (float)(-5.0+10.0*(now
-start_time
)/1000/duration
);
494 if (winetest_debug
>2)
495 trace("listener position=%g\n",listener_param
.vPosition
.x
);
496 rc
=IDirectSound3DListener_SetPosition(listener
,
497 listener_param
.vPosition
.x
,listener_param
.vPosition
.y
,
498 listener_param
.vPosition
.z
,DS3D_IMMEDIATE
);
499 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %08x\n",rc
);
501 if (buffer3d
&& move_sound
) {
502 buffer_param
.vPosition
.x
= (float)(100-200.0*(now
-start_time
)/1000/duration
);
503 if (winetest_debug
>2)
504 trace("sound position=%g\n",buffer_param
.vPosition
.x
);
505 rc
=IDirectSound3DBuffer_SetPosition(buffer
,
506 buffer_param
.vPosition
.x
,buffer_param
.vPosition
.y
,
507 buffer_param
.vPosition
.z
,DS3D_IMMEDIATE
);
508 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc
);
511 /* Check the sound duration was within 10% of the expected value */
513 ok(fabs(1000*duration
-now
+start_time
)<=100*duration
,
514 "The sound played for %d ms instead of %g ms\n",
515 now
-start_time
,1000*duration
);
517 HeapFree(GetProcessHeap(), 0, state
.wave
);
519 /* Set the CooperativeLevel back to normal */
520 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
521 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
522 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
523 "failed: %08x\n",rc
);
526 ref
=IDirectSound3DBuffer_Release(buffer
);
527 ok(ref
==0,"IDirectSound3DBuffer_Release() has %d references, "
528 "should have 0\n",ref
);
533 static HRESULT
test_secondary8(LPGUID lpGuid
, BOOL play
,
534 BOOL has_3d
, BOOL has_3dbuffer
,
535 BOOL has_listener
, BOOL has_duplicate
,
536 BOOL move_listener
, BOOL move_sound
)
539 LPDIRECTSOUND8 dso
=NULL
;
540 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
541 LPDIRECTSOUND3DLISTENER listener
=NULL
;
542 DSBUFFERDESC bufdesc
;
543 WAVEFORMATEX wfx
, wfx1
;
546 /* Create the DirectSound object */
547 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
548 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
552 /* We must call SetCooperativeLevel before creating primary buffer */
553 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
554 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
555 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
559 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
560 bufdesc
.dwSize
=sizeof(bufdesc
);
561 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
563 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
565 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
566 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
567 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
568 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: %08x\n",has_3d
?"3D ":"", rc
);
569 if (rc
== DSERR_CONTROLUNAVAIL
)
570 trace(" No Primary\n");
571 else if (rc
==DS_OK
&& primary
!=NULL
) {
572 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
573 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc
);
578 rc
=IDirectSoundBuffer_QueryInterface(primary
,
579 &IID_IDirectSound3DListener
,
581 ok(rc
==DS_OK
&& listener
!=NULL
,
582 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
583 "listener %08x\n",rc
);
584 ref
=IDirectSoundBuffer_Release(primary
);
585 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
586 "should have 0\n",ref
);
587 if (rc
==DS_OK
&& listener
!=NULL
) {
588 DS3DLISTENER listener_param
;
589 ZeroMemory(&listener_param
,sizeof(listener_param
));
590 /* DSOUND: Error: Invalid buffer */
591 rc
=IDirectSound3DListener_GetAllParameters(listener
,0);
592 ok(rc
==DSERR_INVALIDPARAM
,
593 "IDirectSound3dListener_GetAllParameters() should have "
594 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
596 /* DSOUND: Error: Invalid buffer */
597 rc
=IDirectSound3DListener_GetAllParameters(listener
,
599 ok(rc
==DSERR_INVALIDPARAM
,
600 "IDirectSound3dListener_GetAllParameters() should have "
601 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc
);
603 listener_param
.dwSize
=sizeof(listener_param
);
604 rc
=IDirectSound3DListener_GetAllParameters(listener
,
606 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
607 "failed: %08x\n",rc
);
609 ok(listener
==NULL
, "IDirectSoundBuffer_QueryInterface() "
610 "failed but returned a listener anyway\n");
611 ok(rc
!=DS_OK
, "IDirectSoundBuffer_QueryInterface() succeeded "
612 "but returned a NULL listener\n");
614 ref
=IDirectSound3DListener_Release(listener
);
615 ok(ref
==0,"IDirectSound3dListener_Release() listener has "
616 "%d references, should have 0\n",ref
);
622 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,2);
624 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
625 bufdesc
.dwSize
=sizeof(bufdesc
);
626 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
628 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
631 (DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
632 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
634 bufdesc
.lpwfxFormat
=&wfx
;
636 /* a stereo 3D buffer should fail */
637 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
638 ok(rc
==DSERR_INVALIDPARAM
,
639 "IDirectSound8_CreateSoundBuffer(secondary) should have "
640 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
641 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,1);
643 /* Invalid flag combination */
644 bufdesc
.dwFlags
|=DSBCAPS_CTRLPAN
;
645 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
646 ok(rc
==DSERR_INVALIDPARAM
,
647 "IDirectSound8_CreateSoundBuffer(secondary) should have "
648 "returned DSERR_INVALIDPARAM, returned %08x\n", rc
);
649 bufdesc
.dwFlags
&=~DSBCAPS_CTRLPAN
;
652 if (winetest_interactive
) {
653 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
654 "with a primary buffer at %dx%dx%d\n",
655 has_3dbuffer
?"3D ":"",
656 has_duplicate
?"duplicated ":"",
657 listener
!=NULL
||move_sound
?"with ":"",
658 move_listener
?"moving ":"",
659 listener
!=NULL
?"listener ":"",
660 listener
&&move_sound
?"and moving sound ":move_sound
?
662 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
663 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
665 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
666 ok(rc
==DS_OK
&& secondary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
667 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %08x\n",
668 has_3dbuffer
?"3D ":"", has_duplicate
?"duplicated ":"",
669 listener
!=NULL
||move_sound
?"with ":"", move_listener
?"moving ":"",
670 listener
!=NULL
?"listener ":"",
671 listener
&&move_sound
?"and moving sound ":move_sound
?
673 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
674 getDSBCAPS(bufdesc
.dwFlags
),rc
);
675 if (rc
==DS_OK
&& secondary
!=NULL
) {
677 LONG refvol
,vol
,refpan
,pan
;
679 /* Check the initial secondary buffer's volume and pan */
680 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
681 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(secondary) failed: %08x\n",rc
);
682 ok(vol
==0,"wrong volume for a new secondary buffer: %d\n",vol
);
683 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
684 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc
);
685 ok(pan
==0,"wrong pan for a new secondary buffer: %d\n",pan
);
687 /* Check that changing the secondary buffer's volume and pan
688 * does not impact the primary buffer's volume and pan
690 rc
=IDirectSoundBuffer_GetVolume(primary
,&refvol
);
691 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc
);
692 rc
=IDirectSoundBuffer_GetPan(primary
,&refpan
);
693 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
695 rc
=IDirectSoundBuffer_SetVolume(secondary
,-1000);
696 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
697 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
698 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
699 ok(vol
==-1000,"secondary: wrong volume %d instead of -1000\n",
701 rc
=IDirectSoundBuffer_SetPan(secondary
,-1000);
702 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
703 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
704 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc
);
705 ok(pan
==-1000,"secondary: wrong pan %d instead of -1000\n",
708 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
709 ok(rc
==DS_OK
,"IDirectSoundBuffer_`GetVolume(primary) failed: i%08x\n",rc
);
710 ok(vol
==refvol
,"The primary volume changed from %d to %d\n",
712 rc
=IDirectSoundBuffer_GetPan(primary
,&pan
);
713 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc
);
714 ok(pan
==refpan
,"The primary pan changed from %d to %d\n",
717 rc
=IDirectSoundBuffer_SetVolume(secondary
,0);
718 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc
);
719 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
720 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc
);
724 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
725 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
726 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
727 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
728 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_SetPan() "
729 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc
);
733 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
735 /* DSOUND: Error: Invalid source buffer */
736 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,0);
737 ok(rc
==DSERR_INVALIDPARAM
,
738 "IDirectSound8_DuplicateSoundBuffer() should have returned "
739 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
741 /* DSOUND: Error: Invalid dest buffer */
742 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,0);
743 ok(rc
==DSERR_INVALIDPARAM
,
744 "IDirectSound8_DuplicateSoundBuffer() should have returned "
745 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
747 /* DSOUND: Error: Invalid source buffer */
748 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,&duplicated
);
749 ok(rc
==DSERR_INVALIDPARAM
,
750 "IDirectSound8_DuplicateSoundBuffer() should have returned "
751 "DSERR_INVALIDPARAM, returned: %08x\n",rc
);
754 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,
756 ok(rc
==DS_OK
&& duplicated
!=NULL
,
757 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
758 "a secondary buffer: %08x\n",rc
);
760 if (rc
==DS_OK
&& duplicated
!=NULL
) {
761 ref
=IDirectSoundBuffer_Release(secondary
);
762 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d "
763 "references, should have 0\n",ref
);
764 secondary
=duplicated
;
768 if (rc
==DS_OK
&& secondary
!=NULL
) {
770 duration
=(move_listener
|| move_sound
?4.0:1.0);
771 test_buffer8(dso
,&secondary
,FALSE
,FALSE
,0,FALSE
,0,
772 winetest_interactive
,duration
,has_3dbuffer
,
773 listener
,move_listener
,move_sound
);
774 ref
=IDirectSoundBuffer_Release(secondary
);
775 ok(ref
==0,"IDirectSoundBuffer_Release() %s has %d references, "
776 "should have 0\n",has_duplicate
?"duplicated":"secondary",
783 ref
=IDirectSound3DListener_Release(listener
);
784 ok(ref
==0,"IDirectSound3dListener_Release() listener has %d "
785 "references, should have 0\n",ref
);
788 ref
=IDirectSoundBuffer_Release(primary
);
789 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
790 "should have 0\n",ref
);
793 ok(primary
==NULL
,"IDirectSound8_CreateSoundBuffer(primary) failed "
794 "but primary created anyway\n");
795 ok(rc
!=DS_OK
,"IDirectSound8_CreateSoundBuffer(primary) succeeded "
796 "but primary not created\n");
798 ref
=IDirectSoundBuffer_Release(primary
);
799 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
800 "should have 0\n",ref
);
804 /* Set the CooperativeLevel back to normal */
805 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
806 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
807 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
810 ref
=IDirectSound8_Release(dso
);
811 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
813 return DSERR_GENERIC
;
818 static HRESULT
test_for_driver8(LPGUID lpGuid
)
821 LPDIRECTSOUND8 dso
=NULL
;
824 /* Create the DirectSound object */
825 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
826 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
827 "DirectSoundCreate8() failed: %08x\n",rc
);
831 ref
=IDirectSound8_Release(dso
);
832 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
834 return DSERR_GENERIC
;
839 static HRESULT
test_primary8(LPGUID lpGuid
)
842 LPDIRECTSOUND8 dso
=NULL
;
843 LPDIRECTSOUNDBUFFER primary
=NULL
;
844 DSBUFFERDESC bufdesc
;
848 /* Create the DirectSound object */
849 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
850 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
854 /* Get the device capabilities */
855 ZeroMemory(&dscaps
, sizeof(dscaps
));
856 dscaps
.dwSize
=sizeof(dscaps
);
857 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
858 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
862 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
863 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
864 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
865 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
869 /* Testing the primary buffer */
871 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
872 bufdesc
.dwSize
=sizeof(bufdesc
);
873 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
;
874 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
875 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
876 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc
);
877 if (rc
== DSERR_CONTROLUNAVAIL
)
878 trace(" No Primary\n");
879 else if (rc
==DS_OK
&& primary
!=NULL
) {
880 test_buffer8(dso
,&primary
,TRUE
,TRUE
,0,TRUE
,0,
881 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
882 1.0,FALSE
,NULL
,FALSE
,FALSE
);
883 if (winetest_interactive
) {
886 volume
= DSBVOLUME_MAX
;
887 for (i
= 0; i
< 6; i
++) {
888 test_buffer8(dso
,&primary
,TRUE
,TRUE
,volume
,TRUE
,0,
889 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
890 1.0,FALSE
,NULL
,FALSE
,FALSE
);
891 volume
-= ((DSBVOLUME_MAX
-DSBVOLUME_MIN
) / 40);
895 for (i
= 0; i
< 7; i
++) {
896 test_buffer8(dso
,&primary
,TRUE
,TRUE
,0,TRUE
,pan
,
897 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
898 1.0,FALSE
,NULL
,FALSE
,FALSE
);
899 pan
+= ((DSBPAN_RIGHT
-DSBPAN_LEFT
) / 6);
902 ref
=IDirectSoundBuffer_Release(primary
);
903 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
904 "should have 0\n",ref
);
907 /* Set the CooperativeLevel back to normal */
908 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
909 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
910 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
913 ref
=IDirectSound8_Release(dso
);
914 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
916 return DSERR_GENERIC
;
921 static HRESULT
test_primary_3d8(LPGUID lpGuid
)
924 LPDIRECTSOUND8 dso
=NULL
;
925 LPDIRECTSOUNDBUFFER primary
=NULL
;
926 DSBUFFERDESC bufdesc
;
930 /* Create the DirectSound object */
931 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
932 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
936 /* Get the device capabilities */
937 ZeroMemory(&dscaps
, sizeof(dscaps
));
938 dscaps
.dwSize
=sizeof(dscaps
);
939 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
940 ok(rc
==DS_OK
,"IDirectSound8_GetCaps failed: %08x\n",rc
);
944 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
945 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
946 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
947 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
952 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
953 bufdesc
.dwSize
=sizeof(bufdesc
);
954 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
955 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
956 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
957 "to create a primary buffer: %08x\n",rc
);
958 if (rc
==DS_OK
&& primary
!=NULL
) {
959 ref
=IDirectSoundBuffer_Release(primary
);
960 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
961 "should have 0\n",ref
);
963 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
964 bufdesc
.dwSize
=sizeof(bufdesc
);
965 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
966 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
967 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
968 "failed to create a 3D primary buffer: %08x\n",rc
);
969 if (rc
==DS_OK
&& primary
!=NULL
) {
970 test_buffer8(dso
,&primary
,TRUE
,FALSE
,0,FALSE
,0,
971 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
972 1.0,FALSE
,NULL
,FALSE
,FALSE
);
973 ref
=IDirectSoundBuffer_Release(primary
);
974 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
975 "should have 0\n",ref
);
978 /* Set the CooperativeLevel back to normal */
979 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
980 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
981 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc
);
984 ref
=IDirectSound8_Release(dso
);
985 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
987 return DSERR_GENERIC
;
992 static HRESULT
test_primary_3d_with_listener8(LPGUID lpGuid
)
995 LPDIRECTSOUND8 dso
=NULL
;
996 LPDIRECTSOUNDBUFFER primary
=NULL
;
997 DSBUFFERDESC bufdesc
;
1001 /* Create the DirectSound object */
1002 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
1003 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %08x\n", rc
);
1007 /* Get the device capabilities */
1008 ZeroMemory(&dscaps
, sizeof(dscaps
));
1009 dscaps
.dwSize
=sizeof(dscaps
);
1010 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
1011 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %08x\n",rc
);
1015 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1016 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1017 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1018 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc
);
1022 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1023 bufdesc
.dwSize
=sizeof(bufdesc
);
1024 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1025 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1026 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
1027 "to create a 3D primary buffer %08x\n",rc
);
1028 if (rc
==DS_OK
&& primary
!=NULL
) {
1029 LPDIRECTSOUND3DLISTENER listener
=NULL
;
1030 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1031 &IID_IDirectSound3DListener
,
1032 (void **)&listener
);
1033 ok(rc
==DS_OK
&& listener
!=NULL
,"IDirectSoundBuffer_QueryInterface() "
1034 "failed to get a 3D listener: %08x\n",rc
);
1035 if (rc
==DS_OK
&& listener
!=NULL
) {
1036 LPDIRECTSOUNDBUFFER temp_buffer
=NULL
;
1038 /* Checking the COM interface */
1039 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1040 &IID_IDirectSoundBuffer
,
1041 (LPVOID
*)&temp_buffer
);
1042 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1043 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1044 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1045 if (rc
==DS_OK
&& temp_buffer
!=NULL
) {
1046 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1047 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1048 "should have 1\n",ref
);
1051 rc
=IDirectSound3DListener_QueryInterface(listener
,
1052 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1053 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1054 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc
);
1055 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1056 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1057 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1058 "should have 1\n",ref
);
1060 /* Testing the buffer */
1061 test_buffer8(dso
,&primary
,TRUE
,FALSE
,0,FALSE
,0,
1062 winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
1063 1.0,FALSE
,listener
,FALSE
,FALSE
);
1066 /* Testing the reference counting */
1067 ref
=IDirectSound3DListener_Release(listener
);
1068 ok(ref
==0,"IDirectSound3DListener_Release() listener has %d "
1069 "references, should have 0\n",ref
);
1072 /* Testing the reference counting */
1073 ref
=IDirectSoundBuffer_Release(primary
);
1074 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1075 "should have 0\n",ref
);
1079 ref
=IDirectSound8_Release(dso
);
1080 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
1082 return DSERR_GENERIC
;
1087 static unsigned driver_count
= 0;
1089 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1090 LPCSTR lpcstrModule
, LPVOID lpContext
)
1093 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1096 rc
= test_for_driver8(lpGuid
);
1097 if (rc
== DSERR_NODRIVER
) {
1098 trace(" No Driver\n");
1100 } else if (rc
== DSERR_ALLOCATED
) {
1101 trace(" Already In Use\n");
1103 } else if (rc
== E_FAIL
) {
1104 trace(" No Device\n");
1108 trace(" Testing the primary buffer\n");
1109 test_primary8(lpGuid
);
1111 trace(" Testing 3D primary buffer\n");
1112 test_primary_3d8(lpGuid
);
1114 trace(" Testing 3D primary buffer with listener\n");
1115 test_primary_3d_with_listener8(lpGuid
);
1117 /* Testing secondary buffers */
1118 test_secondary8(lpGuid
,winetest_interactive
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
);
1119 test_secondary8(lpGuid
,winetest_interactive
,FALSE
,FALSE
,FALSE
,TRUE
, FALSE
,FALSE
);
1121 /* Testing 3D secondary buffers */
1122 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,FALSE
,FALSE
,FALSE
,FALSE
);
1123 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, FALSE
,FALSE
,FALSE
,FALSE
);
1124 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, FALSE
,TRUE
, FALSE
,FALSE
);
1125 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,TRUE
, FALSE
,FALSE
,FALSE
);
1126 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, FALSE
,TRUE
, TRUE
, FALSE
,FALSE
);
1127 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,FALSE
,FALSE
);
1128 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, TRUE
, FALSE
,FALSE
);
1129 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,TRUE
, FALSE
);
1130 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,FALSE
,TRUE
);
1131 test_secondary8(lpGuid
,winetest_interactive
,TRUE
, TRUE
, TRUE
, FALSE
,TRUE
, TRUE
);
1136 static void ds3d8_tests(void)
1139 rc
=pDirectSoundEnumerateA(&dsenum_callback
,NULL
);
1140 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %08x\n",rc
);
1141 trace("tested %u DirectSound drivers\n", driver_count
);
1150 hDsound
= LoadLibraryA("dsound.dll");
1154 pDirectSoundEnumerateA
= (void*)GetProcAddress(hDsound
,
1155 "DirectSoundEnumerateA");
1156 pDirectSoundCreate8
= (void*)GetProcAddress(hDsound
,
1157 "DirectSoundCreate8");
1158 if (pDirectSoundCreate8
)
1161 skip("DirectSoundCreate8 missing - skipping all tests\n");
1163 FreeLibrary(hDsound
);
1166 skip("dsound.dll not found - skipping all tests\n");