From 32140adefa3e2362903614abeb9797d2619f24c6 Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Sat, 11 Jan 2003 20:54:56 +0000 Subject: [PATCH] DSB.SetFormat:Trace the requested format as soon as possible in case it is not supported and simplify validity check. Initialize the buffer format, and only from the fields we checked. DirectSoundCreate8 fully initializes the buffer format (just in case). --- dlls/dsound/dsound_main.c | 1 + dlls/dsound/primary.c | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index 8628d5254ed..5264b84b813 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -644,6 +644,7 @@ HRESULT WINAPI DirectSoundCreate8(REFGUID lpGUID,LPDIRECTSOUND8 *ppDS,IUnknown * (*ippDS)->wfx.nChannels = 2; (*ippDS)->wfx.nBlockAlign = (*ippDS)->wfx.wBitsPerSample * (*ippDS)->wfx.nChannels / 8; (*ippDS)->wfx.nAvgBytesPerSec = (*ippDS)->wfx.nSamplesPerSec * (*ippDS)->wfx.nBlockAlign; + (*ippDS)->wfx.cbSize = 0; /* If the driver requests being opened through MMSYSTEM * (which is recommended by the DDK), it is supposed to happen diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 7cb438d2a67..3afd2b4a4d5 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -109,7 +109,7 @@ static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This) if (newbuf == NULL) { ERR("failed to allocate primary buffer\n"); merr = DSERR_OUTOFMEMORY; - /* but the old buffer might still exists and must be re-prepared */ + /* but the old buffer might still exist and must be re-prepared */ } else { This->buffer = newbuf; This->buflen = buflen; @@ -281,13 +281,21 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( } /* Let's be pedantic! */ - if ((wfex == NULL) || - (wfex->wFormatTag != WAVE_FORMAT_PCM) || + if (wfex == NULL) { + TRACE("wfex==NULL!\n"); + return DSERR_INVALIDPARAM; + } + 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) || (wfex->nChannels < 1) || (wfex->nChannels > 2) || (wfex->nSamplesPerSec < 1) || - (wfex->nBlockAlign < 1) || (wfex->nChannels > 4) || ((wfex->wBitsPerSample != 8) && (wfex->wBitsPerSample != 16))) { - TRACE("failed pedantic check!\n"); + TRACE("unsupported format!\n"); return DSERR_INVALIDPARAM; } @@ -308,14 +316,10 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( } } - memcpy(&(dsound->wfx), wfex, sizeof(dsound->wfx)); - - 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); - + dsound->wfx.nSamplesPerSec = wfex->nSamplesPerSec; + dsound->wfx.nChannels = wfex->nChannels; + dsound->wfx.wBitsPerSample = wfex->wBitsPerSample; + dsound->wfx.nBlockAlign = dsound->wfx.wBitsPerSample / 8 * dsound->wfx.nChannels; dsound->wfx.nAvgBytesPerSec = dsound->wfx.nSamplesPerSec * dsound->wfx.nBlockAlign;