From c70388dbeb1b1939caae67d6401d4caa61ea4bd0 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:18:41 +0200 Subject: [PATCH] HLE DSP: Actually interpolate audio --- src/core/audio/hle_core.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/core/audio/hle_core.cpp b/src/core/audio/hle_core.cpp index 593dd477..96e51aae 100644 --- a/src/core/audio/hle_core.cpp +++ b/src/core/audio/hle_core.cpp @@ -488,7 +488,7 @@ namespace Audio { decodeBuffer(source); } else { uint maxSampleCount = uint(float(Audio::samplesInFrame) * 1.0); - uint outputCount = 0; + usize outputCount = 0; while (outputCount < maxSampleCount) { if (source.currentSamples.empty()) { @@ -499,19 +499,27 @@ namespace Audio { } } - const uint sampleCount = std::min(maxSampleCount - outputCount, source.currentSamples.size()); + switch (source.interpolationMode) { + case Source::InterpolationMode::Linear: + Audio::Interpolation::linear( + source.interpolationState, source.currentSamples, source.rateMultiplier, source.currentFrame, outputCount + ); + break; + case Source::InterpolationMode::None: + Audio::Interpolation::none( + source.interpolationState, source.currentSamples, source.rateMultiplier, source.currentFrame, outputCount + ); + break; - // Copy samples to current frame buffer - // TODO: Implement linear/polyphase interpolation + case Source::InterpolationMode::Polyphase: + // Currently stubbed to be the same as linear + Audio::Interpolation::polyphase( + source.interpolationState, source.currentSamples, source.rateMultiplier, source.currentFrame, outputCount + ); + break; + } - std::copy( - source.currentSamples.begin(), std::next(source.currentSamples.begin(), sampleCount), source.currentFrame.begin() + outputCount - ); - // Remove samples from sample buffer - source.currentSamples.erase(source.currentSamples.begin(), std::next(source.currentSamples.begin(), sampleCount)); - // Advance sample position - source.samplePosition += sampleCount; - outputCount += sampleCount; + source.samplePosition += u32(outputCount); } } }