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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
32 #include "wine/test.h"
36 #include "dsound_test.h"
38 #define PI 3.14159265358979323846
39 char* wave_generate_la(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
46 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
47 *size
=nb_samples
*wfx
->nBlockAlign
;
49 for (i
=0;i
<nb_samples
;i
++) {
50 double y
=sin(440.0*2*PI
*i
/wfx
->nSamplesPerSec
);
51 if (wfx
->wBitsPerSample
==8) {
52 unsigned char sample
=(unsigned char)((double)127.5*(y
+1.0));
54 if (wfx
->nChannels
==2)
57 signed short sample
=(signed short)((double)32767.5*y
-0.5);
61 if (wfx
->nChannels
==2) {
71 const char * getDSBCAPS(DWORD xmask
) {
76 #define FE(x) { x, #x },
77 FE(DSBCAPS_PRIMARYBUFFER
)
79 FE(DSBCAPS_LOCHARDWARE
)
80 FE(DSBCAPS_LOCSOFTWARE
)
82 FE(DSBCAPS_CTRLFREQUENCY
)
84 FE(DSBCAPS_CTRLVOLUME
)
85 FE(DSBCAPS_CTRLPOSITIONNOTIFY
)
86 FE(DSBCAPS_STICKYFOCUS
)
87 FE(DSBCAPS_GLOBALFOCUS
)
88 FE(DSBCAPS_GETCURRENTPOSITION2
)
89 FE(DSBCAPS_MUTE3DATMAXDISTANCE
)
92 static char buffer
[512];
98 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++) {
99 if ((flags
[i
].mask
& xmask
) == flags
[i
].mask
) {
104 strcat(buffer
, flags
[i
].name
);
113 HWND hwnd
=GetForegroundWindow();
115 hwnd
=GetDesktopWindow();
119 void init_format(WAVEFORMATEX
* wfx
, int format
, int rate
, int depth
,
122 wfx
->wFormatTag
=format
;
123 wfx
->nChannels
=channels
;
124 wfx
->wBitsPerSample
=depth
;
125 wfx
->nSamplesPerSec
=rate
;
126 wfx
->nBlockAlign
=wfx
->nChannels
*wfx
->wBitsPerSample
/8;
127 /* FIXME: Shouldn't this test be if (format!=WAVE_FORMAT_PCM) */
128 if (wfx
->nBlockAlign
==0)
130 /* align compressed formats to byte boundary */
133 wfx
->nAvgBytesPerSec
=wfx
->nSamplesPerSec
*wfx
->nBlockAlign
;
141 LPDIRECTSOUNDBUFFER dsbo
;
149 static int buffer_refill(play_state_t
* state
, DWORD size
)
155 if (size
>state
->wave_len
-state
->written
)
156 size
=state
->wave_len
-state
->written
;
158 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
159 &ptr1
,&len1
,&ptr2
,&len2
,0);
160 ok(rc
==DS_OK
,"IDirectSoundBuffer_Lock() failed: %s\n",
161 DXGetErrorString8(rc
));
165 memcpy(ptr1
,state
->wave
+state
->written
,len1
);
166 state
->written
+=len1
;
168 memcpy(ptr2
,state
->wave
+state
->written
,len2
);
169 state
->written
+=len2
;
171 state
->offset
=state
->written
% state
->buffer_size
;
172 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
173 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %s\n",
174 DXGetErrorString8(rc
));
180 static int buffer_silence(play_state_t
* state
, DWORD size
)
187 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
188 &ptr1
,&len1
,&ptr2
,&len2
,0);
189 ok(rc
==DS_OK
,"IDirectSoundBuffer_Lock() failed: %s\n",
190 DXGetErrorString8(rc
));
194 s
=(state
->wfx
->wBitsPerSample
==8?0x80:0);
199 state
->offset
=(state
->offset
+size
) % state
->buffer_size
;
200 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
201 ok(rc
==DS_OK
,"IDirectSoundBuffer_Unlock() failed: %s\n",
202 DXGetErrorString8(rc
));
208 static int buffer_service(play_state_t
* state
)
210 DWORD last_play_pos
,play_pos
,buf_free
;
213 rc
=IDirectSoundBuffer_GetCurrentPosition(state
->dsbo
,&play_pos
,NULL
);
214 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
215 DXGetErrorString8(rc
));
220 /* Update the amount played */
221 last_play_pos
=state
->played
% state
->buffer_size
;
222 if (play_pos
<last_play_pos
)
223 state
->played
+=state
->buffer_size
-last_play_pos
+play_pos
;
225 state
->played
+=play_pos
-last_play_pos
;
227 if (winetest_debug
> 1)
228 trace("buf size=%ld last_play_pos=%ld play_pos=%ld played=%ld / %ld\n",
229 state
->buffer_size
,last_play_pos
,play_pos
,state
->played
,
232 if (state
->played
>state
->wave_len
)
234 /* Everything has been played */
238 /* Refill the buffer */
239 if (state
->offset
<=play_pos
)
240 buf_free
=play_pos
-state
->offset
;
242 buf_free
=state
->buffer_size
-state
->offset
+play_pos
;
244 if (winetest_debug
> 1)
245 trace("offset=%ld free=%ld written=%ld / %ld\n",
246 state
->offset
,buf_free
,state
->written
,state
->wave_len
);
250 if (state
->written
<state
->wave_len
)
252 int w
=buffer_refill(state
,buf_free
);
256 if (state
->written
==state
->wave_len
&& winetest_debug
> 1)
257 trace("last sound byte at %ld\n",
258 (state
->written
% state
->buffer_size
));
262 /* Fill with silence */
263 if (winetest_debug
> 1)
264 trace("writing %ld bytes of silence\n",buf_free
);
265 if (buffer_silence(state
,buf_free
)==-1)
271 if (winetest_debug
> 1)
272 trace("stopping playback\n");
273 rc
=IDirectSoundBuffer_Stop(state
->dsbo
);
274 ok(rc
==DS_OK
,"IDirectSoundBuffer_Stop() failed: %s\n",
275 DXGetErrorString8(rc
));
279 void test_buffer(LPDIRECTSOUND dso
, LPDIRECTSOUNDBUFFER dsbo
,
280 BOOL is_primary
, BOOL set_volume
, LONG volume
,
281 BOOL set_pan
, LONG pan
, BOOL play
, double duration
,
282 BOOL buffer3d
, LPDIRECTSOUND3DLISTENER listener
,
283 BOOL move_listener
, BOOL move_sound
,
284 BOOL set_frequency
, DWORD frequency
)
288 WAVEFORMATEX wfx
,wfx2
;
289 DWORD size
,status
,freq
;
293 rc
=IDirectSoundBuffer_SetFrequency(dsbo
,frequency
);
294 ok(rc
==DS_OK
||rc
==DSERR_CONTROLUNAVAIL
,
295 "IDirectSoundBuffer_SetFrequency() failed to set frequency "
296 "%s\n",DXGetErrorString8(rc
));
301 /* DSOUND: Error: Invalid caps pointer */
302 rc
=IDirectSoundBuffer_GetCaps(dsbo
,0);
303 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
304 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
306 ZeroMemory(&dsbcaps
, sizeof(dsbcaps
));
308 /* DSOUND: Error: Invalid caps pointer */
309 rc
=IDirectSoundBuffer_GetCaps(dsbo
,&dsbcaps
);
310 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetCaps() should have "
311 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
313 dsbcaps
.dwSize
=sizeof(dsbcaps
);
314 rc
=IDirectSoundBuffer_GetCaps(dsbo
,&dsbcaps
);
315 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetCaps() failed: %s\n",
316 DXGetErrorString8(rc
));
317 if (rc
==DS_OK
&& winetest_debug
> 1) {
318 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps
.dwFlags
,
319 dsbcaps
.dwBufferBytes
);
322 /* Query the format size. Note that it may not match sizeof(wfx) */
324 rc
=IDirectSoundBuffer_GetFormat(dsbo
,NULL
,0,&size
);
325 ok(rc
==DS_OK
&& size
!=0,"IDirectSoundBuffer_GetFormat() should have "
326 "returned the needed size: rc=%s size=%ld\n",DXGetErrorString8(rc
),size
);
328 rc
=IDirectSoundBuffer_GetFormat(dsbo
,&wfx
,sizeof(wfx
),NULL
);
329 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %s\n",
330 DXGetErrorString8(rc
));
331 if (rc
==DS_OK
&& winetest_debug
> 1) {
332 trace(" Format: %s tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
333 is_primary
? "Primary" : "Secondary",
334 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
335 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
338 /* DSOUND: Error: Invalid frequency buffer */
339 rc
=IDirectSoundBuffer_GetFrequency(dsbo
,0);
340 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetFrequency() should have "
341 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
343 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
344 rc
=IDirectSoundBuffer_GetFrequency(dsbo
,&freq
);
345 ok((rc
==DS_OK
&& !is_primary
) || (rc
==DSERR_CONTROLUNAVAIL
&&is_primary
) ||
346 (rc
==DSERR_CONTROLUNAVAIL
&&!(dsbcaps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
)),
347 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc
));
349 DWORD f
= set_frequency
?frequency
:wfx
.nSamplesPerSec
;
350 ok(freq
==f
,"The frequency returned by GetFrequency "
351 "%ld does not match the format %ld\n",freq
,f
);
354 /* DSOUND: Error: Invalid status pointer */
355 rc
=IDirectSoundBuffer_GetStatus(dsbo
,0);
356 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_GetStatus() should have "
357 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
359 rc
=IDirectSoundBuffer_GetStatus(dsbo
,&status
);
360 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %s\n",
361 DXGetErrorString8(rc
));
362 ok(status
==0,"status=0x%lx instead of 0\n",status
);
365 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
366 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
367 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
368 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
369 "%s\n",DXGetErrorString8(rc
));
373 /* DSOUND: Error: Invalid format pointer */
374 rc
=IDirectSoundBuffer_SetFormat(dsbo
,0);
375 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSoundBuffer_SetFormat() should have "
376 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
378 init_format(&wfx2
,WAVE_FORMAT_PCM
,11025,16,2);
379 rc
=IDirectSoundBuffer_SetFormat(dsbo
,&wfx2
);
380 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetFormat() failed: %s\n",
381 DXGetErrorString8(rc
));
383 /* There is no garantee that SetFormat will actually change the
384 * format to what we asked for. It depends on what the soundcard
385 * supports. So we must re-query the format.
387 rc
=IDirectSoundBuffer_GetFormat(dsbo
,&wfx
,sizeof(wfx
),NULL
);
388 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetFormat() failed: %s\n",
389 DXGetErrorString8(rc
));
391 (wfx
.wFormatTag
!=wfx2
.wFormatTag
||
392 wfx
.nSamplesPerSec
!=wfx2
.nSamplesPerSec
||
393 wfx
.wBitsPerSample
!=wfx2
.wBitsPerSample
||
394 wfx
.nChannels
!=wfx2
.nChannels
)) {
395 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
396 wfx2
.wFormatTag
,wfx2
.nSamplesPerSec
,wfx2
.wBitsPerSample
,
397 wfx2
.nChannels
,wfx2
.nAvgBytesPerSec
,wfx2
.nBlockAlign
);
398 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
399 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
400 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
403 /* Set the CooperativeLevel back to normal */
404 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
405 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
406 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: "
407 "%s\n",DXGetErrorString8(rc
));
412 DS3DLISTENER listener_param
;
413 LPDIRECTSOUND3DBUFFER buffer
=NULL
;
414 DS3DBUFFER buffer_param
;
415 DWORD start_time
,now
;
417 if (winetest_interactive
) {
419 trace(" Playing %g second 440Hz tone at %ldx%dx%d with a "
420 "frequency of %ld (%ldHz)\n", duration
,
421 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
, wfx
.nChannels
,
422 frequency
, (440 * frequency
) / wfx
.nSamplesPerSec
);
424 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration
,
425 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
, wfx
.nChannels
);
429 /* We must call SetCooperativeLevel to be allowed to call Lock */
430 /* DSOUND: Setting DirectSound cooperative level to
431 * DSSCL_WRITEPRIMARY */
432 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),
434 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_WRITEPRIMARY) "
435 "failed: %s\n",DXGetErrorString8(rc
));
440 LPDIRECTSOUNDBUFFER temp_buffer
;
442 rc
=IDirectSoundBuffer_QueryInterface(dsbo
,&IID_IDirectSound3DBuffer
,
444 ok(rc
==DS_OK
,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
445 DXGetErrorString8(rc
));
449 /* check the COM interface */
450 rc
=IDirectSoundBuffer_QueryInterface(dsbo
, &IID_IDirectSoundBuffer
,
451 (LPVOID
*)&temp_buffer
);
452 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
453 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
454 DXGetErrorString8(rc
));
455 ok(temp_buffer
==dsbo
,"COM interface broken: 0x%08lx != 0x%08lx\n",
456 (DWORD
)temp_buffer
,(DWORD
)dsbo
);
457 ref
=IDirectSoundBuffer_Release(temp_buffer
);
458 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
459 "should have 1\n",ref
);
462 rc
=IDirectSound3DBuffer_QueryInterface(dsbo
,
463 &IID_IDirectSoundBuffer
,
464 (LPVOID
*)&temp_buffer
);
465 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
466 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
467 DXGetErrorString8(rc
));
468 ok(temp_buffer
==dsbo
,"COM interface broken: 0x%08lx != 0x%08lx\n",
469 (DWORD
)temp_buffer
,(DWORD
)dsbo
);
470 ref
=IDirectSoundBuffer_Release(temp_buffer
);
471 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
472 "should have 1\n",ref
);
475 /* FIXME: this works on windows */
476 ref
=IDirectSoundBuffer_Release(dsbo
);
477 ok(ref
==0,"IDirectSoundBuffer_Release() has %d references, "
478 "should have 0\n",ref
);
480 rc
=IDirectSound3DBuffer_QueryInterface(buffer
,
481 &IID_IDirectSoundBuffer
,
483 ok(rc
==DS_OK
&& dsbo
!=NULL
,"IDirectSound3DBuffer_QueryInterface() "
484 "failed: %s\n",DXGetErrorString8(rc
));
487 /* DSOUND: Error: Invalid buffer */
488 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,0);
489 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
490 "failed: %s\n",DXGetErrorString8(rc
));
492 ZeroMemory(&buffer_param
, sizeof(buffer_param
));
494 /* DSOUND: Error: Invalid buffer */
495 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
496 ok(rc
==DSERR_INVALIDPARAM
,"IDirectSound3DBuffer_GetAllParameters() "
497 "failed: %s\n",DXGetErrorString8(rc
));
499 buffer_param
.dwSize
=sizeof(buffer_param
);
500 rc
=IDirectSound3DBuffer_GetAllParameters(buffer
,&buffer_param
);
501 ok(rc
==DS_OK
,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
502 DXGetErrorString8(rc
));
505 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
507 rc
=IDirectSoundBuffer_GetVolume(dsbo
,&val
);
508 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume() failed: %s\n",
509 DXGetErrorString8(rc
));
511 rc
=IDirectSoundBuffer_SetVolume(dsbo
,volume
);
512 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume() failed: %s\n",
513 DXGetErrorString8(rc
));
515 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
516 rc
=IDirectSoundBuffer_GetVolume(dsbo
,&volume
);
517 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetVolume() "
518 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
519 DXGetErrorString8(rc
));
524 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLPAN
) {
526 rc
=IDirectSoundBuffer_GetPan(dsbo
,&val
);
527 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan() failed: %s\n",
528 DXGetErrorString8(rc
));
530 rc
=IDirectSoundBuffer_SetPan(dsbo
,pan
);
531 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan() failed: %s\n",
532 DXGetErrorString8(rc
));
534 /* DSOUND: Error: Buffer does not have CTRLPAN */
535 rc
=IDirectSoundBuffer_GetPan(dsbo
,&pan
);
536 ok(rc
==DSERR_CONTROLUNAVAIL
,"IDirectSoundBuffer_GetPan() "
537 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
538 DXGetErrorString8(rc
));
543 state
.wave
=wave_generate_la(&wfx
,(duration
*frequency
)/wfx
.nSamplesPerSec
,&state
.wave_len
);
545 state
.wave
=wave_generate_la(&wfx
,duration
,&state
.wave_len
);
549 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
550 state
.played
=state
.written
=state
.offset
=0;
551 buffer_refill(&state
,state
.buffer_size
);
553 rc
=IDirectSoundBuffer_Play(dsbo
,0,0,DSBPLAY_LOOPING
);
554 ok(rc
==DS_OK
,"IDirectSoundBuffer_Play() failed: %s\n",
555 DXGetErrorString8(rc
));
557 rc
=IDirectSoundBuffer_GetStatus(dsbo
,&status
);
558 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetStatus() failed: %s\n",
559 DXGetErrorString8(rc
));
560 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
561 "GetStatus: bad status: %lx\n",status
);
564 ZeroMemory(&listener_param
,sizeof(listener_param
));
565 listener_param
.dwSize
=sizeof(listener_param
);
566 rc
=IDirectSound3DListener_GetAllParameters(listener
,
568 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
569 "failed: %s\n",DXGetErrorString8(rc
));
571 listener_param
.vPosition
.x
= -5.0;
572 listener_param
.vVelocity
.x
= 10.0/duration
;
574 rc
=IDirectSound3DListener_SetAllParameters(listener
,
577 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: %s\n",
578 DXGetErrorString8(rc
));
582 buffer_param
.vPosition
.x
= 100.0;
583 buffer_param
.vVelocity
.x
= -200.0/duration
;
585 buffer_param
.flMinDistance
= 10;
586 rc
=IDirectSound3DBuffer_SetAllParameters(buffer
,&buffer_param
,
588 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
589 DXGetErrorString8(rc
));
592 start_time
=GetTickCount();
593 while (buffer_service(&state
)) {
594 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
);
596 if (listener
&& move_listener
) {
597 listener_param
.vPosition
.x
= -5.0+10.0*(now
-start_time
)/
599 if (winetest_debug
>2)
600 trace("listener position=%g\n",listener_param
.vPosition
.x
);
601 rc
=IDirectSound3DListener_SetPosition(listener
,
602 listener_param
.vPosition
.x
,listener_param
.vPosition
.y
,
603 listener_param
.vPosition
.z
,DS3D_IMMEDIATE
);
604 ok(rc
==DS_OK
,"IDirectSound3dListener_SetPosition() failed: "
605 "%s\n",DXGetErrorString8(rc
));
607 if (buffer3d
&& move_sound
) {
608 buffer_param
.vPosition
.x
= 100-200.0*(now
-start_time
)/
610 if (winetest_debug
>2)
611 trace("sound position=%g\n",buffer_param
.vPosition
.x
);
612 rc
=IDirectSound3DBuffer_SetPosition(buffer
,
613 buffer_param
.vPosition
.x
,buffer_param
.vPosition
.y
,
614 buffer_param
.vPosition
.z
,DS3D_IMMEDIATE
);
615 ok(rc
==DS_OK
,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
616 DXGetErrorString8(rc
));
619 /* Check the sound duration was within 10% of the expected value */
621 ok(fabs(1000*duration
-now
+start_time
)<=100*duration
,
622 "The sound played for %ld ms instead of %g ms\n",
623 now
-start_time
,1000*duration
);
627 /* Set the CooperativeLevel back to normal */
628 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
629 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
630 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) "
631 "failed: %s\n",DXGetErrorString8(rc
));
634 ref
=IDirectSound3DBuffer_Release(buffer
);
635 ok(ref
==0,"IDirectSound3DBuffer_Release() has %d references, "
636 "should have 0\n",ref
);
641 static HRESULT
test_secondary(LPGUID lpGuid
, int play
,
642 int has_3d
, int has_3dbuffer
,
643 int has_listener
, int has_duplicate
,
644 int move_listener
, int move_sound
)
647 LPDIRECTSOUND dso
=NULL
;
648 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
649 LPDIRECTSOUND3DLISTENER listener
=NULL
;
650 DSBUFFERDESC bufdesc
;
651 WAVEFORMATEX wfx
, wfx1
;
654 /* Create the DirectSound object */
655 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
656 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate() failed: %s\n",
657 DXGetErrorString8(rc
));
661 /* We must call SetCooperativeLevel before creating primary buffer */
662 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
663 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
664 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
665 "%s\n",DXGetErrorString8(rc
));
669 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
670 bufdesc
.dwSize
=sizeof(bufdesc
);
671 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
673 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
675 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
676 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
677 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
==DSERR_CONTROLUNAVAIL
),
678 "IDirectSound_CreateSoundBuffer() failed to create a %sprimary buffer: "
679 "%s\n",has_3d
?"3D ":"", DXGetErrorString8(rc
));
680 if (rc
==DSERR_CONTROLUNAVAIL
)
681 trace(" No Primary\n");
682 else if (rc
==DS_OK
&& primary
!=NULL
) {
683 rc
=IDirectSoundBuffer_GetFormat(primary
,&wfx1
,sizeof(wfx1
),NULL
);
684 ok(rc
==DS_OK
,"IDirectSoundBuffer8_Getformat() failed: %s\n",
685 DXGetErrorString8(rc
));
690 rc
=IDirectSoundBuffer_QueryInterface(primary
,
691 &IID_IDirectSound3DListener
,
693 ok(rc
==DS_OK
&& listener
!=NULL
,
694 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
695 "listener: %s\n",DXGetErrorString8(rc
));
696 ref
=IDirectSoundBuffer_Release(primary
);
697 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
698 "should have 0\n",ref
);
699 if (rc
==DS_OK
&& listener
!=NULL
) {
700 DS3DLISTENER listener_param
;
701 ZeroMemory(&listener_param
,sizeof(listener_param
));
702 /* DSOUND: Error: Invalid buffer */
703 rc
=IDirectSound3DListener_GetAllParameters(listener
,0);
704 ok(rc
==DSERR_INVALIDPARAM
,
705 "IDirectSound3dListener_GetAllParameters() should have "
706 "returned DSERR_INVALIDPARAM, returned: %s\n",
707 DXGetErrorString8(rc
));
709 /* DSOUND: Error: Invalid buffer */
710 rc
=IDirectSound3DListener_GetAllParameters(listener
,
712 ok(rc
==DSERR_INVALIDPARAM
,
713 "IDirectSound3dListener_GetAllParameters() should have "
714 "returned DSERR_INVALIDPARAM, returned: %s\n",
715 DXGetErrorString8(rc
));
717 listener_param
.dwSize
=sizeof(listener_param
);
718 rc
=IDirectSound3DListener_GetAllParameters(listener
,
720 ok(rc
==DS_OK
,"IDirectSound3dListener_GetAllParameters() "
721 "failed: %s\n",DXGetErrorString8(rc
));
727 init_format(&wfx
,WAVE_FORMAT_PCM
,22050,16,2);
729 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
730 bufdesc
.dwSize
=sizeof(bufdesc
);
731 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
733 bufdesc
.dwFlags
|=DSBCAPS_CTRL3D
;
736 (DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
737 bufdesc
.dwBufferBytes
=align(wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000,
739 bufdesc
.lpwfxFormat
=&wfx
;
740 if (winetest_interactive
) {
741 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d "
742 "with a primary buffer at %ldx%dx%d\n",
743 has_3dbuffer
?"3D ":"",
744 has_duplicate
?"duplicated ":"",
745 listener
!=NULL
||move_sound
?"with ":"",
746 move_listener
?"moving ":"",
747 listener
!=NULL
?"listener ":"",
748 listener
&&move_sound
?"and moving sound ":move_sound
?
750 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
751 wfx1
.nSamplesPerSec
,wfx1
.wBitsPerSample
,wfx1
.nChannels
);
753 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
754 ok(rc
==DS_OK
&& secondary
!=NULL
,"IDirectSound_CreateSoundBuffer() "
755 "failed to create a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d (%s): %s\n",
756 has_3dbuffer
?"3D ":"", has_duplicate
?"duplicated ":"",
757 listener
!=NULL
||move_sound
?"with ":"", move_listener
?"moving ":"",
758 listener
!=NULL
?"listener ":"",
759 listener
&&move_sound
?"and moving sound ":move_sound
?
761 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
,
762 getDSBCAPS(bufdesc
.dwFlags
),DXGetErrorString8(rc
));
763 if (rc
==DS_OK
&& secondary
!=NULL
) {
768 /* Check the initial secondary buffer's volume and pan */
769 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
770 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(secondary) failed: "
771 "%s\n",DXGetErrorString8(rc
));
772 ok(vol
==0,"wrong volume for a new secondary buffer: %ld\n",vol
);
773 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
774 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(secondary) failed: "
775 "%s\n",DXGetErrorString8(rc
));
776 ok(pan
==0,"wrong pan for a new secondary buffer: %ld\n",pan
);
778 /* Check that changing the secondary buffer's volume and pan
779 * does not impact the primary buffer's volume and pan
781 rc
=IDirectSoundBuffer_GetVolume(primary
,&refvol
);
782 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: "
783 "%s\n",DXGetErrorString8(rc
));
784 rc
=IDirectSoundBuffer_GetPan(primary
,&refpan
);
785 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %s\n",
786 DXGetErrorString8(rc
));
788 rc
=IDirectSoundBuffer_SetVolume(secondary
,-1000);
789 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
790 "%s\n",DXGetErrorString8(rc
));
791 rc
=IDirectSoundBuffer_GetVolume(secondary
,&vol
);
792 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
793 "%s\n",DXGetErrorString8(rc
));
794 ok(vol
==-1000,"secondary: wrong volume %ld instead of -1000\n",
796 rc
=IDirectSoundBuffer_SetPan(secondary
,-1000);
797 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
798 "%s\n",DXGetErrorString8(rc
));
799 rc
=IDirectSoundBuffer_GetPan(secondary
,&pan
);
800 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
801 "%s\n",DXGetErrorString8(rc
));
802 ok(pan
==-1000,"secondary: wrong pan %ld instead of -1000\n",
805 rc
=IDirectSoundBuffer_GetVolume(primary
,&vol
);
806 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetVolume(primary) failed: "
807 "%s\n",DXGetErrorString8(rc
));
808 ok(vol
==refvol
,"The primary volume changed from %ld to %ld\n",
810 rc
=IDirectSoundBuffer_GetPan(primary
,&pan
);
811 ok(rc
==DS_OK
,"IDirectSoundBuffer_GetPan(primary) failed: %s\n",
812 DXGetErrorString8(rc
));
813 ok(pan
==refpan
,"The primary pan changed from %ld to %ld\n",
816 rc
=IDirectSoundBuffer_SetVolume(secondary
,0);
817 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetVolume(secondary) failed: "
818 "%s\n",DXGetErrorString8(rc
));
819 rc
=IDirectSoundBuffer_SetPan(secondary
,0);
820 ok(rc
==DS_OK
,"IDirectSoundBuffer_SetPan(secondary) failed: "
821 "%s\n",DXGetErrorString8(rc
));
824 LPDIRECTSOUNDBUFFER duplicated
=NULL
;
826 /* DSOUND: Error: Invalid source buffer */
827 rc
=IDirectSound_DuplicateSoundBuffer(dso
,0,0);
828 ok(rc
==DSERR_INVALIDPARAM
,
829 "IDirectSound_DuplicateSoundBuffer() should have returned "
830 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
832 /* DSOUND: Error: Invalid dest buffer */
833 rc
=IDirectSound_DuplicateSoundBuffer(dso
,secondary
,0);
834 ok(rc
==DSERR_INVALIDPARAM
,
835 "IDirectSound_DuplicateSoundBuffer() should have returned "
836 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
838 /* DSOUND: Error: Invalid source buffer */
839 rc
=IDirectSound_DuplicateSoundBuffer(dso
,0,&duplicated
);
840 ok(rc
==DSERR_INVALIDPARAM
,
841 "IDirectSound_DuplicateSoundBuffer() should have returned "
842 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc
));
845 rc
=IDirectSound_DuplicateSoundBuffer(dso
,secondary
,
847 ok(rc
==DS_OK
&& duplicated
!=NULL
,
848 "IDirectSound_DuplicateSoundBuffer() failed to duplicate "
849 "a secondary buffer: %s\n",DXGetErrorString8(rc
));
851 if (rc
==DS_OK
&& duplicated
!=NULL
) {
852 ref
=IDirectSoundBuffer_Release(secondary
);
853 ok(ref
==0,"IDirectSoundBuffer_Release() secondary has %d "
854 "references, should have 0\n",ref
);
855 secondary
=duplicated
;
859 if (rc
==DS_OK
&& secondary
!=NULL
) {
861 duration
=(move_listener
|| move_sound
?4.0:1.0);
862 test_buffer(dso
,secondary
,0,FALSE
,0,FALSE
,0,
863 winetest_interactive
,duration
,has_3dbuffer
,
864 listener
,move_listener
,move_sound
,FALSE
,0);
865 ref
=IDirectSoundBuffer_Release(secondary
);
866 ok(ref
==0,"IDirectSoundBuffer_Release() %s has %d references, "
867 "should have 0\n",has_duplicate
?"duplicated":"secondary",
874 ref
=IDirectSound3DListener_Release(listener
);
875 ok(ref
==0,"IDirectSound3dListener_Release() listener has %d "
876 "references, should have 0\n",ref
);
878 ref
=IDirectSoundBuffer_Release(primary
);
879 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
880 "should have 0\n",ref
);
883 /* Set the CooperativeLevel back to normal */
884 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
885 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
886 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
887 DXGetErrorString8(rc
));
890 ref
=IDirectSound_Release(dso
);
891 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
893 return DSERR_GENERIC
;
898 static HRESULT
test_for_driver(LPGUID lpGuid
)
901 LPDIRECTSOUND dso
=NULL
;
904 /* Create the DirectSound object */
905 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
906 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
,
907 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc
));
911 ref
=IDirectSound_Release(dso
);
912 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
914 return DSERR_GENERIC
;
919 static HRESULT
test_primary(LPGUID lpGuid
)
922 LPDIRECTSOUND dso
=NULL
;
923 LPDIRECTSOUNDBUFFER primary
=NULL
;
924 DSBUFFERDESC bufdesc
;
928 /* Create the DirectSound object */
929 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
930 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate() failed: %s\n",
931 DXGetErrorString8(rc
));
935 /* Get the device capabilities */
936 ZeroMemory(&dscaps
, sizeof(dscaps
));
937 dscaps
.dwSize
=sizeof(dscaps
);
938 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
939 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc
));
943 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
944 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
945 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
946 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
947 "%s\n",DXGetErrorString8(rc
));
951 /* Testing the primary buffer */
953 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
954 bufdesc
.dwSize
=sizeof(bufdesc
);
955 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
;
956 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
957 ok((rc
==DS_OK
&& primary
!=NULL
) || (rc
==DSERR_CONTROLUNAVAIL
),
958 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "
959 "%s\n",DXGetErrorString8(rc
));
960 if (rc
==DSERR_CONTROLUNAVAIL
)
961 trace(" No Primary\n");
962 else if (rc
==DS_OK
&& primary
!=NULL
) {
963 test_buffer(dso
,primary
,1,TRUE
,0,TRUE
,0,winetest_interactive
&&
964 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,NULL
,0,0,
966 if (winetest_interactive
) {
969 volume
= DSBVOLUME_MAX
;
970 for (i
= 0; i
< 6; i
++) {
971 test_buffer(dso
,primary
,1,TRUE
,volume
,TRUE
,0,
972 winetest_interactive
&&
973 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),
974 1.0,0,NULL
,0,0,FALSE
,0);
975 volume
-= ((DSBVOLUME_MAX
-DSBVOLUME_MIN
) / 40);
979 for (i
= 0; i
< 7; i
++) {
980 test_buffer(dso
,primary
,1,TRUE
,0,TRUE
,pan
,
981 winetest_interactive
&&
982 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0,FALSE
,0);
983 pan
+= ((DSBPAN_RIGHT
-DSBPAN_LEFT
) / 6);
986 ref
=IDirectSoundBuffer_Release(primary
);
987 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
988 "should have 0\n",ref
);
991 /* Set the CooperativeLevel back to normal */
992 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
993 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
994 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
995 DXGetErrorString8(rc
));
998 ref
=IDirectSound_Release(dso
);
999 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1001 return DSERR_GENERIC
;
1006 static HRESULT
test_primary_3d(LPGUID lpGuid
)
1009 LPDIRECTSOUND dso
=NULL
;
1010 LPDIRECTSOUNDBUFFER primary
=NULL
;
1011 DSBUFFERDESC bufdesc
;
1015 /* Create the DirectSound object */
1016 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
1017 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate() failed: %s\n",
1018 DXGetErrorString8(rc
));
1022 /* Get the device capabilities */
1023 ZeroMemory(&dscaps
, sizeof(dscaps
));
1024 dscaps
.dwSize
=sizeof(dscaps
);
1025 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
1026 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc
));
1030 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1031 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1032 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1033 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
1034 "%s\n",DXGetErrorString8(rc
));
1039 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1040 bufdesc
.dwSize
=sizeof(bufdesc
);
1041 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
1042 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1043 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound_CreateSoundBuffer() failed "
1044 "to create a primary buffer: %s\n",DXGetErrorString8(rc
));
1045 if (rc
==DS_OK
&& primary
!=NULL
) {
1046 ref
=IDirectSoundBuffer_Release(primary
);
1047 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1048 "should have 0\n",ref
);
1050 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1051 bufdesc
.dwSize
=sizeof(bufdesc
);
1052 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1053 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1054 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound_CreateSoundBuffer() "
1055 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc
));
1056 if (rc
==DS_OK
&& primary
!=NULL
) {
1057 test_buffer(dso
,primary
,1,FALSE
,0,FALSE
,0,winetest_interactive
&&
1058 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,0,0,0,
1060 ref
=IDirectSoundBuffer_Release(primary
);
1061 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1062 "should have 0\n",ref
);
1065 /* Set the CooperativeLevel back to normal */
1066 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1067 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
1068 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
1069 DXGetErrorString8(rc
));
1072 ref
=IDirectSound_Release(dso
);
1073 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1075 return DSERR_GENERIC
;
1080 static HRESULT
test_primary_3d_with_listener(LPGUID lpGuid
)
1083 LPDIRECTSOUND dso
=NULL
;
1084 LPDIRECTSOUNDBUFFER primary
=NULL
;
1085 DSBUFFERDESC bufdesc
;
1089 /* Create the DirectSound object */
1090 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
1091 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
,"DirectSoundCreate() failed: %s\n",
1092 DXGetErrorString8(rc
));
1096 /* Get the device capabilities */
1097 ZeroMemory(&dscaps
, sizeof(dscaps
));
1098 dscaps
.dwSize
=sizeof(dscaps
);
1099 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
1100 ok(rc
==DS_OK
,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc
));
1104 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1105 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1106 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
1107 ok(rc
==DS_OK
,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
1108 "%s\n",DXGetErrorString8(rc
));
1112 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
1113 bufdesc
.dwSize
=sizeof(bufdesc
);
1114 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
|DSBCAPS_CTRL3D
;
1115 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
1116 ok(rc
==DS_OK
&& primary
!=NULL
,"IDirectSound_CreateSoundBuffer() failed "
1117 "to create a 3D primary buffer: %s\n",DXGetErrorString8(rc
));
1118 if (rc
==DS_OK
&& primary
!=NULL
) {
1119 LPDIRECTSOUND3DLISTENER listener
=NULL
;
1120 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1121 &IID_IDirectSound3DListener
,(void **)&listener
);
1122 ok(rc
==DS_OK
&& listener
!=NULL
,"IDirectSoundBuffer_QueryInterface() "
1123 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc
));
1124 if (rc
==DS_OK
&& listener
!=NULL
) {
1125 LPDIRECTSOUNDBUFFER temp_buffer
=NULL
;
1127 /* Checking the COM interface */
1128 rc
=IDirectSoundBuffer_QueryInterface(primary
,
1129 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1130 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1131 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1132 DXGetErrorString8(rc
));
1133 ok(temp_buffer
==primary
,
1134 "COM interface broken: 0x%08lx != 0x%08lx\n",
1135 (DWORD
)temp_buffer
,(DWORD
)primary
);
1136 if (rc
==DS_OK
&& temp_buffer
!=NULL
) {
1137 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1138 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1139 "should have 1\n",ref
);
1142 rc
=IDirectSound3DListener_QueryInterface(listener
,
1143 &IID_IDirectSoundBuffer
,(LPVOID
*)&temp_buffer
);
1144 ok(rc
==DS_OK
&& temp_buffer
!=NULL
,
1145 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1146 DXGetErrorString8(rc
));
1147 ok(temp_buffer
==primary
,
1148 "COM interface broken: 0x%08lx != 0x%08lx\n",
1149 (DWORD
)temp_buffer
,(DWORD
)primary
);
1150 ref
=IDirectSoundBuffer_Release(temp_buffer
);
1151 ok(ref
==1,"IDirectSoundBuffer_Release() has %d references, "
1152 "should have 1\n",ref
);
1154 /* Testing the buffer */
1155 test_buffer(dso
,primary
,1,FALSE
,0,FALSE
,0,
1156 winetest_interactive
&&
1157 !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),1.0,0,
1158 listener
,0,0,FALSE
,0);
1161 /* Testing the reference counting */
1162 ref
=IDirectSound3DListener_Release(listener
);
1163 ok(ref
==0,"IDirectSound3DListener_Release() listener has %d "
1164 "references, should have 0\n",ref
);
1167 /* Testing the reference counting */
1168 ref
=IDirectSoundBuffer_Release(primary
);
1169 ok(ref
==0,"IDirectSoundBuffer_Release() primary has %d references, "
1170 "should have 0\n",ref
);
1174 ref
=IDirectSound_Release(dso
);
1175 ok(ref
==0,"IDirectSound_Release() has %d references, should have 0\n",ref
);
1177 return DSERR_GENERIC
;
1182 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
1183 LPCSTR lpcstrModule
, LPVOID lpContext
)
1186 trace("*** Testing %s - %s ***\n",lpcstrDescription
,lpcstrModule
);
1188 rc
= test_for_driver(lpGuid
);
1189 if (rc
== DSERR_NODRIVER
) {
1190 trace(" No Driver\n");
1192 } else if (rc
== DSERR_ALLOCATED
) {
1193 trace(" Already In Use\n");
1195 } else if (rc
== E_FAIL
) {
1196 trace(" No Device\n");
1200 trace(" Testing the primary buffer\n");
1201 test_primary(lpGuid
);
1203 trace(" Testing 3D primary buffer\n");
1204 test_primary_3d(lpGuid
);
1206 trace(" Testing 3D primary buffer with listener\n");
1207 test_primary_3d_with_listener(lpGuid
);
1209 /* Testing secondary buffers */
1210 test_secondary(lpGuid
,winetest_interactive
,0,0,0,0,0,0);
1211 test_secondary(lpGuid
,winetest_interactive
,0,0,0,1,0,0);
1213 /* Testing 3D secondary buffers */
1214 test_secondary(lpGuid
,winetest_interactive
,1,0,0,0,0,0);
1215 test_secondary(lpGuid
,winetest_interactive
,1,1,0,0,0,0);
1216 test_secondary(lpGuid
,winetest_interactive
,1,1,0,1,0,0);
1217 test_secondary(lpGuid
,winetest_interactive
,1,0,1,0,0,0);
1218 test_secondary(lpGuid
,winetest_interactive
,1,0,1,1,0,0);
1219 test_secondary(lpGuid
,winetest_interactive
,1,1,1,0,0,0);
1220 test_secondary(lpGuid
,winetest_interactive
,1,1,1,1,0,0);
1221 test_secondary(lpGuid
,winetest_interactive
,1,1,1,0,1,0);
1222 test_secondary(lpGuid
,winetest_interactive
,1,1,1,0,0,1);
1223 test_secondary(lpGuid
,winetest_interactive
,1,1,1,0,1,1);
1228 static void ds3d_tests(void)
1231 rc
=DirectSoundEnumerateA(&dsenum_callback
,NULL
);
1232 ok(rc
==DS_OK
,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc
));
1239 trace("DLL Version: %s\n", get_file_version("dsound.dll"));