summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/WASAPIStream.cpp
diff options
context:
space:
mode:
authorSilent <zdanio95@gmail.com>2019-08-17 11:44:51 +0200
committerSilent <zdanio95@gmail.com>2021-01-12 19:24:49 +0100
commitc373890505ee3cce3687078d4fe99b8f38ca9d2b (patch)
tree0ff430705d2938f413aa3af9557d88f606f2bdf5 /Source/Core/AudioCommon/WASAPIStream.cpp
parent991b3ba8c2543ccfc08a89929e44e6e8a33ce559 (diff)
AudioCommon/WASAPI: Do volume adjustment only when really needed
This skips a potentially costly loop if volume is 100% or 0%, as for former there is no need for volume adjustment, while latter can be solved by specifying a AUDCLNT_BUFFERFLAGS_SILENT flag
Diffstat (limited to 'Source/Core/AudioCommon/WASAPIStream.cpp')
-rw-r--r--Source/Core/AudioCommon/WASAPIStream.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/Source/Core/AudioCommon/WASAPIStream.cpp b/Source/Core/AudioCommon/WASAPIStream.cpp
index 9be46cb751..552e60cd55 100644
--- a/Source/Core/AudioCommon/WASAPIStream.cpp
+++ b/Source/Core/AudioCommon/WASAPIStream.cpp
@@ -361,14 +361,23 @@ void WASAPIStream::SoundLoop()
WaitForSingleObject(m_need_data_event.get(), 1000);
m_audio_renderer->GetBuffer(m_frames_in_buffer, &data);
- GetMixer()->Mix(reinterpret_cast<s16*>(data), m_frames_in_buffer);
- float volume = SConfig::GetInstance().m_IsMuted ? 0 : SConfig::GetInstance().m_Volume / 100.;
+ s16* audio_data = reinterpret_cast<s16*>(data);
+ GetMixer()->Mix(audio_data, m_frames_in_buffer);
- for (u32 i = 0; i < m_frames_in_buffer * 2; i++)
- reinterpret_cast<s16*>(data)[i] = static_cast<s16>(reinterpret_cast<s16*>(data)[i] * volume);
+ const SConfig& config = SConfig::GetInstance();
+ const bool is_muted = config.m_IsMuted || config.m_Volume == 0;
+ const bool need_volume_adjustment = config.m_Volume != 100 && !is_muted;
- m_audio_renderer->ReleaseBuffer(m_frames_in_buffer, 0);
+ if (need_volume_adjustment)
+ {
+ const float volume = config.m_Volume / 100.0f;
+
+ for (u32 i = 0; i < m_frames_in_buffer * 2; i++)
+ *audio_data++ *= volume;
+ }
+
+ m_audio_renderer->ReleaseBuffer(m_frames_in_buffer, is_muted ? AUDCLNT_BUFFERFLAGS_SILENT : 0);
}
}