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).
This commit is contained in:
Francois Gouget 2003-01-11 20:54:56 +00:00 committed by Alexandre Julliard
parent 3fd4087dde
commit 32140adefa
2 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -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;