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"
33 #include "dsound_test.h"
35 #define PI 3.14159265358979323846
38 static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
39 static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID,LPDIRECTSOUND*,
42 char* wave_generate_la(WAVEFORMATEX* wfx, double duration, DWORD* size)
49 nb_samples=(int)(duration*wfx->nSamplesPerSec);
50 *size=nb_samples*wfx->nBlockAlign;
52 for (i=0;i<nb_samples;i++) {
53 double y=sin(440.0*2*PI*i/wfx->nSamplesPerSec);
54 if (wfx->wBitsPerSample==8) {
55 unsigned char sample=(unsigned char)((double)127.5*(y+1.0));
57 if (wfx->nChannels==2)
59 } else if (wfx->wBitsPerSample == 16) {
60 signed short sample=(signed short)((double)32767.5*y-0.5);
64 if (wfx->nChannels==2) {
69 } else if (wfx->wBitsPerSample == 24) {
70 signed int sample=(signed int)((double)8388607.5*y-0.5);
72 b[1]=(sample >> 8)&0xff;
75 if (wfx->nChannels==2) {
77 b[1]=(sample >> 8)&0xff;
81 } else if (wfx->wBitsPerSample == 32) {
82 signed int sample=(signed int)((double)2147483647.5*y-0.5);
84 b[1]=(sample >> 8)&0xff;
85 b[2]=(sample >> 16)&0xff;
88 if (wfx->nChannels==2) {
90 b[1]=(sample >> 8)&0xff;
91 b[2]=(sample >> 16)&0xff;
100 const char * getDSBCAPS(DWORD xmask) {
105 #define FE(x) { x, #x },
106 FE(DSBCAPS_PRIMARYBUFFER)
108 FE(DSBCAPS_LOCHARDWARE)
109 FE(DSBCAPS_LOCSOFTWARE)
111 FE(DSBCAPS_CTRLFREQUENCY)
113 FE(DSBCAPS_CTRLVOLUME)
114 FE(DSBCAPS_CTRLPOSITIONNOTIFY)
115 FE(DSBCAPS_STICKYFOCUS)
116 FE(DSBCAPS_GLOBALFOCUS)
117 FE(DSBCAPS_GETCURRENTPOSITION2)
118 FE(DSBCAPS_MUTE3DATMAXDISTANCE)
121 static char buffer[512];
127 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) {
128 if ((flags[i].mask & xmask) == flags[i].mask) {
133 strcat(buffer, flags[i].name);
142 HWND hwnd=GetForegroundWindow();
144 hwnd=GetDesktopWindow();
148 void init_format(WAVEFORMATEX* wfx, int format, int rate, int depth,
151 wfx->wFormatTag=format;
152 wfx->nChannels=channels;
153 wfx->wBitsPerSample=depth;
154 wfx->nSamplesPerSec=rate;
155 wfx->nBlockAlign=wfx->nChannels*wfx->wBitsPerSample/8;
156 /* FIXME: Shouldn't this test be if (format!=WAVE_FORMAT_PCM) */
157 if (wfx->nBlockAlign==0)
159 /* align compressed formats to byte boundary */
162 wfx->nAvgBytesPerSec=wfx->nSamplesPerSec*wfx->nBlockAlign;
170 LPDIRECTSOUNDBUFFER dsbo;
178 static int buffer_refill(play_state_t* state, DWORD size)
184 if (size>state->wave_len-state->written)
185 size=state->wave_len-state->written;
187 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
188 &ptr1,&len1,&ptr2,&len2,0);
189 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %08x\n", rc);
193 memcpy(ptr1,state->wave+state->written,len1);
194 state->written+=len1;
196 memcpy(ptr2,state->wave+state->written,len2);
197 state->written+=len2;
199 state->offset=state->written % state->buffer_size;
200 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
201 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc);
207 static int buffer_silence(play_state_t* state, DWORD size)
214 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
215 &ptr1,&len1,&ptr2,&len2,0);
216 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %08x\n", rc);
220 s=(state->wfx->wBitsPerSample==8?0x80:0);
225 state->offset=(state->offset+size) % state->buffer_size;
226 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
227 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc);
233 static int buffer_service(play_state_t* state)
235 DWORD last_play_pos,play_pos,buf_free;
238 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
239 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %08x\n", rc);
244 /* Update the amount played */
245 last_play_pos=state->played % state->buffer_size;
246 if (play_pos<last_play_pos)
247 state->played+=state->buffer_size-last_play_pos+play_pos;
249 state->played+=play_pos-last_play_pos;
251 if (winetest_debug > 1)
252 trace("buf size=%d last_play_pos=%d play_pos=%d played=%d / %d\n",
253 state->buffer_size,last_play_pos,play_pos,state->played,
256 if (state->played>state->wave_len)
258 /* Everything has been played */
262 /* Refill the buffer */
263 if (state->offset<=play_pos)
264 buf_free=play_pos-state->offset;
266 buf_free=state->buffer_size-state->offset+play_pos;
268 if (winetest_debug > 1)
269 trace("offset=%d free=%d written=%d / %d\n",
270 state->offset,buf_free,state->written,state->wave_len);
274 if (state->written<state->wave_len)
276 int w=buffer_refill(state,buf_free);
280 if (state->written==state->wave_len && winetest_debug > 1)
281 trace("last sound byte at %d\n",
282 (state->written % state->buffer_size));
286 /* Fill with silence */
287 if (winetest_debug > 1)
288 trace("writing %d bytes of silence\n",buf_free);
289 if (buffer_silence(state,buf_free)==-1)
295 if (winetest_debug > 1)
296 trace("stopping playback\n");
297 rc=IDirectSoundBuffer_Stop(state->dsbo);
298 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %08x\n", rc);
302 void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
303 BOOL is_primary, BOOL set_volume, LONG volume,
304 BOOL set_pan, LONG pan, BOOL play, double duration,
305 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
306 BOOL move_listener, BOOL move_sound,
307 BOOL set_frequency, DWORD frequency)
311 WAVEFORMATEX wfx,wfx2;
312 DWORD size,status,freq;
316 rc=IDirectSoundBuffer_SetFrequency(*dsbo,frequency);
317 ok(rc==DS_OK||rc==DSERR_CONTROLUNAVAIL,
318 "IDirectSoundBuffer_SetFrequency() failed to set frequency %08x\n",rc);
323 /* DSOUND: Error: Invalid caps pointer */
324 rc=IDirectSoundBuffer_GetCaps(*dsbo,0);
325 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
326 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
328 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
330 /* DSOUND: Error: Invalid caps pointer */
331 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
332 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
333 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
335 dsbcaps.dwSize=sizeof(dsbcaps);
336 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
337 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc);
338 if (rc==DS_OK && winetest_debug > 1) {
339 trace(" Caps: flags=0x%08x size=%d\n",dsbcaps.dwFlags,
340 dsbcaps.dwBufferBytes);
343 /* Query the format size. */
345 rc=IDirectSoundBuffer_GetFormat(*dsbo,NULL,0,&size);
346 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
347 "returned the needed size: rc=%08x size=%d\n",rc,size);
349 ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
350 "Expected a correct structure size, got %d\n", size);
352 if (size == sizeof(WAVEFORMATEX)) {
353 rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,size,NULL);
355 else if (size == sizeof(WAVEFORMATEXTENSIBLE)) {
356 WAVEFORMATEXTENSIBLE wfxe;
357 rc=IDirectSoundBuffer_GetFormat(*dsbo,(WAVEFORMATEX*)&wfxe,size,NULL);
361 "IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
362 if (rc==DS_OK && winetest_debug > 1) {
363 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
364 is_primary ? "Primary" : "Secondary",
365 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
366 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
369 /* DSOUND: Error: Invalid frequency buffer */
370 rc=IDirectSoundBuffer_GetFrequency(*dsbo,0);
371 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have "
372 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
374 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
375 rc=IDirectSoundBuffer_GetFrequency(*dsbo,&freq);
376 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
377 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
378 "IDirectSoundBuffer_GetFrequency() failed: %08x\n",rc);
380 DWORD f = set_frequency?frequency:wfx.nSamplesPerSec;
381 ok(freq==f,"The frequency returned by GetFrequency "
382 "%d does not match the format %d\n",freq,f);
385 /* DSOUND: Error: Invalid status pointer */
386 rc=IDirectSoundBuffer_GetStatus(*dsbo,0);
387 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have "
388 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
390 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
391 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc);
392 ok(status==0,"status=0x%x instead of 0\n",status);
396 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
397 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
398 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
399 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
403 /* DSOUND: Error: Invalid format pointer */
404 rc=IDirectSoundBuffer_SetFormat(*dsbo,0);
405 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
406 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
408 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
409 rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx2);
410 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
411 format_string(&wfx2), rc);
413 /* There is no guarantee that SetFormat will actually change the
414 * format to what we asked for. It depends on what the soundcard
415 * supports. So we must re-query the format.
417 rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,sizeof(wfx),NULL);
418 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
420 (wfx.wFormatTag!=wfx2.wFormatTag ||
421 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
422 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
423 wfx.nChannels!=wfx2.nChannels)) {
424 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
425 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
426 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
427 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
428 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
429 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
432 ZeroMemory(&new_dsbcaps, sizeof(new_dsbcaps));
433 new_dsbcaps.dwSize = sizeof(new_dsbcaps);
434 rc=IDirectSoundBuffer_GetCaps(*dsbo,&new_dsbcaps);
435 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc);
436 if (rc==DS_OK && winetest_debug > 1) {
437 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps.dwFlags,
438 new_dsbcaps.dwBufferBytes);
441 /* Check for primary buffer size change */
442 ok(new_dsbcaps.dwBufferBytes == dsbcaps.dwBufferBytes,
443 " buffer size changed after SetFormat() - "
444 "previous size was %u, current size is %u\n",
445 dsbcaps.dwBufferBytes, new_dsbcaps.dwBufferBytes);
446 dsbcaps.dwBufferBytes = new_dsbcaps.dwBufferBytes;
448 /* Check for primary buffer flags change */
449 ok(new_dsbcaps.dwFlags == dsbcaps.dwFlags,
450 " flags changed after SetFormat() - "
451 "previous flags were %08x, current flags are %08x\n",
452 dsbcaps.dwFlags, new_dsbcaps.dwFlags);
454 /* Set the CooperativeLevel back to normal */
455 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
456 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
457 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc);
462 DS3DLISTENER listener_param;
463 LPDIRECTSOUND3DBUFFER buffer=NULL;
464 DS3DBUFFER buffer_param;
465 DWORD start_time,now;
469 if (winetest_interactive) {
471 trace(" Playing %g second 440Hz tone at %dx%dx%d with a "
472 "frequency of %d (%dHz)\n", duration,
473 wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels,
474 frequency, (440 * frequency) / wfx.nSamplesPerSec);
476 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration,
477 wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
481 /* We must call SetCooperativeLevel to be allowed to call Lock */
482 /* DSOUND: Setting DirectSound cooperative level to
483 * DSSCL_WRITEPRIMARY */
484 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),
486 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_WRITEPRIMARY) "
487 "failed: %08x\n",rc);
492 LPDIRECTSOUNDBUFFER temp_buffer;
494 rc=IDirectSoundBuffer_QueryInterface(*dsbo,&IID_IDirectSound3DBuffer,
496 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
500 /* check the COM interface */
501 rc=IDirectSoundBuffer_QueryInterface(*dsbo, &IID_IDirectSoundBuffer,
502 (LPVOID *)&temp_buffer);
503 ok(rc==DS_OK && temp_buffer!=NULL,
504 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
505 ok(temp_buffer==*dsbo,"COM interface broken: %p != %p\n",
507 ref=IDirectSoundBuffer_Release(temp_buffer);
508 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
509 "should have 1\n",ref);
512 rc=IDirectSound3DBuffer_QueryInterface(*dsbo,
513 &IID_IDirectSoundBuffer,
514 (LPVOID *)&temp_buffer);
515 ok(rc==DS_OK && temp_buffer!=NULL,
516 "IDirectSound3DBuffer_QueryInterface() failed: %08x\n", rc);
517 ok(temp_buffer==*dsbo,"COM interface broken: %p != %p\n",
519 ref=IDirectSoundBuffer_Release(temp_buffer);
520 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
521 "should have 1\n",ref);
523 ref=IDirectSoundBuffer_Release(*dsbo);
524 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
525 "should have 0\n",ref);
527 rc=IDirectSound3DBuffer_QueryInterface(buffer,
528 &IID_IDirectSoundBuffer,
530 ok(rc==DS_OK && *dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
531 "failed: %08x\n",rc);
533 /* DSOUND: Error: Invalid buffer */
534 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
535 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
536 "failed: %08x\n",rc);
538 ZeroMemory(&buffer_param, sizeof(buffer_param));
540 /* DSOUND: Error: Invalid buffer */
541 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
542 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
543 "failed: %08x\n",rc);
545 buffer_param.dwSize=sizeof(buffer_param);
546 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
547 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %08x\n", rc);
550 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
552 rc=IDirectSoundBuffer_GetVolume(*dsbo,&val);
553 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc);
555 rc=IDirectSoundBuffer_SetVolume(*dsbo,volume);
556 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %08x\n", rc);
558 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
559 rc=IDirectSoundBuffer_GetVolume(*dsbo,&volume);
560 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
561 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
566 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
568 rc=IDirectSoundBuffer_GetPan(*dsbo,&val);
569 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %08x\n", rc);
571 rc=IDirectSoundBuffer_SetPan(*dsbo,pan);
572 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %08x\n", rc);
574 /* DSOUND: Error: Buffer does not have CTRLPAN */
575 rc=IDirectSoundBuffer_GetPan(*dsbo,&pan);
576 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
577 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
581 /* try an offset past the end of the buffer */
582 rc = IDirectSoundBuffer_Lock(*dsbo, dsbcaps.dwBufferBytes, 0, &buffer1,
583 &length1, NULL, NULL,
584 DSBLOCK_ENTIREBUFFER);
585 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
586 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
588 /* try a size larger than the buffer */
589 rc = IDirectSoundBuffer_Lock(*dsbo, 0, dsbcaps.dwBufferBytes + 1,
590 &buffer1, &length1, NULL, NULL,
591 DSBLOCK_FROMWRITECURSOR);
592 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
593 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
596 state.wave=wave_generate_la(&wfx,(duration*frequency)/wfx.nSamplesPerSec,&state.wave_len);
598 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
602 state.buffer_size=dsbcaps.dwBufferBytes;
603 state.played=state.written=state.offset=0;
604 buffer_refill(&state,state.buffer_size);
606 rc=IDirectSoundBuffer_Play(*dsbo,0,0,DSBPLAY_LOOPING);
607 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %08x\n", rc);
609 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
610 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc);
611 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
612 "GetStatus: bad status: %x\n",status);
615 ZeroMemory(&listener_param,sizeof(listener_param));
616 listener_param.dwSize=sizeof(listener_param);
617 rc=IDirectSound3DListener_GetAllParameters(listener,
619 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
620 "failed: %08x\n",rc);
622 listener_param.vPosition.x = -5.0f;
623 listener_param.vVelocity.x = (float)(10.0/duration);
625 rc=IDirectSound3DListener_SetAllParameters(listener,
628 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %08x\n", rc);
632 buffer_param.vPosition.x = 100.0f;
633 buffer_param.vVelocity.x = (float)(-200.0/duration);
635 buffer_param.flMinDistance = 10;
636 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
638 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc);
641 start_time=GetTickCount();
642 while (buffer_service(&state)) {
643 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
645 if (listener && move_listener) {
646 listener_param.vPosition.x = (float)(-5.0+10.0*(now-start_time)/1000/duration);
647 if (winetest_debug>2)
648 trace("listener position=%g\n",listener_param.vPosition.x);
649 rc=IDirectSound3DListener_SetPosition(listener,
650 listener_param.vPosition.x,listener_param.vPosition.y,
651 listener_param.vPosition.z,DS3D_IMMEDIATE);
652 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %08x\n",rc);
654 if (buffer3d && move_sound) {
655 buffer_param.vPosition.x = (float)(100-200.0*(now-start_time)/1000/duration);
656 if (winetest_debug>2)
657 trace("sound position=%g\n",buffer_param.vPosition.x);
658 rc=IDirectSound3DBuffer_SetPosition(buffer,
659 buffer_param.vPosition.x,buffer_param.vPosition.y,
660 buffer_param.vPosition.z,DS3D_IMMEDIATE);
661 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc);
664 /* Check the sound duration was within 10% of the expected value */
666 ok(fabs(1000*duration-now+start_time)<=100*duration,
667 "The sound played for %d ms instead of %g ms\n",
668 now-start_time,1000*duration);
672 /* Set the CooperativeLevel back to normal */
673 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
674 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
675 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) "
676 "failed: %08x\n",rc);
679 ref=IDirectSound3DBuffer_Release(buffer);
680 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
681 "should have 0\n",ref);
686 static HRESULT test_secondary(LPGUID lpGuid, int play,
687 int has_3d, int has_3dbuffer,
688 int has_listener, int has_duplicate,
689 int move_listener, int move_sound)
692 LPDIRECTSOUND dso=NULL;
693 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
694 LPDIRECTSOUND3DLISTENER listener=NULL;
695 DSBUFFERDESC bufdesc;
696 WAVEFORMATEX wfx, wfx1;
699 /* Create the DirectSound object */
700 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
701 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %08x\n", rc);
705 /* We must call SetCooperativeLevel before creating primary buffer */
706 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
707 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
708 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
712 ZeroMemory(&bufdesc, sizeof(bufdesc));
713 bufdesc.dwSize=sizeof(bufdesc);
714 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
716 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
718 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
719 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
720 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
721 "IDirectSound_CreateSoundBuffer() failed to create a %sprimary buffer: %08x\n",has_3d?"3D ":"", rc);
722 if (rc==DSERR_CONTROLUNAVAIL)
723 trace(" No Primary\n");
724 else if (rc==DS_OK && primary!=NULL) {
725 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
726 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
731 rc=IDirectSoundBuffer_QueryInterface(primary,
732 &IID_IDirectSound3DListener,
734 ok(rc==DS_OK && listener!=NULL,
735 "IDirectSoundBuffer_QueryInterface() failed to get a 3D listener: %08x\n",rc);
736 ref=IDirectSoundBuffer_Release(primary);
737 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
738 "should have 0\n",ref);
739 if (rc==DS_OK && listener!=NULL) {
740 DS3DLISTENER listener_param;
741 ZeroMemory(&listener_param,sizeof(listener_param));
742 /* DSOUND: Error: Invalid buffer */
743 rc=IDirectSound3DListener_GetAllParameters(listener,0);
744 ok(rc==DSERR_INVALIDPARAM,
745 "IDirectSound3dListener_GetAllParameters() should have "
746 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
748 /* DSOUND: Error: Invalid buffer */
749 rc=IDirectSound3DListener_GetAllParameters(listener,
751 ok(rc==DSERR_INVALIDPARAM,
752 "IDirectSound3dListener_GetAllParameters() should have "
753 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
755 listener_param.dwSize=sizeof(listener_param);
756 rc=IDirectSound3DListener_GetAllParameters(listener,
758 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
759 "failed: %08x\n",rc);
761 ok(listener==NULL, "IDirectSoundBuffer_QueryInterface() "
762 "failed but returned a listener anyway\n");
763 ok(rc!=DS_OK, "IDirectSoundBuffer_QueryInterface() succeeded "
764 "but returned a NULL listener\n");
766 ref=IDirectSound3DListener_Release(listener);
767 ok(ref==0,"IDirectSound3dListener_Release() listener has "
768 "%d references, should have 0\n",ref);
774 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
776 ZeroMemory(&bufdesc, sizeof(bufdesc));
777 bufdesc.dwSize=sizeof(bufdesc);
778 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
780 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
783 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
784 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
786 bufdesc.lpwfxFormat=&wfx;
787 if (winetest_interactive) {
788 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
789 "with a primary buffer at %dx%dx%d\n",
790 has_3dbuffer?"3D ":"",
791 has_duplicate?"duplicated ":"",
792 listener!=NULL||move_sound?"with ":"",
793 move_listener?"moving ":"",
794 listener!=NULL?"listener ":"",
795 listener&&move_sound?"and moving sound ":move_sound?
797 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
798 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
800 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
801 ok(rc==DS_OK && secondary!=NULL,"IDirectSound_CreateSoundBuffer() "
802 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %08x\n",
803 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
804 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
805 listener!=NULL?"listener ":"",
806 listener&&move_sound?"and moving sound ":move_sound?
808 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
809 getDSBCAPS(bufdesc.dwFlags),rc);
810 if (rc==DS_OK && secondary!=NULL) {
812 LONG refvol,vol,refpan,pan;
814 /* Check the initial secondary buffer's volume and pan */
815 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
816 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: %08x\n",rc);
817 ok(vol==0,"wrong volume for a new secondary buffer: %d\n",vol);
818 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
819 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc);
820 ok(pan==0,"wrong pan for a new secondary buffer: %d\n",pan);
822 /* Check that changing the secondary buffer's volume and pan
823 * does not impact the primary buffer's volume and pan
825 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
826 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc);
827 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
828 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n", rc);
830 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
831 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
832 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
833 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
834 ok(vol==-1000,"secondary: wrong volume %d instead of -1000\n",
836 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
837 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc);
838 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
839 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc);
840 ok(pan==-1000,"secondary: wrong pan %d instead of -1000\n",
843 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
844 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc);
845 ok(vol==refvol,"The primary volume changed from %d to %d\n",
847 rc=IDirectSoundBuffer_GetPan(primary,&pan);
848 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n", rc);
849 ok(pan==refpan,"The primary pan changed from %d to %d\n",
852 rc=IDirectSoundBuffer_SetVolume(secondary,0);
853 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
854 rc=IDirectSoundBuffer_SetPan(secondary,0);
855 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc);
858 LPDIRECTSOUNDBUFFER duplicated=NULL;
860 /* DSOUND: Error: Invalid source buffer */
861 rc=IDirectSound_DuplicateSoundBuffer(dso,0,0);
862 ok(rc==DSERR_INVALIDPARAM,
863 "IDirectSound_DuplicateSoundBuffer() should have returned "
864 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
866 /* DSOUND: Error: Invalid dest buffer */
867 rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,0);
868 ok(rc==DSERR_INVALIDPARAM,
869 "IDirectSound_DuplicateSoundBuffer() should have returned "
870 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
872 /* DSOUND: Error: Invalid source buffer */
873 rc=IDirectSound_DuplicateSoundBuffer(dso,0,&duplicated);
874 ok(rc==DSERR_INVALIDPARAM,
875 "IDirectSound_DuplicateSoundBuffer() should have returned "
876 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
879 rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,
881 ok(rc==DS_OK && duplicated!=NULL,
882 "IDirectSound_DuplicateSoundBuffer() failed to duplicate "
883 "a secondary buffer: %08x\n",rc);
885 if (rc==DS_OK && duplicated!=NULL) {
886 ref=IDirectSoundBuffer_Release(secondary);
887 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
888 "references, should have 0\n",ref);
889 secondary=duplicated;
893 if (rc==DS_OK && secondary!=NULL) {
895 duration=(move_listener || move_sound?4.0:1.0);
896 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
897 winetest_interactive,duration,has_3dbuffer,
898 listener,move_listener,move_sound,FALSE,0);
899 ref=IDirectSoundBuffer_Release(secondary);
900 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
901 "should have 0\n",has_duplicate?"duplicated":"secondary",
907 ref=IDirectSound3DListener_Release(listener);
908 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
909 "references, should have 0\n",ref);
911 ref=IDirectSoundBuffer_Release(primary);
912 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
913 "should have 0\n",ref);
916 ok(primary==NULL,"IDirectSound_CreateSoundBuffer(primary) failed "
917 "but primary created anyway\n");
918 ok(rc!=DS_OK,"IDirectSound_CreateSoundBuffer(primary) succeeded "
919 "but primary not created\n");
921 ref=IDirectSoundBuffer_Release(primary);
922 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
923 "should have 0\n",ref);
927 /* Set the CooperativeLevel back to normal */
928 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
929 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
930 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n", rc);
933 ref=IDirectSound_Release(dso);
934 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
936 return DSERR_GENERIC;
941 static HRESULT test_for_driver(LPGUID lpGuid)
944 LPDIRECTSOUND dso=NULL;
947 /* Create the DirectSound object */
948 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
949 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
950 "DirectSoundCreate() failed: %08x\n",rc);
954 ref=IDirectSound_Release(dso);
955 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
957 return DSERR_GENERIC;
962 static HRESULT test_primary(LPGUID lpGuid)
965 LPDIRECTSOUND dso=NULL;
966 LPDIRECTSOUNDBUFFER primary=NULL;
967 DSBUFFERDESC bufdesc;
971 /* Create the DirectSound object */
972 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
973 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %08x\n", rc);
977 /* Get the device capabilities */
978 ZeroMemory(&dscaps, sizeof(dscaps));
979 dscaps.dwSize=sizeof(dscaps);
980 rc=IDirectSound_GetCaps(dso,&dscaps);
981 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
985 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
986 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
987 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
988 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
992 /* Testing the primary buffer */
994 ZeroMemory(&bufdesc, sizeof(bufdesc));
995 bufdesc.dwSize=sizeof(bufdesc);
996 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
997 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
998 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
999 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc);
1000 if (rc==DSERR_CONTROLUNAVAIL)
1001 trace(" No Primary\n");
1002 else if (rc==DS_OK && primary!=NULL) {
1003 test_buffer(dso,&primary,1,TRUE,0,TRUE,0,winetest_interactive &&
1004 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0,
1006 if (winetest_interactive) {
1009 volume = DSBVOLUME_MAX;
1010 for (i = 0; i < 6; i++) {
1011 test_buffer(dso,&primary,1,TRUE,volume,TRUE,0,
1012 winetest_interactive &&
1013 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1014 1.0,0,NULL,0,0,FALSE,0);
1015 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
1019 for (i = 0; i < 7; i++) {
1020 test_buffer(dso,&primary,1,TRUE,0,TRUE,pan,
1021 winetest_interactive &&
1022 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0,FALSE,0);
1023 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
1026 ref=IDirectSoundBuffer_Release(primary);
1027 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1028 "should have 0\n",ref);
1031 /* Set the CooperativeLevel back to normal */
1032 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1033 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1034 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n", rc);
1037 ref=IDirectSound_Release(dso);
1038 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1040 return DSERR_GENERIC;
1045 static HRESULT test_primary_3d(LPGUID lpGuid)
1048 LPDIRECTSOUND dso=NULL;
1049 LPDIRECTSOUNDBUFFER primary=NULL;
1050 DSBUFFERDESC bufdesc;
1054 /* Create the DirectSound object */
1055 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
1056 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %08x\n", rc);
1060 /* Get the device capabilities */
1061 ZeroMemory(&dscaps, sizeof(dscaps));
1062 dscaps.dwSize=sizeof(dscaps);
1063 rc=IDirectSound_GetCaps(dso,&dscaps);
1064 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
1068 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1069 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1070 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1071 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
1076 ZeroMemory(&bufdesc, sizeof(bufdesc));
1077 bufdesc.dwSize=sizeof(bufdesc);
1078 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
1079 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1080 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1081 "to create a primary buffer: %08x\n",rc);
1082 if (rc==DS_OK && primary!=NULL) {
1083 ref=IDirectSoundBuffer_Release(primary);
1084 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1085 "should have 0\n",ref);
1087 ZeroMemory(&bufdesc, sizeof(bufdesc));
1088 bufdesc.dwSize=sizeof(bufdesc);
1089 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
1090 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1091 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() "
1092 "failed to create a 3D primary buffer: %08x\n",rc);
1093 if (rc==DS_OK && primary!=NULL) {
1094 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
1095 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0,
1097 ref=IDirectSoundBuffer_Release(primary);
1098 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1099 "should have 0\n",ref);
1102 /* Set the CooperativeLevel back to normal */
1103 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1104 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1105 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n", rc);
1108 ref=IDirectSound_Release(dso);
1109 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1111 return DSERR_GENERIC;
1116 static HRESULT test_primary_3d_with_listener(LPGUID lpGuid)
1119 LPDIRECTSOUND dso=NULL;
1120 LPDIRECTSOUNDBUFFER primary=NULL;
1121 DSBUFFERDESC bufdesc;
1125 /* Create the DirectSound object */
1126 rc=pDirectSoundCreate(lpGuid,&dso,NULL);
1127 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %08x\n", rc);
1131 /* Get the device capabilities */
1132 ZeroMemory(&dscaps, sizeof(dscaps));
1133 dscaps.dwSize=sizeof(dscaps);
1134 rc=IDirectSound_GetCaps(dso,&dscaps);
1135 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %08x\n",rc);
1139 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1140 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1141 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1142 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
1146 ZeroMemory(&bufdesc, sizeof(bufdesc));
1147 bufdesc.dwSize=sizeof(bufdesc);
1148 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
1149 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1150 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1151 "to create a 3D primary buffer: %08x\n",rc);
1152 if (rc==DS_OK && primary!=NULL) {
1153 LPDIRECTSOUND3DLISTENER listener=NULL;
1154 rc=IDirectSoundBuffer_QueryInterface(primary,
1155 &IID_IDirectSound3DListener,(void **)&listener);
1156 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
1157 "failed to get a 3D listener: %08x\n",rc);
1158 if (rc==DS_OK && listener!=NULL) {
1159 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
1161 /* Checking the COM interface */
1162 rc=IDirectSoundBuffer_QueryInterface(primary,
1163 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1164 ok(rc==DS_OK && temp_buffer!=NULL,
1165 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
1166 ok(temp_buffer==primary,
1167 "COM interface broken: %p != %p\n",
1168 temp_buffer,primary);
1169 if (rc==DS_OK && temp_buffer!=NULL) {
1170 ref=IDirectSoundBuffer_Release(temp_buffer);
1171 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1172 "should have 1\n",ref);
1175 rc=IDirectSound3DListener_QueryInterface(listener,
1176 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1177 ok(rc==DS_OK && temp_buffer!=NULL,
1178 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
1179 ok(temp_buffer==primary,
1180 "COM interface broken: %p != %p\n",
1181 temp_buffer,primary);
1182 ref=IDirectSoundBuffer_Release(temp_buffer);
1183 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1184 "should have 1\n",ref);
1186 /* Testing the buffer */
1187 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,
1188 winetest_interactive &&
1189 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,
1190 listener,0,0,FALSE,0);
1193 /* Testing the reference counting */
1194 ref=IDirectSound3DListener_Release(listener);
1195 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1196 "references, should have 0\n",ref);
1199 /* Testing the reference counting */
1200 ref=IDirectSoundBuffer_Release(primary);
1201 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1202 "should have 0\n",ref);
1206 ref=IDirectSound_Release(dso);
1207 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1209 return DSERR_GENERIC;
1214 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1215 LPCSTR lpcstrModule, LPVOID lpContext)
1218 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1220 rc = test_for_driver(lpGuid);
1221 if (rc == DSERR_NODRIVER) {
1222 trace(" No Driver\n");
1224 } else if (rc == DSERR_ALLOCATED) {
1225 trace(" Already In Use\n");
1227 } else if (rc == E_FAIL) {
1228 trace(" No Device\n");
1232 trace(" Testing the primary buffer\n");
1233 test_primary(lpGuid);
1235 trace(" Testing 3D primary buffer\n");
1236 test_primary_3d(lpGuid);
1238 trace(" Testing 3D primary buffer with listener\n");
1239 test_primary_3d_with_listener(lpGuid);
1241 /* Testing secondary buffers */
1242 test_secondary(lpGuid,winetest_interactive,0,0,0,0,0,0);
1243 test_secondary(lpGuid,winetest_interactive,0,0,0,1,0,0);
1245 /* Testing 3D secondary buffers */
1246 test_secondary(lpGuid,winetest_interactive,1,0,0,0,0,0);
1247 test_secondary(lpGuid,winetest_interactive,1,1,0,0,0,0);
1248 test_secondary(lpGuid,winetest_interactive,1,1,0,1,0,0);
1249 test_secondary(lpGuid,winetest_interactive,1,0,1,0,0,0);
1250 test_secondary(lpGuid,winetest_interactive,1,0,1,1,0,0);
1251 test_secondary(lpGuid,winetest_interactive,1,1,1,0,0,0);
1252 test_secondary(lpGuid,winetest_interactive,1,1,1,1,0,0);
1253 test_secondary(lpGuid,winetest_interactive,1,1,1,0,1,0);
1254 test_secondary(lpGuid,winetest_interactive,1,1,1,0,0,1);
1255 test_secondary(lpGuid,winetest_interactive,1,1,1,0,1,1);
1260 static void ds3d_tests(void)
1263 rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
1264 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %08x\n",rc);
1273 hDsound = LoadLibrary("dsound.dll");
1276 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
1278 pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
1279 "DirectSoundEnumerateA");
1280 pDirectSoundCreate = (void*)GetProcAddress(hDsound,
1281 "DirectSoundCreate");
1285 FreeLibrary(hDsound);
1288 skip("dsound.dll not found!\n");