- wfex = lpcDSCBufferDesc->lpwfxFormat;
-
- if (wfex) {
- TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
- "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
- wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
- wfex->nAvgBytesPerSec, wfex->nBlockAlign,
- wfex->wBitsPerSample, wfex->cbSize);
-
- if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
- ipDSC->device->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX));
- CopyMemory(ipDSC->device->pwfx, wfex, sizeof(WAVEFORMATEX));
- ipDSC->device->pwfx->cbSize = 0;
- } else {
- ipDSC->device->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX)+wfex->cbSize);
- CopyMemory(ipDSC->device->pwfx, wfex, sizeof(WAVEFORMATEX)+wfex->cbSize);
- }
- } else {
- WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
- *ppobj = NULL;
- return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
- }
-
- *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
- sizeof(IDirectSoundCaptureBufferImpl));
-
- if ( *ppobj == NULL ) {
- WARN("out of memory\n");
- *ppobj = NULL;
- return DSERR_OUTOFMEMORY;
- } else {
- HRESULT err = DS_OK;
- LPBYTE newbuf;
- DWORD buflen;
- IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)*ppobj;
-
- This->ref = 1;
- This->dsound = ipDSC;
- This->dsound->device->capture_buffer = This;
- This->notify = NULL;
- This->nrofnotifies = 0;
- This->hwnotify = NULL;
-
- This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
- lpcDSCBufferDesc->dwSize);
- if (This->pdscbd)
- CopyMemory(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
- else {
- WARN("no memory\n");
- This->dsound->device->capture_buffer = 0;
- HeapFree( GetProcessHeap(), 0, This );
- *ppobj = NULL;
- return DSERR_OUTOFMEMORY;
- }
-
- This->lpVtbl = &dscbvt;
-
- if (ipDSC->device->driver) {
- if (This->dsound->device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
- FIXME("DSDDESC_DOMMSYSTEMOPEN not supported\n");
-
- if (This->dsound->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
- /* allocate buffer from system memory */
- buflen = lpcDSCBufferDesc->dwBufferBytes;
- TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->device->buffer);
- if (ipDSC->device->buffer)
- newbuf = HeapReAlloc(GetProcessHeap(),0,ipDSC->device->buffer,buflen);
- else
- newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
-
- if (newbuf == NULL) {
- WARN("failed to allocate capture buffer\n");
- err = DSERR_OUTOFMEMORY;
- /* but the old buffer might still exist and must be re-prepared */
- } else {
- ipDSC->device->buffer = newbuf;
- ipDSC->device->buflen = buflen;
- }
- } else {
- /* let driver allocate memory */
- ipDSC->device->buflen = lpcDSCBufferDesc->dwBufferBytes;
- /* FIXME: */
- HeapFree( GetProcessHeap(), 0, ipDSC->device->buffer);
- ipDSC->device->buffer = NULL;
- }
-
- err = IDsCaptureDriver_CreateCaptureBuffer(ipDSC->device->driver,
- ipDSC->device->pwfx,0,0,&(ipDSC->device->buflen),&(ipDSC->device->buffer),(LPVOID*)&(ipDSC->device->hwbuf));
- if (err != DS_OK) {
- WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
- This->dsound->device->capture_buffer = 0;
- HeapFree( GetProcessHeap(), 0, This );
- *ppobj = NULL;
- return err;
- }
- } else {
- DWORD flags = CALLBACK_FUNCTION;
- if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
- flags |= WAVE_DIRECTSOUND;
- err = mmErr(waveInOpen(&(ipDSC->device->hwi),
- ipDSC->device->drvdesc.dnDevNode, ipDSC->device->pwfx,
- (DWORD_PTR)DSOUND_capture_callback, (DWORD)ipDSC->device, flags));
- if (err != DS_OK) {
- WARN("waveInOpen failed\n");
- This->dsound->device->capture_buffer = 0;
- HeapFree( GetProcessHeap(), 0, This );
- *ppobj = NULL;
- return err;
- }
-
- buflen = lpcDSCBufferDesc->dwBufferBytes;
- TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->device->buffer);
- if (ipDSC->device->buffer)
- newbuf = HeapReAlloc(GetProcessHeap(),0,ipDSC->device->buffer,buflen);
- else
- newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
- if (newbuf == NULL) {
- WARN("failed to allocate capture buffer\n");
- err = DSERR_OUTOFMEMORY;
- /* but the old buffer might still exist and must be re-prepared */
- } else {
- ipDSC->device->buffer = newbuf;
- ipDSC->device->buflen = buflen;
- }
- }
- }
-
- TRACE("returning DS_OK\n");
- return DS_OK;
-}
-
-/*******************************************************************************
- * IDirectSoundCaptureNotify
- */
-static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface(
- LPDIRECTSOUNDNOTIFY iface,
- REFIID riid,
- LPVOID *ppobj)
-{
- IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
- TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
- if (This->dscb == NULL) {
- WARN("invalid parameter\n");
- return E_INVALIDARG;
- }
-
- return IDirectSoundCaptureBuffer_QueryInterface((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb, riid, ppobj);
-}