diff options
Diffstat (limited to 'src/audio_core/interpolate.cpp')
| -rw-r--r-- | src/audio_core/interpolate.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/audio_core/interpolate.cpp b/src/audio_core/interpolate.cpp index fcd3aa066..7751c545d 100644 --- a/src/audio_core/interpolate.cpp +++ b/src/audio_core/interpolate.cpp | |||
| @@ -17,7 +17,8 @@ constexpr u64 scale_mask = scale_factor - 1; | |||
| 17 | /// Here we step over the input in steps of rate_multiplier, until we consume all of the input. | 17 | /// Here we step over the input in steps of rate_multiplier, until we consume all of the input. |
| 18 | /// Three adjacent samples are passed to fn each step. | 18 | /// Three adjacent samples are passed to fn each step. |
| 19 | template <typename Function> | 19 | template <typename Function> |
| 20 | static StereoBuffer16 StepOverSamples(State& state, const StereoBuffer16& input, float rate_multiplier, Function fn) { | 20 | static StereoBuffer16 StepOverSamples(State& state, const StereoBuffer16& input, |
| 21 | float rate_multiplier, Function fn) { | ||
| 21 | ASSERT(rate_multiplier > 0); | 22 | ASSERT(rate_multiplier > 0); |
| 22 | 23 | ||
| 23 | if (input.size() < 2) | 24 | if (input.size() < 2) |
| @@ -63,22 +64,21 @@ static StereoBuffer16 StepOverSamples(State& state, const StereoBuffer16& input, | |||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier) { | 66 | StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier) { |
| 66 | return StepOverSamples(state, input, rate_multiplier, [](u64 fraction, const auto& x0, const auto& x1, const auto& x2) { | 67 | return StepOverSamples( |
| 67 | return x0; | 68 | state, input, rate_multiplier, |
| 68 | }); | 69 | [](u64 fraction, const auto& x0, const auto& x1, const auto& x2) { return x0; }); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier) { | 72 | StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier) { |
| 72 | // Note on accuracy: Some values that this produces are +/- 1 from the actual firmware. | 73 | // Note on accuracy: Some values that this produces are +/- 1 from the actual firmware. |
| 73 | return StepOverSamples(state, input, rate_multiplier, [](u64 fraction, const auto& x0, const auto& x1, const auto& x2) { | 74 | return StepOverSamples(state, input, rate_multiplier, [](u64 fraction, const auto& x0, |
| 75 | const auto& x1, const auto& x2) { | ||
| 74 | // This is a saturated subtraction. (Verified by black-box fuzzing.) | 76 | // This is a saturated subtraction. (Verified by black-box fuzzing.) |
| 75 | s64 delta0 = MathUtil::Clamp<s64>(x1[0] - x0[0], -32768, 32767); | 77 | s64 delta0 = MathUtil::Clamp<s64>(x1[0] - x0[0], -32768, 32767); |
| 76 | s64 delta1 = MathUtil::Clamp<s64>(x1[1] - x0[1], -32768, 32767); | 78 | s64 delta1 = MathUtil::Clamp<s64>(x1[1] - x0[1], -32768, 32767); |
| 77 | 79 | ||
| 78 | return std::array<s16, 2> { | 80 | return std::array<s16, 2>{static_cast<s16>(x0[0] + fraction * delta0 / scale_factor), |
| 79 | static_cast<s16>(x0[0] + fraction * delta0 / scale_factor), | 81 | static_cast<s16>(x0[1] + fraction * delta1 / scale_factor)}; |
| 80 | static_cast<s16>(x0[1] + fraction * delta1 / scale_factor) | ||
| 81 | }; | ||
| 82 | }); | 82 | }); |
| 83 | } | 83 | } |
| 84 | 84 | ||