aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorheapo <heapo3@gmail.com>2018-12-06 09:15:47 -0800
committerheapo <heapo3@gmail.com>2018-12-06 09:46:08 -0800
commit4c83e5cd1e3e5dff270c701cb8a0ac47914d87e7 (patch)
tree1baa2c45bf3c1f63b0820a10ef8cae69c410bcd4 /src
parentd6f17bdcc9bd3ff73f3c0c544bc6a5c582c3e434 (diff)
Avoid (expensive) audio interpolation when sample rates already match
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/algorithm/interpolate.cpp5
-rw-r--r--src/audio_core/audio_renderer.cpp7
2 files changed, 8 insertions, 4 deletions
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp
index 3aea9b0f2c..5005ba5199 100644
--- a/src/audio_core/algorithm/interpolate.cpp
+++ b/src/audio_core/algorithm/interpolate.cpp
@@ -54,8 +54,9 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
double l = 0.0;
double r = 0.0;
for (std::size_t j = 0; j < h.size(); j++) {
- l += Lanczos(taps, pos + j - taps + 1) * h[j][0];
- r += Lanczos(taps, pos + j - taps + 1) * h[j][1];
+ const double lanczos_calc = Lanczos(taps, pos + j - taps + 1);
+ l += lanczos_calc * h[j][0];
+ r += lanczos_calc * h[j][1];
}
output.emplace_back(static_cast<s16>(std::clamp(l, -32768.0, 32767.0)));
output.emplace_back(static_cast<s16>(std::clamp(r, -32768.0, 32767.0)));
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp
index 2e59894ab4..2683f3a5fa 100644
--- a/src/audio_core/audio_renderer.cpp
+++ b/src/audio_core/audio_renderer.cpp
@@ -285,8 +285,11 @@ void AudioRenderer::VoiceState::RefreshBuffer() {
break;
}
- samples =
- Interpolate(interp_state, std::move(samples), GetInfo().sample_rate, STREAM_SAMPLE_RATE);
+ // Only interpolate when necessary, expensive.
+ if (GetInfo().sample_rate != STREAM_SAMPLE_RATE) {
+ samples = Interpolate(interp_state, std::move(samples), GetInfo().sample_rate,
+ STREAM_SAMPLE_RATE);
+ }
is_refresh_pending = false;
}