From b09c5702b4d0b12ecde59fc748143cedb9d103c3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 8 Jan 2003 01:36:06 +0000 Subject: [PATCH] Double-check the buffer size. Don't use DSBCAPS_STATIC. --- stepmania/src/arch/Sound/DSoundHelpers.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/stepmania/src/arch/Sound/DSoundHelpers.cpp b/stepmania/src/arch/Sound/DSoundHelpers.cpp index f3b4f160f5..484e443a98 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.cpp +++ b/stepmania/src/arch/Sound/DSoundHelpers.cpp @@ -80,12 +80,12 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, memset(&format, 0, sizeof(format)); format.dwSize = sizeof(format); format.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; + /* Don't use DSBCAPS_STATIC. It's meant for static buffers, and we + * only use streaming buffers. */ if(hardware == HW_HARDWARE) format.dwFlags |= DSBCAPS_LOCHARDWARE; - else if(hardware == HW_SOFTWARE) + else format.dwFlags |= DSBCAPS_LOCSOFTWARE; - if(hardware == HW_DONT_CARE) - format.dwFlags |= DSBCAPS_STATIC; if(vol != 1) format.dwFlags |= DSBCAPS_CTRLVOLUME; format.dwBufferBytes = buffersize; @@ -98,9 +98,21 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, RageException::ThrowNonfatal(hr_ssprintf(hr, "CreateSoundBuffer failed")); sndbuf_buf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &buf); + ASSERT(buf); - if(buf == NULL) - RageException::ThrowNonfatal("foo"); // XXX + /* I'm not sure this should ever be needed, but ... */ + DSBCAPS bcaps; + bcaps.dwSize=sizeof(bcaps); + hr = buf->GetCaps(&bcaps); + if(FAILED(hr)) + RageException::Throw(hr_ssprintf(hr, "buf->GetCaps")); + if(int(bcaps.dwBufferBytes) != buffersize) + { + LOG->Warn("bcaps.dwBufferBytes (%i) != buffersize(%i); adjusting", + bcaps.dwBufferBytes, buffersize); + buffersize = bcaps.dwBufferBytes; + writeahead = min(writeahead, buffersize); + } float vl2 = log10f(vol) / log10f(2); /* vol log 2 */