diff options
| author | 2023-01-14 15:19:11 +0000 | |
|---|---|---|
| committer | 2023-01-14 15:19:11 +0000 | |
| commit | 122a8faa38be83c55a7ab0eaee548b1dffcf9c05 (patch) | |
| tree | 3a172d939894fa198a14e16149435531aff85e58 /src/audio_core | |
| parent | Merge pull request #9605 from german77/mouse_mapping (diff) | |
| download | yuzu-122a8faa38be83c55a7ab0eaee548b1dffcf9c05.tar.gz yuzu-122a8faa38be83c55a7ab0eaee548b1dffcf9c05.tar.xz yuzu-122a8faa38be83c55a7ab0eaee548b1dffcf9c05.zip | |
audio_core: Fix off-by-one error in upsampler
Diffstat (limited to 'src/audio_core')
| -rw-r--r-- | src/audio_core/renderer/command/resample/upsample.cpp | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/src/audio_core/renderer/command/resample/upsample.cpp b/src/audio_core/renderer/command/resample/upsample.cpp index 6c3ff31f7..1e5fd3e28 100644 --- a/src/audio_core/renderer/command/resample/upsample.cpp +++ b/src/audio_core/renderer/command/resample/upsample.cpp | |||
| @@ -94,49 +94,28 @@ static void SrcProcessFrame(std::span<s32> output, std::span<const s32> input, | |||
| 94 | auto calculate_sample = [&state](std::span<const Common::FixedPoint<24, 8>> coeffs1, | 94 | auto calculate_sample = [&state](std::span<const Common::FixedPoint<24, 8>> coeffs1, |
| 95 | std::span<const Common::FixedPoint<24, 8>> coeffs2) -> s32 { | 95 | std::span<const Common::FixedPoint<24, 8>> coeffs2) -> s32 { |
| 96 | auto output_index{state->history_output_index}; | 96 | auto output_index{state->history_output_index}; |
| 97 | auto start_pos{output_index - state->history_start_index + 1U}; | 97 | u64 result{0}; |
| 98 | auto end_pos{10U}; | ||
| 99 | 98 | ||
| 100 | if (start_pos < 10) { | 99 | for (u32 coeff_index = 0; coeff_index < 10; coeff_index++) { |
| 101 | end_pos = start_pos; | 100 | result += static_cast<u64>(state->history[output_index].to_raw()) * |
| 102 | } | 101 | coeffs1[coeff_index].to_raw(); |
| 103 | |||
| 104 | u64 prev_contrib{0}; | ||
| 105 | u32 coeff_index{0}; | ||
| 106 | for (; coeff_index < end_pos; coeff_index++, output_index--) { | ||
| 107 | prev_contrib += static_cast<u64>(state->history[output_index].to_raw()) * | ||
| 108 | coeffs1[coeff_index].to_raw(); | ||
| 109 | } | ||
| 110 | 102 | ||
| 111 | auto end_index{state->history_end_index}; | 103 | output_index = output_index == state->history_start_index ? state->history_end_index |
| 112 | for (; start_pos < 9; start_pos++, coeff_index++, end_index--) { | 104 | : output_index - 1; |
| 113 | prev_contrib += static_cast<u64>(state->history[end_index].to_raw()) * | ||
| 114 | coeffs1[coeff_index].to_raw(); | ||
| 115 | } | 105 | } |
| 116 | 106 | ||
| 117 | output_index = | 107 | output_index = |
| 118 | static_cast<u16>((state->history_output_index + 1) % UpsamplerState::HistorySize); | 108 | static_cast<u16>((state->history_output_index + 1) % UpsamplerState::HistorySize); |
| 119 | start_pos = state->history_end_index - output_index + 1U; | ||
| 120 | end_pos = 10U; | ||
| 121 | 109 | ||
| 122 | if (start_pos < 10) { | 110 | for (u32 coeff_index = 0; coeff_index < 10; coeff_index++) { |
| 123 | end_pos = start_pos; | 111 | result += static_cast<u64>(state->history[output_index].to_raw()) * |
| 124 | } | 112 | coeffs2[coeff_index].to_raw(); |
| 125 | |||
| 126 | u64 next_contrib{0}; | ||
| 127 | coeff_index = 0; | ||
| 128 | for (; coeff_index < end_pos; coeff_index++, output_index++) { | ||
| 129 | next_contrib += static_cast<u64>(state->history[output_index].to_raw()) * | ||
| 130 | coeffs2[coeff_index].to_raw(); | ||
| 131 | } | ||
| 132 | 113 | ||
| 133 | auto start_index{state->history_start_index}; | 114 | output_index = output_index == state->history_end_index ? state->history_start_index |
| 134 | for (; start_pos < 9; start_pos++, start_index++, coeff_index++) { | 115 | : output_index + 1; |
| 135 | next_contrib += static_cast<u64>(state->history[start_index].to_raw()) * | ||
| 136 | coeffs2[coeff_index].to_raw(); | ||
| 137 | } | 116 | } |
| 138 | 117 | ||
| 139 | return static_cast<s32>(((prev_contrib >> 15) + (next_contrib >> 15)) >> 8); | 118 | return static_cast<s32>(result >> (8 + 15)); |
| 140 | }; | 119 | }; |
| 141 | 120 | ||
| 142 | switch (state->ratio.to_int_floor()) { | 121 | switch (state->ratio.to_int_floor()) { |