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
33 #include "wine/test.h"
39 #include "dsound_test.h"
41 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL;
47 LPDIRECTSOUNDBUFFER dsbo;
55 static int buffer_refill8(play_state_t* state, DWORD size)
61 if (size>state->wave_len-state->written)
62 size=state->wave_len-state->written;
64 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
65 &ptr1,&len1,&ptr2,&len2,0);
66 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
67 DXGetErrorString8(rc));
71 memcpy(ptr1,state->wave+state->written,len1);
74 memcpy(ptr2,state->wave+state->written,len2);
77 state->offset=state->written % state->buffer_size;
78 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
79 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
80 DXGetErrorString8(rc));
86 static int buffer_silence8(play_state_t* state, DWORD size)
93 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
94 &ptr1,&len1,&ptr2,&len2,0);
95 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
96 DXGetErrorString8(rc));
100 s=(state->wfx->wBitsPerSample==8?0x80:0);
105 state->offset=(state->offset+size) % state->buffer_size;
106 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
107 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
108 DXGetErrorString8(rc));
114 static int buffer_service8(play_state_t* state)
116 DWORD last_play_pos,play_pos,buf_free;
119 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
120 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
121 DXGetErrorString8(rc));
126 /* Update the amount played */
127 last_play_pos=state->played % state->buffer_size;
128 if (play_pos<last_play_pos)
129 state->played+=state->buffer_size-last_play_pos+play_pos;
131 state->played+=play_pos-last_play_pos;
133 if (winetest_debug > 1)
134 trace("buf size=%ld last_play_pos=%ld play_pos=%ld played=%ld / %ld\n",
135 state->buffer_size,last_play_pos,play_pos,state->played,
138 if (state->played>state->wave_len)
140 /* Everything has been played */
144 /* Refill the buffer */
145 if (state->offset<=play_pos)
146 buf_free=play_pos-state->offset;
148 buf_free=state->buffer_size-state->offset+play_pos;
150 if (winetest_debug > 1)
151 trace("offset=%ld free=%ld written=%ld / %ld\n",
152 state->offset,buf_free,state->written,state->wave_len);
156 if (state->written<state->wave_len)
158 int w=buffer_refill8(state,buf_free);
162 if (state->written==state->wave_len && winetest_debug > 1)
163 trace("last sound byte at %ld\n",
164 (state->written % state->buffer_size));
168 /* Fill with silence */
169 if (winetest_debug > 1)
170 trace("writing %ld bytes of silence\n",buf_free);
171 if (buffer_silence8(state,buf_free)==-1)
177 if (winetest_debug > 1)
178 trace("stopping playback\n");
179 rc=IDirectSoundBuffer_Stop(state->dsbo);
180 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %s\n",
181 DXGetErrorString8(rc));
185 void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER dsbo,
186 BOOL is_primary, BOOL set_volume, LONG volume,
187 BOOL set_pan, LONG pan, BOOL play, double duration,
188 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
189 BOOL move_listener, BOOL move_sound)
193 WAVEFORMATEX wfx,wfx2;
194 DWORD size,status,freq;
197 /* DSOUND: Error: Invalid caps pointer */
198 rc=IDirectSoundBuffer_GetCaps(dsbo,0);
199 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
200 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
202 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
204 /* DSOUND: Error: Invalid caps pointer */
205 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
206 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
207 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
209 dsbcaps.dwSize=sizeof(dsbcaps);
210 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
211 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n",
212 DXGetErrorString8(rc));
213 if (rc==DS_OK && winetest_debug > 1) {
214 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,
215 dsbcaps.dwBufferBytes);
218 /* Query the format size. Note that it may not match sizeof(wfx) */
220 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
221 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
222 "returned the needed size: rc=%s size=%ld\n",DXGetErrorString8(rc),size);
224 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
225 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
226 DXGetErrorString8(rc));
227 if (rc==DS_OK && winetest_debug > 1) {
228 trace(" Format: %s tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
229 is_primary ? "Primary" : "Secondary",
230 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
231 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
234 /* DSOUND: Error: Invalid frequency buffer */
235 rc=IDirectSoundBuffer_GetFrequency(dsbo,0);
236 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have "
237 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
239 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
240 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
241 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
242 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
243 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc));
245 ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency "
246 "%ld does not match the format %ld\n",freq,wfx.nSamplesPerSec);
249 /* DSOUND: Error: Invalid status pointer */
250 rc=IDirectSoundBuffer_GetStatus(dsbo,0);
251 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have "
252 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
254 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
255 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
256 DXGetErrorString8(rc));
257 ok(status==0,"status=0x%lx instead of 0\n",status);
260 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
261 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
262 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
263 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
264 "failed: %s\n",DXGetErrorString8(rc));
268 /* DSOUND: Error: Invalid format pointer */
269 rc=IDirectSoundBuffer_SetFormat(dsbo,0);
270 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
271 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
273 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
274 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
275 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n",
276 DXGetErrorString8(rc));
278 /* There is no garantee that SetFormat will actually change the
279 * format to what we asked for. It depends on what the soundcard
280 * supports. So we must re-query the format.
282 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
283 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
284 DXGetErrorString8(rc));
286 (wfx.wFormatTag!=wfx2.wFormatTag ||
287 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
288 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
289 wfx.nChannels!=wfx2.nChannels)) {
290 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
291 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
292 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
293 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
294 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
295 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
298 /* Set the CooperativeLevel back to normal */
299 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
300 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
301 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
302 "failed: %s\n",DXGetErrorString8(rc));
307 DS3DLISTENER listener_param;
308 LPDIRECTSOUND3DBUFFER buffer=NULL;
309 DS3DBUFFER buffer_param;
310 DWORD start_time,now;
312 if (winetest_interactive) {
313 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration,
314 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
318 /* We must call SetCooperativeLevel to be allowed to call Lock */
319 /* DSOUND: Setting DirectSound cooperative level to
320 * DSSCL_WRITEPRIMARY */
321 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),
324 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: "
325 "%s\n",DXGetErrorString8(rc));
330 LPDIRECTSOUNDBUFFER temp_buffer;
332 rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer,
334 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
335 DXGetErrorString8(rc));
339 /* check the COM interface */
340 rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
341 (LPVOID *)&temp_buffer);
342 ok(rc==DS_OK && temp_buffer!=NULL,
343 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
344 DXGetErrorString8(rc));
345 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
346 (DWORD)temp_buffer,(DWORD)dsbo);
347 ref=IDirectSoundBuffer_Release(temp_buffer);
348 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
349 "should have 1\n",ref);
352 rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
353 (LPVOID *)&temp_buffer);
354 ok(rc==DS_OK && temp_buffer!=NULL,
355 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
356 DXGetErrorString8(rc));
357 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
358 (DWORD)temp_buffer,(DWORD)dsbo);
359 ref=IDirectSoundBuffer_Release(temp_buffer);
360 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
361 "should have 1\n",ref);
364 /* FIXME: this works on windows */
365 ref=IDirectSoundBuffer_Release(dsbo);
366 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
367 "should have 0\n",ref);
369 rc=IDirectSound3DBuffer_QueryInterface(buffer,
370 &IID_IDirectSoundBuffer,
372 ok(rc==DS_OK && dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
373 "failed: %s\n",DXGetErrorString8(rc),
376 /* DSOUND: Error: Invalid buffer */
377 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
378 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
379 "failed: %s\n",DXGetErrorString8(rc));
381 ZeroMemory(&buffer_param, sizeof(buffer_param));
383 /* DSOUND: Error: Invalid buffer */
384 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
385 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
386 "failed: %s\n",DXGetErrorString8(rc));
388 buffer_param.dwSize=sizeof(buffer_param);
389 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
390 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
391 DXGetErrorString8(rc));
394 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
396 rc=IDirectSoundBuffer_GetVolume(dsbo,&val);
397 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
398 DXGetErrorString8(rc));
400 rc=IDirectSoundBuffer_SetVolume(dsbo,volume);
401 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %s\n",
402 DXGetErrorString8(rc));
404 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
405 rc=IDirectSoundBuffer_GetVolume(dsbo,&volume);
406 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
407 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
408 DXGetErrorString8(rc));
413 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
415 rc=IDirectSoundBuffer_GetPan(dsbo,&val);
416 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %s\n",
417 DXGetErrorString8(rc));
419 rc=IDirectSoundBuffer_SetPan(dsbo,pan);
420 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %s\n",
421 DXGetErrorString8(rc));
423 /* DSOUND: Error: Buffer does not have CTRLPAN */
424 rc=IDirectSoundBuffer_GetPan(dsbo,&pan);
425 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
426 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
427 DXGetErrorString8(rc));
431 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
435 state.buffer_size=dsbcaps.dwBufferBytes;
436 state.played=state.written=state.offset=0;
437 buffer_refill8(&state,state.buffer_size);
439 rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING);
440 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %s\n",
441 DXGetErrorString8(rc));
443 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
444 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
445 DXGetErrorString8(rc));
446 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
447 "GetStatus: bad status: %lx\n",status);
450 ZeroMemory(&listener_param,sizeof(listener_param));
451 listener_param.dwSize=sizeof(listener_param);
452 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
453 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
454 "failed: %s\n",DXGetErrorString8(rc));
456 listener_param.vPosition.x = -5.0;
457 listener_param.vVelocity.x = 10.0/duration;
459 rc=IDirectSound3DListener_SetAllParameters(listener,
462 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %s\n",
463 DXGetErrorString8(rc));
467 buffer_param.vPosition.x = 100.0;
468 buffer_param.vVelocity.x = -200.0/duration;
470 buffer_param.flMinDistance = 10;
471 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
473 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
474 DXGetErrorString8(rc));
477 start_time=GetTickCount();
478 while (buffer_service8(&state)) {
479 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
481 if (listener && move_listener) {
482 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/
484 if (winetest_debug>2)
485 trace("listener position=%g\n",listener_param.vPosition.x);
486 rc=IDirectSound3DListener_SetPosition(listener,
487 listener_param.vPosition.x,listener_param.vPosition.y,
488 listener_param.vPosition.z,DS3D_IMMEDIATE);
489 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: "
490 "%s\n",DXGetErrorString8(rc));
492 if (buffer3d && move_sound) {
493 buffer_param.vPosition.x = 100-200.0*(now-start_time)/
495 if (winetest_debug>2)
496 trace("sound position=%g\n",buffer_param.vPosition.x);
497 rc=IDirectSound3DBuffer_SetPosition(buffer,
498 buffer_param.vPosition.x,buffer_param.vPosition.y,
499 buffer_param.vPosition.z,DS3D_IMMEDIATE);
500 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
501 DXGetErrorString8(rc));
504 /* Check the sound duration was within 10% of the expected value */
506 ok(fabs(1000*duration-now+start_time)<=100*duration,
507 "The sound played for %ld ms instead of %g ms\n",
508 now-start_time,1000*duration);
512 /* Set the CooperativeLevel back to normal */
513 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
514 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
515 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
516 "failed: %s\n",DXGetErrorString8(rc));
519 ref=IDirectSound3DBuffer_Release(buffer);
520 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
521 "should have 0\n",ref);
526 static HRESULT test_secondary8(LPGUID lpGuid, int play,
527 int has_3d, int has_3dbuffer,
528 int has_listener, int has_duplicate,
529 int move_listener, int move_sound)
532 LPDIRECTSOUND8 dso=NULL;
533 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
534 LPDIRECTSOUND3DLISTENER listener=NULL;
535 DSBUFFERDESC bufdesc;
539 /* Create the DirectSound object */
540 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
541 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
545 /* We must call SetCooperativeLevel before creating primary buffer */
546 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
547 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
548 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
549 "%s\n",DXGetErrorString8(rc));
553 ZeroMemory(&bufdesc, sizeof(bufdesc));
554 bufdesc.dwSize=sizeof(bufdesc);
555 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
557 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
559 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
560 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
561 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
562 "failed to create a %sprimary buffer: %s\n",has_3d?"3D ":"",
563 DXGetErrorString8(rc));
565 if (rc==DS_OK && primary!=NULL) {
567 rc=IDirectSoundBuffer_QueryInterface(primary,
568 &IID_IDirectSound3DListener,
570 ok(rc==DS_OK && listener!=NULL,
571 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
572 "listener %s\n",DXGetErrorString8(rc));
573 ref=IDirectSoundBuffer_Release(primary);
574 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
575 "should have 0\n",ref);
576 if (rc==DS_OK && listener!=NULL) {
577 DS3DLISTENER listener_param;
578 ZeroMemory(&listener_param,sizeof(listener_param));
579 /* DSOUND: Error: Invalid buffer */
580 rc=IDirectSound3DListener_GetAllParameters(listener,0);
581 ok(rc==DSERR_INVALIDPARAM,
582 "IDirectSound3dListener_GetAllParameters() should have "
583 "returned DSERR_INVALIDPARAM, returned: %s\n",
584 DXGetErrorString8(rc));
586 /* DSOUND: Error: Invalid buffer */
587 rc=IDirectSound3DListener_GetAllParameters(listener,
589 ok(rc==DSERR_INVALIDPARAM,
590 "IDirectSound3dListener_GetAllParameters() should have "
591 "returned DSERR_INVALIDPARAM, returned: %s\n",
592 DXGetErrorString8(rc));
594 listener_param.dwSize=sizeof(listener_param);
595 rc=IDirectSound3DListener_GetAllParameters(listener,
597 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
598 "failed: %s\n",DXGetErrorString8(rc));
604 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
606 ZeroMemory(&bufdesc, sizeof(bufdesc));
607 bufdesc.dwSize=sizeof(bufdesc);
608 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
610 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
613 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
614 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
615 bufdesc.lpwfxFormat=&wfx;
617 /* a stereo 3D buffer should fail */
618 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
619 ok(rc==DSERR_INVALIDPARAM,
620 "IDirectSound8_CreateSoundBuffer(secondary) should have "
621 "returned DSERR_INVALIDPARAM, returned %s\n",
622 DXGetErrorString8(rc));
624 ref=IDirectSoundBuffer_Release(secondary);
625 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
628 if (winetest_interactive) {
629 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d\n",
630 has_3dbuffer?"3D ":"",
631 has_duplicate?"duplicated ":"",
632 listener!=NULL||move_sound?"with ":"",
633 move_listener?"moving ":"",
634 listener!=NULL?"listener ":"",
635 listener&&move_sound?"and moving sound ":move_sound?
637 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
639 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
640 ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() "
641 "failed to create a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d (%s): %s\n",
642 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
643 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
644 listener!=NULL?"listener ":"",
645 listener&&move_sound?"and moving sound ":move_sound?
647 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
648 getDSBCAPS(bufdesc.dwFlags),DXGetErrorString8(rc));
649 if (rc==DS_OK && secondary!=NULL) {
654 /* Check the initial secondary buffer's volume and pan */
655 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
656 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: "
657 "%s\n",DXGetErrorString8(rc));
658 ok(vol==0,"wrong volume for a new secondary buffer: %ld\n",vol);
659 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
660 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: "
661 "%s\n",DXGetErrorString8(rc));
662 ok(pan==0,"wrong pan for a new secondary buffer: %ld\n",pan);
664 /* Check that changing the secondary buffer's volume and pan
665 * does not impact the primary buffer's volume and pan
667 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
668 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: "
669 "%s\n",DXGetErrorString8(rc));
670 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
671 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
672 "%s\n",DXGetErrorString8(rc));
674 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
675 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
676 "%s\n",DXGetErrorString8(rc));
677 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
678 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
679 "%s\n",DXGetErrorString8(rc));
680 ok(vol==-1000,"secondary: wrong volume %ld instead of -1000\n",
682 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
683 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
684 "%s\n",DXGetErrorString8(rc));
685 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
686 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
687 "%s\n",DXGetErrorString8(rc));
688 ok(pan==-1000,"secondary: wrong pan %ld instead of -1000\n",
691 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
692 ok(rc==DS_OK,"IDirectSoundBuffer_`GetVolume(primary) failed: i"
693 "%s\n",DXGetErrorString8(rc));
694 ok(vol==refvol,"The primary volume changed from %ld to %ld\n",
696 rc=IDirectSoundBuffer_GetPan(primary,&pan);
697 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
698 "%s\n",DXGetErrorString8(rc));
699 ok(pan==refpan,"The primary pan changed from %ld to %ld\n",
702 rc=IDirectSoundBuffer_SetVolume(secondary,0);
703 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
704 "%s\n",DXGetErrorString8(rc));
705 rc=IDirectSoundBuffer_SetPan(secondary,0);
706 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
707 "%s\n",DXGetErrorString8(rc));
710 LPDIRECTSOUNDBUFFER duplicated=NULL;
712 /* DSOUND: Error: Invalid source buffer */
713 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0);
714 ok(rc==DSERR_INVALIDPARAM,
715 "IDirectSound8_DuplicateSoundBuffer() should have returned "
716 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
718 /* DSOUND: Error: Invalid dest buffer */
719 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0);
720 ok(rc==DSERR_INVALIDPARAM,
721 "IDirectSound8_DuplicateSoundBuffer() should have returned "
722 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
724 /* DSOUND: Error: Invalid source buffer */
725 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated);
726 ok(rc==DSERR_INVALIDPARAM,
727 "IDirectSound8_DuplicateSoundBuffer() should have returned "
728 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
731 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,
733 ok(rc==DS_OK && duplicated!=NULL,
734 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
735 "a secondary buffer: %s\n",DXGetErrorString8(rc));
737 if (rc==DS_OK && duplicated!=NULL) {
738 ref=IDirectSoundBuffer_Release(secondary);
739 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
740 "references, should have 0\n",ref);
741 secondary=duplicated;
745 if (rc==DS_OK && secondary!=NULL) {
747 duration=(move_listener || move_sound?4.0:1.0);
748 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,
749 winetest_interactive,duration,has_3dbuffer,
750 listener,move_listener,move_sound);
751 ref=IDirectSoundBuffer_Release(secondary);
752 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
753 "should have 0\n",has_duplicate?"duplicated":"secondary",
759 ref=IDirectSound3DListener_Release(listener);
760 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
761 "references, should have 0\n",ref);
763 ref=IDirectSoundBuffer_Release(primary);
764 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
765 "should have 0\n",ref);
768 /* Set the CooperativeLevel back to normal */
769 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
770 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
771 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
772 "%s\n",DXGetErrorString8(rc));
775 ref=IDirectSound8_Release(dso);
776 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
778 return DSERR_GENERIC;
783 static HRESULT test_primary8(LPGUID lpGuid)
786 LPDIRECTSOUND8 dso=NULL;
787 LPDIRECTSOUNDBUFFER primary=NULL;
788 DSBUFFERDESC bufdesc;
792 /* Create the DirectSound object */
793 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
794 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
798 /* Get the device capabilities */
799 ZeroMemory(&dscaps, sizeof(dscaps));
800 dscaps.dwSize=sizeof(dscaps);
801 rc=IDirectSound8_GetCaps(dso,&dscaps);
802 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
806 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
807 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
808 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
809 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
810 "%s\n",DXGetErrorString8(rc));
814 /* Testing the primary buffer */
816 ZeroMemory(&bufdesc, sizeof(bufdesc));
817 bufdesc.dwSize=sizeof(bufdesc);
818 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
819 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
820 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
821 "to create a primary buffer: 0x%lx\n",rc);
822 if (rc==DS_OK && primary!=NULL) {
823 test_buffer8(dso,primary,1,TRUE,0,TRUE,0,winetest_interactive &&
824 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0);
825 if (winetest_interactive) {
828 volume = DSBVOLUME_MAX;
829 for (i = 0; i < 6; i++) {
830 test_buffer8(dso,primary,1,TRUE,volume,TRUE,0,
831 winetest_interactive &&
832 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
834 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
838 for (i = 0; i < 7; i++) {
839 test_buffer8(dso,primary,1,TRUE,0,TRUE,pan,
840 winetest_interactive &&
841 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
842 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
845 ref=IDirectSoundBuffer_Release(primary);
846 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
847 "should have 0\n",ref);
850 /* Set the CooperativeLevel back to normal */
851 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
852 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
853 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
854 "%s\n",DXGetErrorString8(rc));
857 ref=IDirectSound8_Release(dso);
858 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
860 return DSERR_GENERIC;
865 static HRESULT test_primary_3d8(LPGUID lpGuid)
868 LPDIRECTSOUND8 dso=NULL;
869 LPDIRECTSOUNDBUFFER primary=NULL;
870 DSBUFFERDESC bufdesc;
874 /* Create the DirectSound object */
875 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
876 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
880 /* Get the device capabilities */
881 ZeroMemory(&dscaps, sizeof(dscaps));
882 dscaps.dwSize=sizeof(dscaps);
883 rc=IDirectSound8_GetCaps(dso,&dscaps);
884 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc));
888 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
889 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
890 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
891 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
892 "%s\n",DXGetErrorString8(rc));
897 ZeroMemory(&bufdesc, sizeof(bufdesc));
898 bufdesc.dwSize=sizeof(bufdesc);
899 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
900 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
901 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
902 "to create a primary buffer: %s\n",DXGetErrorString8(rc));
903 if (rc==DS_OK && primary!=NULL) {
904 ref=IDirectSoundBuffer_Release(primary);
905 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
906 "should have 0\n",ref);
908 ZeroMemory(&bufdesc, sizeof(bufdesc));
909 bufdesc.dwSize=sizeof(bufdesc);
910 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
911 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
912 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
913 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc));
914 if (rc==DS_OK && primary!=NULL) {
915 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
916 winetest_interactive &&
917 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
918 ref=IDirectSoundBuffer_Release(primary);
919 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
920 "should have 0\n",ref);
923 /* Set the CooperativeLevel back to normal */
924 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
925 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
926 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
927 "%s\n",DXGetErrorString8(rc));
930 ref=IDirectSound8_Release(dso);
931 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
933 return DSERR_GENERIC;
938 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid)
941 LPDIRECTSOUND8 dso=NULL;
942 LPDIRECTSOUNDBUFFER primary=NULL;
943 DSBUFFERDESC bufdesc;
947 /* Create the DirectSound object */
948 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
949 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
953 /* Get the device capabilities */
954 ZeroMemory(&dscaps, sizeof(dscaps));
955 dscaps.dwSize=sizeof(dscaps);
956 rc=IDirectSound8_GetCaps(dso,&dscaps);
957 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
961 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
962 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
963 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
964 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
965 "%s\n",DXGetErrorString8(rc));
969 ZeroMemory(&bufdesc, sizeof(bufdesc));
970 bufdesc.dwSize=sizeof(bufdesc);
971 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
972 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
973 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
974 "to create a 3D primary buffer %s\n",DXGetErrorString8(rc));
975 if (rc==DS_OK && primary!=NULL) {
976 LPDIRECTSOUND3DLISTENER listener=NULL;
977 rc=IDirectSoundBuffer_QueryInterface(primary,
978 &IID_IDirectSound3DListener,
980 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
981 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc));
982 if (rc==DS_OK && listener!=NULL) {
983 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
985 /* Checking the COM interface */
986 rc=IDirectSoundBuffer_QueryInterface(primary,
987 &IID_IDirectSoundBuffer,
988 (LPVOID *)&temp_buffer);
989 ok(rc==DS_OK && temp_buffer!=NULL,
990 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
991 DXGetErrorString8(rc));
992 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
993 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
994 if (rc==DS_OK && temp_buffer!=NULL) {
995 ref=IDirectSoundBuffer_Release(temp_buffer);
996 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
997 "should have 1\n",ref);
1000 rc=IDirectSound3DListener_QueryInterface(listener,
1001 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1002 ok(rc==DS_OK && temp_buffer!=NULL,
1003 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1004 DXGetErrorString8(rc));
1005 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
1006 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
1007 ref=IDirectSoundBuffer_Release(temp_buffer);
1008 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1009 "should have 1\n",ref);
1011 /* Testing the buffer */
1012 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
1013 winetest_interactive &&
1014 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1015 1.0,0,listener,0,0);
1018 /* Testing the reference counting */
1019 ref=IDirectSound3DListener_Release(listener);
1020 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1021 "references, should have 0\n",ref);
1024 /* Testing the reference counting */
1025 ref=IDirectSoundBuffer_Release(primary);
1026 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1027 "should have 0\n",ref);
1031 ref=IDirectSound8_Release(dso);
1032 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
1034 return DSERR_GENERIC;
1039 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1040 LPCSTR lpcstrModule, LPVOID lpContext)
1042 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1044 trace(" Testing the primary buffer\n");
1045 test_primary8(lpGuid);
1047 trace(" Testing 3D primary buffer\n");
1048 test_primary_3d8(lpGuid);
1050 trace(" Testing 3D primary buffer with listener\n");
1051 test_primary_3d_with_listener8(lpGuid);
1053 /* Testing secondary buffers */
1054 test_secondary8(lpGuid,winetest_interactive,0,0,0,0,0,0);
1055 test_secondary8(lpGuid,winetest_interactive,0,0,0,1,0,0);
1057 /* Testing 3D secondary buffers */
1058 test_secondary8(lpGuid,winetest_interactive,1,0,0,0,0,0);
1059 test_secondary8(lpGuid,winetest_interactive,1,1,0,0,0,0);
1060 test_secondary8(lpGuid,winetest_interactive,1,1,0,1,0,0);
1061 test_secondary8(lpGuid,winetest_interactive,1,0,1,0,0,0);
1062 test_secondary8(lpGuid,winetest_interactive,1,0,1,1,0,0);
1063 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,0);
1064 test_secondary8(lpGuid,winetest_interactive,1,1,1,1,0,0);
1065 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,0);
1066 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,1);
1067 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,1);
1072 static void ds3d8_tests()
1075 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
1076 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1085 hDsound = LoadLibraryA("dsound.dll");
1087 trace("dsound.dll not found\n");
1091 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
1092 if (!pDirectSoundCreate8) {
1093 trace("ds3d8 test skipped\n");