static void test_COM(void) { IDirectSound *ds; IDirectSound8 *ds8 = (IDirectSound8*)0xdeadbeef; IUnknown *unk, *unk8; ULONG refcount; HRESULT hr; /* COM aggregation */ hr = CoCreateInstance(&CLSID_DirectSound8, (IUnknown*)&ds, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&ds8); ok(hr == CLASS_E_NOAGGREGATION, "DirectSound create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr); ok(!ds8, "ds8 = %p\n", ds8); /* Invalid RIID */ hr = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound3DBuffer, (void**)&ds8); ok(hr == E_NOINTERFACE, "DirectSound create failed: %08x, expected E_NOINTERFACE\n", hr); /* Same refcount for IDirectSound and IDirectSound8 */ hr = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound8, (void**)&ds8); ok(hr == S_OK, "DirectSound create failed: %08x, expected S_OK\n", hr); refcount = IDirectSound8_AddRef(ds8); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); hr = IDirectSound8_QueryInterface(ds8, &IID_IDirectSound, (void**)&ds); ok(hr == S_OK, "QueryInterface for IID_IDirectSound failed: %08x\n", hr); refcount = IDirectSound8_AddRef(ds8); ok(refcount == 4, "refcount == %u, expected 4\n", refcount); refcount = IDirectSound_AddRef(ds); ok(refcount == 5, "refcount == %u, expected 5\n", refcount); /* Separate refcount for IUnknown */ hr = IDirectSound_QueryInterface(ds, &IID_IUnknown, (void**)&unk); ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr); refcount = IUnknown_AddRef(unk); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); hr = IDirectSound_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8); ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr); refcount = IUnknown_AddRef(unk8); ok(refcount == 4, "refcount == %u, expected 4\n", refcount); refcount = IDirectSound_AddRef(ds); ok(refcount == 6, "refcount == %u, expected 6\n", refcount); while (IDirectSound_Release(ds)); while (IUnknown_Release(unk)); }
static void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo, BOOL initialized, LPCGUID lpGuidCapture, LPCGUID lpGuidRender) { HRESULT rc; int ref; IUnknown * unknown; IDirectSound * ds; IDirectSound8 * ds8; IDirectSoundCapture * dsc; IDirectSoundFullDuplex * dsfd; /* Try to Query for objects */ rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IUnknown,(LPVOID*)&unknown); ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %08x\n", rc); if (rc==DS_OK) { ref=IDirectSoundFullDuplex_Release(unknown); ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, " "should have 0\n", ref); } rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound,(LPVOID*)&ds); ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %08x\n", rc); if (rc==DS_OK) { ref=IDirectSound_Release(ds); ok(ref==0, "IDirectSound_Release() has %d references, " "should have 0\n", ref); } rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound8,(LPVOID*)&ds8); ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) " "failed: %08x\n",rc); if (rc==DS_OK) { IDirectSoundFullDuplex * dsfd1; rc=IDirectSound8_QueryInterface(ds8,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd1); ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) " "failed: %08x\n",rc); if (rc==DS_OK) { ref=IDirectSoundFullDuplex_Release(dsfd1); ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, " "should have 1\n", ref); } ref=IDirectSound8_Release(ds8); ok(ref==0, "IDirectSound8_Release() has %d references, " "should have 0\n", ref); } rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundCapture,(LPVOID*)&dsc); ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) " "failed: %08x\n",rc); if (rc==DS_OK) { ref=IDirectSoundCapture_Release(dsc); ok(ref==0, "IDirectSoundCapture_Release() has %d references, " "should have 0\n", ref); } rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd); ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) " "failed: %08x\n",rc); if (rc==DS_OK) { ok(dsfdo==dsfd, "different interfaces\n"); ref=IDirectSound8_Release(dsfd); ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, should have 1\n", ref); } ref=IDirectSoundFullDuplex_Release(dsfdo); ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, " "should have 0\n", ref); }
static void test_COM(void) { IDirectSoundFullDuplex *dsfd = (IDirectSoundFullDuplex*)0xdeadbeef; IDirectSound *ds; IDirectSound8 *ds8; IDirectSoundCapture *dsc; IUnknown *unk, *unk8; IDirectSoundBuffer8 *dsb8; IDirectSoundCaptureBuffer8 *dscb8; DSBUFFERDESC bufdesc; DSCBUFFERDESC cbufdesc; WAVEFORMATEX wfx; ULONG refcount; HRESULT hr; /* COM aggregation */ hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, (IUnknown*)&dsfd, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&dsfd); ok(hr == CLASS_E_NOAGGREGATION, "DirectSoundFullDuplex create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr); ok(!dsfd, "dsfd = %p\n", dsfd); /* Invalid RIID */ hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound3DBuffer, (void**)&dsfd); ok(hr == E_NOINTERFACE, "DirectSoundFullDuplex create failed: %08x, expected E_NOINTERFACE\n", hr); /* Different refcount for IDirectSoundFullDuplex and for IUnknown */ hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex, (void**)&dsfd); ok(hr == S_OK, "DirectSoundFullDuplex create failed: %08x, expected S_OK\n", hr); refcount = IDirectSoundFullDuplex_AddRef(dsfd); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IUnknown, (void**)&unk); ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr); refcount = IUnknown_AddRef(unk); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); /* Not initialized */ hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound8, (void**)&ds8); ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectSound8 failed: %08x, expected E_NOINTERFACE\n", hr); hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSoundCapture, (void**)&dsc); ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectSoundCapture failed: %08x, expected E_NOINTERFACE\n", hr); init_format(&wfx, WAVE_FORMAT_PCM, 44100, 16, 1); ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize = sizeof(bufdesc); bufdesc.dwBufferBytes = wfx.nAvgBytesPerSec; bufdesc.lpwfxFormat = &wfx; ZeroMemory(&cbufdesc, sizeof(cbufdesc)); cbufdesc.dwSize = sizeof(cbufdesc); cbufdesc.dwBufferBytes = wfx.nAvgBytesPerSec; cbufdesc.lpwfxFormat = &wfx; hr = IDirectSoundFullDuplex_Initialize(dsfd, NULL, NULL, &cbufdesc, &bufdesc, get_hwnd(), DSSCL_EXCLUSIVE, NULL, NULL); ok(hr == E_INVALIDARG, "IDirectSoundFullDuplex_Initialize failed: %08x, expected E_INVALIDARG\n", hr); hr = IDirectSoundFullDuplex_Initialize(dsfd, NULL, NULL, &cbufdesc, &bufdesc, get_hwnd(), DSSCL_EXCLUSIVE, &dscb8, &dsb8); if (hr == DSERR_NODRIVER || hr == DSERR_INVALIDCALL) { skip("No driver\n"); return; } ok(hr == S_OK, "IDirectSoundFullDuplex_Initialize failed: %08x\n", hr); /* IDirectSound and IDirectSound8 */ hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound8, (void**)&ds8); ok(hr == S_OK, "QueryInterface for IID_IDirectSound8 failed: %08x\n", hr); refcount = IDirectSound8_AddRef(ds8); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound, (void**)&ds); ok(hr == S_OK, "QueryInterface for IID_IDirectSound failed: %08x\n", hr); refcount = IDirectSound8_AddRef(ds8); ok(refcount == 4, "refcount == %u, expected 4\n", refcount); refcount = IDirectSound_AddRef(ds); ok(refcount == 5, "refcount == %u, expected 5\n", refcount); hr = IDirectSound8_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8); ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr); ok(unk == unk8, "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSound\n"); refcount = IUnknown_AddRef(unk8); ok(refcount == 4, "refcount == %u, expected 4\n", refcount); refcount = IDirectSound_AddRef(ds); ok(refcount == 6, "refcount == %u, expected 6\n", refcount); refcount = IDirectSoundFullDuplex_AddRef(dsfd); ok(refcount == 3, "refcount == %u, expected 3\n", refcount); /* IDirectSoundCapture */ hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSoundCapture, (void**)&dsc); ok(hr == S_OK, "QueryInterface for IID_IDirectSoundCapture failed: %08x\n", hr); refcount = IDirectSoundCapture_AddRef(dsc); ok(refcount == 2, "refcount == %u, expected 2\n", refcount); refcount = IDirectSoundFullDuplex_AddRef(dsfd); ok(refcount == 4, "refcount == %u, expected 4\n", refcount); hr = IDirectSoundCapture_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8); ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr); ok(unk == unk8, "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSoundCapture\n"); refcount = IUnknown_AddRef(unk8); ok(refcount == 6, "refcount == %u, expected 6\n", refcount); IDirectSoundBuffer8_Release(dsb8); IDirectSoundCaptureBuffer8_Release(dscb8); while (IDirectSound8_Release(ds8)); while (IDirectSoundCapture_Release(dsc)); while (IDirectSoundFullDuplex_Release(dsfd)); while (IUnknown_Release(unk)); }
static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized, LPCGUID lpGuid) { HRESULT rc; DSCAPS dscaps; int ref; IUnknown * unknown; IDirectSound * ds; IDirectSound8 * ds8; DWORD speaker_config, new_speaker_config; DWORD certified; /* Try to Query for objects */ rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown); ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK) IDirectSound8_Release(unknown); rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds); ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK) IDirectSound_Release(ds); rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8); ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) " "should have returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK) IDirectSound8_Release(ds8); if (initialized == FALSE) { /* try unitialized object */ rc=IDirectSound8_GetCaps(dso,0); ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) " "should have returned DSERR_UNINITIALIZED, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() " "should have returned DSERR_UNINITIALIZED, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_Compact(dso); ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() " "should have returned DSERR_UNINITIALIZED, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config); ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() " "should have returned DSERR_UNINITIALIZED, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_VerifyCertification(dso, &certified); ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() " "should have returned DSERR_UNINITIALIZED, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_Initialize(dso,lpGuid); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, "IDirectSound8_Initialize() failed: %s\n",DXGetErrorString8(rc)); if (rc==DSERR_NODRIVER) { trace(" No Driver\n"); goto EXIT; } else if (rc==E_FAIL) { trace(" No Device\n"); goto EXIT; } else if (rc==DSERR_ALLOCATED) { trace(" Already In Use\n"); goto EXIT; } } rc=IDirectSound8_Initialize(dso,lpGuid); ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound8_Initialize() " "should have returned DSERR_ALREADYINITIALIZED: %s\n", DXGetErrorString8(rc)); /* DSOUND: Error: Invalid caps buffer */ rc=IDirectSound8_GetCaps(dso,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() " "should have returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); ZeroMemory(&dscaps, sizeof(dscaps)); /* DSOUND: Error: Invalid caps buffer */ rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() " "should have returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); dscaps.dwSize=sizeof(dscaps); /* DSOUND: Running on a certified driver */ rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); rc=IDirectSound8_Compact(dso); ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_Compact(dso); ok(rc==DS_OK,"IDirectSound8_Compact() failed: %s\n",DXGetErrorString8(rc)); rc=IDirectSound8_GetSpeakerConfig(dso,0); ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) " "should have returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config); ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n", DXGetErrorString8(rc)); speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE); rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config); ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK) { rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config); ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK && speaker_config!=new_speaker_config) trace("IDirectSound8_GetSpeakerConfig() failed to set speaker " "config: expected 0x%08lx, got 0x%08lx\n", speaker_config,new_speaker_config); } rc=IDirectSound8_VerifyCertification(dso, &certified); ok(rc==DS_OK||rc==E_NOTIMPL,"IDirectSound8_VerifyCertification() failed: %s\n", DXGetErrorString8(rc)); EXIT: ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); }
static HRESULT test_dsound8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; int ref; /* DSOUND: Error: Invalid interface buffer */ rc=pDirectSoundCreate8(lpGuid,0,NULL); ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned " "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); /* Create the DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) return rc; /* Try the enumerated device */ IDirectSound8_test(dso, TRUE, lpGuid); /* Try the COM class factory method of creation with enumerated device */ rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound8, (void**)&dso); ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n", DXGetErrorString8(rc)); if (dso) IDirectSound8_test(dso, FALSE, lpGuid); /* Create a DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { LPDIRECTSOUND8 dso1=NULL; /* Create a second DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso1,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { /* Release the second DirectSound8 object */ ref=IDirectSound8_Release(dso1); ok(ref==0,"IDirectSound8_Release() has %d references, " "should have 0\n",ref); ok(dso!=dso1,"DirectSound8 objects should be unique: " "dso=%p,dso1=%p\n",dso,dso1); } /* Release the first DirectSound8 object */ ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", ref); if (ref!=0) return DSERR_GENERIC; } else return rc; /* Create a DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { LPDIRECTSOUNDBUFFER secondary; DSBUFFERDESC bufdesc; WAVEFORMATEX wfx; init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1); ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D; bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, wfx.nBlockAlign); bufdesc.lpwfxFormat=&wfx; rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary!=NULL, "IDirectSound8_CreateSoundBuffer() failed to create a secondary " "buffer: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK && secondary!=NULL) { LPDIRECTSOUND3DBUFFER buffer3d; LPDIRECTSOUNDBUFFER8 buffer8; rc=IDirectSound8_QueryInterface(secondary, &IID_IDirectSound3DBuffer, (void **)&buffer3d); ok(rc==DS_OK && buffer3d!=NULL, "IDirectSound8_QueryInterface() failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK && buffer3d!=NULL) { ref=IDirectSound3DBuffer_AddRef(buffer3d); ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, " "should have 2\n",ref); } rc=IDirectSound8_QueryInterface(secondary, &IID_IDirectSoundBuffer8, (void **)&buffer8); if (rc==DS_OK && buffer8!=NULL) { ref=IDirectSoundBuffer8_AddRef(buffer8); ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, " "should have 3\n",ref); } ref=IDirectSoundBuffer_AddRef(secondary); ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, " "should have 4\n",ref); } /* release with buffer */ ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", ref); if (ref!=0) return DSERR_GENERIC; } else return rc; return DS_OK; }
void SetupDSoundBuffers(void) { LPDIRECTSOUNDBUFFER lpdsb; DSBUFFERDESC dsPrimaryBuff, dsbdesc; WAVEFORMATEX wfm; HRESULT hr; int count; if (lpdsbuf) { CloseDLL(); InitiateAudio(AudioInfo);} if ( FAILED( hr = DirectSoundCreate( NULL, &lpds, NULL ) ) ) { return FALSE; } if ( FAILED( hr = IDirectSound8_SetCooperativeLevel(lpds, AudioInfo.hwnd, DSSCL_PRIORITY ))) { return FALSE; } for ( count = 0; count < NUMCAPTUREEVENTS; count++ ) { rghEvent[count] = CreateEvent( NULL, FALSE, FALSE, NULL ); if (rghEvent[count] == NULL ) { return FALSE; } } memset( &dsPrimaryBuff, 0, sizeof( DSBUFFERDESC ) ); dsPrimaryBuff.dwSize = sizeof( DSBUFFERDESC ); dsPrimaryBuff.dwFlags = DSBCAPS_PRIMARYBUFFER; dsPrimaryBuff.dwBufferBytes = 0; dsPrimaryBuff.lpwfxFormat = NULL; memset( &wfm, 0, sizeof( WAVEFORMATEX ) ); wfm.wFormatTag = WAVE_FORMAT_PCM; wfm.nChannels = 2; wfm.nSamplesPerSec = 44100; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; hr = IDirectSound8_CreateSoundBuffer(lpds,&dsPrimaryBuff, &lpdsb, NULL); if (SUCCEEDED ( hr ) ) { IDirectSoundBuffer8_SetFormat(lpdsb, &wfm ); IDirectSoundBuffer8_Play(lpdsb, 0, 0, DSBPLAY_LOOPING ); } wfm.nSamplesPerSec = Frequency; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; memset( &dsbdesc, 0, sizeof( DSBUFFERDESC ) ); dsbdesc.dwSize = sizeof( DSBUFFERDESC ); dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; dsbdesc.dwBufferBytes = BufferSize * 3; dsbdesc.lpwfxFormat = &wfm; if ( FAILED( hr = IDirectSound8_CreateSoundBuffer(lpds, &dsbdesc, &lpdsbuf, NULL ) ) ) { DisplayError("Failed in creation of Play buffer 1"); } FillBufferWithSilence( lpdsbuf ); rgdscbpn[0].dwOffset = ( BufferSize ) - 1; rgdscbpn[0].hEventNotify = rghEvent[0]; rgdscbpn[1].dwOffset = ( BufferSize * 2) - 1; rgdscbpn[1].hEventNotify = rghEvent[1]; rgdscbpn[2].dwOffset = ( BufferSize * 3) - 1; rgdscbpn[2].hEventNotify = rghEvent[2]; rgdscbpn[3].dwOffset = DSBPN_OFFSETSTOP; rgdscbpn[3].hEventNotify = rghEvent[3]; if ( FAILED( hr = IDirectSound8_QueryInterface(lpdsbuf, &IID_IDirectSoundNotify, ( VOID ** )&lpdsNotify ) ) ) { DisplayError("IDirectSound8_QueryInterface: Failed\n"); return; } // Set capture buffer notifications. if ( FAILED( hr = IDirectSoundNotify_SetNotificationPositions(lpdsNotify, NUMCAPTUREEVENTS, rgdscbpn ) ) ) { DisplayError("IDirectSoundNotify_SetNotificationPositions: Failed"); return; } //AddEffect(); }