mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / dsound / tests / ds3d8.c
blob465ba040a33ec2127d349076e9917e7e66d9287a
1 /*
2 * Tests the panning and 3D functions of DirectSound
4 * Part of this test involves playing test tones. But this only makes
5 * sense if someone is going to carefully listen to it, and would only
6 * bother everyone else.
7 * So this is only done if the test is being run in interactive mode.
9 * Copyright (c) 2002-2004 Francois Gouget
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <windows.h>
28 #include <math.h>
30 #include "wine/test.h"
31 #include "mmsystem.h"
32 #include "dsound.h"
33 #include "ks.h"
34 #include "ksmedia.h"
35 #include "dsound_test.h"
37 typedef struct {
38 char* wave;
39 DWORD wave_len;
41 LPDIRECTSOUNDBUFFER dsbo;
42 LPWAVEFORMATEX wfx;
43 DWORD buffer_size;
44 DWORD written;
45 DWORD played;
46 DWORD offset;
47 } play_state_t;
49 static int buffer_refill8(play_state_t* state, DWORD size)
51 LPVOID ptr1,ptr2;
52 DWORD len1,len2;
53 HRESULT rc;
55 if (size>state->wave_len-state->written)
56 size=state->wave_len-state->written;
58 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
59 &ptr1,&len1,&ptr2,&len2,0);
60 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %08x\n", rc);
61 if (rc!=DS_OK)
62 return -1;
64 memcpy(ptr1,state->wave+state->written,len1);
65 state->written+=len1;
66 if (ptr2!=NULL) {
67 memcpy(ptr2,state->wave+state->written,len2);
68 state->written+=len2;
70 state->offset=state->written % state->buffer_size;
71 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
72 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc);
73 if (rc!=DS_OK)
74 return -1;
75 return size;
78 static int buffer_silence8(play_state_t* state, DWORD size)
80 LPVOID ptr1,ptr2;
81 DWORD len1,len2;
82 HRESULT rc;
83 BYTE s;
85 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
86 &ptr1,&len1,&ptr2,&len2,0);
87 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %08x\n", rc);
88 if (rc!=DS_OK)
89 return -1;
91 s=(state->wfx->wBitsPerSample==8?0x80:0);
92 memset(ptr1,s,len1);
93 if (ptr2!=NULL) {
94 memset(ptr2,s,len2);
96 state->offset=(state->offset+size) % state->buffer_size;
97 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
98 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %08x\n", rc);
99 if (rc!=DS_OK)
100 return -1;
101 return size;
104 static BOOL buffer_service8(play_state_t* state)
106 DWORD last_play_pos,play_pos,buf_free;
107 HRESULT rc;
109 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
110 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %08x\n", rc);
111 if (rc!=DS_OK) {
112 goto STOP;
115 /* Update the amount played */
116 last_play_pos=state->played % state->buffer_size;
117 if (play_pos<last_play_pos)
118 state->played+=state->buffer_size-last_play_pos+play_pos;
119 else
120 state->played+=play_pos-last_play_pos;
122 if (winetest_debug > 1)
123 trace("buf size=%d last_play_pos=%d play_pos=%d played=%d / %d\n",
124 state->buffer_size,last_play_pos,play_pos,state->played,
125 state->wave_len);
127 if (state->played>state->wave_len)
129 /* Everything has been played */
130 goto STOP;
133 /* Refill the buffer */
134 if (state->offset<=play_pos)
135 buf_free=play_pos-state->offset;
136 else
137 buf_free=state->buffer_size-state->offset+play_pos;
139 if (winetest_debug > 1)
140 trace("offset=%d free=%d written=%d / %d\n",
141 state->offset,buf_free,state->written,state->wave_len);
142 if (buf_free==0)
143 return TRUE;
145 if (state->written<state->wave_len)
147 int w=buffer_refill8(state,buf_free);
148 if (w==-1)
149 goto STOP;
150 buf_free-=w;
151 if (state->written==state->wave_len && winetest_debug > 1)
152 trace("last sound byte at %d\n",
153 (state->written % state->buffer_size));
156 if (buf_free>0) {
157 /* Fill with silence */
158 if (winetest_debug > 1)
159 trace("writing %d bytes of silence\n",buf_free);
160 if (buffer_silence8(state,buf_free)==-1)
161 goto STOP;
163 return TRUE;
165 STOP:
166 if (winetest_debug > 1)
167 trace("stopping playback\n");
168 rc=IDirectSoundBuffer_Stop(state->dsbo);
169 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %08x\n", rc);
170 return FALSE;
173 void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
174 BOOL is_primary, BOOL set_volume, LONG volume,
175 BOOL set_pan, LONG pan, BOOL play, double duration,
176 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
177 BOOL move_listener, BOOL move_sound)
179 HRESULT rc;
180 DSBCAPS dsbcaps;
181 WAVEFORMATEX wfx,wfx2;
182 DWORD size,status,freq;
183 BOOL ieee = FALSE;
184 int ref;
186 /* DSOUND: Error: Invalid caps pointer */
187 rc=IDirectSoundBuffer_GetCaps(*dsbo,0);
188 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
189 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
191 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
193 /* DSOUND: Error: Invalid caps pointer */
194 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
195 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
196 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
198 dsbcaps.dwSize=sizeof(dsbcaps);
199 rc=IDirectSoundBuffer_GetCaps(*dsbo,&dsbcaps);
200 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc);
201 if (rc==DS_OK && winetest_debug > 1) {
202 trace(" Caps: flags=0x%08x size=%d\n",dsbcaps.dwFlags,
203 dsbcaps.dwBufferBytes);
206 /* Query the format size. */
207 size=0;
208 rc=IDirectSoundBuffer_GetFormat(*dsbo,NULL,0,&size);
209 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
210 "returned the needed size: rc=%08x size=%d\n",rc,size);
212 ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
213 "Expected a correct structure size, got %d\n", size);
215 if (size == sizeof(WAVEFORMATEX)) {
216 rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,size,NULL);
217 ieee = (wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT);
218 } else if (size == sizeof(WAVEFORMATEXTENSIBLE)) {
219 WAVEFORMATEXTENSIBLE wfxe;
220 rc=IDirectSoundBuffer_GetFormat(*dsbo,(WAVEFORMATEX*)&wfxe,size,NULL);
221 wfx = wfxe.Format;
222 ieee = IsEqualGUID(&wfxe.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
223 } else
224 return;
226 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
227 if (rc==DS_OK && winetest_debug > 1) {
228 trace(" Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d 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: %08x\n",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: %08x\n",rc);
244 if (rc==DS_OK) {
245 ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency "
246 "%d does not match the format %d\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: %08x\n",rc);
254 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
255 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc);
256 ok(status==0,"status=0x%x instead of 0\n",status);
258 if (is_primary) {
259 DSBCAPS new_dsbcaps;
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: %08x\n",rc);
265 if (rc!=DS_OK)
266 return;
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: %08x\n",rc);
273 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
274 rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx2);
275 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
276 format_string(&wfx2), rc);
278 /* There is no guarantee 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: %08x\n", rc);
284 if (rc==DS_OK &&
285 (wfx.wFormatTag!=wfx2.wFormatTag ||
286 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
287 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
288 wfx.nChannels!=wfx2.nChannels)) {
289 trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
290 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
291 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
292 trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
293 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
294 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
297 ZeroMemory(&new_dsbcaps, sizeof(new_dsbcaps));
298 new_dsbcaps.dwSize = sizeof(new_dsbcaps);
299 rc=IDirectSoundBuffer_GetCaps(*dsbo,&new_dsbcaps);
300 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %08x\n", rc);
301 if (rc==DS_OK && winetest_debug > 1) {
302 trace(" new Caps: flags=0x%08x size=%d\n",new_dsbcaps.dwFlags,
303 new_dsbcaps.dwBufferBytes);
306 /* Check for primary buffer size change */
307 ok(new_dsbcaps.dwBufferBytes == dsbcaps.dwBufferBytes,
308 " buffer size changed after SetFormat() - "
309 "previous size was %u, current size is %u\n",
310 dsbcaps.dwBufferBytes, new_dsbcaps.dwBufferBytes);
311 dsbcaps.dwBufferBytes = new_dsbcaps.dwBufferBytes;
313 /* Check for primary buffer flags change */
314 ok(new_dsbcaps.dwFlags == dsbcaps.dwFlags,
315 " flags changed after SetFormat() - "
316 "previous flags were %08x, current flags are %08x\n",
317 dsbcaps.dwFlags, new_dsbcaps.dwFlags);
319 /* Set the CooperativeLevel back to normal */
320 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
321 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
322 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
323 "failed: %08x\n",rc);
326 if (play) {
327 play_state_t state;
328 DS3DLISTENER listener_param;
329 LPDIRECTSOUND3DBUFFER buffer=NULL;
330 DS3DBUFFER buffer_param;
331 DWORD start_time,now;
332 LPVOID buffer1;
333 DWORD length1;
335 if (winetest_interactive) {
336 trace(" Playing %g second 440Hz tone at %dx%dx%d\n", duration,
337 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
340 if (is_primary) {
341 /* We must call SetCooperativeLevel to be allowed to call Lock */
342 /* DSOUND: Setting DirectSound cooperative level to
343 * DSSCL_WRITEPRIMARY */
344 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),
345 DSSCL_WRITEPRIMARY);
346 ok(rc==DS_OK,
347 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: %08x\n",rc);
348 if (rc!=DS_OK)
349 return;
351 if (buffer3d) {
352 LPDIRECTSOUNDBUFFER temp_buffer;
354 rc=IDirectSoundBuffer_QueryInterface(*dsbo,&IID_IDirectSound3DBuffer,
355 (LPVOID *)&buffer);
356 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
357 if (rc!=DS_OK)
358 return;
360 /* check the COM interface */
361 rc=IDirectSoundBuffer_QueryInterface(*dsbo, &IID_IDirectSoundBuffer,
362 (LPVOID *)&temp_buffer);
363 ok(rc==DS_OK && temp_buffer!=NULL,
364 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
365 ok(temp_buffer==*dsbo,"COM interface broken: %p != %p\n",
366 temp_buffer,*dsbo);
367 ref=IDirectSoundBuffer_Release(temp_buffer);
368 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
369 "should have 1\n",ref);
371 ref=IDirectSoundBuffer_Release(*dsbo);
372 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
373 "should have 0\n",ref);
375 rc=IDirectSound3DBuffer_QueryInterface(buffer,
376 &IID_IDirectSoundBuffer,
377 (LPVOID *)dsbo);
378 ok(rc==DS_OK && *dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
379 "failed: %08x\n",rc);
381 /* DSOUND: Error: Invalid buffer */
382 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
383 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
384 "failed: %08x\n",rc);
386 ZeroMemory(&buffer_param, sizeof(buffer_param));
388 /* DSOUND: Error: Invalid buffer */
389 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
390 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
391 "failed: %08x\n",rc);
393 buffer_param.dwSize=sizeof(buffer_param);
394 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
395 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %08x\n", rc);
397 if (set_volume) {
398 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
399 LONG val;
400 rc=IDirectSoundBuffer_GetVolume(*dsbo,&val);
401 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc);
403 rc=IDirectSoundBuffer_SetVolume(*dsbo,volume);
404 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %08x\n", rc);
405 } else {
406 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
407 rc=IDirectSoundBuffer_GetVolume(*dsbo,&volume);
408 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
409 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
413 if (set_pan) {
414 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
415 LONG val;
416 rc=IDirectSoundBuffer_GetPan(*dsbo,&val);
417 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %08x\n", rc);
419 rc=IDirectSoundBuffer_SetPan(*dsbo,pan);
420 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %08x\n", rc);
421 } else {
422 /* DSOUND: Error: Buffer does not have CTRLPAN */
423 rc=IDirectSoundBuffer_GetPan(*dsbo,&pan);
424 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
425 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
429 /* try an offset past the end of the buffer */
430 rc = IDirectSoundBuffer_Lock(*dsbo, dsbcaps.dwBufferBytes, 0, &buffer1,
431 &length1, NULL, NULL,
432 DSBLOCK_ENTIREBUFFER);
433 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
434 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
436 /* try a size larger than the buffer */
437 rc = IDirectSoundBuffer_Lock(*dsbo, 0, dsbcaps.dwBufferBytes + 1,
438 &buffer1, &length1, NULL, NULL,
439 DSBLOCK_FROMWRITECURSOR);
440 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
441 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
443 state.wave=wave_generate_la(&wfx,duration,&state.wave_len,ieee);
445 state.dsbo=*dsbo;
446 state.wfx=&wfx;
447 state.buffer_size=dsbcaps.dwBufferBytes;
448 state.played=state.written=state.offset=0;
449 buffer_refill8(&state,state.buffer_size);
451 rc=IDirectSoundBuffer_Play(*dsbo,0,0,DSBPLAY_LOOPING);
452 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %08x\n", rc);
454 rc=IDirectSoundBuffer_GetStatus(*dsbo,&status);
455 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %08x\n", rc);
456 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
457 "GetStatus: bad status: %x\n",status);
459 if (listener) {
460 ZeroMemory(&listener_param,sizeof(listener_param));
461 listener_param.dwSize=sizeof(listener_param);
462 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
463 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
464 "failed: %08x\n",rc);
465 if (move_listener) {
466 listener_param.vPosition.x = -5.0f;
467 listener_param.vVelocity.x = (float)(10.0/duration);
469 rc=IDirectSound3DListener_SetAllParameters(listener,
470 &listener_param,
471 DS3D_IMMEDIATE);
472 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %08x\n", rc);
474 if (buffer3d) {
475 if (move_sound) {
476 buffer_param.vPosition.x = 100.0f;
477 buffer_param.vVelocity.x = (float)(-200.0/duration);
479 buffer_param.flMinDistance = 10;
480 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
481 DS3D_IMMEDIATE);
482 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc);
485 start_time=GetTickCount();
486 while (buffer_service8(&state)) {
487 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
488 now=GetTickCount();
489 if (listener && move_listener) {
490 listener_param.vPosition.x = (float)(-5.0+10.0*(now-start_time)/1000/duration);
491 if (winetest_debug>2)
492 trace("listener position=%g\n",listener_param.vPosition.x);
493 rc=IDirectSound3DListener_SetPosition(listener,
494 listener_param.vPosition.x,listener_param.vPosition.y,
495 listener_param.vPosition.z,DS3D_IMMEDIATE);
496 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %08x\n",rc);
498 if (buffer3d && move_sound) {
499 buffer_param.vPosition.x = (float)(100-200.0*(now-start_time)/1000/duration);
500 if (winetest_debug>2)
501 trace("sound position=%g\n",buffer_param.vPosition.x);
502 rc=IDirectSound3DBuffer_SetPosition(buffer,
503 buffer_param.vPosition.x,buffer_param.vPosition.y,
504 buffer_param.vPosition.z,DS3D_IMMEDIATE);
505 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %08x\n", rc);
508 /* Check the sound duration was within 10% of the expected value */
509 now=GetTickCount();
510 ok(fabs(1000*duration-now+start_time)<=100*duration,
511 "The sound played for %d ms instead of %g ms\n",
512 now-start_time,1000*duration);
514 HeapFree(GetProcessHeap(), 0, state.wave);
515 if (is_primary) {
516 /* Set the CooperativeLevel back to normal */
517 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
518 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
519 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
520 "failed: %08x\n",rc);
522 if (buffer3d) {
523 ref=IDirectSound3DBuffer_Release(buffer);
524 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
525 "should have 0\n",ref);
530 static HRESULT test_secondary8(LPGUID lpGuid, BOOL play,
531 BOOL has_3d, BOOL has_3dbuffer,
532 BOOL has_listener, BOOL has_duplicate,
533 BOOL move_listener, BOOL move_sound)
535 HRESULT rc;
536 LPDIRECTSOUND8 dso=NULL;
537 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
538 LPDIRECTSOUND3DLISTENER listener=NULL;
539 DSBUFFERDESC bufdesc;
540 WAVEFORMATEX wfx, wfx1;
541 int ref;
543 /* Create the DirectSound object */
544 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
545 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %08x\n", rc);
546 if (rc!=DS_OK)
547 return rc;
549 /* We must call SetCooperativeLevel before creating primary buffer */
550 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
551 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
552 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
553 if (rc!=DS_OK)
554 goto EXIT;
556 ZeroMemory(&bufdesc, sizeof(bufdesc));
557 bufdesc.dwSize=sizeof(bufdesc);
558 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
559 if (has_3d)
560 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
561 else
562 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
563 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
564 ok((rc==DS_OK && primary!=NULL) || (rc == DSERR_CONTROLUNAVAIL),
565 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: %08x\n",has_3d?"3D ":"", rc);
566 if (rc == DSERR_CONTROLUNAVAIL)
567 trace(" No Primary\n");
568 else if (rc==DS_OK && primary!=NULL) {
569 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
570 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
571 if (rc!=DS_OK)
572 goto EXIT1;
574 if (has_listener) {
575 rc=IDirectSoundBuffer_QueryInterface(primary,
576 &IID_IDirectSound3DListener,
577 (void **)&listener);
578 ok(rc==DS_OK && listener!=NULL,
579 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
580 "listener %08x\n",rc);
581 ref=IDirectSoundBuffer_Release(primary);
582 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
583 "should have 0\n",ref);
584 if (rc==DS_OK && listener!=NULL) {
585 DS3DLISTENER listener_param;
586 ZeroMemory(&listener_param,sizeof(listener_param));
587 /* DSOUND: Error: Invalid buffer */
588 rc=IDirectSound3DListener_GetAllParameters(listener,0);
589 ok(rc==DSERR_INVALIDPARAM,
590 "IDirectSound3dListener_GetAllParameters() should have "
591 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
593 /* DSOUND: Error: Invalid buffer */
594 rc=IDirectSound3DListener_GetAllParameters(listener,
595 &listener_param);
596 ok(rc==DSERR_INVALIDPARAM,
597 "IDirectSound3dListener_GetAllParameters() should have "
598 "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
600 listener_param.dwSize=sizeof(listener_param);
601 rc=IDirectSound3DListener_GetAllParameters(listener,
602 &listener_param);
603 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
604 "failed: %08x\n",rc);
605 } else {
606 ok(listener==NULL, "IDirectSoundBuffer_QueryInterface() "
607 "failed but returned a listener anyway\n");
608 ok(rc!=DS_OK, "IDirectSoundBuffer_QueryInterface() succeeded "
609 "but returned a NULL listener\n");
610 if (listener) {
611 ref=IDirectSound3DListener_Release(listener);
612 ok(ref==0,"IDirectSound3dListener_Release() listener has "
613 "%d references, should have 0\n",ref);
615 goto EXIT2;
619 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
620 secondary=NULL;
621 ZeroMemory(&bufdesc, sizeof(bufdesc));
622 bufdesc.dwSize=sizeof(bufdesc);
623 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
624 if (has_3d)
625 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
626 else
627 bufdesc.dwFlags|=
628 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
629 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
630 wfx.nBlockAlign);
631 bufdesc.lpwfxFormat=&wfx;
632 if (has_3d) {
633 /* a stereo 3D buffer should fail */
634 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
635 ok(rc==DSERR_INVALIDPARAM,
636 "IDirectSound8_CreateSoundBuffer(secondary) should have "
637 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
638 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
640 /* Invalid flag combination */
641 bufdesc.dwFlags|=DSBCAPS_CTRLPAN;
642 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
643 ok(rc==DSERR_INVALIDPARAM,
644 "IDirectSound8_CreateSoundBuffer(secondary) should have "
645 "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
646 bufdesc.dwFlags&=~DSBCAPS_CTRLPAN;
649 if (winetest_interactive) {
650 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %dx%dx%d "
651 "with a primary buffer at %dx%dx%d\n",
652 has_3dbuffer?"3D ":"",
653 has_duplicate?"duplicated ":"",
654 listener!=NULL||move_sound?"with ":"",
655 move_listener?"moving ":"",
656 listener!=NULL?"listener ":"",
657 listener&&move_sound?"and moving sound ":move_sound?
658 "moving sound ":"",
659 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
660 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
662 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
663 ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() "
664 "failed to create a %s%ssecondary buffer %s%s%s%sat %dx%dx%d (%s): %08x\n",
665 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
666 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
667 listener!=NULL?"listener ":"",
668 listener&&move_sound?"and moving sound ":move_sound?
669 "moving sound ":"",
670 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
671 getDSBCAPS(bufdesc.dwFlags),rc);
672 if (rc==DS_OK && secondary!=NULL) {
673 if (!has_3d) {
674 LONG refvol,vol,refpan,pan;
676 /* Check the initial secondary buffer's volume and pan */
677 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
678 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: %08x\n",rc);
679 ok(vol==0,"wrong volume for a new secondary buffer: %d\n",vol);
680 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
681 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc);
682 ok(pan==0,"wrong pan for a new secondary buffer: %d\n",pan);
684 /* Check that changing the secondary buffer's volume and pan
685 * does not impact the primary buffer's volume and pan
687 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
688 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: %08x\n",rc);
689 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
690 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc);
692 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
693 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
694 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
695 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
696 ok(vol==-1000,"secondary: wrong volume %d instead of -1000\n",
697 vol);
698 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
699 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc);
700 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
701 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: %08x\n",rc);
702 ok(pan==-1000,"secondary: wrong pan %d instead of -1000\n",
703 pan);
705 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
706 ok(rc==DS_OK,"IDirectSoundBuffer_`GetVolume(primary) failed: i%08x\n",rc);
707 ok(vol==refvol,"The primary volume changed from %d to %d\n",
708 refvol,vol);
709 rc=IDirectSoundBuffer_GetPan(primary,&pan);
710 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: %08x\n",rc);
711 ok(pan==refpan,"The primary pan changed from %d to %d\n",
712 refpan,pan);
714 rc=IDirectSoundBuffer_SetVolume(secondary,0);
715 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: %08x\n",rc);
716 rc=IDirectSoundBuffer_SetPan(secondary,0);
717 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: %08x\n",rc);
718 } else {
719 LONG pan;
721 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
722 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
723 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
724 rc=IDirectSoundBuffer_SetPan(secondary,0);
725 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_SetPan() "
726 "should have returned DSERR_CONTROLUNAVAIL, returned: %08x\n", rc);
729 if (has_duplicate) {
730 LPDIRECTSOUNDBUFFER duplicated=NULL;
732 /* DSOUND: Error: Invalid source buffer */
733 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0);
734 ok(rc==DSERR_INVALIDPARAM,
735 "IDirectSound8_DuplicateSoundBuffer() should have returned "
736 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
738 /* DSOUND: Error: Invalid dest buffer */
739 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0);
740 ok(rc==DSERR_INVALIDPARAM,
741 "IDirectSound8_DuplicateSoundBuffer() should have returned "
742 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
744 /* DSOUND: Error: Invalid source buffer */
745 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated);
746 ok(rc==DSERR_INVALIDPARAM,
747 "IDirectSound8_DuplicateSoundBuffer() should have returned "
748 "DSERR_INVALIDPARAM, returned: %08x\n",rc);
750 duplicated=NULL;
751 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,
752 &duplicated);
753 ok(rc==DS_OK && duplicated!=NULL,
754 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
755 "a secondary buffer: %08x\n",rc);
757 if (rc==DS_OK && duplicated!=NULL) {
758 ref=IDirectSoundBuffer_Release(secondary);
759 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
760 "references, should have 0\n",ref);
761 secondary=duplicated;
765 if (rc==DS_OK && secondary!=NULL) {
766 double duration;
767 duration=(move_listener || move_sound?4.0:1.0);
768 test_buffer8(dso,&secondary,FALSE,FALSE,0,FALSE,0,
769 winetest_interactive,duration,has_3dbuffer,
770 listener,move_listener,move_sound);
771 ref=IDirectSoundBuffer_Release(secondary);
772 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
773 "should have 0\n",has_duplicate?"duplicated":"secondary",
774 ref);
777 EXIT1:
778 if (has_listener) {
779 if (listener) {
780 ref=IDirectSound3DListener_Release(listener);
781 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
782 "references, should have 0\n",ref);
784 } else {
785 ref=IDirectSoundBuffer_Release(primary);
786 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
787 "should have 0\n",ref);
789 } else {
790 ok(primary==NULL,"IDirectSound8_CreateSoundBuffer(primary) failed "
791 "but primary created anyway\n");
792 ok(rc!=DS_OK,"IDirectSound8_CreateSoundBuffer(primary) succeeded "
793 "but primary not created\n");
794 if (primary) {
795 ref=IDirectSoundBuffer_Release(primary);
796 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
797 "should have 0\n",ref);
800 EXIT2:
801 /* Set the CooperativeLevel back to normal */
802 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
803 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
804 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc);
806 EXIT:
807 ref=IDirectSound8_Release(dso);
808 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
809 if (ref!=0)
810 return DSERR_GENERIC;
812 return rc;
815 static HRESULT test_for_driver8(LPGUID lpGuid)
817 HRESULT rc;
818 LPDIRECTSOUND8 dso=NULL;
819 int ref;
821 /* Create the DirectSound object */
822 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
823 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
824 "DirectSoundCreate8() failed: %08x\n",rc);
825 if (rc!=DS_OK)
826 return rc;
828 ref=IDirectSound8_Release(dso);
829 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
830 if (ref!=0)
831 return DSERR_GENERIC;
833 return rc;
836 static HRESULT test_primary8(LPGUID lpGuid)
838 HRESULT rc;
839 LPDIRECTSOUND8 dso=NULL;
840 LPDIRECTSOUNDBUFFER primary=NULL;
841 DSBUFFERDESC bufdesc;
842 DSCAPS dscaps;
843 int ref, i;
845 /* Create the DirectSound object */
846 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
847 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %08x\n", rc);
848 if (rc!=DS_OK)
849 return rc;
851 /* Get the device capabilities */
852 ZeroMemory(&dscaps, sizeof(dscaps));
853 dscaps.dwSize=sizeof(dscaps);
854 rc=IDirectSound8_GetCaps(dso,&dscaps);
855 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
856 if (rc!=DS_OK)
857 goto EXIT;
859 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
860 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
861 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
862 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
863 if (rc!=DS_OK)
864 goto EXIT;
866 /* Testing the primary buffer */
867 primary=NULL;
868 ZeroMemory(&bufdesc, sizeof(bufdesc));
869 bufdesc.dwSize=sizeof(bufdesc);
870 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
871 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
872 ok((rc==DS_OK && primary!=NULL) || (rc == DSERR_CONTROLUNAVAIL),
873 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: %08x\n",rc);
874 if (rc == DSERR_CONTROLUNAVAIL)
875 trace(" No Primary\n");
876 else if (rc==DS_OK && primary!=NULL) {
877 test_buffer8(dso,&primary,TRUE,TRUE,0,TRUE,0,
878 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
879 1.0,FALSE,NULL,FALSE,FALSE);
880 if (winetest_interactive) {
881 LONG volume,pan;
883 volume = DSBVOLUME_MAX;
884 for (i = 0; i < 6; i++) {
885 test_buffer8(dso,&primary,TRUE,TRUE,volume,TRUE,0,
886 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
887 1.0,FALSE,NULL,FALSE,FALSE);
888 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
891 pan = DSBPAN_LEFT;
892 for (i = 0; i < 7; i++) {
893 test_buffer8(dso,&primary,TRUE,TRUE,0,TRUE,pan,
894 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
895 1.0,FALSE,NULL,FALSE,FALSE);
896 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
899 ref=IDirectSoundBuffer_Release(primary);
900 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
901 "should have 0\n",ref);
904 /* Set the CooperativeLevel back to normal */
905 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
906 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
907 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc);
909 EXIT:
910 ref=IDirectSound8_Release(dso);
911 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
912 if (ref!=0)
913 return DSERR_GENERIC;
915 return rc;
918 static HRESULT test_primary_3d8(LPGUID lpGuid)
920 HRESULT rc;
921 LPDIRECTSOUND8 dso=NULL;
922 LPDIRECTSOUNDBUFFER primary=NULL;
923 DSBUFFERDESC bufdesc;
924 DSCAPS dscaps;
925 int ref;
927 /* Create the DirectSound object */
928 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
929 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %08x\n", rc);
930 if (rc!=DS_OK)
931 return rc;
933 /* Get the device capabilities */
934 ZeroMemory(&dscaps, sizeof(dscaps));
935 dscaps.dwSize=sizeof(dscaps);
936 rc=IDirectSound8_GetCaps(dso,&dscaps);
937 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %08x\n",rc);
938 if (rc!=DS_OK)
939 goto EXIT;
941 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
942 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
943 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
944 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
945 if (rc!=DS_OK)
946 goto EXIT;
948 primary=NULL;
949 ZeroMemory(&bufdesc, sizeof(bufdesc));
950 bufdesc.dwSize=sizeof(bufdesc);
951 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
952 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
953 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
954 "to create a primary buffer: %08x\n",rc);
955 if (rc==DS_OK && primary!=NULL) {
956 ref=IDirectSoundBuffer_Release(primary);
957 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
958 "should have 0\n",ref);
959 primary=NULL;
960 ZeroMemory(&bufdesc, sizeof(bufdesc));
961 bufdesc.dwSize=sizeof(bufdesc);
962 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
963 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
964 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
965 "failed to create a 3D primary buffer: %08x\n",rc);
966 if (rc==DS_OK && primary!=NULL) {
967 test_buffer8(dso,&primary,TRUE,FALSE,0,FALSE,0,
968 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
969 1.0,FALSE,NULL,FALSE,FALSE);
970 ref=IDirectSoundBuffer_Release(primary);
971 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
972 "should have 0\n",ref);
975 /* Set the CooperativeLevel back to normal */
976 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
977 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
978 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: %08x\n",rc);
980 EXIT:
981 ref=IDirectSound8_Release(dso);
982 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
983 if (ref!=0)
984 return DSERR_GENERIC;
986 return rc;
989 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid)
991 HRESULT rc;
992 LPDIRECTSOUND8 dso=NULL;
993 LPDIRECTSOUNDBUFFER primary=NULL;
994 DSBUFFERDESC bufdesc;
995 DSCAPS dscaps;
996 int ref;
998 /* Create the DirectSound object */
999 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
1000 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %08x\n", rc);
1001 if (rc!=DS_OK)
1002 return rc;
1004 /* Get the device capabilities */
1005 ZeroMemory(&dscaps, sizeof(dscaps));
1006 dscaps.dwSize=sizeof(dscaps);
1007 rc=IDirectSound8_GetCaps(dso,&dscaps);
1008 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
1009 if (rc!=DS_OK)
1010 goto EXIT;
1012 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
1013 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
1014 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
1015 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: %08x\n",rc);
1016 if (rc!=DS_OK)
1017 goto EXIT;
1018 primary=NULL;
1019 ZeroMemory(&bufdesc, sizeof(bufdesc));
1020 bufdesc.dwSize=sizeof(bufdesc);
1021 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
1022 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
1023 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
1024 "to create a 3D primary buffer %08x\n",rc);
1025 if (rc==DS_OK && primary!=NULL) {
1026 LPDIRECTSOUND3DLISTENER listener=NULL;
1027 rc=IDirectSoundBuffer_QueryInterface(primary,
1028 &IID_IDirectSound3DListener,
1029 (void **)&listener);
1030 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
1031 "failed to get a 3D listener: %08x\n",rc);
1032 if (rc==DS_OK && listener!=NULL) {
1033 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
1035 /* Checking the COM interface */
1036 rc=IDirectSoundBuffer_QueryInterface(primary,
1037 &IID_IDirectSoundBuffer,
1038 (LPVOID *)&temp_buffer);
1039 ok(rc==DS_OK && temp_buffer!=NULL,
1040 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
1041 ok(temp_buffer==primary,"COM interface broken: %p != %p\n",temp_buffer,primary);
1042 if (rc==DS_OK && temp_buffer!=NULL) {
1043 ref=IDirectSoundBuffer_Release(temp_buffer);
1044 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1045 "should have 1\n",ref);
1047 temp_buffer=NULL;
1048 rc=IDirectSound3DListener_QueryInterface(listener,
1049 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1050 ok(rc==DS_OK && temp_buffer!=NULL,
1051 "IDirectSoundBuffer_QueryInterface() failed: %08x\n", rc);
1052 ok(temp_buffer==primary,"COM interface broken: %p != %p\n",temp_buffer,primary);
1053 ref=IDirectSoundBuffer_Release(temp_buffer);
1054 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1055 "should have 1\n",ref);
1057 /* Testing the buffer */
1058 test_buffer8(dso,&primary,TRUE,FALSE,0,FALSE,0,
1059 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1060 1.0,FALSE,listener,FALSE,FALSE);
1063 /* Testing the reference counting */
1064 ref=IDirectSound3DListener_Release(listener);
1065 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1066 "references, should have 0\n",ref);
1069 /* Testing the reference counting */
1070 ref=IDirectSoundBuffer_Release(primary);
1071 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1072 "should have 0\n",ref);
1075 EXIT:
1076 ref=IDirectSound8_Release(dso);
1077 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
1078 if (ref!=0)
1079 return DSERR_GENERIC;
1081 return rc;
1084 static unsigned driver_count = 0;
1086 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1087 LPCSTR lpcstrModule, LPVOID lpContext)
1089 HRESULT rc;
1090 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1091 driver_count++;
1093 rc = test_for_driver8(lpGuid);
1094 if (rc == DSERR_NODRIVER) {
1095 trace(" No Driver\n");
1096 return TRUE;
1097 } else if (rc == DSERR_ALLOCATED) {
1098 trace(" Already In Use\n");
1099 return TRUE;
1100 } else if (rc == E_FAIL) {
1101 trace(" No Device\n");
1102 return TRUE;
1105 trace(" Testing the primary buffer\n");
1106 test_primary8(lpGuid);
1108 trace(" Testing 3D primary buffer\n");
1109 test_primary_3d8(lpGuid);
1111 trace(" Testing 3D primary buffer with listener\n");
1112 test_primary_3d_with_listener8(lpGuid);
1114 /* Testing secondary buffers */
1115 test_secondary8(lpGuid,winetest_interactive,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE);
1116 test_secondary8(lpGuid,winetest_interactive,FALSE,FALSE,FALSE,TRUE, FALSE,FALSE);
1118 /* Testing 3D secondary buffers */
1119 test_secondary8(lpGuid,winetest_interactive,TRUE, FALSE,FALSE,FALSE,FALSE,FALSE);
1120 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, FALSE,FALSE,FALSE,FALSE);
1121 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, FALSE,TRUE, FALSE,FALSE);
1122 test_secondary8(lpGuid,winetest_interactive,TRUE, FALSE,TRUE, FALSE,FALSE,FALSE);
1123 test_secondary8(lpGuid,winetest_interactive,TRUE, FALSE,TRUE, TRUE, FALSE,FALSE);
1124 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, TRUE, FALSE,FALSE,FALSE);
1125 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, TRUE, TRUE, FALSE,FALSE);
1126 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, TRUE, FALSE,TRUE, FALSE);
1127 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, TRUE, FALSE,FALSE,TRUE );
1128 test_secondary8(lpGuid,winetest_interactive,TRUE, TRUE, TRUE, FALSE,TRUE, TRUE );
1130 return TRUE;
1133 static void ds3d8_tests(void)
1135 HRESULT rc;
1136 rc = DirectSoundEnumerateA(dsenum_callback, NULL);
1137 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %08x\n",rc);
1138 trace("tested %u DirectSound drivers\n", driver_count);
1141 START_TEST(ds3d8)
1143 CoInitialize(NULL);
1145 ds3d8_tests();
1147 CoUninitialize();