summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/Src/DSoundStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/AudioCommon/Src/DSoundStream.cpp')
-rw-r--r--Source/Core/AudioCommon/Src/DSoundStream.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/Core/AudioCommon/Src/DSoundStream.cpp b/Source/Core/AudioCommon/Src/DSoundStream.cpp
index 9ed4d592f4..94a26bd81b 100644
--- a/Source/Core/AudioCommon/Src/DSoundStream.cpp
+++ b/Source/Core/AudioCommon/Src/DSoundStream.cpp
@@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/
#include <windows.h>
+#include <cmath>
#include <dxerr.h>
#include "DSoundStream.h"
@@ -40,7 +41,7 @@ bool DSound::CreateBuffer()
// Fill out DSound buffer description.
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
- dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
+ dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS | DSBCAPS_CTRLVOLUME;
dsbdesc.dwBufferBytes = bufferSize = BUFSIZE;
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf;
dsbdesc.guid3DAlgorithm = DS3DALG_DEFAULT;
@@ -49,6 +50,7 @@ bool DSound::CreateBuffer()
if (SUCCEEDED(res))
{
dsBuffer->SetCurrentPosition(0);
+ dsBuffer->SetVolume(m_volume);
return true;
}
else
@@ -152,6 +154,17 @@ bool DSound::Start()
return true;
}
+void DSound::SetVolume(int volume)
+{
+ // This is in "dBA attenuation" from 0 to -10000, logarithmic
+ m_volume = (int)floor(log10((float)volume) * 5000.0f) - 10000;
+
+ soundCriticalSection.Enter();
+ if (ds != NULL)
+ dsBuffer->SetVolume(m_volume);
+ soundCriticalSection.Leave();
+}
+
void DSound::Update()
{
soundSyncEvent.Set();