Commit dfe3c1c5 authored by Robert Reif's avatar Robert Reif Committed by Alexandre Julliard

Allocate wave format structure dynamically based on format.

Remove format checks to allow driver to decide if format supported. Code cleanups.
parent cae33167
......@@ -134,7 +134,7 @@ DirectSoundCaptureCreate8(
if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
lpcGUID = &DSDEVID_DefaultCapture;
*ippDSC = (IDirectSoundCaptureImpl*)HeapAlloc(GetProcessHeap(),
*ippDSC = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, sizeof(IDirectSoundCaptureImpl));
if (*ippDSC == NULL) {
......@@ -769,9 +769,9 @@ DSOUND_CreateDirectSoundCaptureBuffer(
buflen = lpcDSCBufferDesc->dwBufferBytes;
TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
if (ipDSC->buffer)
newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
newbuf = HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
else
newbuf = (LPBYTE)HeapAlloc(GetProcessHeap(),0,buflen);
newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
if (newbuf == NULL) {
WARN("failed to allocate capture buffer\n");
err = DSERR_OUTOFMEMORY;
......@@ -905,7 +905,7 @@ HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
IDirectSoundCaptureNotifyImpl * dscn;
TRACE("(%p,%p)\n",dscb,pdscn);
dscn = (IDirectSoundCaptureNotifyImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dscn));
dscn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dscn));
if (dscn == NULL) {
WARN("out of memory\n");
......@@ -1736,7 +1736,7 @@ DirectSoundFullDuplexCreate(
return DSERR_NOAGGREGATION;
}
*ippDSFD = (IDirectSoundFullDuplexImpl*)HeapAlloc(GetProcessHeap(),
*ippDSFD = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
if (*ippDSFD == NULL) {
......
......@@ -467,6 +467,7 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
IDirectSoundBufferImpl* pdsb;
IDirectSoundBufferImpl* dsb;
HRESULT hres = DS_OK;
int size;
ICOM_THIS(IDirectSoundImpl,iface);
TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
......@@ -553,7 +554,21 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
dsb->ds3db = NULL;
dsb->iks = NULL; /* FIXME? */
dsb->dsb = NULL;
memcpy(&(dsb->wfx), &(pdsb->wfx), sizeof(dsb->wfx));
/* variable sized struct so calculate size based on format */
size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
if (dsb->pwfx == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
memcpy(dsb->pwfx, pdsb->pwfx, size);
InitializeCriticalSection(&(dsb->lock));
dsb->lock.DebugInfo->Spare[1] = (DWORD)"DSOUNDBUFFER_lock";
/* register buffer */
......@@ -575,6 +590,8 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
IDirectSoundBuffer8_Release(psb);
DeleteCriticalSection(&(dsb->lock));
RtlReleaseResource(&(This->lock));
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb->pwfx);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = 0;
return DSERR_OUTOFMEMORY;
......@@ -821,9 +838,9 @@ HRESULT WINAPI IDirectSoundImpl_Create(
err = IDsDriver_GetDriverDesc(drv,&(pDS->drvdesc));
if (err != DS_OK) {
WARN("IDsDriver_GetDriverDesc failed\n");
HeapFree(GetProcessHeap(),0,pDS);
*ppDS = NULL;
return err;
HeapFree(GetProcessHeap(),0,pDS);
*ppDS = NULL;
return err;
}
} else {
/* if no DirectSound interface available, use WINMM API instead */
......@@ -833,17 +850,25 @@ HRESULT WINAPI IDirectSoundImpl_Create(
pDS->drvdesc.dnDevNode = wod;
/* Set default wave format (may need it for waveOutOpen) */
pDS->wfx.wFormatTag = WAVE_FORMAT_PCM;
pDS->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEX));
if (pDS->pwfx == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,pDS);
*ppDS = NULL;
return DSERR_OUTOFMEMORY;
}
pDS->pwfx->wFormatTag = WAVE_FORMAT_PCM;
/* We rely on the sound driver to return the actual sound format of
* the device if it does not support 22050x8x2 and is given the
* WAVE_DIRECTSOUND flag.
*/
pDS->wfx.nSamplesPerSec = 22050;
pDS->wfx.wBitsPerSample = 8;
pDS->wfx.nChannels = 2;
pDS->wfx.nBlockAlign = pDS->wfx.wBitsPerSample * pDS->wfx.nChannels / 8;
pDS->wfx.nAvgBytesPerSec = pDS->wfx.nSamplesPerSec * pDS->wfx.nBlockAlign;
pDS->wfx.cbSize = 0;
pDS->pwfx->nSamplesPerSec = 22050;
pDS->pwfx->wBitsPerSample = 8;
pDS->pwfx->nChannels = 2;
pDS->pwfx->nBlockAlign = pDS->pwfx->wBitsPerSample * pDS->pwfx->nChannels / 8;
pDS->pwfx->nAvgBytesPerSec = pDS->pwfx->nSamplesPerSec * pDS->pwfx->nBlockAlign;
pDS->pwfx->cbSize = 0;
/* If the driver requests being opened through MMSYSTEM
* (which is recommended by the DDK), it is supposed to happen
......@@ -857,7 +882,7 @@ HRESULT WINAPI IDirectSoundImpl_Create(
flags |= WAVE_DIRECTSOUND;
err = mmErr(waveOutOpen(&(pDS->hwo),
pDS->drvdesc.dnDevNode, &(pDS->wfx),
pDS->drvdesc.dnDevNode, pDS->pwfx,
(DWORD)DSOUND_callback, (DWORD)pDS,
flags));
if (err != DS_OK) {
......
......@@ -78,7 +78,7 @@ struct IDirectSoundImpl
DSDRIVERDESC drvdesc;
DSDRIVERCAPS drvcaps;
DWORD priolevel;
WAVEFORMATEX wfx; /* current main waveformat */
PWAVEFORMATEX pwfx;
HWAVEOUT hwo;
LPWAVEHDR pwave[DS_HEL_FRAGS];
UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
......@@ -197,7 +197,7 @@ struct IDirectSoundBufferImpl
IDirectSoundImpl* dsound;
CRITICAL_SECTION lock;
PIDSDRIVERBUFFER hwbuf;
WAVEFORMATEX wfx;
PWAVEFORMATEX pwfx;
BufferMemory* buffer;
DWORD playflags,state,leadin;
DWORD playpos,startpos,writelead,buflen;
......
......@@ -208,7 +208,7 @@ HRESULT WINAPI IKsBufferPropertySetImpl_Create(
IKsBufferPropertySetImpl *iks;
TRACE("(%p,%p)\n",dsb,piks);
iks = (IKsBufferPropertySetImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*iks));
iks = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*iks));
iks->ref = 0;
iks->dsb = dsb;
dsb->iks = iks;
......@@ -1140,7 +1140,7 @@ HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
{
IKsPrivatePropertySetImpl *iks;
iks = (IKsPrivatePropertySetImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
iks = HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
iks->ref = 0;
iks->lpVtbl = &ikspvt;
......
......@@ -733,7 +733,7 @@ HRESULT WINAPI IDirectSound3DBufferImpl_Create(
IDirectSound3DBufferImpl *ds3db;
TRACE("(%p,%p)\n",dsb,pds3db);
ds3db = (IDirectSound3DBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
ds3db = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
if (ds3db == NULL) {
WARN("out of memory\n");
......@@ -1111,7 +1111,7 @@ HRESULT WINAPI IDirectSound3DListenerImpl_Create(
IDirectSound3DListenerImpl *dsl;
TRACE("(%p,%p)\n",This,pdsl);
dsl = (IDirectSound3DListenerImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsl));
dsl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsl));
if (dsl == NULL) {
WARN("out of memory\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment