dsound.c
来自「Wine-20031016」· C语言 代码 · 共 1,079 行 · 第 1/3 页
C
1,079 行
play_state_t state; LPDIRECTSOUND3DBUFFER buffer=NULL; DS3DBUFFER buffer_param; DS3DLISTENER listener_param; trace(" Playing 440Hz LA at %ldx%dx%d\n", wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels); if (is_primary) { /* We must call SetCooperativeLevel to be allowed to call Lock */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_WRITEPRIMARY */ rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_WRITEPRIMARY); ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc); if (rc!=DS_OK) return; } if (buffer3d) { LPDIRECTSOUNDBUFFER temp_buffer; rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer,(LPVOID *)&buffer); ok(rc==DS_OK,"QueryInterface failed: 0x%lx\n",rc); if(rc!=DS_OK) return; /* check the COM interface */ rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer); ok(rc==DS_OK&&temp_buffer!=NULL,"QueryInterface failed: 0x%lx\n",rc); ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)dsbo); ref=IDirectSoundBuffer_Release(temp_buffer); ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref); temp_buffer=NULL; rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer); ok(rc==DS_OK&&temp_buffer!=NULL,"IDirectSound3DBuffer_QueryInterface failed: 0x%lx\n",rc); ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",(DWORD)temp_buffer,(DWORD)dsbo); ref=IDirectSoundBuffer_Release(temp_buffer); ok(ref==1,"IDirectSoundBuffer_Release has %d references, should have 1\n",ref);#if 0 /* FIXME: this works on windows */ ref=IDirectSoundBuffer_Release(dsbo); ok(ref==0,"IDirectSoundBuffer_Release has %d references, should have 0\n",ref); rc=IDirectSound3DBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer,(LPVOID *)&dsbo); ok(rc==DS_OK&&dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface failed: 0x%lx\n",rc);#endif /* DSOUND: Error: Invalid buffer */ rc=IDirectSound3DBuffer_GetAllParameters(buffer,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc); ZeroMemory(&buffer_param, sizeof(buffer_param)); /* DSOUND: Error: Invalid buffer */ rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param); ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc); buffer_param.dwSize=sizeof(buffer_param); rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param); ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters failed: 0x%lx\n",rc); } if (set_volume) { rc=IDirectSoundBuffer_SetVolume(dsbo,volume); ok(rc==DS_OK,"SetVolume failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_GetVolume(dsbo,&volume); trace(" volume=%ld\n",volume); } else { if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) { rc=IDirectSoundBuffer_GetVolume(dsbo,&volume); ok(rc==DS_OK,"GetVolume failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_SetVolume(dsbo,-300); ok(rc==DS_OK,"SetVolume failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_GetVolume(dsbo,&volume); trace(" volume=%ld\n",volume); } else { /* DSOUND: Error: Buffer does not have CTRLVOLUME */ rc=IDirectSoundBuffer_GetVolume(dsbo,&volume); ok(rc==DSERR_CONTROLUNAVAIL,"GetVolume should have failed: 0x%lx\n",rc); } } if (set_pan) { rc=IDirectSoundBuffer_SetPan(dsbo,pan); ok(rc==DS_OK,"SetPan failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_GetPan(dsbo,&pan); trace(" pan=%ld\n",pan); } else { if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) { rc=IDirectSoundBuffer_GetPan(dsbo,&pan); ok(rc==DS_OK,"GetPan failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_SetPan(dsbo,0); ok(rc==DS_OK,"SetPan failed: 0x%lx\n",rc); rc=IDirectSoundBuffer_GetPan(dsbo,&pan); trace(" pan=%ld\n",pan); } else { /* DSOUND: Error: Buffer does not have CTRLPAN */ rc=IDirectSoundBuffer_GetPan(dsbo,&pan); ok(rc==DSERR_CONTROLUNAVAIL,"GetPan should have failed: 0x%lx\n",rc); } } state.wave=wave_generate_la(&wfx,((double)TONE_DURATION)/1000,&state.wave_len); state.dsbo=dsbo; state.wfx=&wfx; state.buffer_size=dsbcaps.dwBufferBytes; state.written=state.offset=0; buffer_refill(&state,state.buffer_size); rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING); ok(rc==DS_OK,"Play: 0x%lx\n",rc); rc=IDirectSoundBuffer_GetStatus(dsbo,&status); ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc); ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING), "GetStatus: bad status: %lx",status); if (listener) { ZeroMemory(&listener_param,sizeof(listener_param)); listener_param.dwSize=sizeof(listener_param); rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param); ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc); if (move_listener) listener_param.vPosition.x = -5.0; else listener_param.vPosition.x = 0.0; listener_param.vPosition.y = 0.0; listener_param.vPosition.z = 0.0; rc=IDirectSound3DListener_SetPosition(listener,listener_param.vPosition.x,listener_param.vPosition.y,listener_param.vPosition.z,DS3D_IMMEDIATE); ok(rc==DS_OK,"IDirectSound3dListener_SetPosition failed 0x%lx\n",rc); } if (buffer3d) { if (move_sound) buffer_param.vPosition.x = 5.0; else buffer_param.vPosition.x = 0.0; buffer_param.vPosition.y = 0.0; buffer_param.vPosition.z = 0.0; rc=IDirectSound3DBuffer_SetPosition(buffer,buffer_param.vPosition.x,buffer_param.vPosition.y,buffer_param.vPosition.z,DS3D_IMMEDIATE); ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition failed 0x%lx\n",rc); } while (buffer_service(&state)) { WaitForSingleObject(GetCurrentProcess(),TIME_SLICE/2); if (listener&&move_listener) { listener_param.vPosition.x += 0.5; rc=IDirectSound3DListener_SetPosition(listener,listener_param.vPosition.x,listener_param.vPosition.y,listener_param.vPosition.z,DS3D_IMMEDIATE); ok(rc==DS_OK,"IDirectSound3dListener_SetPosition failed 0x%lx\n",rc); } if (buffer3d&&move_sound) { buffer_param.vPosition.x -= 0.5; rc=IDirectSound3DBuffer_SetPosition(buffer,buffer_param.vPosition.x,buffer_param.vPosition.y,buffer_param.vPosition.z,DS3D_IMMEDIATE); ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition failed 0x%lx\n",rc); } } if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) { rc=IDirectSoundBuffer_SetVolume(dsbo,volume); ok(rc==DS_OK,"SetVolume failed: 0x%lx\n",rc); } free(state.wave); if (is_primary) { /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc); } if (buffer3d) { ref=IDirectSound3DBuffer_Release(buffer); ok(ref==0,"IDirectSound3DBuffer_Release has %d references, should have 0\n",ref); } }}static HRESULT test_secondary(LPGUID lpGuid, int play, int has_3d, int has_3dbuffer, int has_listener, int has_duplicate, int move_listener, int move_sound){ HRESULT rc; LPDIRECTSOUND dso=NULL; LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; LPDIRECTSOUND3DLISTENER listener=NULL; DSBUFFERDESC bufdesc; DSCAPS dscaps; WAVEFORMATEX wfx; int f,ref; /* Create the DirectSound object */ rc=DirectSoundCreate(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc); if (rc!=DS_OK) return rc; /* Get the device capabilities */ ZeroMemory(&dscaps, sizeof(dscaps)); dscaps.dwSize=sizeof(dscaps); rc=IDirectSound_GetCaps(dso,&dscaps); ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc); if (rc!=DS_OK) goto EXIT; /* We must call SetCooperativeLevel before creating primary buffer */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc); if(rc!=DS_OK) goto EXIT; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; if (has_3d) bufdesc.dwFlags|=DSBCAPS_CTRL3D; else bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN); rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DS_OK&&primary!=NULL,"CreateSoundBuffer failed to create a %sprimary buffer 0x%lx\n",has_3d?"3D ":"", rc); if (rc==DS_OK&&primary!=NULL) { if (has_listener) { rc=IDirectSoundBuffer_QueryInterface(primary,&IID_IDirectSound3DListener,(void **)&listener); ok(rc==DS_OK&&listener!=NULL,"IDirectSoundBuffer_QueryInterface failed to get a 3D listener 0x%lx\n",rc); ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref); if(rc==DS_OK&&listener!=NULL) { DS3DLISTENER listener_param; ZeroMemory(&listener_param,sizeof(listener_param)); /* DSOUND: Error: Invalid buffer */ rc=IDirectSound3DListener_GetAllParameters(listener,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc); /* DSOUND: Error: Invalid buffer */ rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param); ok(rc==DSERR_INVALIDPARAM,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc); listener_param.dwSize=sizeof(listener_param); rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param); ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters failed 0x%lx\n",rc); } else goto EXIT; } for (f=0;f<NB_FORMATS;f++) { init_format(&wfx,formats[f][0],formats[f][1],formats[f][2]); secondary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; if (has_3d) bufdesc.dwFlags|=DSBCAPS_CTRL3D; else bufdesc.dwFlags|=(DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN); bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000; bufdesc.lpwfxFormat=&wfx; trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d\n", has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"", listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"", listener!=NULL?"listener ":"", listener&&move_sound?"and moving sound ":move_sound?"moving sound ":"", wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels); rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK&&secondary!=NULL,"CreateSoundBuffer failed to create a 3D secondary buffer 0x%lx\n",rc); if (rc==DS_OK&&secondary!=NULL) { if (has_duplicate) { LPDIRECTSOUNDBUFFER duplicated=NULL; /* DSOUND: Error: Invalid source buffer */ rc=IDirectSound_DuplicateSoundBuffer(dso,0,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound_DuplicateSoundBuffer should have failed 0x%lx\n",rc); /* DSOUND: Error: Invalid dest buffer */ rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound_DuplicateSoundBuffer should have failed 0x%lx\n",rc); /* DSOUND: Error: Invalid source buffer */ rc=IDirectSound_DuplicateSoundBuffer(dso,0,&duplicated); ok(rc==DSERR_INVALIDPARAM,"IDirectSound_DuplicateSoundBuffer should have failed 0x%lx\n",rc); duplicated=NULL; rc=IDirectSound_DuplicateSoundBuffer(dso,secondary,&duplicated); ok(rc==DS_OK&&duplicated!=NULL,"IDirectSound_DuplicateSoundBuffer failed to duplicate a secondary buffer 0x%lx\n",rc); if (rc==DS_OK&&duplicated!=NULL) { ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release secondary has %d references, should have 0\n",ref); secondary=duplicated; } } if (rc==DS_OK&&secondary!=NULL) { test_buffer(dso,secondary,0,FALSE,0,FALSE,0,winetest_interactive,has_3dbuffer,listener,move_listener,move_sound); ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release %s has %d references, should have 0\n",has_duplicate?"duplicated":"secondary",ref); } } } if (has_listener) { ref=IDirectSound3DListener_Release(listener); ok(ref==0,"IDirectSound3dListener_Release listener has %d references, should have 0\n",ref); } else { ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref); } } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%0lx\n",rc);EXIT: ref=IDirectSound_Release(dso); ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref); if (ref!=0) return DSERR_GENERIC; return rc;}static HRESULT test_dsound(LPGUID lpGuid){ HRESULT rc; LPDIRECTSOUND dso=NULL; DSCAPS dscaps; DWORD speaker_config, new_speaker_config; int ref; /* DSOUND: Error: Invalid interface buffer */ rc=DirectSoundCreate(lpGuid,0,NULL); ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate should have failed: 0x%lx\n",rc); /* Create the DirectSound object */ rc=DirectSoundCreate(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc); if (rc!=DS_OK) return rc; /* DSOUND: Error: Invalid caps buffer */ rc=IDirectSound_GetCaps(dso,0); ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc); ZeroMemory(&dscaps, sizeof(dscaps)); /* DSOUND: Error: Invalid caps buffer */ rc=IDirectSound_GetCaps(dso,&dscaps); ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc); dscaps.dwSize=sizeof(dscaps); /* DSOUND: Running on a certified driver */ rc=IDirectSound_GetCaps(dso,&dscaps); ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc); if (rc==DS_OK) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?