/* IUnknown methods */ static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface( LPDIRECTSOUND3DLISTENER iface, REFIID riid, LPVOID *ppobj) { IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface; TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj); if (ppobj == NULL) { WARN("invalid parameter\n"); return E_INVALIDARG; } *ppobj = NULL; /* assume failure */ if ( IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirectSound3DListener ) ) { IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)This); *ppobj = This; return S_OK; } if ( IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) { *ppobj = &This->device->primary->IDirectSoundBuffer8_iface; IDirectSoundBuffer8_AddRef(&This->device->primary->IDirectSoundBuffer8_iface); return S_OK; } FIXME( "Unknown IID %s\n", debugstr_guid( riid ) ); return E_NOINTERFACE; }
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; }
HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb, const DSBUFFERDESC *dsbd) { IDirectSoundBufferImpl *dsb; TRACE("%p,%p,%p)\n",device,ppdsb,dsbd); if (dsbd->lpwfxFormat) { WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n"); *ppdsb = NULL; return DSERR_INVALIDPARAM; } dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb)); if (dsb == NULL) { WARN("out of memory\n"); *ppdsb = NULL; return DSERR_OUTOFMEMORY; } dsb->ref = 0; dsb->ref3D = 0; dsb->refiks = 0; dsb->numIfaces = 0; dsb->device = device; dsb->IDirectSoundBuffer8_iface.lpVtbl = &dspbvt; dsb->IDirectSound3DListener_iface.lpVtbl = &ds3dlvt; dsb->IKsPropertySet_iface.lpVtbl = &iksbvt; dsb->dsbd = *dsbd; /* IDirectSound3DListener */ device->ds3dl.dwSize = sizeof(DS3DLISTENER); device->ds3dl.vPosition.x = 0.0; device->ds3dl.vPosition.y = 0.0; device->ds3dl.vPosition.z = 0.0; device->ds3dl.vVelocity.x = 0.0; device->ds3dl.vVelocity.y = 0.0; device->ds3dl.vVelocity.z = 0.0; device->ds3dl.vOrientFront.x = 0.0; device->ds3dl.vOrientFront.y = 0.0; device->ds3dl.vOrientFront.z = 1.0; device->ds3dl.vOrientTop.x = 0.0; device->ds3dl.vOrientTop.y = 1.0; device->ds3dl.vOrientTop.z = 0.0; device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR; device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR; device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR; device->ds3dl_need_recalc = TRUE; TRACE("Created primary buffer at %p\n", dsb); TRACE("(formattag=0x%04x,chans=%d,samplerate=%d," "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n", device->pwfx->wFormatTag, device->pwfx->nChannels, device->pwfx->nSamplesPerSec, device->pwfx->nAvgBytesPerSec, device->pwfx->nBlockAlign, device->pwfx->wBitsPerSample, device->pwfx->cbSize); IDirectSoundBuffer8_AddRef(&dsb->IDirectSoundBuffer8_iface); *ppdsb = dsb; return S_OK; }
static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( LPDIRECTSOUNDFULLDUPLEX iface, LPCGUID pCaptureGuid, LPCGUID pRendererGuid, LPCDSCBUFFERDESC lpDscBufferDesc, LPCDSBUFFERDESC lpDsBufferDesc, HWND hWnd, DWORD dwLevel, LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8, LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 ) { HRESULT hr; IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface; IDirectSoundBufferImpl * dsb; TRACE("(%p,%s,%s,%p,%p,%lx,%lx,%p,%p)\n", This, debugstr_guid(pCaptureGuid), debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel, lplpDirectSoundCaptureBuffer8, lplpDirectSoundBuffer8); if (This->renderer_device != NULL || This->capture_device != NULL) { WARN("already initialized\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return DSERR_ALREADYINITIALIZED; } hr = DirectSoundDevice_Initialize(&This->renderer_device, pRendererGuid); if (hr != DS_OK) { WARN("DirectSoundDevice_Initialize() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } if (dwLevel==DSSCL_PRIORITY || dwLevel==DSSCL_EXCLUSIVE) { WARN("level=%s not fully supported\n", dwLevel==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE"); } This->renderer_device->priolevel = dwLevel; hr = DSOUND_PrimarySetFormat(This->renderer_device, lpDsBufferDesc->lpwfxFormat); if (hr != DS_OK) { WARN("DSOUND_PrimarySetFormat() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } hr = IDirectSoundBufferImpl_Create(This->renderer_device, &dsb, lpDsBufferDesc); if (hr != DS_OK) { WARN("IDirectSoundBufferImpl_Create() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } hr = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl **)lplpDirectSoundBuffer8); if (hr != DS_OK) { WARN("SecondaryBufferImpl_Create() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } IDirectSoundBuffer8_AddRef(*lplpDirectSoundBuffer8); hr = DirectSoundCaptureDevice_Initialize(&This->capture_device, pCaptureGuid); if (hr != DS_OK) { WARN("DirectSoundCaptureDevice_Initialize() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } hr = IDirectSoundCaptureBufferImpl_Create(This->capture_device, (IDirectSoundCaptureBufferImpl **)lplpDirectSoundCaptureBuffer8, lpDscBufferDesc); if (hr != DS_OK) { WARN("IDirectSoundCaptureBufferImpl_Create() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } return hr; }
HRESULT WINAPI IDirectSound8_fnCreateSoundBuffer( LPDIRECTSOUND8 iface, LPCDSBUFFERDESC lpcDSBufferDesc, LPLPDIRECTSOUNDBUFFER lplpDirectSoundBuffer, IUnknown FAR* pUnkOuter) { HRESULT hResult; LPCDirectSoundImpl This = (LPCDirectSoundImpl)CONTAINING_RECORD(iface, CDirectSoundImpl, lpVtbl); if (!This->bInitialized) { /* object not yet initialized */ return DSERR_UNINITIALIZED; } if (!lpcDSBufferDesc || !lplpDirectSoundBuffer || pUnkOuter != NULL) { DPRINT("Invalid parameter %p %p %p\n", lpcDSBufferDesc, lplpDirectSoundBuffer, pUnkOuter); return DSERR_INVALIDPARAM; } /* check buffer description */ if ((lpcDSBufferDesc->dwSize != sizeof(DSBUFFERDESC) && lpcDSBufferDesc->dwSize != sizeof(DSBUFFERDESC1)) || lpcDSBufferDesc->dwReserved != 0) { DPRINT("Invalid buffer description size %u expected %u dwReserved %u\n", lpcDSBufferDesc->dwSize, sizeof(DSBUFFERDESC1), lpcDSBufferDesc->dwReserved); return DSERR_INVALIDPARAM; } DPRINT("This %p dwFlags %x dwBufferBytes %u lpwfxFormat %p dwSize %u\n", This, lpcDSBufferDesc->dwFlags, lpcDSBufferDesc->dwBufferBytes, lpcDSBufferDesc->lpwfxFormat, lpcDSBufferDesc->dwSize); if (lpcDSBufferDesc->dwFlags & DSBCAPS_PRIMARYBUFFER) { if (lpcDSBufferDesc->lpwfxFormat != NULL) { /* format must be null for primary sound buffer */ return DSERR_INVALIDPARAM; } if (lpcDSBufferDesc->dwBufferBytes != 0) { /* buffer size must be zero for primary sound buffer */ return DSERR_INVALIDPARAM; } if (This->PrimaryBuffer) { /* primary buffer already exists */ IDirectSoundBuffer8_AddRef(This->PrimaryBuffer); *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)This->PrimaryBuffer; return S_OK; } hResult = NewPrimarySoundBuffer((LPLPDIRECTSOUNDBUFFER8)lplpDirectSoundBuffer, This->Filter, This->dwLevel, lpcDSBufferDesc->dwFlags); if (SUCCEEDED(hResult)) { /* store primary buffer */ This->PrimaryBuffer = (LPDIRECTSOUNDBUFFER8)*lplpDirectSoundBuffer; } return hResult; } else { if (lpcDSBufferDesc->lpwfxFormat == NULL) { /* format must not be null */ return DSERR_INVALIDPARAM; } if (lpcDSBufferDesc->dwBufferBytes < DSBSIZE_MIN || lpcDSBufferDesc->dwBufferBytes > DSBSIZE_MAX) { /* buffer size must be within bounds for secondary sound buffer*/ return DSERR_INVALIDPARAM; } if (!This->PrimaryBuffer) { hResult = NewPrimarySoundBuffer((LPLPDIRECTSOUNDBUFFER8)lplpDirectSoundBuffer, This->Filter, This->dwLevel, lpcDSBufferDesc->dwFlags); if (SUCCEEDED(hResult)) { /* store primary buffer */ This->PrimaryBuffer = (LPDIRECTSOUNDBUFFER8)*lplpDirectSoundBuffer; } else { DPRINT("Failed to create primary buffer with %x\n", hResult); return hResult; } } ASSERT(This->PrimaryBuffer); DPRINT("This %p wFormatTag %x nChannels %u nSamplesPerSec %u nAvgBytesPerSec %u NBlockAlign %u wBitsPerSample %u cbSize %u\n", This, lpcDSBufferDesc->lpwfxFormat->wFormatTag, lpcDSBufferDesc->lpwfxFormat->nChannels, lpcDSBufferDesc->lpwfxFormat->nSamplesPerSec, lpcDSBufferDesc->lpwfxFormat->nAvgBytesPerSec, lpcDSBufferDesc->lpwfxFormat->nBlockAlign, lpcDSBufferDesc->lpwfxFormat->wBitsPerSample, lpcDSBufferDesc->lpwfxFormat->cbSize); hResult = NewSecondarySoundBuffer((LPLPDIRECTSOUNDBUFFER8)lplpDirectSoundBuffer, This->Filter, This->dwLevel, lpcDSBufferDesc, This->PrimaryBuffer); return hResult; } }