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,"GetCaps should have failed: 0x%lx\n",rc);
199 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
201 /* DSOUND: Error: Invalid caps pointer */
202 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
203 ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
205 dsbcaps.dwSize=sizeof(dsbcaps);
206 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
207 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
208 if (rc==DS_OK && winetest_interactive) {
209 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,
210 dsbcaps.dwBufferBytes);
213 /* Query the format size. Note that it may not match sizeof(wfx) */
215 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
216 ok(rc==DS_OK && size!=0,
217 "GetFormat should have returned the needed size: rc=0x%lx size=%ld\n",
220 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
221 ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
222 if (rc==DS_OK && is_primary && winetest_interactive) {
223 trace("Primary buffer default format: tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
224 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
225 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
228 /* DSOUND: Error: Invalid frequency buffer */
229 rc=IDirectSoundBuffer_GetFrequency(dsbo,0);
230 ok(rc==DSERR_INVALIDPARAM,"GetFrequency should have failed: 0x%lx\n",rc);
232 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
233 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
234 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
235 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
236 "GetFrequency failed: 0x%lx\n",rc);
238 ok(freq==wfx.nSamplesPerSec,
239 "The frequency returned by GetFrequency %ld does not match the format %ld\n",
240 freq,wfx.nSamplesPerSec);
243 /* DSOUND: Error: Invalid status pointer */
244 rc=IDirectSoundBuffer_GetStatus(dsbo,0);
245 ok(rc==DSERR_INVALIDPARAM,"GetStatus should have failed: 0x%lx\n",rc);
247 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
248 ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc);
249 ok(status==0,"status=0x%lx instead of 0\n",status);
252 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
253 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
254 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
255 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
259 /* DSOUND: Error: Invalid format pointer */
260 rc=IDirectSoundBuffer_SetFormat(dsbo,0);
261 ok(rc==DSERR_INVALIDPARAM,"SetFormat should have failed: 0x%lx\n",rc);
263 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
264 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
265 ok(rc==DS_OK,"SetFormat failed: 0x%lx\n",rc);
267 /* There is no garantee that SetFormat will actually change the
268 * format to what we asked for. It depends on what the soundcard
269 * supports. So we must re-query the format.
271 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
272 ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
274 (wfx.wFormatTag!=wfx2.wFormatTag ||
275 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
276 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
277 wfx.nChannels!=wfx2.nChannels)) {
278 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
279 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
280 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
281 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
282 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
283 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
286 /* Set the CooperativeLevel back to normal */
287 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
288 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
289 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
294 DS3DLISTENER listener_param;
295 LPDIRECTSOUND3DBUFFER buffer=NULL;
296 DS3DBUFFER buffer_param;
297 DWORD start_time,now;
299 if (winetest_interactive) {
300 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration,
301 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
305 /* We must call SetCooperativeLevel to be allowed to call Lock */
306 /* DSOUND: Setting DirectSound cooperative level to DSSCL_WRITEPRIMARY */
307 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_WRITEPRIMARY);
308 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
313 LPDIRECTSOUNDBUFFER temp_buffer;
315 rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer,(LPVOID *)&buffer);
316 ok(rc==DS_OK,"QueryInterface failed: 0x%lx\n",rc);
320 /* check the COM interface */
321 rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
322 ok(rc==DS_OK && temp_buffer!=NULL,"QueryInterface failed: 0x%lx\n",rc);
323 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)dsbo);
324 ref=IDirectSoundBuffer_Release(temp_buffer);
325 ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref);
328 rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
329 ok(rc==DS_OK && temp_buffer!=NULL,"IDirectSound3DBuffer_QueryInterface failed: 0x%lx\n",rc);
330 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)dsbo);
331 ref=IDirectSoundBuffer_Release(temp_buffer);
332 ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref);
335 /* FIXME: this works on windows */
336 ref=IDirectSoundBuffer_Release(dsbo);
337 ok(ref==0,"IDirectSoundBuffer_Release has %d references, should have 0\n",ref);
339 rc=IDirectSound3DBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer,(LPVOID *)&dsbo);
340 ok(rc==DS_OK && dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface failed: 0x%lx\n",rc);
343 /* DSOUND: Error: Invalid buffer */
344 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
345 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc);
347 ZeroMemory(&buffer_param, sizeof(buffer_param));
349 /* DSOUND: Error: Invalid buffer */
350 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
351 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc);
353 buffer_param.dwSize=sizeof(buffer_param);
354 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
355 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc);
358 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
360 rc=IDirectSoundBuffer_GetVolume(dsbo,&val);
361 ok(rc==DS_OK,"GetVolume failed: 0x%lx\n",rc);
363 rc=IDirectSoundBuffer_SetVolume(dsbo,volume);
364 ok(rc==DS_OK,"SetVolume failed: 0x%lx\n",rc);
366 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
367 rc=IDirectSoundBuffer_GetVolume(dsbo,&volume);
368 ok(rc==DSERR_CONTROLUNAVAIL,"GetVolume should have failed: 0x%lx\n",rc);
373 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
375 rc=IDirectSoundBuffer_GetPan(dsbo,&val);
376 ok(rc==DS_OK,"GetPan failed: 0x%lx\n",rc);
378 rc=IDirectSoundBuffer_SetPan(dsbo,pan);
379 ok(rc==DS_OK,"SetPan failed: 0x%lx\n",rc);
381 /* DSOUND: Error: Buffer does not have CTRLPAN */
382 rc=IDirectSoundBuffer_GetPan(dsbo,&pan);
383 ok(rc==DSERR_CONTROLUNAVAIL,"GetPan should have failed: 0x%lx\n",rc);
387 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
391 state.buffer_size=dsbcaps.dwBufferBytes;
392 state.played=state.written=state.offset=0;
393 buffer_refill8(&state,state.buffer_size);
395 rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING);
396 ok(rc==DS_OK,"Play: 0x%lx\n",rc);
398 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
399 ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc);
400 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
401 "GetStatus: bad status: %lx\n",status);
404 ZeroMemory(&listener_param,sizeof(listener_param));
405 listener_param.dwSize=sizeof(listener_param);
406 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
407 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc);
410 listener_param.vPosition.x = -5.0;
411 listener_param.vVelocity.x = 10.0/duration;
413 rc=IDirectSound3DListener_SetAllParameters(listener,&listener_param,DS3D_IMMEDIATE);
414 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition failed 0x%lx\n",rc);
419 buffer_param.vPosition.x = 100.0;
420 buffer_param.vVelocity.x = -200.0/duration;
422 buffer_param.flMinDistance = 10;
423 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,DS3D_IMMEDIATE);
424 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition failed 0x%lx\n",rc);
427 start_time=GetTickCount();
428 while (buffer_service8(&state)) {
429 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
431 if (listener && move_listener) {
432 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/1000/duration;
433 if (winetest_debug>2)
434 trace("listener position=%g\n",listener_param.vPosition.x);
435 rc=IDirectSound3DListener_SetPosition(listener,listener_param.vPosition.x,listener_param.vPosition.y,listener_param.vPosition.z,DS3D_IMMEDIATE);
436 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition failed 0x%lx\n",rc);
438 if (buffer3d && move_sound) {
439 buffer_param.vPosition.x = 100-200.0*(now-start_time)/1000/duration;
440 if (winetest_debug>2)
441 trace("sound position=%g\n",buffer_param.vPosition.x);
442 rc=IDirectSound3DBuffer_SetPosition(buffer,buffer_param.vPosition.x,buffer_param.vPosition.y,buffer_param.vPosition.z,DS3D_IMMEDIATE);
443 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition failed 0x%lx\n",rc);
446 /* Check the sound duration was within 10% of the expected value */
448 ok(fabs(1000*duration-now+start_time)<=100*duration,"The sound played for %ld ms instead of %g ms\n",now-start_time,1000*duration);
452 /* Set the CooperativeLevel back to normal */
453 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
454 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
455 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
458 ref=IDirectSound3DBuffer_Release(buffer);
459 ok(ref==0,"IDirectSound3DBuffer_Release has %d references, should have 0\n",ref);
464 static HRESULT test_secondary8(LPGUID lpGuid, int play,
465 int has_3d, int has_3dbuffer,
466 int has_listener, int has_duplicate,
467 int move_listener, int move_sound)
470 LPDIRECTSOUND8 dso=NULL;
471 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
472 LPDIRECTSOUND3DLISTENER listener=NULL;
473 DSBUFFERDESC bufdesc;
477 /* Create the DirectSound object */
478 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
479 ok(rc==DS_OK,"DirectSoundCreate8 failed: 0x%08lx\n",rc);
483 /* We must call SetCooperativeLevel before creating primary buffer */
484 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
485 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
486 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
490 ZeroMemory(&bufdesc, sizeof(bufdesc));
491 bufdesc.dwSize=sizeof(bufdesc);
492 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
494 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
496 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
497 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
498 ok(rc==DS_OK && primary!=NULL,"CreateSoundBuffer failed to create a %sprimary buffer 0x%lx\n",has_3d?"3D ":"", rc);
500 if (rc==DS_OK && primary!=NULL) {
502 rc=IDirectSoundBuffer_QueryInterface(primary,&IID_IDirectSound3DListener,(void **)&listener);
503 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface failed to get a 3D listener 0x%lx\n",rc);
504 ref=IDirectSoundBuffer_Release(primary);
505 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
506 if (rc==DS_OK && listener!=NULL) {
507 DS3DLISTENER listener_param;
508 ZeroMemory(&listener_param,sizeof(listener_param));
509 /* DSOUND: Error: Invalid buffer */
510 rc=IDirectSound3DListener_GetAllParameters(listener,0);
511 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc);
513 /* DSOUND: Error: Invalid buffer */
514 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
515 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc);
517 listener_param.dwSize=sizeof(listener_param);
518 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
519 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc);
525 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
527 ZeroMemory(&bufdesc, sizeof(bufdesc));
528 bufdesc.dwSize=sizeof(bufdesc);
529 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
531 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
533 bufdesc.dwFlags|=(DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
534 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
535 bufdesc.lpwfxFormat=&wfx;
536 if (winetest_interactive) {
537 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d\n",
538 has_3dbuffer?"3D ":"",
539 has_duplicate?"duplicated ":"",
540 listener!=NULL||move_sound?"with ":"",
541 move_listener?"moving ":"",
542 listener!=NULL?"listener ":"",
543 listener&&move_sound?"and moving sound ":move_sound?"moving sound ":"",
544 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
546 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
547 ok(rc==DS_OK && secondary!=NULL,"CreateSoundBuffer failed to create a 3D secondary buffer 0x%lx\n",rc);
548 if (rc==DS_OK && secondary!=NULL) {
551 LONG refvol,refpan,vol,pan;
553 /* Check the initial secondary buffer's volume and pan */
554 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
555 ok(rc==DS_OK,"GetVolume(secondary) failed: %s\n",DXGetErrorString8(rc));
556 ok(vol==0,"wrong volume for a new secondary buffer: %ld\n",vol);
557 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
558 ok(rc==DS_OK,"GetPan(secondary) failed: %s\n",DXGetErrorString8(rc));
559 ok(pan==0,"wrong pan for a new secondary buffer: %ld\n",pan);
561 /* Check that changing the secondary buffer's volume and pan
562 * does not impact the primary buffer's volume and pan
564 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
565 ok(rc==DS_OK,"GetVolume(primary) failed: %s\n",DXGetErrorString8(rc));
566 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
567 ok(rc==DS_OK,"GetPan(primary) failed: %s\n",DXGetErrorString8(rc));
569 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
570 ok(rc==DS_OK,"SetVolume(secondary) failed: %s\n",DXGetErrorString8(rc));
571 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
572 ok(rc==DS_OK,"SetVolume(secondary) failed: %s\n",DXGetErrorString8(rc));
573 ok(vol==-1000,"secondary: wrong volume %ld instead of -1000\n",vol);
574 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
575 ok(rc==DS_OK,"SetPan(secondary) failed: %s\n",DXGetErrorString8(rc));
576 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
577 ok(rc==DS_OK,"SetPan(secondary) failed: %s\n",DXGetErrorString8(rc));
578 ok(vol==-1000,"secondary: wrong pan %ld instead of -1000\n",pan);
580 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
581 ok(rc==DS_OK,"GetVolume(primary) failed: %s\n",DXGetErrorString8(rc));
582 ok(vol==refvol,"The primary volume changed from %ld to %ld\n",refvol,vol);
583 rc=IDirectSoundBuffer_GetPan(primary,&pan);
584 ok(rc==DS_OK,"GetPan(primary) failed: %s\n",DXGetErrorString8(rc));
585 ok(pan==refpan,"The primary pan changed from %ld to %ld\n",refpan,pan);
587 rc=IDirectSoundBuffer_SetVolume(secondary,0);
588 ok(rc==DS_OK,"SetVolume(secondary) failed: %s\n",DXGetErrorString8(rc));
589 rc=IDirectSoundBuffer_SetPan(secondary,0);
590 ok(rc==DS_OK,"SetPan(secondary) failed: %s\n",DXGetErrorString8(rc));
593 LPDIRECTSOUNDBUFFER duplicated=NULL;
595 /* DSOUND: Error: Invalid source buffer */
596 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0);
597 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_DuplicateSoundBuffer should have failed 0x%lx\n",rc);
599 /* DSOUND: Error: Invalid dest buffer */
600 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0);
601 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_DuplicateSoundBuffer should have failed 0x%lx\n",rc);
603 /* DSOUND: Error: Invalid source buffer */
604 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated);
605 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_DuplicateSoundBuffer should have failed 0x%lx\n",rc);
608 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,&duplicated);
609 ok(rc==DS_OK && duplicated!=NULL,"IDirectSound8_DuplicateSoundBuffer failed to duplicate a secondary buffer 0x%lx\n",rc);
611 if (rc==DS_OK && duplicated!=NULL) {
612 ref=IDirectSoundBuffer_Release(secondary);
613 ok(ref==0,"IDirectSoundBuffer_Release secondary has %d references, should have 0\n",ref);
614 secondary=duplicated;
618 if (rc==DS_OK && secondary!=NULL) {
620 duration=(move_listener || move_sound?4.0:1.0);
621 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,winetest_interactive,duration,has_3dbuffer,listener,move_listener,move_sound);
622 ref=IDirectSoundBuffer_Release(secondary);
623 ok(ref==0,"IDirectSoundBuffer_Release %s has %d references, should have 0\n",has_duplicate?"duplicated":"secondary",ref);
628 ref=IDirectSound3DListener_Release(listener);
629 ok(ref==0,"IDirectSound3dListener_Release listener has %d references, should have 0\n",ref);
631 ref=IDirectSoundBuffer_Release(primary);
632 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
635 /* Set the CooperativeLevel back to normal */
636 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
637 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
638 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);
641 ref=IDirectSound8_Release(dso);
642 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
644 return DSERR_GENERIC;
649 static HRESULT test_primary8(LPGUID lpGuid)
652 LPDIRECTSOUND8 dso=NULL;
653 LPDIRECTSOUNDBUFFER primary=NULL;
654 DSBUFFERDESC bufdesc;
658 /* Create the DirectSound object */
659 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
660 ok(rc==DS_OK,"DirectSoundCreate8 failed: 0x%lx\n",rc);
664 /* Get the device capabilities */
665 ZeroMemory(&dscaps, sizeof(dscaps));
666 dscaps.dwSize=sizeof(dscaps);
667 rc=IDirectSound8_GetCaps(dso,&dscaps);
668 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
672 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
673 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
674 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
675 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
679 /* Testing the primary buffer */
681 ZeroMemory(&bufdesc, sizeof(bufdesc));
682 bufdesc.dwSize=sizeof(bufdesc);
683 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
684 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
685 ok(rc==DS_OK && primary!=NULL,"CreateSoundBuffer failed to create a primary buffer: 0x%lx\n",rc);
686 if (rc==DS_OK && primary!=NULL) {
687 test_buffer8(dso,primary,1,TRUE,0,TRUE,0,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0);
688 if (winetest_interactive) {
691 volume = DSBVOLUME_MAX;
692 for (i = 0; i < 6; i++) {
693 test_buffer8(dso,primary,1,TRUE,volume,TRUE,0,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0);
694 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
698 for (i = 0; i < 7; i++) {
699 test_buffer8(dso,primary,1,TRUE,0,TRUE,pan,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
700 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
703 ref=IDirectSoundBuffer_Release(primary);
704 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
707 /* Set the CooperativeLevel back to normal */
708 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
709 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
710 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
713 ref=IDirectSound8_Release(dso);
714 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
716 return DSERR_GENERIC;
721 static HRESULT test_primary_3d8(LPGUID lpGuid)
724 LPDIRECTSOUND8 dso=NULL;
725 LPDIRECTSOUNDBUFFER primary=NULL;
726 DSBUFFERDESC bufdesc;
730 /* Create the DirectSound object */
731 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
732 ok(rc==DS_OK,"DirectSoundCreate8 failed: 0x%lx\n",rc);
736 /* Get the device capabilities */
737 ZeroMemory(&dscaps, sizeof(dscaps));
738 dscaps.dwSize=sizeof(dscaps);
739 rc=IDirectSound8_GetCaps(dso,&dscaps);
740 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
744 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
745 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
746 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
747 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
752 ZeroMemory(&bufdesc, sizeof(bufdesc));
753 bufdesc.dwSize=sizeof(bufdesc);
754 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
755 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
756 ok(rc==DS_OK && primary!=NULL,"CreateSoundBuffer failed to create a primary buffer: 0x%lx\n",rc);
757 if (rc==DS_OK && primary!=NULL) {
758 ref=IDirectSoundBuffer_Release(primary);
759 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
761 ZeroMemory(&bufdesc, sizeof(bufdesc));
762 bufdesc.dwSize=sizeof(bufdesc);
763 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
764 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
765 ok(rc==DS_OK && primary!=NULL,"CreateSoundBuffer failed to create a 3D primary buffer: 0x%lx\n",rc);
766 if (rc==DS_OK && primary!=NULL) {
767 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
768 ref=IDirectSoundBuffer_Release(primary);
769 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
772 /* Set the CooperativeLevel back to normal */
773 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
774 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
775 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
778 ref=IDirectSound8_Release(dso);
779 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
781 return DSERR_GENERIC;
786 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid)
789 LPDIRECTSOUND8 dso=NULL;
790 LPDIRECTSOUNDBUFFER primary=NULL;
791 DSBUFFERDESC bufdesc;
795 /* Create the DirectSound object */
796 rc=DirectSoundCreate8(lpGuid,&dso,NULL);
797 ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc);
801 /* Get the device capabilities */
802 ZeroMemory(&dscaps, sizeof(dscaps));
803 dscaps.dwSize=sizeof(dscaps);
804 rc=IDirectSound8_GetCaps(dso,&dscaps);
805 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
809 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
810 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
811 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
812 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
816 ZeroMemory(&bufdesc, sizeof(bufdesc));
817 bufdesc.dwSize=sizeof(bufdesc);
818 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
819 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
820 ok(rc==DS_OK && primary!=NULL,"CreateSoundBuffer failed to create a 3D primary buffer 0x%lx\n",rc);
821 if (rc==DS_OK && primary!=NULL) {
822 LPDIRECTSOUND3DLISTENER listener=NULL;
823 rc=IDirectSoundBuffer_QueryInterface(primary,&IID_IDirectSound3DListener,(void **)&listener);
824 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface failed to get a 3D listener 0x%lx\n",rc);
825 if (rc==DS_OK && listener!=NULL) {
826 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
828 /* Checking the COM interface */
829 rc=IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
830 ok(rc==DS_OK && temp_buffer!=NULL,"IDirectSoundBuffer_QueryInterface failed: 0x%lx\n",rc);
831 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
832 if (rc==DS_OK && temp_buffer!=NULL) {
833 ref=IDirectSoundBuffer_Release(temp_buffer);
834 ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref);
837 rc=IDirectSound3DListener_QueryInterface(listener, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
838 ok(rc==DS_OK && temp_buffer!=NULL,"IDirectSoundBuffer_QueryInterface failed: 0x%lx\n",rc);
839 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
840 ref=IDirectSoundBuffer_Release(temp_buffer);
841 ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref);
843 /* Testing the buffer */
844 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,listener,0,0);
847 /* Testing the reference counting */
848 ref=IDirectSound3DListener_Release(listener);
849 ok(ref==0,"IDirectSound3DListener_Release listener has %d references, should have 0\n",ref);
852 /* Testing the reference counting */
853 ref=IDirectSoundBuffer_Release(primary);
854 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
858 ref=IDirectSound8_Release(dso);
859 ok(ref==0,"IDirectSound8_Release has %d references, should have 0\n",ref);
861 return DSERR_GENERIC;
866 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
867 LPCSTR lpcstrModule, LPVOID lpContext)
869 trace("*** Testing %s - %s\n",lpcstrDescription,lpcstrModule);
871 trace(" Testing the primary buffer\n");
872 test_primary8(lpGuid);
874 trace(" Testing 3D primary buffer\n");
875 test_primary_3d8(lpGuid);
877 trace(" Testing 3D primary buffer with listener\n");
878 test_primary_3d_with_listener8(lpGuid);
880 /* Testing secondary buffers */
881 test_secondary8(lpGuid,winetest_interactive,0,0,0,0,0,0);
882 test_secondary8(lpGuid,winetest_interactive,0,0,0,1,0,0);
884 /* Testing 3D secondary buffers */
885 test_secondary8(lpGuid,winetest_interactive,1,0,0,0,0,0);
886 test_secondary8(lpGuid,winetest_interactive,1,1,0,0,0,0);
887 test_secondary8(lpGuid,winetest_interactive,1,1,0,1,0,0);
888 test_secondary8(lpGuid,winetest_interactive,1,0,1,0,0,0);
889 test_secondary8(lpGuid,winetest_interactive,1,0,1,1,0,0);
890 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,0);
891 test_secondary8(lpGuid,winetest_interactive,1,1,1,1,0,0);
892 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,0);
893 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,1);
894 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,1);
899 static void ds3d8_tests()
902 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
903 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
913 hDsound = LoadLibraryA("dsound.dll");
915 trace("dsound.dll not found\n");
919 pFunc = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
921 trace("ds3d8 test skipped\n");