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"
34 #include "dsound_test.h"
36 #define PI 3.14159265358979323846
37 char* wave_generate_la(WAVEFORMATEX* wfx, double duration, DWORD* size)
44 nb_samples=(int)(duration*wfx->nSamplesPerSec);
45 *size=nb_samples*wfx->nBlockAlign;
47 for (i=0;i<nb_samples;i++) {
48 double y=sin(440.0*2*PI*i/wfx->nSamplesPerSec);
49 if (wfx->wBitsPerSample==8) {
50 unsigned char sample=(unsigned char)((double)127.5*(y+1.0));
52 if (wfx->nChannels==2)
55 signed short sample=(signed short)((double)32767.5*y-0.5);
59 if (wfx->nChannels==2) {
69 const char * getDSBCAPS(DWORD xmask) {
74 #define FE(x) { x, #x },
75 FE(DSBCAPS_PRIMARYBUFFER)
77 FE(DSBCAPS_LOCHARDWARE)
78 FE(DSBCAPS_LOCSOFTWARE)
80 FE(DSBCAPS_CTRLFREQUENCY)
82 FE(DSBCAPS_CTRLVOLUME)
83 FE(DSBCAPS_CTRLPOSITIONNOTIFY)
84 FE(DSBCAPS_STICKYFOCUS)
85 FE(DSBCAPS_GLOBALFOCUS)
86 FE(DSBCAPS_GETCURRENTPOSITION2)
87 FE(DSBCAPS_MUTE3DATMAXDISTANCE)
90 static char buffer[512];
96 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) {
97 if ((flags[i].mask & xmask) == flags[i].mask) {
102 strcat(buffer, flags[i].name);
111 HWND hwnd=GetForegroundWindow();
113 hwnd=GetDesktopWindow();
117 void init_format(WAVEFORMATEX* wfx, int format, int rate, int depth,
120 wfx->wFormatTag=format;
121 wfx->nChannels=channels;
122 wfx->wBitsPerSample=depth;
123 wfx->nSamplesPerSec=rate;
124 wfx->nBlockAlign=wfx->nChannels*wfx->wBitsPerSample/8;
125 /* FIXME: Shouldn't this test be if (format!=WAVE_FORMAT_PCM) */
126 if (wfx->nBlockAlign==0)
128 /* align compressed formats to byte boundary */
131 wfx->nAvgBytesPerSec=wfx->nSamplesPerSec*wfx->nBlockAlign;
139 LPDIRECTSOUNDBUFFER dsbo;
147 static int buffer_refill(play_state_t* state, DWORD size)
153 if (size>state->wave_len-state->written)
154 size=state->wave_len-state->written;
156 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
157 &ptr1,&len1,&ptr2,&len2,0);
158 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
159 DXGetErrorString8(rc));
163 memcpy(ptr1,state->wave+state->written,len1);
164 state->written+=len1;
166 memcpy(ptr2,state->wave+state->written,len2);
167 state->written+=len2;
169 state->offset=state->written % state->buffer_size;
170 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
171 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
172 DXGetErrorString8(rc));
178 static int buffer_silence(play_state_t* state, DWORD size)
185 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
186 &ptr1,&len1,&ptr2,&len2,0);
187 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
188 DXGetErrorString8(rc));
192 s=(state->wfx->wBitsPerSample==8?0x80:0);
197 state->offset=(state->offset+size) % state->buffer_size;
198 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
199 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
200 DXGetErrorString8(rc));
206 static int buffer_service(play_state_t* state)
208 DWORD last_play_pos,play_pos,buf_free;
211 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
212 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
213 DXGetErrorString8(rc));
218 /* Update the amount played */
219 last_play_pos=state->played % state->buffer_size;
220 if (play_pos<last_play_pos)
221 state->played+=state->buffer_size-last_play_pos+play_pos;
223 state->played+=play_pos-last_play_pos;
225 if (winetest_debug > 1)
226 trace("buf size=%d last_play_pos=%d play_pos=%d played=%d / %d\n",
227 state->buffer_size,last_play_pos,play_pos,state->played,
230 if (state->played>state->wave_len)
232 /* Everything has been played */
236 /* Refill the buffer */
237 if (state->offset<=play_pos)
238 buf_free=play_pos-state->offset;
240 buf_free=state->buffer_size-state->offset+play_pos;
242 if (winetest_debug > 1)
243 trace("offset=%d free=%d written=%d / %d\n",
244 state->offset,buf_free,state->written,state->wave_len);
248 if (state->written<state->wave_len)
250 int w=buffer_refill(state,buf_free);
254 if (state->written==state->wave_len && winetest_debug > 1)
255 trace("last sound byte at %d\n",
256 (state->written % state->buffer_size));
260 /* Fill with silence */
261 if (winetest_debug > 1)
262 trace("writing %d bytes of silence\n",buf_free);
263 if (buffer_silence(state,buf_free)==-1)
269 if (winetest_debug > 1)
270 trace("stopping playback\n");
271 rc=IDirectSoundBuffer_Stop(state->dsbo);
272 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %s\n",
273 DXGetErrorString8(rc));
277 void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
278 BOOL is_primary, BOOL set_volume, LONG volume,
279 BOOL set_pan, LONG pan, BOOL play, double duration,
280 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
281 BOOL move_listener, BOOL move_sound,
282 BOOL set_frequency, DWORD frequency)
286 WAVEFORMATEX wfx,wfx2;
287 DWORD size,status,freq;
291 rc=IDirectSoundBuffer_SetFrequency(*dsbo,frequency);
292 ok(rc==DS_OK||rc==DSERR_CONTROLUNAVAIL,
293 "IDirectSoundBuffer_SetFrequency() failed to set frequency "
294 "%s\n",DXGetErrorString8(rc));
299 /* DSOUND: Error: Invalid caps pointer */
300 rc=IDirectSoundBuffer_GetCaps(*dsbo,0);
301 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
302 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
304 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
306 /* DSOUND: Error: Invalid caps pointer */
307 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
308 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
309 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
311 dsbcaps.dwSize=sizeof(dsbcaps);
312 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
313 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n",
314 DXGetErrorString8(rc));
315 if (rc==DS_OK && winetest_debug > 1) {
316 trace(" Caps: flags=0x%08x size=%d\n",dsbcaps.dwFlags,
317 dsbcaps.dwBufferBytes);
320 /* Query the format size. Note that it may not match sizeof(wfx) */
322 rc=IDirectSoundBuffer_GetFormat(*dsbo,NULL,0,&size);
323 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
324 "returned the needed size: rc=%s size=%d\n",DXGetErrorString8(rc),size);
326 rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,sizeof(wfx),NULL);
327 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
328 DXGetErrorString8(rc));
329 if (rc==DS_OK && winetest_debug > 1) {
330 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
331 is_primary ? "Primary" : "Secondary",
332 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
333 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
336 /* DSOUND: Error: Invalid frequency buffer */
337 rc=IDirectSoundBuffer_GetFrequency(*dsbo,0);
338 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have "
339 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
341 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
342 rc=IDirectSoundBuffer_GetFrequency(*dsbo,&freq);
343 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
344 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
345 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc));
347 DWORD f = set_frequency?frequency:wfx.nSamplesPerSec;
348 ok(freq==f,"The frequency returned by GetFrequency "
349 "%d does not match the format %d\n",freq,f);
352 /* DSOUND: Error: Invalid status pointer */
353 rc=IDirectSoundBuffer_GetStatus(*dsbo,0);
354 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have "
355 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
357 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
358 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
359 DXGetErrorString8(rc));
360 ok(status==0,"status=0x%x instead of 0\n",status);
364 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
365 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
366 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
367 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
368 "%s\n",DXGetErrorString8(rc));
372 /* DSOUND: Error: Invalid format pointer */
373 rc=IDirectSoundBuffer_SetFormat(*dsbo,0);
374 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
375 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
377 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
378 rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx2);
379 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %s\n",
380 format_string(&wfx2), DXGetErrorString8(rc));
382 /* There is no guarantee that SetFormat will actually change the
383 * format to what we asked for. It depends on what the soundcard
384 * supports. So we must re-query the format.
386 rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,sizeof(wfx),NULL);
387 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
388 DXGetErrorString8(rc));
390 (wfx.wFormatTag!=wfx2.wFormatTag ||
391 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
392 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
393 wfx.nChannels!=wfx2.nChannels)) {
394 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
395 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
396 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
397 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
398 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
399 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
402 ZeroMemory(&new_dsbcaps, sizeof(new_dsbcaps));
403 new_dsbcaps.dwSize = sizeof(new_dsbcaps);
404 rc=IDirectSoundBuffer_GetCaps(*dsbo,&new_dsbcaps);
405 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n",
406 DXGetErrorString8(rc));
407 if (rc==DS_OK && winetest_debug > 1) {
408 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps.dwFlags,
409 new_dsbcaps.dwBufferBytes);
412 /* Check for primary buffer size change */
413 ok(new_dsbcaps.dwBufferBytes == dsbcaps.dwBufferBytes,
414 " buffer size changed after SetFormat() - "
415 "previous size was %u, current size is %u\n",
416 dsbcaps.dwBufferBytes, new_dsbcaps.dwBufferBytes);
418 /* Check for primary buffer flags change */
419 ok(new_dsbcaps.dwFlags == dsbcaps.dwFlags,
420 " flags changed after SetFormat() - "
421 "previous flags were %08x, current flags are %08x\n",
422 dsbcaps.dwFlags, new_dsbcaps.dwFlags);
424 /* Set the CooperativeLevel back to normal */
425 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
426 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
427 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: "
428 "%s\n",DXGetErrorString8(rc));
433 DS3DLISTENER listener_param;
434 LPDIRECTSOUND3DBUFFER buffer=NULL;
435 DS3DBUFFER buffer_param;
436 DWORD start_time,now;
440 if (winetest_interactive) {
442 trace(" Playing %g second 440Hz tone at %dx%dx%d with a "
443 "frequency of %d (%dHz)\n", duration,
444 wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels,
445 frequency, (440 * frequency) / wfx.nSamplesPerSec);
447 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration,
448 wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
452 /* We must call SetCooperativeLevel to be allowed to call Lock */
453 /* DSOUND: Setting DirectSound cooperative level to
454 * DSSCL_WRITEPRIMARY */
455 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),
457 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_WRITEPRIMARY) "
458 "failed: %s\n",DXGetErrorString8(rc));
463 LPDIRECTSOUNDBUFFER temp_buffer;
465 rc=IDirectSoundBuffer_QueryInterface(*dsbo,&IID_IDirectSound3DBuffer,
467 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
468 DXGetErrorString8(rc));
472 /* check the COM interface */
473 rc=IDirectSoundBuffer_QueryInterface(*dsbo, &IID_IDirectSoundBuffer,
474 (LPVOID *)&temp_buffer);
475 ok(rc==DS_OK && temp_buffer!=NULL,
476 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
477 DXGetErrorString8(rc));
478 ok(temp_buffer==*dsbo,"COM interface broken: %p != %p\n",
480 ref=IDirectSoundBuffer_Release(temp_buffer);
481 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
482 "should have 1\n",ref);
485 rc=IDirectSound3DBuffer_QueryInterface(*dsbo,
486 &IID_IDirectSoundBuffer,
487 (LPVOID *)&temp_buffer);
488 ok(rc==DS_OK && temp_buffer!=NULL,
489 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
490 DXGetErrorString8(rc));
491 ok(temp_buffer==*dsbo,"COM interface broken: %p != %p\n",
493 ref=IDirectSoundBuffer_Release(temp_buffer);
494 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
495 "should have 1\n",ref);
497 ref=IDirectSoundBuffer_Release(*dsbo);
498 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
499 "should have 0\n",ref);
501 rc=IDirectSound3DBuffer_QueryInterface(buffer,
502 &IID_IDirectSoundBuffer,
504 ok(rc==DS_OK && *dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
505 "failed: %s\n",DXGetErrorString8(rc));
507 /* DSOUND: Error: Invalid buffer */
508 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
509 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
510 "failed: %s\n",DXGetErrorString8(rc));
512 ZeroMemory(&buffer_param, sizeof(buffer_param));
514 /* DSOUND: Error: Invalid buffer */
515 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
516 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
517 "failed: %s\n",DXGetErrorString8(rc));
519 buffer_param.dwSize=sizeof(buffer_param);
520 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
521 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
522 DXGetErrorString8(rc));
525 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
527 rc=IDirectSoundBuffer_GetVolume(*dsbo,&val);
528 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
529 DXGetErrorString8(rc));
531 rc=IDirectSoundBuffer_SetVolume(*dsbo,volume);
532 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %s\n",
533 DXGetErrorString8(rc));
535 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
536 rc=IDirectSoundBuffer_GetVolume(*dsbo,&volume);
537 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
538 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
539 DXGetErrorString8(rc));
544 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
546 rc=IDirectSoundBuffer_GetPan(*dsbo,&val);
547 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %s\n",
548 DXGetErrorString8(rc));
550 rc=IDirectSoundBuffer_SetPan(*dsbo,pan);
551 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %s\n",
552 DXGetErrorString8(rc));
554 /* DSOUND: Error: Buffer does not have CTRLPAN */
555 rc=IDirectSoundBuffer_GetPan(*dsbo,&pan);
556 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
557 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
558 DXGetErrorString8(rc));
562 /* try an offset past the end of the buffer */
563 rc = IDirectSoundBuffer_Lock(*dsbo, dsbcaps.dwBufferBytes, 0, &buffer1,
564 &length1, NULL, NULL,
565 DSBLOCK_ENTIREBUFFER);
566 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
567 "returned DSERR_INVALIDPARAM, returned %s\n", DXGetErrorString8(rc));
569 /* try a size larger than the buffer */
570 rc = IDirectSoundBuffer_Lock(*dsbo, 0, dsbcaps.dwBufferBytes + 1,
571 &buffer1, &length1, NULL, NULL,
572 DSBLOCK_FROMWRITECURSOR);
573 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
574 "returned DSERR_INVALIDPARAM, returned %s\n", DXGetErrorString8(rc));
577 state.wave=wave_generate_la(&wfx,(duration*frequency)/wfx.nSamplesPerSec,&state.wave_len);
579 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
583 state.buffer_size=dsbcaps.dwBufferBytes;
584 state.played=state.written=state.offset=0;
585 buffer_refill(&state,state.buffer_size);
587 rc=IDirectSoundBuffer_Play(*dsbo,0,0,DSBPLAY_LOOPING);
588 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %s\n",
589 DXGetErrorString8(rc));
591 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
592 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
593 DXGetErrorString8(rc));
594 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
595 "GetStatus: bad status: %x\n",status);
598 ZeroMemory(&listener_param,sizeof(listener_param));
599 listener_param.dwSize=sizeof(listener_param);
600 rc=IDirectSound3DListener_GetAllParameters(listener,
602 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
603 "failed: %s\n",DXGetErrorString8(rc));
605 listener_param.vPosition.x = -5.0;
606 listener_param.vVelocity.x = 10.0/duration;
608 rc=IDirectSound3DListener_SetAllParameters(listener,
611 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %s\n",
612 DXGetErrorString8(rc));
616 buffer_param.vPosition.x = 100.0;
617 buffer_param.vVelocity.x = -200.0/duration;
619 buffer_param.flMinDistance = 10;
620 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
622 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
623 DXGetErrorString8(rc));
626 start_time=GetTickCount();
627 while (buffer_service(&state)) {
628 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
630 if (listener && move_listener) {
631 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/
633 if (winetest_debug>2)
634 trace("listener position=%g\n",listener_param.vPosition.x);
635 rc=IDirectSound3DListener_SetPosition(listener,
636 listener_param.vPosition.x,listener_param.vPosition.y,
637 listener_param.vPosition.z,DS3D_IMMEDIATE);
638 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: "
639 "%s\n",DXGetErrorString8(rc));
641 if (buffer3d && move_sound) {
642 buffer_param.vPosition.x = 100-200.0*(now-start_time)/
644 if (winetest_debug>2)
645 trace("sound position=%g\n",buffer_param.vPosition.x);
646 rc=IDirectSound3DBuffer_SetPosition(buffer,
647 buffer_param.vPosition.x,buffer_param.vPosition.y,
648 buffer_param.vPosition.z,DS3D_IMMEDIATE);
649 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
650 DXGetErrorString8(rc));
653 /* Check the sound duration was within 10% of the expected value */
655 ok(fabs(1000*duration-now+start_time)<=100*duration,
656 "The sound played for %d ms instead of %g ms\n",
657 now-start_time,1000*duration);
661 /* Set the CooperativeLevel back to normal */
662 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
663 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
664 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) "
665 "failed: %s\n",DXGetErrorString8(rc));
668 ref=IDirectSound3DBuffer_Release(buffer);
669 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
670 "should have 0\n",ref);
675 static HRESULT test_secondary(LPGUID lpGuid, int play,
676 int has_3d, int has_3dbuffer,
677 int has_listener, int has_duplicate,
678 int move_listener, int move_sound)
681 LPDIRECTSOUND dso=NULL;
682 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
683 LPDIRECTSOUND3DLISTENER listener=NULL;
684 DSBUFFERDESC bufdesc;
685 WAVEFORMATEX wfx, wfx1;
688 /* Create the DirectSound object */
689 rc=DirectSoundCreate(lpGuid,&dso,NULL);
690 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %s\n",
691 DXGetErrorString8(rc));
695 /* We must call SetCooperativeLevel before creating primary buffer */
696 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
697 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
698 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
699 "%s\n",DXGetErrorString8(rc));
703 ZeroMemory(&bufdesc, sizeof(bufdesc));
704 bufdesc.dwSize=sizeof(bufdesc);
705 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
707 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
709 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
710 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
711 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
712 "IDirectSound_CreateSoundBuffer() failed to create a %sprimary buffer: "
713 "%s\n",has_3d?"3D ":"", DXGetErrorString8(rc));
714 if (rc==DSERR_CONTROLUNAVAIL)
715 trace(" No Primary\n");
716 else if (rc==DS_OK && primary!=NULL) {
717 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
718 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n",
719 DXGetErrorString8(rc));
724 rc=IDirectSoundBuffer_QueryInterface(primary,
725 &IID_IDirectSound3DListener,
727 ok(rc==DS_OK && listener!=NULL,
728 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
729 "listener: %s\n",DXGetErrorString8(rc));
730 ref=IDirectSoundBuffer_Release(primary);
731 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
732 "should have 0\n",ref);
733 if (rc==DS_OK && listener!=NULL) {
734 DS3DLISTENER listener_param;
735 ZeroMemory(&listener_param,sizeof(listener_param));
736 /* DSOUND: Error: Invalid buffer */
737 rc=IDirectSound3DListener_GetAllParameters(listener,0);
738 ok(rc==DSERR_INVALIDPARAM,
739 "IDirectSound3dListener_GetAllParameters() should have "
740 "returned DSERR_INVALIDPARAM, returned: %s\n",
741 DXGetErrorString8(rc));
743 /* DSOUND: Error: Invalid buffer */
744 rc=IDirectSound3DListener_GetAllParameters(listener,
746 ok(rc==DSERR_INVALIDPARAM,
747 "IDirectSound3dListener_GetAllParameters() should have "
748 "returned DSERR_INVALIDPARAM, returned: %s\n",
749 DXGetErrorString8(rc));
751 listener_param.dwSize=sizeof(listener_param);
752 rc=IDirectSound3DListener_GetAllParameters(listener,
754 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
755 "failed: %s\n",DXGetErrorString8(rc));
757 ok(listener==NULL, "IDirectSoundBuffer_QueryInterface() "
758 "failed but returned a listener anyway\n");
759 ok(rc!=DS_OK, "IDirectSoundBuffer_QueryInterface() succeeded "
760 "but returned a NULL listener\n");
762 ref=IDirectSound3DListener_Release(listener);
763 ok(ref==0,"IDirectSound3dListener_Release() listener has "
764 "%d references, should have 0\n",ref);
770 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
772 ZeroMemory(&bufdesc, sizeof(bufdesc));
773 bufdesc.dwSize=sizeof(bufdesc);
774 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
776 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
779 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
780 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
782 bufdesc.lpwfxFormat=&wfx;
783 if (winetest_interactive) {
784 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
785 "with a primary buffer at %dx%dx%d\n",
786 has_3dbuffer?"3D ":"",
787 has_duplicate?"duplicated ":"",
788 listener!=NULL||move_sound?"with ":"",
789 move_listener?"moving ":"",
790 listener!=NULL?"listener ":"",
791 listener&&move_sound?"and moving sound ":move_sound?
793 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
794 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
796 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
797 ok(rc==DS_OK && secondary!=NULL,"IDirectSound_CreateSoundBuffer() "
798 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %s\n",
799 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
800 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
801 listener!=NULL?"listener ":"",
802 listener&&move_sound?"and moving sound ":move_sound?
804 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
805 getDSBCAPS(bufdesc.dwFlags),DXGetErrorString8(rc));
806 if (rc==DS_OK && secondary!=NULL) {
808 LONG refvol,vol,refpan,pan;
810 /* Check the initial secondary buffer's volume and pan */
811 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
812 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: "
813 "%s\n",DXGetErrorString8(rc));
814 ok(vol==0,"wrong volume for a new secondary buffer: %d\n",vol);
815 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
816 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: "
817 "%s\n",DXGetErrorString8(rc));
818 ok(pan==0,"wrong pan for a new secondary buffer: %d\n",pan);
820 /* Check that changing the secondary buffer's volume and pan
821 * does not impact the primary buffer's volume and pan
823 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
824 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: "
825 "%s\n",DXGetErrorString8(rc));
826 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
827 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %s\n",
828 DXGetErrorString8(rc));
830 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
831 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
832 "%s\n",DXGetErrorString8(rc));
833 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
834 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
835 "%s\n",DXGetErrorString8(rc));
836 ok(vol==-1000,"secondary: wrong volume %d instead of -1000\n",
838 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
839 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
840 "%s\n",DXGetErrorString8(rc));
841 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
842 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
843 "%s\n",DXGetErrorString8(rc));
844 ok(pan==-1000,"secondary: wrong pan %d instead of -1000\n",
847 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
848 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: "
849 "%s\n",DXGetErrorString8(rc));
850 ok(vol==refvol,"The primary volume changed from %d to %d\n",
852 rc=IDirectSoundBuffer_GetPan(primary,&pan);
853 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %s\n",
854 DXGetErrorString8(rc));
855 ok(pan==refpan,"The primary pan changed from %d to %d\n",
858 rc=IDirectSoundBuffer_SetVolume(secondary,0);
859 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
860 "%s\n",DXGetErrorString8(rc));
861 rc=IDirectSoundBuffer_SetPan(secondary,0);
862 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
863 "%s\n",DXGetErrorString8(rc));
866 LPDIRECTSOUNDBUFFER duplicated=NULL;
868 /* DSOUND: Error: Invalid source buffer */
869 rc=IDirectSound_DuplicateSoundBuffer(dso,0,0);
870 ok(rc==DSERR_INVALIDPARAM,
871 "IDirectSound_DuplicateSoundBuffer() should have returned "
872 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
874 /* DSOUND: Error: Invalid dest buffer */
875 rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,0);
876 ok(rc==DSERR_INVALIDPARAM,
877 "IDirectSound_DuplicateSoundBuffer() should have returned "
878 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
880 /* DSOUND: Error: Invalid source buffer */
881 rc=IDirectSound_DuplicateSoundBuffer(dso,0,&duplicated);
882 ok(rc==DSERR_INVALIDPARAM,
883 "IDirectSound_DuplicateSoundBuffer() should have returned "
884 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
887 rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,
889 ok(rc==DS_OK && duplicated!=NULL,
890 "IDirectSound_DuplicateSoundBuffer() failed to duplicate "
891 "a secondary buffer: %s\n",DXGetErrorString8(rc));
893 if (rc==DS_OK && duplicated!=NULL) {
894 ref=IDirectSoundBuffer_Release(secondary);
895 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
896 "references, should have 0\n",ref);
897 secondary=duplicated;
901 if (rc==DS_OK && secondary!=NULL) {
903 duration=(move_listener || move_sound?4.0:1.0);
904 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
905 winetest_interactive,duration,has_3dbuffer,
906 listener,move_listener,move_sound,FALSE,0);
907 ref=IDirectSoundBuffer_Release(secondary);
908 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
909 "should have 0\n",has_duplicate?"duplicated":"secondary",
915 ref=IDirectSound3DListener_Release(listener);
916 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
917 "references, should have 0\n",ref);
919 ref=IDirectSoundBuffer_Release(primary);
920 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
921 "should have 0\n",ref);
924 ok(primary==NULL,"IDirectSound_CreateSoundBuffer(primary) failed "
925 "but primary created anyway\n");
926 ok(rc!=DS_OK,"IDirectSound_CreateSoundBuffer(primary) succeeded "
927 "but primary not created\n");
929 ref=IDirectSoundBuffer_Release(primary);
930 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
931 "should have 0\n",ref);
935 /* Set the CooperativeLevel back to normal */
936 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
937 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
938 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
939 DXGetErrorString8(rc));
942 ref=IDirectSound_Release(dso);
943 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
945 return DSERR_GENERIC;
950 static HRESULT test_for_driver(LPGUID lpGuid)
953 LPDIRECTSOUND dso=NULL;
956 /* Create the DirectSound object */
957 rc=DirectSoundCreate(lpGuid,&dso,NULL);
958 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
959 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
963 ref=IDirectSound_Release(dso);
964 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
966 return DSERR_GENERIC;
971 static HRESULT test_primary(LPGUID lpGuid)
974 LPDIRECTSOUND dso=NULL;
975 LPDIRECTSOUNDBUFFER primary=NULL;
976 DSBUFFERDESC bufdesc;
980 /* Create the DirectSound object */
981 rc=DirectSoundCreate(lpGuid,&dso,NULL);
982 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %s\n",
983 DXGetErrorString8(rc));
987 /* Get the device capabilities */
988 ZeroMemory(&dscaps, sizeof(dscaps));
989 dscaps.dwSize=sizeof(dscaps);
990 rc=IDirectSound_GetCaps(dso,&dscaps);
991 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
995 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
996 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
997 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
998 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
999 "%s\n",DXGetErrorString8(rc));
1003 /* Testing the primary buffer */
1005 ZeroMemory(&bufdesc, sizeof(bufdesc));
1006 bufdesc.dwSize=sizeof(bufdesc);
1007 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
1008 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1009 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
1010 "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "
1011 "%s\n",DXGetErrorString8(rc));
1012 if (rc==DSERR_CONTROLUNAVAIL)
1013 trace(" No Primary\n");
1014 else if (rc==DS_OK && primary!=NULL) {
1015 test_buffer(dso,&primary,1,TRUE,0,TRUE,0,winetest_interactive &&
1016 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0,
1018 if (winetest_interactive) {
1021 volume = DSBVOLUME_MAX;
1022 for (i = 0; i < 6; i++) {
1023 test_buffer(dso,&primary,1,TRUE,volume,TRUE,0,
1024 winetest_interactive &&
1025 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1026 1.0,0,NULL,0,0,FALSE,0);
1027 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
1031 for (i = 0; i < 7; i++) {
1032 test_buffer(dso,&primary,1,TRUE,0,TRUE,pan,
1033 winetest_interactive &&
1034 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0,FALSE,0);
1035 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
1038 ref=IDirectSoundBuffer_Release(primary);
1039 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1040 "should have 0\n",ref);
1043 /* Set the CooperativeLevel back to normal */
1044 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1045 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1046 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
1047 DXGetErrorString8(rc));
1050 ref=IDirectSound_Release(dso);
1051 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1053 return DSERR_GENERIC;
1058 static HRESULT test_primary_3d(LPGUID lpGuid)
1061 LPDIRECTSOUND dso=NULL;
1062 LPDIRECTSOUNDBUFFER primary=NULL;
1063 DSBUFFERDESC bufdesc;
1067 /* Create the DirectSound object */
1068 rc=DirectSoundCreate(lpGuid,&dso,NULL);
1069 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %s\n",
1070 DXGetErrorString8(rc));
1074 /* Get the device capabilities */
1075 ZeroMemory(&dscaps, sizeof(dscaps));
1076 dscaps.dwSize=sizeof(dscaps);
1077 rc=IDirectSound_GetCaps(dso,&dscaps);
1078 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
1082 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1083 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1084 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1085 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
1086 "%s\n",DXGetErrorString8(rc));
1091 ZeroMemory(&bufdesc, sizeof(bufdesc));
1092 bufdesc.dwSize=sizeof(bufdesc);
1093 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
1094 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1095 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1096 "to create a primary buffer: %s\n",DXGetErrorString8(rc));
1097 if (rc==DS_OK && primary!=NULL) {
1098 ref=IDirectSoundBuffer_Release(primary);
1099 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1100 "should have 0\n",ref);
1102 ZeroMemory(&bufdesc, sizeof(bufdesc));
1103 bufdesc.dwSize=sizeof(bufdesc);
1104 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
1105 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1106 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() "
1107 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc));
1108 if (rc==DS_OK && primary!=NULL) {
1109 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
1110 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0,
1112 ref=IDirectSoundBuffer_Release(primary);
1113 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1114 "should have 0\n",ref);
1117 /* Set the CooperativeLevel back to normal */
1118 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
1119 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
1120 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_NORMAL) failed: %s\n",
1121 DXGetErrorString8(rc));
1124 ref=IDirectSound_Release(dso);
1125 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1127 return DSERR_GENERIC;
1132 static HRESULT test_primary_3d_with_listener(LPGUID lpGuid)
1135 LPDIRECTSOUND dso=NULL;
1136 LPDIRECTSOUNDBUFFER primary=NULL;
1137 DSBUFFERDESC bufdesc;
1141 /* Create the DirectSound object */
1142 rc=DirectSoundCreate(lpGuid,&dso,NULL);
1143 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate() failed: %s\n",
1144 DXGetErrorString8(rc));
1148 /* Get the device capabilities */
1149 ZeroMemory(&dscaps, sizeof(dscaps));
1150 dscaps.dwSize=sizeof(dscaps);
1151 rc=IDirectSound_GetCaps(dso,&dscaps);
1152 ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
1156 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1157 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1158 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1159 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
1160 "%s\n",DXGetErrorString8(rc));
1164 ZeroMemory(&bufdesc, sizeof(bufdesc));
1165 bufdesc.dwSize=sizeof(bufdesc);
1166 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
1167 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1168 ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
1169 "to create a 3D primary buffer: %s\n",DXGetErrorString8(rc));
1170 if (rc==DS_OK && primary!=NULL) {
1171 LPDIRECTSOUND3DLISTENER listener=NULL;
1172 rc=IDirectSoundBuffer_QueryInterface(primary,
1173 &IID_IDirectSound3DListener,(void **)&listener);
1174 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
1175 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc));
1176 if (rc==DS_OK && listener!=NULL) {
1177 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
1179 /* Checking the COM interface */
1180 rc=IDirectSoundBuffer_QueryInterface(primary,
1181 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1182 ok(rc==DS_OK && temp_buffer!=NULL,
1183 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1184 DXGetErrorString8(rc));
1185 ok(temp_buffer==primary,
1186 "COM interface broken: %p != %p\n",
1187 temp_buffer,primary);
1188 if (rc==DS_OK && temp_buffer!=NULL) {
1189 ref=IDirectSoundBuffer_Release(temp_buffer);
1190 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1191 "should have 1\n",ref);
1194 rc=IDirectSound3DListener_QueryInterface(listener,
1195 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1196 ok(rc==DS_OK && temp_buffer!=NULL,
1197 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1198 DXGetErrorString8(rc));
1199 ok(temp_buffer==primary,
1200 "COM interface broken: %p != %p\n",
1201 temp_buffer,primary);
1202 ref=IDirectSoundBuffer_Release(temp_buffer);
1203 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1204 "should have 1\n",ref);
1206 /* Testing the buffer */
1207 test_buffer(dso,&primary,1,FALSE,0,FALSE,0,
1208 winetest_interactive &&
1209 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,
1210 listener,0,0,FALSE,0);
1213 /* Testing the reference counting */
1214 ref=IDirectSound3DListener_Release(listener);
1215 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1216 "references, should have 0\n",ref);
1219 /* Testing the reference counting */
1220 ref=IDirectSoundBuffer_Release(primary);
1221 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1222 "should have 0\n",ref);
1226 ref=IDirectSound_Release(dso);
1227 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
1229 return DSERR_GENERIC;
1234 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1235 LPCSTR lpcstrModule, LPVOID lpContext)
1238 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1240 rc = test_for_driver(lpGuid);
1241 if (rc == DSERR_NODRIVER) {
1242 trace(" No Driver\n");
1244 } else if (rc == DSERR_ALLOCATED) {
1245 trace(" Already In Use\n");
1247 } else if (rc == E_FAIL) {
1248 trace(" No Device\n");
1252 trace(" Testing the primary buffer\n");
1253 test_primary(lpGuid);
1255 trace(" Testing 3D primary buffer\n");
1256 test_primary_3d(lpGuid);
1258 trace(" Testing 3D primary buffer with listener\n");
1259 test_primary_3d_with_listener(lpGuid);
1261 /* Testing secondary buffers */
1262 test_secondary(lpGuid,winetest_interactive,0,0,0,0,0,0);
1263 test_secondary(lpGuid,winetest_interactive,0,0,0,1,0,0);
1265 /* Testing 3D secondary buffers */
1266 test_secondary(lpGuid,winetest_interactive,1,0,0,0,0,0);
1267 test_secondary(lpGuid,winetest_interactive,1,1,0,0,0,0);
1268 test_secondary(lpGuid,winetest_interactive,1,1,0,1,0,0);
1269 test_secondary(lpGuid,winetest_interactive,1,0,1,0,0,0);
1270 test_secondary(lpGuid,winetest_interactive,1,0,1,1,0,0);
1271 test_secondary(lpGuid,winetest_interactive,1,1,1,0,0,0);
1272 test_secondary(lpGuid,winetest_interactive,1,1,1,1,0,0);
1273 test_secondary(lpGuid,winetest_interactive,1,1,1,0,1,0);
1274 test_secondary(lpGuid,winetest_interactive,1,1,1,0,0,1);
1275 test_secondary(lpGuid,winetest_interactive,1,1,1,0,1,1);
1280 static void ds3d_tests(void)
1283 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
1284 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1291 trace("DLL Version: %s\n", get_file_version("dsound.dll"));