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
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
32 #include "wine/test.h"
36 #include "dsound_test.h"
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: %s\n",
64 DXGetErrorString8(rc
));
68 memcpy(ptr1
,state
->wave
+state
->written
,len1
);
71 memcpy(ptr2
,state
->wave
+state
->written
,len2
);
74 state
->offset
=state
->written
% state
->buffer_size
;
75 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
76 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %s\n",
77 DXGetErrorString8(rc
));
83 static int buffer_silence8(play_state_t
* state
, DWORD size
)
90 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
91 &ptr1
,&len1
,&ptr2
,&len2
,0);
92 ok(rc
==DS_OK
,"IDirectSoundBuffer_Lock() failed: %s\n",
93 DXGetErrorString8(rc
));
97 s
=(state
->wfx
->wBitsPerSample
==8?0x80:0);
102 state
->offset
=(state
->offset
+size
) % state
->buffer_size
;
103 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
104 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %s\n",
105 DXGetErrorString8(rc
));
111 static int buffer_service8(play_state_t
* state
)
113 DWORD last_play_pos
,play_pos
,buf_free
;
116 rc
=IDirectSoundBuffer_GetCurrentPosition(state
->dsbo
,&play_pos
,NULL
);
117 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
118 DXGetErrorString8(rc
));
123 /* Update the amount played */
124 last_play_pos
=state
->played
% state
->buffer_size
;
125 if (play_pos
<last_play_pos
)
126 state
->played
+=state
->buffer_size
-last_play_pos
+play_pos
;
128 state
->played
+=play_pos
-last_play_pos
;
130 if (winetest_debug
> 1)
131 trace("buf size=%d last_play_pos=%d play_pos=%d played=%d / %d\n",
132 state
->buffer_size
,last_play_pos
,play_pos
,state
->played
,
135 if (state
->played
>state
->wave_len
)
137 /* Everything has been played */
141 /* Refill the buffer */
142 if (state
->offset
<=play_pos
)
143 buf_free
=play_pos
-state
->offset
;
145 buf_free
=state
->buffer_size
-state
->offset
+play_pos
;
147 if (winetest_debug
> 1)
148 trace("offset=%d free=%d written=%d / %d\n",
149 state
->offset
,buf_free
,state
->written
,state
->wave_len
);
153 if (state
->written
<state
->wave_len
)
155 int w
=buffer_refill8(state
,buf_free
);
159 if (state
->written
==state
->wave_len
&& winetest_debug
> 1)
160 trace("last sound byte at %d\n",
161 (state
->written
% state
->buffer_size
));
165 /* Fill with silence */
166 if (winetest_debug
> 1)
167 trace("writing %d bytes of silence\n",buf_free
);
168 if (buffer_silence8(state
,buf_free
)==-1)
174 if (winetest_debug
> 1)
175 trace("stopping playback\n");
176 rc
=IDirectSoundBuffer_Stop(state
->dsbo
);
177 ok(rc
==DS_OK
,"IDirectSoundBuffer_Stop() failed: %s\n",
178 DXGetErrorString8(rc
));
182 void test_buffer8(LPDIRECTSOUND8 dso
, LPDIRECTSOUNDBUFFER
* dsbo
,
183 BOOL is_primary
, BOOL set_volume
, LONG volume
,
184 BOOL set_pan
, LONG pan
, BOOL play
, double duration
,
185 BOOL buffer3d
, LPDIRECTSOUND3DLISTENER listener
,
186 BOOL move_listener
, BOOL move_sound
)
190 WAVEFORMATEX wfx
,wfx2
;
191 DWORD size
,status
,freq
;
194 /* DSOUND: Error: Invalid caps pointer */
195 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,0);
196 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
197 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
199 ZeroMemory(&dsbcaps
, sizeof(dsbcaps
));
201 /* DSOUND: Error: Invalid caps pointer */
202 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&dsbcaps
);
203 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
204 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
206 dsbcaps
.dwSize
=sizeof(dsbcaps
);
207 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&dsbcaps
);
208 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %s\n",
209 DXGetErrorString8(rc
));
210 if (rc
==DS_OK
&& winetest_debug
> 1) {
211 trace(" Caps: flags=0x%08x size=%d\n",dsbcaps
.dwFlags
,
212 dsbcaps
.dwBufferBytes
);
215 /* Query the format size. Note that it may not match sizeof(wfx) */
217 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,NULL
,0,&size
);
218 ok(rc
==DS_OK
&& size
!=0,"IDirectSoundBuffer_GetFormat() should have "
219 "returned the needed size: rc=%s size=%d\n",DXGetErrorString8(rc
),size
);
221 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,&wfx
,sizeof(wfx
),NULL
);
222 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %s\n",
223 DXGetErrorString8(rc
));
224 if (rc
==DS_OK
&& winetest_debug
> 1) {
225 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
226 is_primary
? "Primary" : "Secondary",
227 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
228 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
231 /* DSOUND: Error: Invalid frequency buffer */
232 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,0);
233 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetFrequency() should have "
234 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
236 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
237 rc
=IDirectSoundBuffer_GetFrequency(*dsbo
,&freq
);
238 ok((rc
==DS_OK
&& !is_primary
) || (rc
==DSERR_CONTROLUNAVAIL
&&is_primary
) ||
239 (rc
==DSERR_CONTROLUNAVAIL
&&!(dsbcaps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
)),
240 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc
));
242 ok(freq
==wfx
.nSamplesPerSec
,"The frequency returned by GetFrequency "
243 "%d does not match the format %d\n",freq
,wfx
.nSamplesPerSec
);
246 /* DSOUND: Error: Invalid status pointer */
247 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,0);
248 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetStatus() should have "
249 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
251 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
252 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %s\n",
253 DXGetErrorString8(rc
));
254 ok(status
==0,"status=0x%x instead of 0\n",status
);
258 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
259 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
260 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
261 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
262 "failed: %s\n",DXGetErrorString8(rc
));
266 /* DSOUND: Error: Invalid format pointer */
267 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,0);
268 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_SetFormat() should have "
269 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
271 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
272 rc
=IDirectSoundBuffer_SetFormat(*dsbo
,&wfx2
);
273 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat(%s) failed: %s\n",
274 format_string(&wfx2
), DXGetErrorString8(rc
));
276 /* There is no guarantee that SetFormat will actually change the
277 * format to what we asked for. It depends on what the soundcard
278 * supports. So we must re-query the format.
280 rc
=IDirectSoundBuffer_GetFormat(*dsbo
,&wfx
,sizeof(wfx
),NULL
);
281 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %s\n",
282 DXGetErrorString8(rc
));
284 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
285 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
286 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
287 wfx
.nChannels
!=wfx2
.nChannels
)) {
288 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
289 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
290 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
291 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
292 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
293 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
296 ZeroMemory(&new_dsbcaps
, sizeof(new_dsbcaps
));
297 new_dsbcaps
.dwSize
= sizeof(new_dsbcaps
);
298 rc
=IDirectSoundBuffer_GetCaps(*dsbo
,&new_dsbcaps
);
299 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %s\n",
300 DXGetErrorString8(rc
));
301 if (rc
==DS_OK
&& winetest_debug
> 1) {
302 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps
.dwFlags
,
303 new_dsbcaps
.dwBufferBytes
);
306 /* Check for primary buffer size change */
307 ok(new_dsbcaps
.dwBufferBytes
== dsbcaps
.dwBufferBytes
,
308 " buffer size changed after SetFormat() - "
309 "previous size was %u, current size is %u\n",
310 dsbcaps
.dwBufferBytes
, new_dsbcaps
.dwBufferBytes
);
312 /* Check for primary buffer flags change */
313 ok(new_dsbcaps
.dwFlags
== dsbcaps
.dwFlags
,
314 " flags changed after SetFormat() - "
315 "previous flags were %08x, current flags are %08x\n",
316 dsbcaps
.dwFlags
, new_dsbcaps
.dwFlags
);
318 /* Set the CooperativeLevel back to normal */
319 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
320 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
321 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
322 "failed: %s\n",DXGetErrorString8(rc
));
327 DS3DLISTENER listener_param
;
328 LPDIRECTSOUND3DBUFFER buffer
=NULL
;
329 DS3DBUFFER buffer_param
;
330 DWORD start_time
,now
;
334 if (winetest_interactive
) {
335 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration
,
336 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
,wfx
.nChannels
);
340 /* We must call SetCooperativeLevel to be allowed to call Lock */
341 /* DSOUND: Setting DirectSound cooperative level to
342 * DSSCL_WRITEPRIMARY */
343 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),
346 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: "
347 "%s\n",DXGetErrorString8(rc
));
352 LPDIRECTSOUNDBUFFER temp_buffer
;
354 rc
=IDirectSoundBuffer_QueryInterface(*dsbo
,&IID_IDirectSound3DBuffer
,
356 ok(rc
==DS_OK
,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
357 DXGetErrorString8(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: %s\n",
366 DXGetErrorString8(rc
));
367 ok(temp_buffer
==*dsbo
,"COM interface broken: %p != %p\n",
369 ref
=IDirectSoundBuffer_Release(temp_buffer
);
370 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
371 "should have 1\n",ref
);
374 rc
=IDirectSound3DBuffer_QueryInterface(*dsbo
, &IID_IDirectSoundBuffer
,
375 (LPVOID
*)&temp_buffer
);
376 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
377 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
378 DXGetErrorString8(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: %s\n",DXGetErrorString8(rc
));
395 /* DSOUND: Error: Invalid buffer */
396 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,0);
397 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
398 "failed: %s\n",DXGetErrorString8(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: %s\n",DXGetErrorString8(rc
));
407 buffer_param
.dwSize
=sizeof(buffer_param
);
408 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
409 ok(rc
==DS_OK
,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
410 DXGetErrorString8(rc
));
413 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
415 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&val
);
416 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %s\n",
417 DXGetErrorString8(rc
));
419 rc
=IDirectSoundBuffer_SetVolume(*dsbo
,volume
);
420 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume() failed: %s\n",
421 DXGetErrorString8(rc
));
423 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
424 rc
=IDirectSoundBuffer_GetVolume(*dsbo
,&volume
);
425 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetVolume() "
426 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
427 DXGetErrorString8(rc
));
432 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLPAN
) {
434 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&val
);
435 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan() failed: %s\n",
436 DXGetErrorString8(rc
));
438 rc
=IDirectSoundBuffer_SetPan(*dsbo
,pan
);
439 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan() failed: %s\n",
440 DXGetErrorString8(rc
));
442 /* DSOUND: Error: Buffer does not have CTRLPAN */
443 rc
=IDirectSoundBuffer_GetPan(*dsbo
,&pan
);
444 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
445 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
446 DXGetErrorString8(rc
));
450 /* try an offset past the end of the buffer */
451 rc
= IDirectSoundBuffer_Lock(*dsbo
, dsbcaps
.dwBufferBytes
, 0, &buffer1
,
452 &length1
, NULL
, NULL
,
453 DSBLOCK_ENTIREBUFFER
);
454 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
455 "returned DSERR_INVALIDPARAM, returned %s\n", DXGetErrorString8(rc
));
457 /* try a size larger than the buffer */
458 rc
= IDirectSoundBuffer_Lock(*dsbo
, 0, dsbcaps
.dwBufferBytes
+ 1,
459 &buffer1
, &length1
, NULL
, NULL
,
460 DSBLOCK_FROMWRITECURSOR
);
461 ok(rc
==DSERR_INVALIDPARAM
, "IDirectSoundBuffer_Lock() should have "
462 "returned DSERR_INVALIDPARAM, returned %s\n", DXGetErrorString8(rc
));
464 state
.wave
=wave_generate_la(&wfx
,duration
,&state
.wave_len
);
468 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
469 state
.played
=state
.written
=state
.offset
=0;
470 buffer_refill8(&state
,state
.buffer_size
);
472 rc
=IDirectSoundBuffer_Play(*dsbo
,0,0,DSBPLAY_LOOPING
);
473 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play() failed: %s\n",
474 DXGetErrorString8(rc
));
476 rc
=IDirectSoundBuffer_GetStatus(*dsbo
,&status
);
477 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %s\n",
478 DXGetErrorString8(rc
));
479 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
480 "GetStatus: bad status: %x\n",status
);
483 ZeroMemory(&listener_param
,sizeof(listener_param
));
484 listener_param
.dwSize
=sizeof(listener_param
);
485 rc
=IDirectSound3DListener_GetAllParameters(listener
,&listener_param
);
486 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
487 "failed: %s\n",DXGetErrorString8(rc
));
489 listener_param
.vPosition
.x
= -5.0;
490 listener_param
.vVelocity
.x
= 10.0/duration
;
492 rc
=IDirectSound3DListener_SetAllParameters(listener
,
495 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %s\n",
496 DXGetErrorString8(rc
));
500 buffer_param
.vPosition
.x
= 100.0;
501 buffer_param
.vVelocity
.x
= -200.0/duration
;
503 buffer_param
.flMinDistance
= 10;
504 rc
=IDirectSound3DBuffer_SetAllParameters(buffer
,&buffer_param
,
506 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
507 DXGetErrorString8(rc
));
510 start_time
=GetTickCount();
511 while (buffer_service8(&state
)) {
512 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
);
514 if (listener
&& move_listener
) {
515 listener_param
.vPosition
.x
= -5.0+10.0*(now
-start_time
)/
517 if (winetest_debug
>2)
518 trace("listener position=%g\n",listener_param
.vPosition
.x
);
519 rc
=IDirectSound3DListener_SetPosition(listener
,
520 listener_param
.vPosition
.x
,listener_param
.vPosition
.y
,
521 listener_param
.vPosition
.z
,DS3D_IMMEDIATE
);
522 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: "
523 "%s\n",DXGetErrorString8(rc
));
525 if (buffer3d
&& move_sound
) {
526 buffer_param
.vPosition
.x
= 100-200.0*(now
-start_time
)/
528 if (winetest_debug
>2)
529 trace("sound position=%g\n",buffer_param
.vPosition
.x
);
530 rc
=IDirectSound3DBuffer_SetPosition(buffer
,
531 buffer_param
.vPosition
.x
,buffer_param
.vPosition
.y
,
532 buffer_param
.vPosition
.z
,DS3D_IMMEDIATE
);
533 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
534 DXGetErrorString8(rc
));
537 /* Check the sound duration was within 10% of the expected value */
539 ok(fabs(1000*duration
-now
+start_time
)<=100*duration
,
540 "The sound played for %d ms instead of %g ms\n",
541 now
-start_time
,1000*duration
);
545 /* Set the CooperativeLevel back to normal */
546 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
547 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
548 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
549 "failed: %s\n",DXGetErrorString8(rc
));
552 ref
=IDirectSound3DBuffer_Release(buffer
);
553 ok(ref
==0,"IDirectSound3DBuffer_Release() has %d references, "
554 "should have 0\n",ref
);
559 static HRESULT
test_secondary8(LPGUID lpGuid
, int play
,
560 int has_3d
, int has_3dbuffer
,
561 int has_listener
, int has_duplicate
,
562 int move_listener
, int move_sound
)
565 LPDIRECTSOUND8 dso
=NULL
;
566 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
567 LPDIRECTSOUND3DLISTENER listener
=NULL
;
568 DSBUFFERDESC bufdesc
;
569 WAVEFORMATEX wfx
, wfx1
;
572 /* Create the DirectSound object */
573 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
574 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %s\n",
575 DXGetErrorString8(rc
));
579 /* We must call SetCooperativeLevel before creating primary buffer */
580 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
581 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
582 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
583 "%s\n",DXGetErrorString8(rc
));
587 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
588 bufdesc
.dwSize
=sizeof(bufdesc
);
589 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
591 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
593 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
594 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
595 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
596 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: "
597 "%s\n",has_3d
?"3D ":"", DXGetErrorString8(rc
));
598 if (rc
== DSERR_CONTROLUNAVAIL
)
599 trace(" No Primary\n");
600 else if (rc
==DS_OK
&& primary
!=NULL
) {
601 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
602 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %s\n",
603 DXGetErrorString8(rc
));
608 rc
=IDirectSoundBuffer_QueryInterface(primary
,
609 &IID_IDirectSound3DListener
,
611 ok(rc
==DS_OK
&& listener
!=NULL
,
612 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
613 "listener %s\n",DXGetErrorString8(rc
));
614 ref
=IDirectSoundBuffer_Release(primary
);
615 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
616 "should have 0\n",ref
);
617 if (rc
==DS_OK
&& listener
!=NULL
) {
618 DS3DLISTENER listener_param
;
619 ZeroMemory(&listener_param
,sizeof(listener_param
));
620 /* DSOUND: Error: Invalid buffer */
621 rc
=IDirectSound3DListener_GetAllParameters(listener
,0);
622 ok(rc
==DSERR_INVALIDPARAM
,
623 "IDirectSound3dListener_GetAllParameters() should have "
624 "returned DSERR_INVALIDPARAM, returned: %s\n",
625 DXGetErrorString8(rc
));
627 /* DSOUND: Error: Invalid buffer */
628 rc
=IDirectSound3DListener_GetAllParameters(listener
,
630 ok(rc
==DSERR_INVALIDPARAM
,
631 "IDirectSound3dListener_GetAllParameters() should have "
632 "returned DSERR_INVALIDPARAM, returned: %s\n",
633 DXGetErrorString8(rc
));
635 listener_param
.dwSize
=sizeof(listener_param
);
636 rc
=IDirectSound3DListener_GetAllParameters(listener
,
638 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
639 "failed: %s\n",DXGetErrorString8(rc
));
645 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,2);
647 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
648 bufdesc
.dwSize
=sizeof(bufdesc
);
649 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
651 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
654 (DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
655 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
657 bufdesc
.lpwfxFormat
=&wfx
;
659 /* a stereo 3D buffer should fail */
660 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
661 ok(rc
==DSERR_INVALIDPARAM
,
662 "IDirectSound8_CreateSoundBuffer(secondary) should have "
663 "returned DSERR_INVALIDPARAM, returned %s\n",
664 DXGetErrorString8(rc
));
666 ref
=IDirectSoundBuffer_Release(secondary
);
667 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,1);
670 if (winetest_interactive
) {
671 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
672 "with a primary buffer at %dx%dx%d\n",
673 has_3dbuffer
?"3D ":"",
674 has_duplicate
?"duplicated ":"",
675 listener
!=NULL
||move_sound
?"with ":"",
676 move_listener
?"moving ":"",
677 listener
!=NULL
?"listener ":"",
678 listener
&&move_sound
?"and moving sound ":move_sound
?
680 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
681 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
683 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
684 ok(rc
==DS_OK
&& secondary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
685 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %s\n",
686 has_3dbuffer
?"3D ":"", has_duplicate
?"duplicated ":"",
687 listener
!=NULL
||move_sound
?"with ":"", move_listener
?"moving ":"",
688 listener
!=NULL
?"listener ":"",
689 listener
&&move_sound
?"and moving sound ":move_sound
?
691 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
692 getDSBCAPS(bufdesc
.dwFlags
),DXGetErrorString8(rc
));
693 if (rc
==DS_OK
&& secondary
!=NULL
) {
695 LONG refvol
,vol
,refpan
,pan
;
697 /* Check the initial secondary buffer's volume and pan */
698 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
699 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(secondary) failed: "
700 "%s\n",DXGetErrorString8(rc
));
701 ok(vol
==0,"wrong volume for a new secondary buffer: %d\n",vol
);
702 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
703 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: "
704 "%s\n",DXGetErrorString8(rc
));
705 ok(pan
==0,"wrong pan for a new secondary buffer: %d\n",pan
);
707 /* Check that changing the secondary buffer's volume and pan
708 * does not impact the primary buffer's volume and pan
710 rc
=IDirectSoundBuffer_GetVolume(primary
,&refvol
);
711 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: "
712 "%s\n",DXGetErrorString8(rc
));
713 rc
=IDirectSoundBuffer_GetPan(primary
,&refpan
);
714 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: "
715 "%s\n",DXGetErrorString8(rc
));
717 rc
=IDirectSoundBuffer_SetVolume(secondary
,-1000);
718 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
719 "%s\n",DXGetErrorString8(rc
));
720 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
721 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
722 "%s\n",DXGetErrorString8(rc
));
723 ok(vol
==-1000,"secondary: wrong volume %d instead of -1000\n",
725 rc
=IDirectSoundBuffer_SetPan(secondary
,-1000);
726 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
727 "%s\n",DXGetErrorString8(rc
));
728 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
729 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
730 "%s\n",DXGetErrorString8(rc
));
731 ok(pan
==-1000,"secondary: wrong pan %d instead of -1000\n",
734 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
735 ok(rc
==DS_OK
,"IDirectSoundBuffer_`GetVolume(primary) failed: i"
736 "%s\n",DXGetErrorString8(rc
));
737 ok(vol
==refvol
,"The primary volume changed from %d to %d\n",
739 rc
=IDirectSoundBuffer_GetPan(primary
,&pan
);
740 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: "
741 "%s\n",DXGetErrorString8(rc
));
742 ok(pan
==refpan
,"The primary pan changed from %d to %d\n",
745 rc
=IDirectSoundBuffer_SetVolume(secondary
,0);
746 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
747 "%s\n",DXGetErrorString8(rc
));
748 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
749 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
750 "%s\n",DXGetErrorString8(rc
));
753 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
755 /* DSOUND: Error: Invalid source buffer */
756 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,0);
757 ok(rc
==DSERR_INVALIDPARAM
,
758 "IDirectSound8_DuplicateSoundBuffer() should have returned "
759 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
761 /* DSOUND: Error: Invalid dest buffer */
762 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,0);
763 ok(rc
==DSERR_INVALIDPARAM
,
764 "IDirectSound8_DuplicateSoundBuffer() should have returned "
765 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
767 /* DSOUND: Error: Invalid source buffer */
768 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,0,&duplicated
);
769 ok(rc
==DSERR_INVALIDPARAM
,
770 "IDirectSound8_DuplicateSoundBuffer() should have returned "
771 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
774 rc
=IDirectSound8_DuplicateSoundBuffer(dso
,secondary
,
776 ok(rc
==DS_OK
&& duplicated
!=NULL
,
777 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
778 "a secondary buffer: %s\n",DXGetErrorString8(rc
));
780 if (rc
==DS_OK
&& duplicated
!=NULL
) {
781 ref
=IDirectSoundBuffer_Release(secondary
);
782 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d "
783 "references, should have 0\n",ref
);
784 secondary
=duplicated
;
788 if (rc
==DS_OK
&& secondary
!=NULL
) {
790 duration
=(move_listener
|| move_sound
?4.0:1.0);
791 test_buffer8(dso
,&secondary
,0,FALSE
,0,FALSE
,0,
792 winetest_interactive
,duration
,has_3dbuffer
,
793 listener
,move_listener
,move_sound
);
794 ref
=IDirectSoundBuffer_Release(secondary
);
795 ok(ref
==0,"IDirectSoundBuffer_Release() %s has %d references, "
796 "should have 0\n",has_duplicate
?"duplicated":"secondary",
803 ref
=IDirectSound3DListener_Release(listener
);
804 ok(ref
==0,"IDirectSound3dListener_Release() listener has %d "
805 "references, should have 0\n",ref
);
807 ref
=IDirectSoundBuffer_Release(primary
);
808 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
809 "should have 0\n",ref
);
812 /* Set the CooperativeLevel back to normal */
813 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
814 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
815 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
816 "%s\n",DXGetErrorString8(rc
));
819 ref
=IDirectSound8_Release(dso
);
820 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
822 return DSERR_GENERIC
;
827 static HRESULT
test_for_driver8(LPGUID lpGuid
)
830 LPDIRECTSOUND8 dso
=NULL
;
833 /* Create the DirectSound object */
834 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
835 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
836 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc
));
840 ref
=IDirectSound8_Release(dso
);
841 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
843 return DSERR_GENERIC
;
848 static HRESULT
test_primary8(LPGUID lpGuid
)
851 LPDIRECTSOUND8 dso
=NULL
;
852 LPDIRECTSOUNDBUFFER primary
=NULL
;
853 DSBUFFERDESC bufdesc
;
857 /* Create the DirectSound object */
858 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
859 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %s\n",
860 DXGetErrorString8(rc
));
864 /* Get the device capabilities */
865 ZeroMemory(&dscaps
, sizeof(dscaps
));
866 dscaps
.dwSize
=sizeof(dscaps
);
867 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
868 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc
));
872 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
873 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
874 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
875 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
876 "%s\n",DXGetErrorString8(rc
));
880 /* Testing the primary buffer */
882 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
883 bufdesc
.dwSize
=sizeof(bufdesc
);
884 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
;
885 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
886 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
== DSERR_CONTROLUNAVAIL
),
887 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: "
888 "%s\n",DXGetErrorString8(rc
));
889 if (rc
== DSERR_CONTROLUNAVAIL
)
890 trace(" No Primary\n");
891 else if (rc
==DS_OK
&& primary
!=NULL
) {
892 test_buffer8(dso
,&primary
,1,TRUE
,0,TRUE
,0,winetest_interactive
&&
893 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,NULL
,0,0);
894 if (winetest_interactive
) {
897 volume
= DSBVOLUME_MAX
;
898 for (i
= 0; i
< 6; i
++) {
899 test_buffer8(dso
,&primary
,1,TRUE
,volume
,TRUE
,0,
900 winetest_interactive
&&
901 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
903 volume
-= ((DSBVOLUME_MAX
-DSBVOLUME_MIN
) / 40);
907 for (i
= 0; i
< 7; i
++) {
908 test_buffer8(dso
,&primary
,1,TRUE
,0,TRUE
,pan
,
909 winetest_interactive
&&
910 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0);
911 pan
+= ((DSBPAN_RIGHT
-DSBPAN_LEFT
) / 6);
914 ref
=IDirectSoundBuffer_Release(primary
);
915 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
916 "should have 0\n",ref
);
919 /* Set the CooperativeLevel back to normal */
920 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
921 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
922 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
923 "%s\n",DXGetErrorString8(rc
));
926 ref
=IDirectSound8_Release(dso
);
927 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
929 return DSERR_GENERIC
;
934 static HRESULT
test_primary_3d8(LPGUID lpGuid
)
937 LPDIRECTSOUND8 dso
=NULL
;
938 LPDIRECTSOUNDBUFFER primary
=NULL
;
939 DSBUFFERDESC bufdesc
;
943 /* Create the DirectSound object */
944 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
945 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %s\n",
946 DXGetErrorString8(rc
));
950 /* Get the device capabilities */
951 ZeroMemory(&dscaps
, sizeof(dscaps
));
952 dscaps
.dwSize
=sizeof(dscaps
);
953 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
954 ok(rc
==DS_OK
,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc
));
958 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
959 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
960 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
961 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
962 "%s\n",DXGetErrorString8(rc
));
967 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
968 bufdesc
.dwSize
=sizeof(bufdesc
);
969 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
970 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
971 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
972 "to create a primary buffer: %s\n",DXGetErrorString8(rc
));
973 if (rc
==DS_OK
&& primary
!=NULL
) {
974 ref
=IDirectSoundBuffer_Release(primary
);
975 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
976 "should have 0\n",ref
);
978 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
979 bufdesc
.dwSize
=sizeof(bufdesc
);
980 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
981 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
982 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() "
983 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc
));
984 if (rc
==DS_OK
&& primary
!=NULL
) {
985 test_buffer8(dso
,&primary
,1,FALSE
,0,FALSE
,0,
986 winetest_interactive
&&
987 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0);
988 ref
=IDirectSoundBuffer_Release(primary
);
989 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
990 "should have 0\n",ref
);
993 /* Set the CooperativeLevel back to normal */
994 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
995 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
996 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
997 "%s\n",DXGetErrorString8(rc
));
1000 ref
=IDirectSound8_Release(dso
);
1001 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
1003 return DSERR_GENERIC
;
1008 static HRESULT
test_primary_3d_with_listener8(LPGUID lpGuid
)
1011 LPDIRECTSOUND8 dso
=NULL
;
1012 LPDIRECTSOUNDBUFFER primary
=NULL
;
1013 DSBUFFERDESC bufdesc
;
1017 /* Create the DirectSound object */
1018 rc
=pDirectSoundCreate8(lpGuid
,&dso
,NULL
);
1019 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate8() failed: %s\n",
1020 DXGetErrorString8(rc
));
1024 /* Get the device capabilities */
1025 ZeroMemory(&dscaps
, sizeof(dscaps
));
1026 dscaps
.dwSize
=sizeof(dscaps
);
1027 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
1028 ok(rc
==DS_OK
,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc
));
1032 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1033 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1034 rc
=IDirectSound8_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1035 ok(rc
==DS_OK
,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
1036 "%s\n",DXGetErrorString8(rc
));
1040 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1041 bufdesc
.dwSize
=sizeof(bufdesc
);
1042 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1043 rc
=IDirectSound8_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1044 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound8_CreateSoundBuffer() failed "
1045 "to create a 3D primary buffer %s\n",DXGetErrorString8(rc
));
1046 if (rc
==DS_OK
&& primary
!=NULL
) {
1047 LPDIRECTSOUND3DLISTENER listener
=NULL
;
1048 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1049 &IID_IDirectSound3DListener
,
1050 (void **)&listener
);
1051 ok(rc
==DS_OK
&& listener
!=NULL
,"IDirectSoundBuffer_QueryInterface() "
1052 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc
));
1053 if (rc
==DS_OK
&& listener
!=NULL
) {
1054 LPDIRECTSOUNDBUFFER temp_buffer
=NULL
;
1056 /* Checking the COM interface */
1057 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1058 &IID_IDirectSoundBuffer
,
1059 (LPVOID
*)&temp_buffer
);
1060 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1061 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1062 DXGetErrorString8(rc
));
1063 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1064 if (rc
==DS_OK
&& temp_buffer
!=NULL
) {
1065 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1066 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1067 "should have 1\n",ref
);
1070 rc
=IDirectSound3DListener_QueryInterface(listener
,
1071 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1072 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1073 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1074 DXGetErrorString8(rc
));
1075 ok(temp_buffer
==primary
,"COM interface broken: %p != %p\n",temp_buffer
,primary
);
1076 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1077 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1078 "should have 1\n",ref
);
1080 /* Testing the buffer */
1081 test_buffer8(dso
,&primary
,1,FALSE
,0,FALSE
,0,
1082 winetest_interactive
&&
1083 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
1084 1.0,0,listener
,0,0);
1087 /* Testing the reference counting */
1088 ref
=IDirectSound3DListener_Release(listener
);
1089 ok(ref
==0,"IDirectSound3DListener_Release() listener has %d "
1090 "references, should have 0\n",ref
);
1093 /* Testing the reference counting */
1094 ref
=IDirectSoundBuffer_Release(primary
);
1095 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1096 "should have 0\n",ref
);
1100 ref
=IDirectSound8_Release(dso
);
1101 ok(ref
==0,"IDirectSound8_Release() has %d references, should have 0\n",ref
);
1103 return DSERR_GENERIC
;
1108 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1109 LPCSTR lpcstrModule
, LPVOID lpContext
)
1112 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1114 rc
= test_for_driver8(lpGuid
);
1115 if (rc
== DSERR_NODRIVER
) {
1116 trace(" No Driver\n");
1118 } else if (rc
== DSERR_ALLOCATED
) {
1119 trace(" Already In Use\n");
1121 } else if (rc
== E_FAIL
) {
1122 trace(" No Device\n");
1126 trace(" Testing the primary buffer\n");
1127 test_primary8(lpGuid
);
1129 trace(" Testing 3D primary buffer\n");
1130 test_primary_3d8(lpGuid
);
1132 trace(" Testing 3D primary buffer with listener\n");
1133 test_primary_3d_with_listener8(lpGuid
);
1135 /* Testing secondary buffers */
1136 test_secondary8(lpGuid
,winetest_interactive
,0,0,0,0,0,0);
1137 test_secondary8(lpGuid
,winetest_interactive
,0,0,0,1,0,0);
1139 /* Testing 3D secondary buffers */
1140 test_secondary8(lpGuid
,winetest_interactive
,1,0,0,0,0,0);
1141 test_secondary8(lpGuid
,winetest_interactive
,1,1,0,0,0,0);
1142 test_secondary8(lpGuid
,winetest_interactive
,1,1,0,1,0,0);
1143 test_secondary8(lpGuid
,winetest_interactive
,1,0,1,0,0,0);
1144 test_secondary8(lpGuid
,winetest_interactive
,1,0,1,1,0,0);
1145 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,0,0);
1146 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,1,0,0);
1147 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,1,0);
1148 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,0,1);
1149 test_secondary8(lpGuid
,winetest_interactive
,1,1,1,0,1,1);
1154 static void ds3d8_tests(void)
1157 rc
=DirectSoundEnumerateA(&dsenum_callback
,NULL
);
1158 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc
));
1167 hDsound
= LoadLibraryA("dsound.dll");
1169 trace("dsound.dll not found\n");
1173 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
1175 pDirectSoundCreate8
= (void*)GetProcAddress(hDsound
, "DirectSoundCreate8");
1176 if (!pDirectSoundCreate8
) {
1177 trace("ds3d8 test skipped\n");