Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygends3d8.c
Go to the documentation of this file.
00001 /* 00002 * Tests the panning and 3D functions of DirectSound 00003 * 00004 * Part of this test involves playing test tones. But this only makes 00005 * sense if someone is going to carefully listen to it, and would only 00006 * bother everyone else. 00007 * So this is only done if the test is being run in interactive mode. 00008 * 00009 * Copyright (c) 2002-2004 Francois Gouget 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Lesser General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2.1 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 */ 00025 00026 #define NONAMELESSSTRUCT 00027 #define NONAMELESSUNION 00028 #include <windows.h> 00029 00030 #include <math.h> 00031 00032 #include "wine/test.h" 00033 #include "dsound.h" 00034 #include "dxerr8.h" 00035 00036 #include "dsound_test.h" 00037 00038 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL; 00039 00040 typedef struct { 00041 char* wave; 00042 DWORD wave_len; 00043 00044 LPDIRECTSOUNDBUFFER dsbo; 00045 LPWAVEFORMATEX wfx; 00046 DWORD buffer_size; 00047 DWORD written; 00048 DWORD played; 00049 DWORD offset; 00050 } play_state_t; 00051 00052 static int buffer_refill8(play_state_t* state, DWORD size) 00053 { 00054 LPVOID ptr1,ptr2; 00055 DWORD len1,len2; 00056 HRESULT rc; 00057 00058 if (size>state->wave_len-state->written) 00059 size=state->wave_len-state->written; 00060 00061 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size, 00062 &ptr1,&len1,&ptr2,&len2,0); 00063 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n", 00064 DXGetErrorString8(rc)); 00065 if (rc!=DS_OK) 00066 return -1; 00067 00068 memcpy(ptr1,state->wave+state->written,len1); 00069 state->written+=len1; 00070 if (ptr2!=NULL) { 00071 memcpy(ptr2,state->wave+state->written,len2); 00072 state->written+=len2; 00073 } 00074 state->offset=state->written % state->buffer_size; 00075 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2); 00076 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n", 00077 DXGetErrorString8(rc)); 00078 if (rc!=DS_OK) 00079 return -1; 00080 return size; 00081 } 00082 00083 static int buffer_silence8(play_state_t* state, DWORD size) 00084 { 00085 LPVOID ptr1,ptr2; 00086 DWORD len1,len2; 00087 HRESULT rc; 00088 BYTE s; 00089 00090 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size, 00091 &ptr1,&len1,&ptr2,&len2,0); 00092 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n", 00093 DXGetErrorString8(rc)); 00094 if (rc!=DS_OK) 00095 return -1; 00096 00097 s=(state->wfx->wBitsPerSample==8?0x80:0); 00098 memset(ptr1,s,len1); 00099 if (ptr2!=NULL) { 00100 memset(ptr2,s,len2); 00101 } 00102 state->offset=(state->offset+size) % state->buffer_size; 00103 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2); 00104 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n", 00105 DXGetErrorString8(rc)); 00106 if (rc!=DS_OK) 00107 return -1; 00108 return size; 00109 } 00110 00111 static int buffer_service8(play_state_t* state) 00112 { 00113 DWORD last_play_pos,play_pos,buf_free; 00114 HRESULT rc; 00115 00116 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL); 00117 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n", 00118 DXGetErrorString8(rc)); 00119 if (rc!=DS_OK) { 00120 goto STOP; 00121 } 00122 00123 /* Update the amount played */ 00124 last_play_pos=state->played % state->buffer_size; 00125 if (play_pos<last_play_pos) 00126 state->played+=state->buffer_size-last_play_pos+play_pos; 00127 else 00128 state->played+=play_pos-last_play_pos; 00129 00130 if (winetest_debug > 1) 00131 trace("buf size=%ld last_play_pos=%ld play_pos=%ld played=%ld / %ld\n", 00132 state->buffer_size,last_play_pos,play_pos,state->played, 00133 state->wave_len); 00134 00135 if (state->played>state->wave_len) 00136 { 00137 /* Everything has been played */ 00138 goto STOP; 00139 } 00140 00141 /* Refill the buffer */ 00142 if (state->offset<=play_pos) 00143 buf_free=play_pos-state->offset; 00144 else 00145 buf_free=state->buffer_size-state->offset+play_pos; 00146 00147 if (winetest_debug > 1) 00148 trace("offset=%ld free=%ld written=%ld / %ld\n", 00149 state->offset,buf_free,state->written,state->wave_len); 00150 if (buf_free==0) 00151 return 1; 00152 00153 if (state->written<state->wave_len) 00154 { 00155 int w=buffer_refill8(state,buf_free); 00156 if (w==-1) 00157 goto STOP; 00158 buf_free-=w; 00159 if (state->written==state->wave_len && winetest_debug > 1) 00160 trace("last sound byte at %ld\n", 00161 (state->written % state->buffer_size)); 00162 } 00163 00164 if (buf_free>0) { 00165 /* Fill with silence */ 00166 if (winetest_debug > 1) 00167 trace("writing %ld bytes of silence\n",buf_free); 00168 if (buffer_silence8(state,buf_free)==-1) 00169 goto STOP; 00170 } 00171 return 1; 00172 00173 STOP: 00174 if (winetest_debug > 1) 00175 trace("stopping playback\n"); 00176 rc=IDirectSoundBuffer_Stop(state->dsbo); 00177 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %s\n", 00178 DXGetErrorString8(rc)); 00179 return 0; 00180 } 00181 00182 void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER dsbo, 00183 BOOL is_primary, BOOL set_volume, LONG volume, 00184 BOOL set_pan, LONG pan, BOOL play, double duration, 00185 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener, 00186 BOOL move_listener, BOOL move_sound) 00187 { 00188 HRESULT rc; 00189 DSBCAPS dsbcaps; 00190 WAVEFORMATEX wfx,wfx2; 00191 DWORD size,status,freq; 00192 int ref; 00193 00194 /* DSOUND: Error: Invalid caps pointer */ 00195 rc=IDirectSoundBuffer_GetCaps(dsbo,0); 00196 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have " 00197 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00198 00199 ZeroMemory(&dsbcaps, sizeof(dsbcaps)); 00200 00201 /* DSOUND: Error: Invalid caps pointer */ 00202 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps); 00203 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have " 00204 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00205 00206 dsbcaps.dwSize=sizeof(dsbcaps); 00207 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps); 00208 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n", 00209 DXGetErrorString8(rc)); 00210 if (rc==DS_OK && winetest_debug > 1) { 00211 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags, 00212 dsbcaps.dwBufferBytes); 00213 } 00214 00215 /* Query the format size. Note that it may not match sizeof(wfx) */ 00216 size=0; 00217 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size); 00218 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have " 00219 "returned the needed size: rc=%s size=%ld\n",DXGetErrorString8(rc),size); 00220 00221 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL); 00222 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n", 00223 DXGetErrorString8(rc)); 00224 if (rc==DS_OK && winetest_debug > 1) { 00225 trace(" Format: %s tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", 00226 is_primary ? "Primary" : "Secondary", 00227 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample, 00228 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign); 00229 } 00230 00231 /* DSOUND: Error: Invalid frequency buffer */ 00232 rc=IDirectSoundBuffer_GetFrequency(dsbo,0); 00233 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have " 00234 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00235 00236 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */ 00237 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq); 00238 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) || 00239 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)), 00240 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc)); 00241 if (rc==DS_OK) { 00242 ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency " 00243 "%ld does not match the format %ld\n",freq,wfx.nSamplesPerSec); 00244 } 00245 00246 /* DSOUND: Error: Invalid status pointer */ 00247 rc=IDirectSoundBuffer_GetStatus(dsbo,0); 00248 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have " 00249 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00250 00251 rc=IDirectSoundBuffer_GetStatus(dsbo,&status); 00252 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n", 00253 DXGetErrorString8(rc)); 00254 ok(status==0,"status=0x%lx instead of 0\n",status); 00255 00256 if (is_primary) { 00257 /* We must call SetCooperativeLevel to be allowed to call SetFormat */ 00258 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00259 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00260 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) " 00261 "failed: %s\n",DXGetErrorString8(rc)); 00262 if (rc!=DS_OK) 00263 return; 00264 00265 /* DSOUND: Error: Invalid format pointer */ 00266 rc=IDirectSoundBuffer_SetFormat(dsbo,0); 00267 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have " 00268 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00269 00270 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2); 00271 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2); 00272 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n", 00273 DXGetErrorString8(rc)); 00274 00275 /* There is no garantee that SetFormat will actually change the 00276 * format to what we asked for. It depends on what the soundcard 00277 * supports. So we must re-query the format. 00278 */ 00279 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL); 00280 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n", 00281 DXGetErrorString8(rc)); 00282 if (rc==DS_OK && 00283 (wfx.wFormatTag!=wfx2.wFormatTag || 00284 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec || 00285 wfx.wBitsPerSample!=wfx2.wBitsPerSample || 00286 wfx.nChannels!=wfx2.nChannels)) { 00287 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", 00288 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample, 00289 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign); 00290 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", 00291 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample, 00292 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign); 00293 } 00294 00295 /* Set the CooperativeLevel back to normal */ 00296 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00297 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00298 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) " 00299 "failed: %s\n",DXGetErrorString8(rc)); 00300 } 00301 00302 if (play) { 00303 play_state_t state; 00304 DS3DLISTENER listener_param; 00305 LPDIRECTSOUND3DBUFFER buffer=NULL; 00306 DS3DBUFFER buffer_param; 00307 DWORD start_time,now; 00308 00309 if (winetest_interactive) { 00310 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration, 00311 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels); 00312 } 00313 00314 if (is_primary) { 00315 /* We must call SetCooperativeLevel to be allowed to call Lock */ 00316 /* DSOUND: Setting DirectSound cooperative level to 00317 * DSSCL_WRITEPRIMARY */ 00318 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(), 00319 DSSCL_WRITEPRIMARY); 00320 ok(rc==DS_OK, 00321 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: " 00322 "%s\n",DXGetErrorString8(rc)); 00323 if (rc!=DS_OK) 00324 return; 00325 } 00326 if (buffer3d) { 00327 LPDIRECTSOUNDBUFFER temp_buffer; 00328 00329 rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer, 00330 (LPVOID *)&buffer); 00331 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %s\n", 00332 DXGetErrorString8(rc)); 00333 if (rc!=DS_OK) 00334 return; 00335 00336 /* check the COM interface */ 00337 rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer, 00338 (LPVOID *)&temp_buffer); 00339 ok(rc==DS_OK && temp_buffer!=NULL, 00340 "IDirectSoundBuffer_QueryInterface() failed: %s\n", 00341 DXGetErrorString8(rc)); 00342 ok(temp_buffer==dsbo,"COM interface broken: %p != %p\n", 00343 temp_buffer,dsbo); 00344 ref=IDirectSoundBuffer_Release(temp_buffer); 00345 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, " 00346 "should have 1\n",ref); 00347 00348 temp_buffer=NULL; 00349 rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer, 00350 (LPVOID *)&temp_buffer); 00351 ok(rc==DS_OK && temp_buffer!=NULL, 00352 "IDirectSound3DBuffer_QueryInterface() failed: %s\n", 00353 DXGetErrorString8(rc)); 00354 ok(temp_buffer==dsbo,"COM interface broken: %p != %p\n", 00355 temp_buffer,dsbo); 00356 ref=IDirectSoundBuffer_Release(temp_buffer); 00357 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, " 00358 "should have 1\n",ref); 00359 00360 #if 0 00361 /* FIXME: this works on windows */ 00362 ref=IDirectSoundBuffer_Release(dsbo); 00363 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " 00364 "should have 0\n",ref); 00365 00366 rc=IDirectSound3DBuffer_QueryInterface(buffer, 00367 &IID_IDirectSoundBuffer, 00368 (LPVOID *)&dsbo); 00369 ok(rc==DS_OK && dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() " 00370 "failed: %s\n",DXGetErrorString8(rc), 00371 #endif 00372 00373 /* DSOUND: Error: Invalid buffer */ 00374 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0); 00375 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() " 00376 "failed: %s\n",DXGetErrorString8(rc)); 00377 00378 ZeroMemory(&buffer_param, sizeof(buffer_param)); 00379 00380 /* DSOUND: Error: Invalid buffer */ 00381 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param); 00382 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() " 00383 "failed: %s\n",DXGetErrorString8(rc)); 00384 00385 buffer_param.dwSize=sizeof(buffer_param); 00386 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param); 00387 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n", 00388 DXGetErrorString8(rc)); 00389 } 00390 if (set_volume) { 00391 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) { 00392 LONG val; 00393 rc=IDirectSoundBuffer_GetVolume(dsbo,&val); 00394 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n", 00395 DXGetErrorString8(rc)); 00396 00397 rc=IDirectSoundBuffer_SetVolume(dsbo,volume); 00398 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %s\n", 00399 DXGetErrorString8(rc)); 00400 } else { 00401 /* DSOUND: Error: Buffer does not have CTRLVOLUME */ 00402 rc=IDirectSoundBuffer_GetVolume(dsbo,&volume); 00403 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() " 00404 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n", 00405 DXGetErrorString8(rc)); 00406 } 00407 } 00408 00409 if (set_pan) { 00410 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) { 00411 LONG val; 00412 rc=IDirectSoundBuffer_GetPan(dsbo,&val); 00413 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %s\n", 00414 DXGetErrorString8(rc)); 00415 00416 rc=IDirectSoundBuffer_SetPan(dsbo,pan); 00417 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %s\n", 00418 DXGetErrorString8(rc)); 00419 } else { 00420 /* DSOUND: Error: Buffer does not have CTRLPAN */ 00421 rc=IDirectSoundBuffer_GetPan(dsbo,&pan); 00422 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() " 00423 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n", 00424 DXGetErrorString8(rc)); 00425 } 00426 } 00427 00428 state.wave=wave_generate_la(&wfx,duration,&state.wave_len); 00429 00430 state.dsbo=dsbo; 00431 state.wfx=&wfx; 00432 state.buffer_size=dsbcaps.dwBufferBytes; 00433 state.played=state.written=state.offset=0; 00434 buffer_refill8(&state,state.buffer_size); 00435 00436 rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING); 00437 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %s\n", 00438 DXGetErrorString8(rc)); 00439 00440 rc=IDirectSoundBuffer_GetStatus(dsbo,&status); 00441 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n", 00442 DXGetErrorString8(rc)); 00443 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING), 00444 "GetStatus: bad status: %lx\n",status); 00445 00446 if (listener) { 00447 ZeroMemory(&listener_param,sizeof(listener_param)); 00448 listener_param.dwSize=sizeof(listener_param); 00449 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param); 00450 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() " 00451 "failed: %s\n",DXGetErrorString8(rc)); 00452 if (move_listener) { 00453 listener_param.vPosition.x = -5.0; 00454 listener_param.vVelocity.x = 10.0/duration; 00455 } 00456 rc=IDirectSound3DListener_SetAllParameters(listener, 00457 &listener_param, 00458 DS3D_IMMEDIATE); 00459 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %s\n", 00460 DXGetErrorString8(rc)); 00461 } 00462 if (buffer3d) { 00463 if (move_sound) { 00464 buffer_param.vPosition.x = 100.0; 00465 buffer_param.vVelocity.x = -200.0/duration; 00466 } 00467 buffer_param.flMinDistance = 10; 00468 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param, 00469 DS3D_IMMEDIATE); 00470 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n", 00471 DXGetErrorString8(rc)); 00472 } 00473 00474 start_time=GetTickCount(); 00475 while (buffer_service8(&state)) { 00476 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE); 00477 now=GetTickCount(); 00478 if (listener && move_listener) { 00479 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/ 00480 1000/duration; 00481 if (winetest_debug>2) 00482 trace("listener position=%g\n",listener_param.vPosition.x); 00483 rc=IDirectSound3DListener_SetPosition(listener, 00484 listener_param.vPosition.x,listener_param.vPosition.y, 00485 listener_param.vPosition.z,DS3D_IMMEDIATE); 00486 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: " 00487 "%s\n",DXGetErrorString8(rc)); 00488 } 00489 if (buffer3d && move_sound) { 00490 buffer_param.vPosition.x = 100-200.0*(now-start_time)/ 00491 1000/duration; 00492 if (winetest_debug>2) 00493 trace("sound position=%g\n",buffer_param.vPosition.x); 00494 rc=IDirectSound3DBuffer_SetPosition(buffer, 00495 buffer_param.vPosition.x,buffer_param.vPosition.y, 00496 buffer_param.vPosition.z,DS3D_IMMEDIATE); 00497 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n", 00498 DXGetErrorString8(rc)); 00499 } 00500 } 00501 /* Check the sound duration was within 10% of the expected value */ 00502 now=GetTickCount(); 00503 ok(fabs(1000*duration-now+start_time)<=100*duration, 00504 "The sound played for %ld ms instead of %g ms\n", 00505 now-start_time,1000*duration); 00506 00507 free(state.wave); 00508 if (is_primary) { 00509 /* Set the CooperativeLevel back to normal */ 00510 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00511 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00512 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) " 00513 "failed: %s\n",DXGetErrorString8(rc)); 00514 } 00515 if (buffer3d) { 00516 ref=IDirectSound3DBuffer_Release(buffer); 00517 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, " 00518 "should have 0\n",ref); 00519 } 00520 } 00521 } 00522 00523 static HRESULT test_secondary8(LPGUID lpGuid, int play, 00524 int has_3d, int has_3dbuffer, 00525 int has_listener, int has_duplicate, 00526 int move_listener, int move_sound) 00527 { 00528 HRESULT rc; 00529 LPDIRECTSOUND8 dso=NULL; 00530 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; 00531 LPDIRECTSOUND3DLISTENER listener=NULL; 00532 DSBUFFERDESC bufdesc; 00533 WAVEFORMATEX wfx, wfx1; 00534 int ref; 00535 00536 /* Create the DirectSound object */ 00537 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00538 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n", 00539 DXGetErrorString8(rc)); 00540 if (rc!=DS_OK) 00541 return rc; 00542 00543 /* We must call SetCooperativeLevel before creating primary buffer */ 00544 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00545 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00546 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: " 00547 "%s\n",DXGetErrorString8(rc)); 00548 if (rc!=DS_OK) 00549 goto EXIT; 00550 00551 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00552 bufdesc.dwSize=sizeof(bufdesc); 00553 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; 00554 if (has_3d) 00555 bufdesc.dwFlags|=DSBCAPS_CTRL3D; 00556 else 00557 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN); 00558 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00559 ok((rc==DS_OK && primary!=NULL) || (rc == DSERR_CONTROLUNAVAIL), 00560 "IDirectSound8_CreateSoundBuffer() failed to create a %sprimary buffer: " 00561 "%s\n",has_3d?"3D ":"", DXGetErrorString8(rc)); 00562 if (rc == DSERR_CONTROLUNAVAIL) 00563 trace(" No Primary\n"); 00564 else if (rc==DS_OK && primary!=NULL) { 00565 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL); 00566 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n", 00567 DXGetErrorString8(rc)); 00568 if (rc!=DS_OK) 00569 goto EXIT1; 00570 00571 if (has_listener) { 00572 rc=IDirectSoundBuffer_QueryInterface(primary, 00573 &IID_IDirectSound3DListener, 00574 (void **)&listener); 00575 ok(rc==DS_OK && listener!=NULL, 00576 "IDirectSoundBuffer_QueryInterface() failed to get a 3D " 00577 "listener %s\n",DXGetErrorString8(rc)); 00578 ref=IDirectSoundBuffer_Release(primary); 00579 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00580 "should have 0\n",ref); 00581 if (rc==DS_OK && listener!=NULL) { 00582 DS3DLISTENER listener_param; 00583 ZeroMemory(&listener_param,sizeof(listener_param)); 00584 /* DSOUND: Error: Invalid buffer */ 00585 rc=IDirectSound3DListener_GetAllParameters(listener,0); 00586 ok(rc==DSERR_INVALIDPARAM, 00587 "IDirectSound3dListener_GetAllParameters() should have " 00588 "returned DSERR_INVALIDPARAM, returned: %s\n", 00589 DXGetErrorString8(rc)); 00590 00591 /* DSOUND: Error: Invalid buffer */ 00592 rc=IDirectSound3DListener_GetAllParameters(listener, 00593 &listener_param); 00594 ok(rc==DSERR_INVALIDPARAM, 00595 "IDirectSound3dListener_GetAllParameters() should have " 00596 "returned DSERR_INVALIDPARAM, returned: %s\n", 00597 DXGetErrorString8(rc)); 00598 00599 listener_param.dwSize=sizeof(listener_param); 00600 rc=IDirectSound3DListener_GetAllParameters(listener, 00601 &listener_param); 00602 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() " 00603 "failed: %s\n",DXGetErrorString8(rc)); 00604 } 00605 else 00606 goto EXIT; 00607 } 00608 00609 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2); 00610 secondary=NULL; 00611 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00612 bufdesc.dwSize=sizeof(bufdesc); 00613 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 00614 if (has_3d) 00615 bufdesc.dwFlags|=DSBCAPS_CTRL3D; 00616 else 00617 bufdesc.dwFlags|= 00618 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN); 00619 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, 00620 wfx.nBlockAlign); 00621 bufdesc.lpwfxFormat=&wfx; 00622 if (has_3d) { 00623 /* a stereo 3D buffer should fail */ 00624 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00625 ok(rc==DSERR_INVALIDPARAM, 00626 "IDirectSound8_CreateSoundBuffer(secondary) should have " 00627 "returned DSERR_INVALIDPARAM, returned %s\n", 00628 DXGetErrorString8(rc)); 00629 if (secondary) 00630 ref=IDirectSoundBuffer_Release(secondary); 00631 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1); 00632 } 00633 00634 if (winetest_interactive) { 00635 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d " 00636 "with a primary buffer at %ldx%dx%d\n", 00637 has_3dbuffer?"3D ":"", 00638 has_duplicate?"duplicated ":"", 00639 listener!=NULL||move_sound?"with ":"", 00640 move_listener?"moving ":"", 00641 listener!=NULL?"listener ":"", 00642 listener&&move_sound?"and moving sound ":move_sound? 00643 "moving sound ":"", 00644 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, 00645 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels); 00646 } 00647 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00648 ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() " 00649 "failed to create a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d (%s): %s\n", 00650 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"", 00651 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"", 00652 listener!=NULL?"listener ":"", 00653 listener&&move_sound?"and moving sound ":move_sound? 00654 "moving sound ":"", 00655 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, 00656 getDSBCAPS(bufdesc.dwFlags),DXGetErrorString8(rc)); 00657 if (rc==DS_OK && secondary!=NULL) { 00658 if (!has_3d) { 00659 LONG refvol,vol,refpan,pan; 00660 00661 /* Check the initial secondary buffer's volume and pan */ 00662 rc=IDirectSoundBuffer_GetVolume(secondary,&vol); 00663 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: " 00664 "%s\n",DXGetErrorString8(rc)); 00665 ok(vol==0,"wrong volume for a new secondary buffer: %ld\n",vol); 00666 rc=IDirectSoundBuffer_GetPan(secondary,&pan); 00667 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: " 00668 "%s\n",DXGetErrorString8(rc)); 00669 ok(pan==0,"wrong pan for a new secondary buffer: %ld\n",pan); 00670 00671 /* Check that changing the secondary buffer's volume and pan 00672 * does not impact the primary buffer's volume and pan 00673 */ 00674 rc=IDirectSoundBuffer_GetVolume(primary,&refvol); 00675 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: " 00676 "%s\n",DXGetErrorString8(rc)); 00677 rc=IDirectSoundBuffer_GetPan(primary,&refpan); 00678 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: " 00679 "%s\n",DXGetErrorString8(rc)); 00680 00681 rc=IDirectSoundBuffer_SetVolume(secondary,-1000); 00682 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: " 00683 "%s\n",DXGetErrorString8(rc)); 00684 rc=IDirectSoundBuffer_GetVolume(secondary,&vol); 00685 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: " 00686 "%s\n",DXGetErrorString8(rc)); 00687 ok(vol==-1000,"secondary: wrong volume %ld instead of -1000\n", 00688 vol); 00689 rc=IDirectSoundBuffer_SetPan(secondary,-1000); 00690 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: " 00691 "%s\n",DXGetErrorString8(rc)); 00692 rc=IDirectSoundBuffer_GetPan(secondary,&pan); 00693 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: " 00694 "%s\n",DXGetErrorString8(rc)); 00695 ok(pan==-1000,"secondary: wrong pan %ld instead of -1000\n", 00696 pan); 00697 00698 rc=IDirectSoundBuffer_GetVolume(primary,&vol); 00699 ok(rc==DS_OK,"IDirectSoundBuffer_`GetVolume(primary) failed: i" 00700 "%s\n",DXGetErrorString8(rc)); 00701 ok(vol==refvol,"The primary volume changed from %ld to %ld\n", 00702 refvol,vol); 00703 rc=IDirectSoundBuffer_GetPan(primary,&pan); 00704 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: " 00705 "%s\n",DXGetErrorString8(rc)); 00706 ok(pan==refpan,"The primary pan changed from %ld to %ld\n", 00707 refpan,pan); 00708 00709 rc=IDirectSoundBuffer_SetVolume(secondary,0); 00710 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: " 00711 "%s\n",DXGetErrorString8(rc)); 00712 rc=IDirectSoundBuffer_SetPan(secondary,0); 00713 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: " 00714 "%s\n",DXGetErrorString8(rc)); 00715 } 00716 if (has_duplicate) { 00717 LPDIRECTSOUNDBUFFER duplicated=NULL; 00718 00719 /* DSOUND: Error: Invalid source buffer */ 00720 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0); 00721 ok(rc==DSERR_INVALIDPARAM, 00722 "IDirectSound8_DuplicateSoundBuffer() should have returned " 00723 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00724 00725 /* DSOUND: Error: Invalid dest buffer */ 00726 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0); 00727 ok(rc==DSERR_INVALIDPARAM, 00728 "IDirectSound8_DuplicateSoundBuffer() should have returned " 00729 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00730 00731 /* DSOUND: Error: Invalid source buffer */ 00732 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated); 00733 ok(rc==DSERR_INVALIDPARAM, 00734 "IDirectSound8_DuplicateSoundBuffer() should have returned " 00735 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00736 00737 duplicated=NULL; 00738 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary, 00739 &duplicated); 00740 ok(rc==DS_OK && duplicated!=NULL, 00741 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate " 00742 "a secondary buffer: %s\n",DXGetErrorString8(rc)); 00743 00744 if (rc==DS_OK && duplicated!=NULL) { 00745 ref=IDirectSoundBuffer_Release(secondary); 00746 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d " 00747 "references, should have 0\n",ref); 00748 secondary=duplicated; 00749 } 00750 } 00751 00752 if (rc==DS_OK && secondary!=NULL) { 00753 double duration; 00754 duration=(move_listener || move_sound?4.0:1.0); 00755 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0, 00756 winetest_interactive,duration,has_3dbuffer, 00757 listener,move_listener,move_sound); 00758 ref=IDirectSoundBuffer_Release(secondary); 00759 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, " 00760 "should have 0\n",has_duplicate?"duplicated":"secondary", 00761 ref); 00762 } 00763 } 00764 } 00765 EXIT1: 00766 if (has_listener) { 00767 ref=IDirectSound3DListener_Release(listener); 00768 ok(ref==0,"IDirectSound3dListener_Release() listener has %d " 00769 "references, should have 0\n",ref); 00770 } else { 00771 ref=IDirectSoundBuffer_Release(primary); 00772 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00773 "should have 0\n",ref); 00774 } 00775 00776 /* Set the CooperativeLevel back to normal */ 00777 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00778 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00779 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: " 00780 "%s\n",DXGetErrorString8(rc)); 00781 00782 EXIT: 00783 ref=IDirectSound8_Release(dso); 00784 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00785 if (ref!=0) 00786 return DSERR_GENERIC; 00787 00788 return rc; 00789 } 00790 00791 static HRESULT test_for_driver8(LPGUID lpGuid) 00792 { 00793 HRESULT rc; 00794 LPDIRECTSOUND8 dso=NULL; 00795 int ref; 00796 00797 /* Create the DirectSound object */ 00798 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00799 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00800 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00801 if (rc!=DS_OK) 00802 return rc; 00803 00804 ref=IDirectSound8_Release(dso); 00805 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00806 if (ref!=0) 00807 return DSERR_GENERIC; 00808 00809 return rc; 00810 } 00811 00812 static HRESULT test_primary8(LPGUID lpGuid) 00813 { 00814 HRESULT rc; 00815 LPDIRECTSOUND8 dso=NULL; 00816 LPDIRECTSOUNDBUFFER primary=NULL; 00817 DSBUFFERDESC bufdesc; 00818 DSCAPS dscaps; 00819 int ref, i; 00820 00821 /* Create the DirectSound object */ 00822 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00823 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n", 00824 DXGetErrorString8(rc)); 00825 if (rc!=DS_OK) 00826 return rc; 00827 00828 /* Get the device capabilities */ 00829 ZeroMemory(&dscaps, sizeof(dscaps)); 00830 dscaps.dwSize=sizeof(dscaps); 00831 rc=IDirectSound8_GetCaps(dso,&dscaps); 00832 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00833 if (rc!=DS_OK) 00834 goto EXIT; 00835 00836 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */ 00837 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00838 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00839 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: " 00840 "%s\n",DXGetErrorString8(rc)); 00841 if (rc!=DS_OK) 00842 goto EXIT; 00843 00844 /* Testing the primary buffer */ 00845 primary=NULL; 00846 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00847 bufdesc.dwSize=sizeof(bufdesc); 00848 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN; 00849 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00850 ok((rc==DS_OK && primary!=NULL) || (rc == DSERR_CONTROLUNAVAIL), 00851 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: " 00852 "%s\n",DXGetErrorString8(rc)); 00853 if (rc == DSERR_CONTROLUNAVAIL) 00854 trace(" No Primary\n"); 00855 else if (rc==DS_OK && primary!=NULL) { 00856 test_buffer8(dso,primary,1,TRUE,0,TRUE,0,winetest_interactive && 00857 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0); 00858 if (winetest_interactive) { 00859 LONG volume,pan; 00860 00861 volume = DSBVOLUME_MAX; 00862 for (i = 0; i < 6; i++) { 00863 test_buffer8(dso,primary,1,TRUE,volume,TRUE,0, 00864 winetest_interactive && 00865 !(dscaps.dwFlags & DSCAPS_EMULDRIVER), 00866 1.0,0,NULL,0,0); 00867 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40); 00868 } 00869 00870 pan = DSBPAN_LEFT; 00871 for (i = 0; i < 7; i++) { 00872 test_buffer8(dso,primary,1,TRUE,0,TRUE,pan, 00873 winetest_interactive && 00874 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0); 00875 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6); 00876 } 00877 } 00878 ref=IDirectSoundBuffer_Release(primary); 00879 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00880 "should have 0\n",ref); 00881 } 00882 00883 /* Set the CooperativeLevel back to normal */ 00884 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00885 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00886 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: " 00887 "%s\n",DXGetErrorString8(rc)); 00888 00889 EXIT: 00890 ref=IDirectSound8_Release(dso); 00891 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00892 if (ref!=0) 00893 return DSERR_GENERIC; 00894 00895 return rc; 00896 } 00897 00898 static HRESULT test_primary_3d8(LPGUID lpGuid) 00899 { 00900 HRESULT rc; 00901 LPDIRECTSOUND8 dso=NULL; 00902 LPDIRECTSOUNDBUFFER primary=NULL; 00903 DSBUFFERDESC bufdesc; 00904 DSCAPS dscaps; 00905 int ref; 00906 00907 /* Create the DirectSound object */ 00908 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00909 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n", 00910 DXGetErrorString8(rc)); 00911 if (rc!=DS_OK) 00912 return rc; 00913 00914 /* Get the device capabilities */ 00915 ZeroMemory(&dscaps, sizeof(dscaps)); 00916 dscaps.dwSize=sizeof(dscaps); 00917 rc=IDirectSound8_GetCaps(dso,&dscaps); 00918 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc)); 00919 if (rc!=DS_OK) 00920 goto EXIT; 00921 00922 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */ 00923 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00924 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00925 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: " 00926 "%s\n",DXGetErrorString8(rc)); 00927 if (rc!=DS_OK) 00928 goto EXIT; 00929 00930 primary=NULL; 00931 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00932 bufdesc.dwSize=sizeof(bufdesc); 00933 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; 00934 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00935 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed " 00936 "to create a primary buffer: %s\n",DXGetErrorString8(rc)); 00937 if (rc==DS_OK && primary!=NULL) { 00938 ref=IDirectSoundBuffer_Release(primary); 00939 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00940 "should have 0\n",ref); 00941 primary=NULL; 00942 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00943 bufdesc.dwSize=sizeof(bufdesc); 00944 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D; 00945 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00946 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() " 00947 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc)); 00948 if (rc==DS_OK && primary!=NULL) { 00949 test_buffer8(dso,primary,1,FALSE,0,FALSE,0, 00950 winetest_interactive && 00951 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0); 00952 ref=IDirectSoundBuffer_Release(primary); 00953 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00954 "should have 0\n",ref); 00955 } 00956 } 00957 /* Set the CooperativeLevel back to normal */ 00958 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00959 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00960 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: " 00961 "%s\n",DXGetErrorString8(rc)); 00962 00963 EXIT: 00964 ref=IDirectSound8_Release(dso); 00965 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00966 if (ref!=0) 00967 return DSERR_GENERIC; 00968 00969 return rc; 00970 } 00971 00972 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid) 00973 { 00974 HRESULT rc; 00975 LPDIRECTSOUND8 dso=NULL; 00976 LPDIRECTSOUNDBUFFER primary=NULL; 00977 DSBUFFERDESC bufdesc; 00978 DSCAPS dscaps; 00979 int ref; 00980 00981 /* Create the DirectSound object */ 00982 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00983 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n", 00984 DXGetErrorString8(rc)); 00985 if (rc!=DS_OK) 00986 return rc; 00987 00988 /* Get the device capabilities */ 00989 ZeroMemory(&dscaps, sizeof(dscaps)); 00990 dscaps.dwSize=sizeof(dscaps); 00991 rc=IDirectSound8_GetCaps(dso,&dscaps); 00992 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00993 if (rc!=DS_OK) 00994 goto EXIT; 00995 00996 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */ 00997 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00998 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00999 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: " 01000 "%s\n",DXGetErrorString8(rc)); 01001 if (rc!=DS_OK) 01002 goto EXIT; 01003 primary=NULL; 01004 ZeroMemory(&bufdesc, sizeof(bufdesc)); 01005 bufdesc.dwSize=sizeof(bufdesc); 01006 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D; 01007 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 01008 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed " 01009 "to create a 3D primary buffer %s\n",DXGetErrorString8(rc)); 01010 if (rc==DS_OK && primary!=NULL) { 01011 LPDIRECTSOUND3DLISTENER listener=NULL; 01012 rc=IDirectSoundBuffer_QueryInterface(primary, 01013 &IID_IDirectSound3DListener, 01014 (void **)&listener); 01015 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() " 01016 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc)); 01017 if (rc==DS_OK && listener!=NULL) { 01018 LPDIRECTSOUNDBUFFER temp_buffer=NULL; 01019 01020 /* Checking the COM interface */ 01021 rc=IDirectSoundBuffer_QueryInterface(primary, 01022 &IID_IDirectSoundBuffer, 01023 (LPVOID *)&temp_buffer); 01024 ok(rc==DS_OK && temp_buffer!=NULL, 01025 "IDirectSoundBuffer_QueryInterface() failed: %s\n", 01026 DXGetErrorString8(rc)); 01027 ok(temp_buffer==primary,"COM interface broken: %p != %p\n",temp_buffer,primary); 01028 if (rc==DS_OK && temp_buffer!=NULL) { 01029 ref=IDirectSoundBuffer_Release(temp_buffer); 01030 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, " 01031 "should have 1\n",ref); 01032 01033 temp_buffer=NULL; 01034 rc=IDirectSound3DListener_QueryInterface(listener, 01035 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer); 01036 ok(rc==DS_OK && temp_buffer!=NULL, 01037 "IDirectSoundBuffer_QueryInterface() failed: %s\n", 01038 DXGetErrorString8(rc)); 01039 ok(temp_buffer==primary,"COM interface broken: %p != %p\n",temp_buffer,primary); 01040 ref=IDirectSoundBuffer_Release(temp_buffer); 01041 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, " 01042 "should have 1\n",ref); 01043 01044 /* Testing the buffer */ 01045 test_buffer8(dso,primary,1,FALSE,0,FALSE,0, 01046 winetest_interactive && 01047 !(dscaps.dwFlags & DSCAPS_EMULDRIVER), 01048 1.0,0,listener,0,0); 01049 } 01050 01051 /* Testing the reference counting */ 01052 ref=IDirectSound3DListener_Release(listener); 01053 ok(ref==0,"IDirectSound3DListener_Release() listener has %d " 01054 "references, should have 0\n",ref); 01055 } 01056 01057 /* Testing the reference counting */ 01058 ref=IDirectSoundBuffer_Release(primary); 01059 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 01060 "should have 0\n",ref); 01061 } 01062 01063 EXIT: 01064 ref=IDirectSound8_Release(dso); 01065 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 01066 if (ref!=0) 01067 return DSERR_GENERIC; 01068 01069 return rc; 01070 } 01071 01072 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, 01073 LPCSTR lpcstrModule, LPVOID lpContext) 01074 { 01075 HRESULT rc; 01076 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule); 01077 01078 rc = test_for_driver8(lpGuid); 01079 if (rc == DSERR_NODRIVER) { 01080 trace(" No Driver\n"); 01081 return 1; 01082 } else if (rc == DSERR_ALLOCATED) { 01083 trace(" Already In Use\n"); 01084 return 1; 01085 } else if (rc == E_FAIL) { 01086 trace(" No Device\n"); 01087 return 1; 01088 } 01089 01090 trace(" Testing the primary buffer\n"); 01091 test_primary8(lpGuid); 01092 01093 trace(" Testing 3D primary buffer\n"); 01094 test_primary_3d8(lpGuid); 01095 01096 trace(" Testing 3D primary buffer with listener\n"); 01097 test_primary_3d_with_listener8(lpGuid); 01098 01099 /* Testing secondary buffers */ 01100 test_secondary8(lpGuid,winetest_interactive,0,0,0,0,0,0); 01101 test_secondary8(lpGuid,winetest_interactive,0,0,0,1,0,0); 01102 01103 /* Testing 3D secondary buffers */ 01104 test_secondary8(lpGuid,winetest_interactive,1,0,0,0,0,0); 01105 test_secondary8(lpGuid,winetest_interactive,1,1,0,0,0,0); 01106 test_secondary8(lpGuid,winetest_interactive,1,1,0,1,0,0); 01107 test_secondary8(lpGuid,winetest_interactive,1,0,1,0,0,0); 01108 test_secondary8(lpGuid,winetest_interactive,1,0,1,1,0,0); 01109 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,0); 01110 test_secondary8(lpGuid,winetest_interactive,1,1,1,1,0,0); 01111 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,0); 01112 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,1); 01113 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,1); 01114 01115 return 1; 01116 } 01117 01118 static void ds3d8_tests(void) 01119 { 01120 HRESULT rc; 01121 rc=DirectSoundEnumerateA(&dsenum_callback,NULL); 01122 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc)); 01123 } 01124 01125 START_TEST(ds3d8) 01126 { 01127 HMODULE hDsound; 01128 01129 CoInitialize(NULL); 01130 01131 hDsound = LoadLibraryA("dsound.dll"); 01132 if (!hDsound) { 01133 trace("dsound.dll not found\n"); 01134 return; 01135 } 01136 01137 trace("DLL Version: %s\n", get_file_version("dsound.dll")); 01138 01139 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound, "DirectSoundCreate8"); 01140 if (!pDirectSoundCreate8) { 01141 trace("ds3d8 test skipped\n"); 01142 return; 01143 } 01144 01145 ds3d8_tests(); 01146 01147 CoUninitialize(); 01148 } Generated on Sat May 26 2012 04:20:14 for ReactOS by
1.7.6.1
|