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"
45 LPDIRECTSOUNDBUFFER dsbo;
53 static int buffer_refill8(play_state_t* state, DWORD size)
59 if (size>state->wave_len-state->written)
60 size=state->wave_len-state->written;
62 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
63 &ptr1,&len1,&ptr2,&len2,0);
64 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
65 DXGetErrorString8(rc));
69 memcpy(ptr1,state->wave+state->written,len1);
72 memcpy(ptr2,state->wave+state->written,len2);
75 state->offset=state->written % state->buffer_size;
76 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
77 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
78 DXGetErrorString8(rc));
84 static int buffer_silence8(play_state_t* state, DWORD size)
91 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
92 &ptr1,&len1,&ptr2,&len2,0);
93 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
94 DXGetErrorString8(rc));
98 s=(state->wfx->wBitsPerSample==8?0x80:0);
103 state->offset=(state->offset+size) % state->buffer_size;
104 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
105 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
106 DXGetErrorString8(rc));
112 static int buffer_service8(play_state_t* state)
114 DWORD last_play_pos,play_pos,buf_free;
117 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
118 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
119 DXGetErrorString8(rc));
124 /* Update the amount played */
125 last_play_pos=state->played % state->buffer_size;
126 if (play_pos<last_play_pos)
127 state->played+=state->buffer_size-last_play_pos+play_pos;
129 state->played+=play_pos-last_play_pos;
131 if (winetest_debug > 1)
132 trace("buf size=%ld last_play_pos=%ld play_pos=%ld played=%ld / %ld\n",
133 state->buffer_size,last_play_pos,play_pos,state->played,
136 if (state->played>state->wave_len)
138 /* Everything has been played */
142 /* Refill the buffer */
143 if (state->offset<=play_pos)
144 buf_free=play_pos-state->offset;
146 buf_free=state->buffer_size-state->offset+play_pos;
148 if (winetest_debug > 1)
149 trace("offset=%ld free=%ld written=%ld / %ld\n",
150 state->offset,buf_free,state->written,state->wave_len);
154 if (state->written<state->wave_len)
156 int w=buffer_refill8(state,buf_free);
160 if (state->written==state->wave_len && winetest_debug > 1)
161 trace("last sound byte at %ld\n",
162 (state->written % state->buffer_size));
166 /* Fill with silence */
167 if (winetest_debug > 1)
168 trace("writing %ld bytes of silence\n",buf_free);
169 if (buffer_silence8(state,buf_free)==-1)
175 if (winetest_debug > 1)
176 trace("stopping playback\n");
177 rc=IDirectSoundBuffer_Stop(state->dsbo);
178 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %s\n",
179 DXGetErrorString8(rc));
183 void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER dsbo,
184 BOOL is_primary, BOOL set_volume, LONG volume,
185 BOOL set_pan, LONG pan, BOOL play, double duration,
186 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
187 BOOL move_listener, BOOL move_sound)
191 WAVEFORMATEX wfx,wfx2;
192 DWORD size,status,freq;
195 /* DSOUND: Error: Invalid caps pointer */
196 rc=IDirectSoundBuffer_GetCaps(dsbo,0);
197 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
198 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
200 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
202 /* DSOUND: Error: Invalid caps pointer */
203 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
204 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
205 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
207 dsbcaps.dwSize=sizeof(dsbcaps);
208 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
209 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n",
210 DXGetErrorString8(rc));
211 if (rc==DS_OK && winetest_debug > 1) {
212 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,
213 dsbcaps.dwBufferBytes);
216 /* Query the format size. Note that it may not match sizeof(wfx) */
218 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
219 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
220 "returned the needed size: rc=%s size=%ld\n",DXGetErrorString8(rc),size);
222 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
223 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
224 DXGetErrorString8(rc));
225 if (rc==DS_OK && winetest_debug > 1) {
226 trace(" Format: %s tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
227 is_primary ? "Primary" : "Secondary",
228 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
229 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
232 /* DSOUND: Error: Invalid frequency buffer */
233 rc=IDirectSoundBuffer_GetFrequency(dsbo,0);
234 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have "
235 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
237 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
238 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
239 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
240 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
241 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc));
243 ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency "
244 "%ld does not match the format %ld\n",freq,wfx.nSamplesPerSec);
247 /* DSOUND: Error: Invalid status pointer */
248 rc=IDirectSoundBuffer_GetStatus(dsbo,0);
249 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have "
250 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
252 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
253 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
254 DXGetErrorString8(rc));
255 ok(status==0,"status=0x%lx instead of 0\n",status);
258 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
259 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
260 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
261 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
262 "failed: %s\n",DXGetErrorString8(rc));
266 /* DSOUND: Error: Invalid format pointer */
267 rc=IDirectSoundBuffer_SetFormat(dsbo,0);
268 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
269 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
271 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
272 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
273 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n",
274 DXGetErrorString8(rc));
276 /* There is no garantee that SetFormat will actually change the
277 * format to what we asked for. It depends on what the soundcard
278 * supports. So we must re-query the format.
280 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
281 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
282 DXGetErrorString8(rc));
284 (wfx.wFormatTag!=wfx2.wFormatTag ||
285 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
286 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
287 wfx.nChannels!=wfx2.nChannels)) {
288 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
289 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
290 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
291 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
292 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
293 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
296 /* Set the CooperativeLevel back to normal */
297 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
298 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
299 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
300 "failed: %s\n",DXGetErrorString8(rc));
305 DS3DLISTENER listener_param;
306 LPDIRECTSOUND3DBUFFER buffer=NULL;
307 DS3DBUFFER buffer_param;
308 DWORD start_time,now;
310 if (winetest_interactive) {
311 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration,
312 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
316 /* We must call SetCooperativeLevel to be allowed to call Lock */
317 /* DSOUND: Setting DirectSound cooperative level to
318 * DSSCL_WRITEPRIMARY */
319 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),
322 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: "
323 "%s\n",DXGetErrorString8(rc));
328 LPDIRECTSOUNDBUFFER temp_buffer;
330 rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer,
332 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
333 DXGetErrorString8(rc));
337 /* check the COM interface */
338 rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
339 (LPVOID *)&temp_buffer);
340 ok(rc==DS_OK && temp_buffer!=NULL,
341 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
342 DXGetErrorString8(rc));
343 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
344 (DWORD)temp_buffer,(DWORD)dsbo);
345 ref=IDirectSoundBuffer_Release(temp_buffer);
346 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
347 "should have 1\n",ref);
350 rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
351 (LPVOID *)&temp_buffer);
352 ok(rc==DS_OK && temp_buffer!=NULL,
353 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
354 DXGetErrorString8(rc));
355 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
356 (DWORD)temp_buffer,(DWORD)dsbo);
357 ref=IDirectSoundBuffer_Release(temp_buffer);
358 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
359 "should have 1\n",ref);
362 /* FIXME: this works on windows */
363 ref=IDirectSoundBuffer_Release(dsbo);
364 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
365 "should have 0\n",ref);
367 rc=IDirectSound3DBuffer_QueryInterface(buffer,
368 &IID_IDirectSoundBuffer,
370 ok(rc==DS_OK && dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
371 "failed: %s\n",DXGetErrorString8(rc),
374 /* DSOUND: Error: Invalid buffer */
375 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
376 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
377 "failed: %s\n",DXGetErrorString8(rc));
379 ZeroMemory(&buffer_param, sizeof(buffer_param));
381 /* DSOUND: Error: Invalid buffer */
382 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
383 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
384 "failed: %s\n",DXGetErrorString8(rc));
386 buffer_param.dwSize=sizeof(buffer_param);
387 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
388 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
389 DXGetErrorString8(rc));
392 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
394 rc=IDirectSoundBuffer_GetVolume(dsbo,&val);
395 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
396 DXGetErrorString8(rc));
398 rc=IDirectSoundBuffer_SetVolume(dsbo,volume);
399 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %s\n",
400 DXGetErrorString8(rc));
402 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
403 rc=IDirectSoundBuffer_GetVolume(dsbo,&volume);
404 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
405 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
406 DXGetErrorString8(rc));
411 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
413 rc=IDirectSoundBuffer_GetPan(dsbo,&val);
414 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %s\n",
415 DXGetErrorString8(rc));
417 rc=IDirectSoundBuffer_SetPan(dsbo,pan);
418 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %s\n",
419 DXGetErrorString8(rc));
421 /* DSOUND: Error: Buffer does not have CTRLPAN */
422 rc=IDirectSoundBuffer_GetPan(dsbo,&pan);
423 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
424 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
425 DXGetErrorString8(rc));
429 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
433 state.buffer_size=dsbcaps.dwBufferBytes;
434 state.played=state.written=state.offset=0;
435 buffer_refill8(&state,state.buffer_size);
437 rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING);
438 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %s\n",
439 DXGetErrorString8(rc));
441 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
442 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
443 DXGetErrorString8(rc));
444 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
445 "GetStatus: bad status: %lx\n",status);
448 ZeroMemory(&listener_param,sizeof(listener_param));
449 listener_param.dwSize=sizeof(listener_param);
450 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
451 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
452 "failed: %s\n",DXGetErrorString8(rc));
454 listener_param.vPosition.x = -5.0;
455 listener_param.vVelocity.x = 10.0/duration;
457 rc=IDirectSound3DListener_SetAllParameters(listener,
460 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %s\n",
461 DXGetErrorString8(rc));
465 buffer_param.vPosition.x = 100.0;
466 buffer_param.vVelocity.x = -200.0/duration;
468 buffer_param.flMinDistance = 10;
469 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
471 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
472 DXGetErrorString8(rc));
475 start_time=GetTickCount();
476 while (buffer_service8(&state)) {
477 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
479 if (listener && move_listener) {
480 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/
482 if (winetest_debug>2)
483 trace("listener position=%g\n",listener_param.vPosition.x);
484 rc=IDirectSound3DListener_SetPosition(listener,
485 listener_param.vPosition.x,listener_param.vPosition.y,
486 listener_param.vPosition.z,DS3D_IMMEDIATE);
487 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: "
488 "%s\n",DXGetErrorString8(rc));
490 if (buffer3d && move_sound) {
491 buffer_param.vPosition.x = 100-200.0*(now-start_time)/
493 if (winetest_debug>2)
494 trace("sound position=%g\n",buffer_param.vPosition.x);
495 rc=IDirectSound3DBuffer_SetPosition(buffer,
496 buffer_param.vPosition.x,buffer_param.vPosition.y,
497 buffer_param.vPosition.z,DS3D_IMMEDIATE);
498 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
499 DXGetErrorString8(rc));
502 /* Check the sound duration was within 10% of the expected value */
504 ok(fabs(1000*duration-now+start_time)<=100*duration,
505 "The sound played for %ld ms instead of %g ms\n",
506 now-start_time,1000*duration);
510 /* Set the CooperativeLevel back to normal */
511 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
512 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
513 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
514 "failed: %s\n",DXGetErrorString8(rc));
517 ref=IDirectSound3DBuffer_Release(buffer);
518 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
519 "should have 0\n",ref);
524 static HRESULT test_secondary8(LPGUID lpGuid, int play,
525 int has_3d, int has_3dbuffer,
526 int has_listener, int has_duplicate,
527 int move_listener, int move_sound)
530 LPDIRECTSOUND8 dso=NULL;
531 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
532 LPDIRECTSOUND3DLISTENER listener=NULL;
533 DSBUFFERDESC bufdesc;
537 /* Create the DirectSound object */
538 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
539 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
543 /* We must call SetCooperativeLevel before creating primary buffer */
544 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
545 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
546 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
547 "%s\n",DXGetErrorString8(rc));
551 ZeroMemory(&bufdesc, sizeof(bufdesc));
552 bufdesc.dwSize=sizeof(bufdesc);
553 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
555 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
557 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
558 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
559 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
560 "failed to create a %sprimary buffer: %s\n",has_3d?"3D ":"",
561 DXGetErrorString8(rc));
563 if (rc==DS_OK && primary!=NULL) {
565 rc=IDirectSoundBuffer_QueryInterface(primary,
566 &IID_IDirectSound3DListener,
568 ok(rc==DS_OK && listener!=NULL,
569 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
570 "listener %s\n",DXGetErrorString8(rc));
571 ref=IDirectSoundBuffer_Release(primary);
572 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
573 "should have 0\n",ref);
574 if (rc==DS_OK && listener!=NULL) {
575 DS3DLISTENER listener_param;
576 ZeroMemory(&listener_param,sizeof(listener_param));
577 /* DSOUND: Error: Invalid buffer */
578 rc=IDirectSound3DListener_GetAllParameters(listener,0);
579 ok(rc==DSERR_INVALIDPARAM,
580 "IDirectSound3dListener_GetAllParameters() should have "
581 "returned DSERR_INVALIDPARAM, returned: %s\n",
582 DXGetErrorString8(rc));
584 /* DSOUND: Error: Invalid buffer */
585 rc=IDirectSound3DListener_GetAllParameters(listener,
587 ok(rc==DSERR_INVALIDPARAM,
588 "IDirectSound3dListener_GetAllParameters() should have "
589 "returned DSERR_INVALIDPARAM, returned: %s\n",
590 DXGetErrorString8(rc));
592 listener_param.dwSize=sizeof(listener_param);
593 rc=IDirectSound3DListener_GetAllParameters(listener,
595 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
596 "failed: %s\n",DXGetErrorString8(rc));
602 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
604 ZeroMemory(&bufdesc, sizeof(bufdesc));
605 bufdesc.dwSize=sizeof(bufdesc);
606 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
608 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
611 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
612 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
613 bufdesc.lpwfxFormat=&wfx;
615 /* a stereo 3D buffer should fail */
616 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
617 ok(rc==DSERR_INVALIDPARAM,
618 "IDirectSound8_CreateSoundBuffer(secondary) should have "
619 "returned DSERR_INVALIDPARAM, returned %s\n",
620 DXGetErrorString8(rc));
622 ref=IDirectSoundBuffer_Release(secondary);
623 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
626 if (winetest_interactive) {
627 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d\n",
628 has_3dbuffer?"3D ":"",
629 has_duplicate?"duplicated ":"",
630 listener!=NULL||move_sound?"with ":"",
631 move_listener?"moving ":"",
632 listener!=NULL?"listener ":"",
633 listener&&move_sound?"and moving sound ":move_sound?
635 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
637 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
638 ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() "
639 "failed to create a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d (%s): %s\n",
640 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
641 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
642 listener!=NULL?"listener ":"",
643 listener&&move_sound?"and moving sound ":move_sound?
645 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
646 getDSBCAPS(bufdesc.dwFlags),DXGetErrorString8(rc));
647 if (rc==DS_OK && secondary!=NULL) {
652 /* Check the initial secondary buffer's volume and pan */
653 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
654 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: "
655 "%s\n",DXGetErrorString8(rc));
656 ok(vol==0,"wrong volume for a new secondary buffer: %ld\n",vol);
657 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
658 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: "
659 "%s\n",DXGetErrorString8(rc));
660 ok(pan==0,"wrong pan for a new secondary buffer: %ld\n",pan);
662 /* Check that changing the secondary buffer's volume and pan
663 * does not impact the primary buffer's volume and pan
665 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
666 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: "
667 "%s\n",DXGetErrorString8(rc));
668 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
669 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
670 "%s\n",DXGetErrorString8(rc));
672 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
673 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
674 "%s\n",DXGetErrorString8(rc));
675 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
676 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
677 "%s\n",DXGetErrorString8(rc));
678 ok(vol==-1000,"secondary: wrong volume %ld instead of -1000\n",
680 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
681 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
682 "%s\n",DXGetErrorString8(rc));
683 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
684 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
685 "%s\n",DXGetErrorString8(rc));
686 ok(pan==-1000,"secondary: wrong pan %ld instead of -1000\n",
689 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
690 ok(rc==DS_OK,"IDirectSoundBuffer_`GetVolume(primary) failed: i"
691 "%s\n",DXGetErrorString8(rc));
692 ok(vol==refvol,"The primary volume changed from %ld to %ld\n",
694 rc=IDirectSoundBuffer_GetPan(primary,&pan);
695 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
696 "%s\n",DXGetErrorString8(rc));
697 ok(pan==refpan,"The primary pan changed from %ld to %ld\n",
700 rc=IDirectSoundBuffer_SetVolume(secondary,0);
701 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
702 "%s\n",DXGetErrorString8(rc));
703 rc=IDirectSoundBuffer_SetPan(secondary,0);
704 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
705 "%s\n",DXGetErrorString8(rc));
708 LPDIRECTSOUNDBUFFER duplicated=NULL;
710 /* DSOUND: Error: Invalid source buffer */
711 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0);
712 ok(rc==DSERR_INVALIDPARAM,
713 "IDirectSound8_DuplicateSoundBuffer() should have returned "
714 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
716 /* DSOUND: Error: Invalid dest buffer */
717 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0);
718 ok(rc==DSERR_INVALIDPARAM,
719 "IDirectSound8_DuplicateSoundBuffer() should have returned "
720 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
722 /* DSOUND: Error: Invalid source buffer */
723 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated);
724 ok(rc==DSERR_INVALIDPARAM,
725 "IDirectSound8_DuplicateSoundBuffer() should have returned "
726 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
729 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,
731 ok(rc==DS_OK && duplicated!=NULL,
732 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
733 "a secondary buffer: %s\n",DXGetErrorString8(rc));
735 if (rc==DS_OK && duplicated!=NULL) {
736 ref=IDirectSoundBuffer_Release(secondary);
737 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
738 "references, should have 0\n",ref);
739 secondary=duplicated;
743 if (rc==DS_OK && secondary!=NULL) {
745 duration=(move_listener || move_sound?4.0:1.0);
746 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,
747 winetest_interactive,duration,has_3dbuffer,
748 listener,move_listener,move_sound);
749 ref=IDirectSoundBuffer_Release(secondary);
750 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
751 "should have 0\n",has_duplicate?"duplicated":"secondary",
757 ref=IDirectSound3DListener_Release(listener);
758 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
759 "references, should have 0\n",ref);
761 ref=IDirectSoundBuffer_Release(primary);
762 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
763 "should have 0\n",ref);
766 /* Set the CooperativeLevel back to normal */
767 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
768 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
769 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
770 "%s\n",DXGetErrorString8(rc));
773 ref=IDirectSound8_Release(dso);
774 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
776 return DSERR_GENERIC;
781 static HRESULT test_primary8(LPGUID lpGuid)
784 LPDIRECTSOUND8 dso=NULL;
785 LPDIRECTSOUNDBUFFER primary=NULL;
786 DSBUFFERDESC bufdesc;
790 /* Create the DirectSound object */
791 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
792 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
796 /* Get the device capabilities */
797 ZeroMemory(&dscaps, sizeof(dscaps));
798 dscaps.dwSize=sizeof(dscaps);
799 rc=IDirectSound8_GetCaps(dso,&dscaps);
800 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
804 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
805 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
806 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
807 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
808 "%s\n",DXGetErrorString8(rc));
812 /* Testing the primary buffer */
814 ZeroMemory(&bufdesc, sizeof(bufdesc));
815 bufdesc.dwSize=sizeof(bufdesc);
816 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
817 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
818 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
819 "to create a primary buffer: 0x%lx\n",rc);
820 if (rc==DS_OK && primary!=NULL) {
821 test_buffer8(dso,primary,1,TRUE,0,TRUE,0,winetest_interactive &&
822 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0);
823 if (winetest_interactive) {
826 volume = DSBVOLUME_MAX;
827 for (i = 0; i < 6; i++) {
828 test_buffer8(dso,primary,1,TRUE,volume,TRUE,0,
829 winetest_interactive &&
830 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
832 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
836 for (i = 0; i < 7; i++) {
837 test_buffer8(dso,primary,1,TRUE,0,TRUE,pan,
838 winetest_interactive &&
839 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
840 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
843 ref=IDirectSoundBuffer_Release(primary);
844 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
845 "should have 0\n",ref);
848 /* Set the CooperativeLevel back to normal */
849 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
850 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
851 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
852 "%s\n",DXGetErrorString8(rc));
855 ref=IDirectSound8_Release(dso);
856 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
858 return DSERR_GENERIC;
863 static HRESULT test_primary_3d8(LPGUID lpGuid)
866 LPDIRECTSOUND8 dso=NULL;
867 LPDIRECTSOUNDBUFFER primary=NULL;
868 DSBUFFERDESC bufdesc;
872 /* Create the DirectSound object */
873 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
874 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
878 /* Get the device capabilities */
879 ZeroMemory(&dscaps, sizeof(dscaps));
880 dscaps.dwSize=sizeof(dscaps);
881 rc=IDirectSound8_GetCaps(dso,&dscaps);
882 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc));
886 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
887 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
888 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
889 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
890 "%s\n",DXGetErrorString8(rc));
895 ZeroMemory(&bufdesc, sizeof(bufdesc));
896 bufdesc.dwSize=sizeof(bufdesc);
897 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
898 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
899 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
900 "to create a primary buffer: %s\n",DXGetErrorString8(rc));
901 if (rc==DS_OK && primary!=NULL) {
902 ref=IDirectSoundBuffer_Release(primary);
903 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
904 "should have 0\n",ref);
906 ZeroMemory(&bufdesc, sizeof(bufdesc));
907 bufdesc.dwSize=sizeof(bufdesc);
908 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
909 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
910 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
911 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc));
912 if (rc==DS_OK && primary!=NULL) {
913 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
914 winetest_interactive &&
915 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
916 ref=IDirectSoundBuffer_Release(primary);
917 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
918 "should have 0\n",ref);
921 /* Set the CooperativeLevel back to normal */
922 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
923 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
924 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
925 "%s\n",DXGetErrorString8(rc));
928 ref=IDirectSound8_Release(dso);
929 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
931 return DSERR_GENERIC;
936 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid)
939 LPDIRECTSOUND8 dso=NULL;
940 LPDIRECTSOUNDBUFFER primary=NULL;
941 DSBUFFERDESC bufdesc;
945 /* Create the DirectSound object */
946 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
947 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc));
951 /* Get the device capabilities */
952 ZeroMemory(&dscaps, sizeof(dscaps));
953 dscaps.dwSize=sizeof(dscaps);
954 rc=IDirectSound8_GetCaps(dso,&dscaps);
955 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
959 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
960 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
961 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
962 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
963 "%s\n",DXGetErrorString8(rc));
967 ZeroMemory(&bufdesc, sizeof(bufdesc));
968 bufdesc.dwSize=sizeof(bufdesc);
969 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
970 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
971 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
972 "to create a 3D primary buffer %s\n",DXGetErrorString8(rc));
973 if (rc==DS_OK && primary!=NULL) {
974 LPDIRECTSOUND3DLISTENER listener=NULL;
975 rc=IDirectSoundBuffer_QueryInterface(primary,
976 &IID_IDirectSound3DListener,
978 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
979 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc));
980 if (rc==DS_OK && listener!=NULL) {
981 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
983 /* Checking the COM interface */
984 rc=IDirectSoundBuffer_QueryInterface(primary,
985 &IID_IDirectSoundBuffer,
986 (LPVOID *)&temp_buffer);
987 ok(rc==DS_OK && temp_buffer!=NULL,
988 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
989 DXGetErrorString8(rc));
990 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
991 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
992 if (rc==DS_OK && temp_buffer!=NULL) {
993 ref=IDirectSoundBuffer_Release(temp_buffer);
994 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
995 "should have 1\n",ref);
998 rc=IDirectSound3DListener_QueryInterface(listener,
999 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1000 ok(rc==DS_OK && temp_buffer!=NULL,
1001 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1002 DXGetErrorString8(rc));
1003 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
1004 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
1005 ref=IDirectSoundBuffer_Release(temp_buffer);
1006 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1007 "should have 1\n",ref);
1009 /* Testing the buffer */
1010 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
1011 winetest_interactive &&
1012 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1013 1.0,0,listener,0,0);
1016 /* Testing the reference counting */
1017 ref=IDirectSound3DListener_Release(listener);
1018 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1019 "references, should have 0\n",ref);
1022 /* Testing the reference counting */
1023 ref=IDirectSoundBuffer_Release(primary);
1024 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1025 "should have 0\n",ref);
1029 ref=IDirectSound8_Release(dso);
1030 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
1032 return DSERR_GENERIC;
1037 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1038 LPCSTR lpcstrModule, LPVOID lpContext)
1040 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1042 trace(" Testing the primary buffer\n");
1043 test_primary8(lpGuid);
1045 trace(" Testing 3D primary buffer\n");
1046 test_primary_3d8(lpGuid);
1048 trace(" Testing 3D primary buffer with listener\n");
1049 test_primary_3d_with_listener8(lpGuid);
1051 /* Testing secondary buffers */
1052 test_secondary8(lpGuid,winetest_interactive,0,0,0,0,0,0);
1053 test_secondary8(lpGuid,winetest_interactive,0,0,0,1,0,0);
1055 /* Testing 3D secondary buffers */
1056 test_secondary8(lpGuid,winetest_interactive,1,0,0,0,0,0);
1057 test_secondary8(lpGuid,winetest_interactive,1,1,0,0,0,0);
1058 test_secondary8(lpGuid,winetest_interactive,1,1,0,1,0,0);
1059 test_secondary8(lpGuid,winetest_interactive,1,0,1,0,0,0);
1060 test_secondary8(lpGuid,winetest_interactive,1,0,1,1,0,0);
1061 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,0);
1062 test_secondary8(lpGuid,winetest_interactive,1,1,1,1,0,0);
1063 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,0);
1064 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,1);
1065 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,1);
1070 static void ds3d8_tests()
1073 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
1074 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1084 hDsound = LoadLibraryA("dsound.dll");
1086 trace("dsound.dll not found\n");
1090 pFunc = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
1092 trace("ds3d8 test skipped\n");