Browse Source
Merge pull request #1877 from heapo/audio_interp
Perf: Avoid (expensive) audio interpolation when sample rates already match
pull/15/merge
bunnei
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
8 additions and
4 deletions
-
src/audio_core/algorithm/interpolate.cpp
-
src/audio_core/audio_renderer.cpp
|
|
@ -54,8 +54,9 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, |
|
|
double l = 0.0; |
|
|
double l = 0.0; |
|
|
double r = 0.0; |
|
|
double r = 0.0; |
|
|
for (std::size_t j = 0; j < h.size(); j++) { |
|
|
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(l, -32768.0, 32767.0))); |
|
|
output.emplace_back(static_cast<s16>(std::clamp(r, -32768.0, 32767.0))); |
|
|
output.emplace_back(static_cast<s16>(std::clamp(r, -32768.0, 32767.0))); |
|
|
|
|
|
@ -285,8 +285,11 @@ void AudioRenderer::VoiceState::RefreshBuffer() { |
|
|
break; |
|
|
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; |
|
|
is_refresh_pending = false; |
|
|
} |
|
|
} |
|
|
|