From 92d2a289403b8952d1737a001e8892e3ee92e643 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 8 Jan 2003 00:44:17 +0000 Subject: [PATCH] set mixer volume --- stepmania/src/arch/Sound/DSoundHelpers.cpp | 17 ++++++++++++++++- stepmania/src/arch/Sound/DSoundHelpers.h | 3 ++- .../src/arch/Sound/RageSoundDriver_DSound.cpp | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/stepmania/src/arch/Sound/DSoundHelpers.cpp b/stepmania/src/arch/Sound/DSoundHelpers.cpp index afed58659c..f3b4f160f5 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.cpp +++ b/stepmania/src/arch/Sound/DSoundHelpers.cpp @@ -7,6 +7,8 @@ #include #include +#include + #pragma comment(lib, "dsound.lib") #pragma comment(lib, "dxguid.lib") @@ -44,8 +46,12 @@ bool DSound::IsEmulated() const } DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, - int channels_, int samplerate_, int samplebits_, int writeahead_) + int channels_, int samplerate_, int samplebits_, int writeahead_, + float vol) { + ASSERT(vol >= 0); + ASSERT(vol <= 1); + channels = channels_; samplerate = samplerate_; samplebits = samplebits_; @@ -80,6 +86,8 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, format.dwFlags |= DSBCAPS_LOCSOFTWARE; if(hardware == HW_DONT_CARE) format.dwFlags |= DSBCAPS_STATIC; + if(vol != 1) + format.dwFlags |= DSBCAPS_CTRLVOLUME; format.dwBufferBytes = buffersize; format.dwReserved = 0; format.lpwfxFormat = &waveformat; @@ -94,8 +102,15 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, if(buf == NULL) RageException::ThrowNonfatal("foo"); // XXX + float vl2 = log10f(vol) / log10f(2); /* vol log 2 */ + + /* Volume is in percent; SetVolume wants attenuation in thousands of a + * decibel. */ + if(vol != 1) + buf->SetVolume(max(int(1000 * vl2), DSBVOLUME_MIN)); } + DSoundBuf::~DSoundBuf() { buf->Release(); diff --git a/stepmania/src/arch/Sound/DSoundHelpers.h b/stepmania/src/arch/Sound/DSoundHelpers.h index e326c235f6..9bbe0e7bc9 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.h +++ b/stepmania/src/arch/Sound/DSoundHelpers.h @@ -40,7 +40,8 @@ class DSoundBuf public: enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE }; DSoundBuf(DSound &ds, hw hardware, - int channels, int samplerate, int samplebits, int writeahead); + int channels, int samplerate, int samplebits, int writeahead, + float vol=1); bool get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, int chunksize); void release_output_buf(char *buffer, unsigned bufsiz); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp index bfa03d2042..5730d945dd 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp @@ -161,7 +161,8 @@ RageSound_DSound::RageSound_DSound() try { newbuf = new DSoundBuf(ds, DSoundBuf::HW_HARDWARE, - channels, samplerate, 16, buffersize); + channels, samplerate, 16, buffersize, + 0.50f); } catch(const RageException &e) { /* If we didn't get at least 8, fail. */ if(i >= 8) break; /* OK */