summaryrefslogtreecommitdiff
path: root/src/audio_core/algorithm
diff options
context:
space:
mode:
authorGravatar Kelebek12022-07-16 23:48:45 +0100
committerGravatar Kelebek12022-07-22 01:11:32 +0100
commit458da8a94877677f086f06cdeecf959ec4283a33 (patch)
tree583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/algorithm
parentMerge pull request #8598 from Link4565/recv-dontwait (diff)
downloadyuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip
Project Andio
Diffstat (limited to 'src/audio_core/algorithm')
-rw-r--r--src/audio_core/algorithm/filter.cpp79
-rw-r--r--src/audio_core/algorithm/filter.h61
-rw-r--r--src/audio_core/algorithm/interpolate.cpp232
-rw-r--r--src/audio_core/algorithm/interpolate.h43
4 files changed, 0 insertions, 415 deletions
diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp
deleted file mode 100644
index 96e37991f..000000000
--- a/src/audio_core/algorithm/filter.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#define _USE_MATH_DEFINES
5
6#include <algorithm>
7#include <array>
8#include <cmath>
9#include <vector>
10#include "audio_core/algorithm/filter.h"
11#include "common/common_types.h"
12
13namespace AudioCore {
14
15Filter Filter::LowPass(double cutoff, double Q) {
16 const double w0 = 2.0 * M_PI * cutoff;
17 const double sin_w0 = std::sin(w0);
18 const double cos_w0 = std::cos(w0);
19 const double alpha = sin_w0 / (2 * Q);
20
21 const double a0 = 1 + alpha;
22 const double a1 = -2.0 * cos_w0;
23 const double a2 = 1 - alpha;
24 const double b0 = 0.5 * (1 - cos_w0);
25 const double b1 = 1.0 * (1 - cos_w0);
26 const double b2 = 0.5 * (1 - cos_w0);
27
28 return {a0, a1, a2, b0, b1, b2};
29}
30
31Filter::Filter() : Filter(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) {}
32
33Filter::Filter(double a0_, double a1_, double a2_, double b0_, double b1_, double b2_)
34 : a1(a1_ / a0_), a2(a2_ / a0_), b0(b0_ / a0_), b1(b1_ / a0_), b2(b2_ / a0_) {}
35
36void Filter::Process(std::vector<s16>& signal) {
37 const std::size_t num_frames = signal.size() / 2;
38 for (std::size_t i = 0; i < num_frames; i++) {
39 std::rotate(in.begin(), in.end() - 1, in.end());
40 std::rotate(out.begin(), out.end() - 1, out.end());
41
42 for (std::size_t ch = 0; ch < channel_count; ch++) {
43 in[0][ch] = signal[i * channel_count + ch];
44
45 out[0][ch] = b0 * in[0][ch] + b1 * in[1][ch] + b2 * in[2][ch] - a1 * out[1][ch] -
46 a2 * out[2][ch];
47
48 signal[i * 2 + ch] = static_cast<s16>(std::clamp(out[0][ch], -32768.0, 32767.0));
49 }
50 }
51}
52
53/// Calculates the appropriate Q for each biquad in a cascading filter.
54/// @param total_count The total number of biquads to be cascaded.
55/// @param index 0-index of the biquad to calculate the Q value for.
56static double CascadingBiquadQ(std::size_t total_count, std::size_t index) {
57 const auto pole =
58 M_PI * static_cast<double>(2 * index + 1) / (4.0 * static_cast<double>(total_count));
59 return 1.0 / (2.0 * std::cos(pole));
60}
61
62CascadingFilter CascadingFilter::LowPass(double cutoff, std::size_t cascade_size) {
63 std::vector<Filter> cascade(cascade_size);
64 for (std::size_t i = 0; i < cascade_size; i++) {
65 cascade[i] = Filter::LowPass(cutoff, CascadingBiquadQ(cascade_size, i));
66 }
67 return CascadingFilter{std::move(cascade)};
68}
69
70CascadingFilter::CascadingFilter() = default;
71CascadingFilter::CascadingFilter(std::vector<Filter> filters_) : filters(std::move(filters_)) {}
72
73void CascadingFilter::Process(std::vector<s16>& signal) {
74 for (auto& filter : filters) {
75 filter.Process(signal);
76 }
77}
78
79} // namespace AudioCore
diff --git a/src/audio_core/algorithm/filter.h b/src/audio_core/algorithm/filter.h
deleted file mode 100644
index 2586f0079..000000000
--- a/src/audio_core/algorithm/filter.h
+++ /dev/null
@@ -1,61 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7#include <vector>
8#include "common/common_types.h"
9
10namespace AudioCore {
11
12/// Digital biquad filter:
13///
14/// b0 + b1 z^-1 + b2 z^-2
15/// H(z) = ------------------------
16/// a0 + a1 z^-1 + b2 z^-2
17class Filter {
18public:
19 /// Creates a low-pass filter.
20 /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0.
21 /// @param Q Determines the quality factor of this filter.
22 static Filter LowPass(double cutoff, double Q = 0.7071);
23
24 /// Passthrough filter.
25 Filter();
26
27 Filter(double a0_, double a1_, double a2_, double b0_, double b1_, double b2_);
28
29 void Process(std::vector<s16>& signal);
30
31private:
32 static constexpr std::size_t channel_count = 2;
33
34 /// Coefficients are in normalized form (a0 = 1.0).
35 double a1, a2, b0, b1, b2;
36 /// Input History
37 std::array<std::array<double, channel_count>, 3> in;
38 /// Output History
39 std::array<std::array<double, channel_count>, 3> out;
40};
41
42/// Cascade filters to build up higher-order filters from lower-order ones.
43class CascadingFilter {
44public:
45 /// Creates a cascading low-pass filter.
46 /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0.
47 /// @param cascade_size Number of biquads in cascade.
48 static CascadingFilter LowPass(double cutoff, std::size_t cascade_size);
49
50 /// Passthrough.
51 CascadingFilter();
52
53 explicit CascadingFilter(std::vector<Filter> filters_);
54
55 void Process(std::vector<s16>& signal);
56
57private:
58 std::vector<Filter> filters;
59};
60
61} // namespace AudioCore
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp
deleted file mode 100644
index d2a4cd53f..000000000
--- a/src/audio_core/algorithm/interpolate.cpp
+++ /dev/null
@@ -1,232 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#define _USE_MATH_DEFINES
5
6#include <algorithm>
7#include <climits>
8#include <cmath>
9#include <vector>
10
11#include "audio_core/algorithm/interpolate.h"
12#include "common/common_types.h"
13#include "common/logging/log.h"
14
15namespace AudioCore {
16
17constexpr std::array<s16, 512> curve_lut0{
18 6600, 19426, 6722, 3, 6479, 19424, 6845, 9, 6359, 19419, 6968, 15, 6239,
19 19412, 7093, 22, 6121, 19403, 7219, 28, 6004, 19391, 7345, 34, 5888, 19377,
20 7472, 41, 5773, 19361, 7600, 48, 5659, 19342, 7728, 55, 5546, 19321, 7857,
21 62, 5434, 19298, 7987, 69, 5323, 19273, 8118, 77, 5213, 19245, 8249, 84,
22 5104, 19215, 8381, 92, 4997, 19183, 8513, 101, 4890, 19148, 8646, 109, 4785,
23 19112, 8780, 118, 4681, 19073, 8914, 127, 4579, 19031, 9048, 137, 4477, 18988,
24 9183, 147, 4377, 18942, 9318, 157, 4277, 18895, 9454, 168, 4179, 18845, 9590,
25 179, 4083, 18793, 9726, 190, 3987, 18738, 9863, 202, 3893, 18682, 10000, 215,
26 3800, 18624, 10137, 228, 3709, 18563, 10274, 241, 3618, 18500, 10411, 255, 3529,
27 18436, 10549, 270, 3441, 18369, 10687, 285, 3355, 18300, 10824, 300, 3269, 18230,
28 10962, 317, 3186, 18157, 11100, 334, 3103, 18082, 11238, 351, 3022, 18006, 11375,
29 369, 2942, 17927, 11513, 388, 2863, 17847, 11650, 408, 2785, 17765, 11788, 428,
30 2709, 17681, 11925, 449, 2635, 17595, 12062, 471, 2561, 17507, 12198, 494, 2489,
31 17418, 12334, 517, 2418, 17327, 12470, 541, 2348, 17234, 12606, 566, 2280, 17140,
32 12741, 592, 2213, 17044, 12876, 619, 2147, 16946, 13010, 647, 2083, 16846, 13144,
33 675, 2020, 16745, 13277, 704, 1958, 16643, 13409, 735, 1897, 16539, 13541, 766,
34 1838, 16434, 13673, 798, 1780, 16327, 13803, 832, 1723, 16218, 13933, 866, 1667,
35 16109, 14062, 901, 1613, 15998, 14191, 937, 1560, 15885, 14318, 975, 1508, 15772,
36 14445, 1013, 1457, 15657, 14571, 1052, 1407, 15540, 14695, 1093, 1359, 15423, 14819,
37 1134, 1312, 15304, 14942, 1177, 1266, 15185, 15064, 1221, 1221, 15064, 15185, 1266,
38 1177, 14942, 15304, 1312, 1134, 14819, 15423, 1359, 1093, 14695, 15540, 1407, 1052,
39 14571, 15657, 1457, 1013, 14445, 15772, 1508, 975, 14318, 15885, 1560, 937, 14191,
40 15998, 1613, 901, 14062, 16109, 1667, 866, 13933, 16218, 1723, 832, 13803, 16327,
41 1780, 798, 13673, 16434, 1838, 766, 13541, 16539, 1897, 735, 13409, 16643, 1958,
42 704, 13277, 16745, 2020, 675, 13144, 16846, 2083, 647, 13010, 16946, 2147, 619,
43 12876, 17044, 2213, 592, 12741, 17140, 2280, 566, 12606, 17234, 2348, 541, 12470,
44 17327, 2418, 517, 12334, 17418, 2489, 494, 12198, 17507, 2561, 471, 12062, 17595,
45 2635, 449, 11925, 17681, 2709, 428, 11788, 17765, 2785, 408, 11650, 17847, 2863,
46 388, 11513, 17927, 2942, 369, 11375, 18006, 3022, 351, 11238, 18082, 3103, 334,
47 11100, 18157, 3186, 317, 10962, 18230, 3269, 300, 10824, 18300, 3355, 285, 10687,
48 18369, 3441, 270, 10549, 18436, 3529, 255, 10411, 18500, 3618, 241, 10274, 18563,
49 3709, 228, 10137, 18624, 3800, 215, 10000, 18682, 3893, 202, 9863, 18738, 3987,
50 190, 9726, 18793, 4083, 179, 9590, 18845, 4179, 168, 9454, 18895, 4277, 157,
51 9318, 18942, 4377, 147, 9183, 18988, 4477, 137, 9048, 19031, 4579, 127, 8914,
52 19073, 4681, 118, 8780, 19112, 4785, 109, 8646, 19148, 4890, 101, 8513, 19183,
53 4997, 92, 8381, 19215, 5104, 84, 8249, 19245, 5213, 77, 8118, 19273, 5323,
54 69, 7987, 19298, 5434, 62, 7857, 19321, 5546, 55, 7728, 19342, 5659, 48,
55 7600, 19361, 5773, 41, 7472, 19377, 5888, 34, 7345, 19391, 6004, 28, 7219,
56 19403, 6121, 22, 7093, 19412, 6239, 15, 6968, 19419, 6359, 9, 6845, 19424,
57 6479, 3, 6722, 19426, 6600};
58
59constexpr std::array<s16, 512> curve_lut1{
60 -68, 32639, 69, -5, -200, 32630, 212, -15, -328, 32613, 359, -26, -450,
61 32586, 512, -36, -568, 32551, 669, -47, -680, 32507, 832, -58, -788, 32454,
62 1000, -69, -891, 32393, 1174, -80, -990, 32323, 1352, -92, -1084, 32244, 1536,
63 -103, -1173, 32157, 1724, -115, -1258, 32061, 1919, -128, -1338, 31956, 2118, -140,
64 -1414, 31844, 2322, -153, -1486, 31723, 2532, -167, -1554, 31593, 2747, -180, -1617,
65 31456, 2967, -194, -1676, 31310, 3192, -209, -1732, 31157, 3422, -224, -1783, 30995,
66 3657, -240, -1830, 30826, 3897, -256, -1874, 30649, 4143, -272, -1914, 30464, 4393,
67 -289, -1951, 30272, 4648, -307, -1984, 30072, 4908, -325, -2014, 29866, 5172, -343,
68 -2040, 29652, 5442, -362, -2063, 29431, 5716, -382, -2083, 29203, 5994, -403, -2100,
69 28968, 6277, -424, -2114, 28727, 6565, -445, -2125, 28480, 6857, -468, -2133, 28226,
70 7153, -490, -2139, 27966, 7453, -514, -2142, 27700, 7758, -538, -2142, 27428, 8066,
71 -563, -2141, 27151, 8378, -588, -2136, 26867, 8694, -614, -2130, 26579, 9013, -641,
72 -2121, 26285, 9336, -668, -2111, 25987, 9663, -696, -2098, 25683, 9993, -724, -2084,
73 25375, 10326, -753, -2067, 25063, 10662, -783, -2049, 24746, 11000, -813, -2030, 24425,
74 11342, -844, -2009, 24100, 11686, -875, -1986, 23771, 12033, -907, -1962, 23438, 12382,
75 -939, -1937, 23103, 12733, -972, -1911, 22764, 13086, -1005, -1883, 22422, 13441, -1039,
76 -1855, 22077, 13798, -1072, -1825, 21729, 14156, -1107, -1795, 21380, 14516, -1141, -1764,
77 21027, 14877, -1176, -1732, 20673, 15239, -1211, -1700, 20317, 15602, -1246, -1667, 19959,
78 15965, -1282, -1633, 19600, 16329, -1317, -1599, 19239, 16694, -1353, -1564, 18878, 17058,
79 -1388, -1530, 18515, 17423, -1424, -1495, 18151, 17787, -1459, -1459, 17787, 18151, -1495,
80 -1424, 17423, 18515, -1530, -1388, 17058, 18878, -1564, -1353, 16694, 19239, -1599, -1317,
81 16329, 19600, -1633, -1282, 15965, 19959, -1667, -1246, 15602, 20317, -1700, -1211, 15239,
82 20673, -1732, -1176, 14877, 21027, -1764, -1141, 14516, 21380, -1795, -1107, 14156, 21729,
83 -1825, -1072, 13798, 22077, -1855, -1039, 13441, 22422, -1883, -1005, 13086, 22764, -1911,
84 -972, 12733, 23103, -1937, -939, 12382, 23438, -1962, -907, 12033, 23771, -1986, -875,
85 11686, 24100, -2009, -844, 11342, 24425, -2030, -813, 11000, 24746, -2049, -783, 10662,
86 25063, -2067, -753, 10326, 25375, -2084, -724, 9993, 25683, -2098, -696, 9663, 25987,
87 -2111, -668, 9336, 26285, -2121, -641, 9013, 26579, -2130, -614, 8694, 26867, -2136,
88 -588, 8378, 27151, -2141, -563, 8066, 27428, -2142, -538, 7758, 27700, -2142, -514,
89 7453, 27966, -2139, -490, 7153, 28226, -2133, -468, 6857, 28480, -2125, -445, 6565,
90 28727, -2114, -424, 6277, 28968, -2100, -403, 5994, 29203, -2083, -382, 5716, 29431,
91 -2063, -362, 5442, 29652, -2040, -343, 5172, 29866, -2014, -325, 4908, 30072, -1984,
92 -307, 4648, 30272, -1951, -289, 4393, 30464, -1914, -272, 4143, 30649, -1874, -256,
93 3897, 30826, -1830, -240, 3657, 30995, -1783, -224, 3422, 31157, -1732, -209, 3192,
94 31310, -1676, -194, 2967, 31456, -1617, -180, 2747, 31593, -1554, -167, 2532, 31723,
95 -1486, -153, 2322, 31844, -1414, -140, 2118, 31956, -1338, -128, 1919, 32061, -1258,
96 -115, 1724, 32157, -1173, -103, 1536, 32244, -1084, -92, 1352, 32323, -990, -80,
97 1174, 32393, -891, -69, 1000, 32454, -788, -58, 832, 32507, -680, -47, 669,
98 32551, -568, -36, 512, 32586, -450, -26, 359, 32613, -328, -15, 212, 32630,
99 -200, -5, 69, 32639, -68};
100
101constexpr std::array<s16, 512> curve_lut2{
102 3195, 26287, 3329, -32, 3064, 26281, 3467, -34, 2936, 26270, 3608, -38, 2811,
103 26253, 3751, -42, 2688, 26230, 3897, -46, 2568, 26202, 4046, -50, 2451, 26169,
104 4199, -54, 2338, 26130, 4354, -58, 2227, 26085, 4512, -63, 2120, 26035, 4673,
105 -67, 2015, 25980, 4837, -72, 1912, 25919, 5004, -76, 1813, 25852, 5174, -81,
106 1716, 25780, 5347, -87, 1622, 25704, 5522, -92, 1531, 25621, 5701, -98, 1442,
107 25533, 5882, -103, 1357, 25440, 6066, -109, 1274, 25342, 6253, -115, 1193, 25239,
108 6442, -121, 1115, 25131, 6635, -127, 1040, 25018, 6830, -133, 967, 24899, 7027,
109 -140, 897, 24776, 7227, -146, 829, 24648, 7430, -153, 764, 24516, 7635, -159,
110 701, 24379, 7842, -166, 641, 24237, 8052, -174, 583, 24091, 8264, -181, 526,
111 23940, 8478, -187, 472, 23785, 8695, -194, 420, 23626, 8914, -202, 371, 23462,
112 9135, -209, 324, 23295, 9358, -215, 279, 23123, 9583, -222, 236, 22948, 9809,
113 -230, 194, 22769, 10038, -237, 154, 22586, 10269, -243, 117, 22399, 10501, -250,
114 81, 22208, 10735, -258, 47, 22015, 10970, -265, 15, 21818, 11206, -271, -16,
115 21618, 11444, -277, -44, 21415, 11684, -283, -71, 21208, 11924, -290, -97, 20999,
116 12166, -296, -121, 20786, 12409, -302, -143, 20571, 12653, -306, -163, 20354, 12898,
117 -311, -183, 20134, 13143, -316, -201, 19911, 13389, -321, -218, 19686, 13635, -325,
118 -234, 19459, 13882, -328, -248, 19230, 14130, -332, -261, 18998, 14377, -335, -273,
119 18765, 14625, -337, -284, 18531, 14873, -339, -294, 18295, 15121, -341, -302, 18057,
120 15369, -341, -310, 17817, 15617, -341, -317, 17577, 15864, -340, -323, 17335, 16111,
121 -340, -328, 17092, 16357, -338, -332, 16848, 16603, -336, -336, 16603, 16848, -332,
122 -338, 16357, 17092, -328, -340, 16111, 17335, -323, -340, 15864, 17577, -317, -341,
123 15617, 17817, -310, -341, 15369, 18057, -302, -341, 15121, 18295, -294, -339, 14873,
124 18531, -284, -337, 14625, 18765, -273, -335, 14377, 18998, -261, -332, 14130, 19230,
125 -248, -328, 13882, 19459, -234, -325, 13635, 19686, -218, -321, 13389, 19911, -201,
126 -316, 13143, 20134, -183, -311, 12898, 20354, -163, -306, 12653, 20571, -143, -302,
127 12409, 20786, -121, -296, 12166, 20999, -97, -290, 11924, 21208, -71, -283, 11684,
128 21415, -44, -277, 11444, 21618, -16, -271, 11206, 21818, 15, -265, 10970, 22015,
129 47, -258, 10735, 22208, 81, -250, 10501, 22399, 117, -243, 10269, 22586, 154,
130 -237, 10038, 22769, 194, -230, 9809, 22948, 236, -222, 9583, 23123, 279, -215,
131 9358, 23295, 324, -209, 9135, 23462, 371, -202, 8914, 23626, 420, -194, 8695,
132 23785, 472, -187, 8478, 23940, 526, -181, 8264, 24091, 583, -174, 8052, 24237,
133 641, -166, 7842, 24379, 701, -159, 7635, 24516, 764, -153, 7430, 24648, 829,
134 -146, 7227, 24776, 897, -140, 7027, 24899, 967, -133, 6830, 25018, 1040, -127,
135 6635, 25131, 1115, -121, 6442, 25239, 1193, -115, 6253, 25342, 1274, -109, 6066,
136 25440, 1357, -103, 5882, 25533, 1442, -98, 5701, 25621, 1531, -92, 5522, 25704,
137 1622, -87, 5347, 25780, 1716, -81, 5174, 25852, 1813, -76, 5004, 25919, 1912,
138 -72, 4837, 25980, 2015, -67, 4673, 26035, 2120, -63, 4512, 26085, 2227, -58,
139 4354, 26130, 2338, -54, 4199, 26169, 2451, -50, 4046, 26202, 2568, -46, 3897,
140 26230, 2688, -42, 3751, 26253, 2811, -38, 3608, 26270, 2936, -34, 3467, 26281,
141 3064, -32, 3329, 26287, 3195};
142
143std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, double ratio) {
144 if (input.size() < 2)
145 return {};
146
147 if (ratio <= 0) {
148 LOG_ERROR(Audio, "Nonsensical interpolation ratio {}", ratio);
149 return input;
150 }
151
152 const s32 step{static_cast<s32>(ratio * 0x8000)};
153 const std::array<s16, 512>& lut = [step] {
154 if (step > 0xaaaa) {
155 return curve_lut0;
156 }
157 if (step <= 0x8000) {
158 return curve_lut1;
159 }
160 return curve_lut2;
161 }();
162
163 const std::size_t num_frames{input.size() / 2};
164
165 std::vector<s16> output;
166 output.reserve(static_cast<std::size_t>(static_cast<double>(input.size()) / ratio +
167 InterpolationState::taps));
168
169 for (std::size_t frame{}; frame < num_frames; ++frame) {
170 const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps};
171
172 std::rotate(state.history.begin(), state.history.end() - 1, state.history.end());
173 state.history[0][0] = input[frame * 2 + 0];
174 state.history[0][1] = input[frame * 2 + 1];
175
176 while (state.position <= 1.0) {
177 const s32 left{state.history[0][0] * lut[lut_index + 0] +
178 state.history[1][0] * lut[lut_index + 1] +
179 state.history[2][0] * lut[lut_index + 2] +
180 state.history[3][0] * lut[lut_index + 3]};
181 const s32 right{state.history[0][1] * lut[lut_index + 0] +
182 state.history[1][1] * lut[lut_index + 1] +
183 state.history[2][1] * lut[lut_index + 2] +
184 state.history[3][1] * lut[lut_index + 3]};
185 const s32 new_offset{state.fraction + step};
186
187 state.fraction = new_offset & 0x7fff;
188
189 output.emplace_back(static_cast<s16>(std::clamp(left >> 15, SHRT_MIN, SHRT_MAX)));
190 output.emplace_back(static_cast<s16>(std::clamp(right >> 15, SHRT_MIN, SHRT_MAX)));
191
192 state.position += ratio;
193 }
194 state.position -= 1.0;
195 }
196
197 return output;
198}
199
200void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size_t sample_count) {
201 const std::array<s16, 512>& lut = [pitch] {
202 if (pitch > 0xaaaa) {
203 return curve_lut0;
204 }
205 if (pitch <= 0x8000) {
206 return curve_lut1;
207 }
208 return curve_lut2;
209 }();
210
211 std::size_t index{};
212
213 for (std::size_t i = 0; i < sample_count; i++) {
214 const std::size_t lut_index{(static_cast<std::size_t>(fraction) >> 8) * 4};
215 const auto l0 = lut[lut_index + 0];
216 const auto l1 = lut[lut_index + 1];
217 const auto l2 = lut[lut_index + 2];
218 const auto l3 = lut[lut_index + 3];
219
220 const auto s0 = static_cast<s32>(input[index + 0]);
221 const auto s1 = static_cast<s32>(input[index + 1]);
222 const auto s2 = static_cast<s32>(input[index + 2]);
223 const auto s3 = static_cast<s32>(input[index + 3]);
224
225 output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15;
226 fraction += pitch;
227 index += (fraction >> 15);
228 fraction &= 0x7fff;
229 }
230}
231
232} // namespace AudioCore
diff --git a/src/audio_core/algorithm/interpolate.h b/src/audio_core/algorithm/interpolate.h
deleted file mode 100644
index 5e59f4d70..000000000
--- a/src/audio_core/algorithm/interpolate.h
+++ /dev/null
@@ -1,43 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7#include <vector>
8
9#include "common/common_types.h"
10
11namespace AudioCore {
12
13struct InterpolationState {
14 static constexpr std::size_t taps{4};
15 static constexpr std::size_t history_size{taps * 2 - 1};
16 std::array<std::array<s16, 2>, history_size> history{};
17 double position{};
18 s32 fraction{};
19};
20
21/// Interpolates input signal to produce output signal.
22/// @param input The signal to interpolate.
23/// @param ratio Interpolation ratio.
24/// ratio > 1.0 results in fewer output samples.
25/// ratio < 1.0 results in more output samples.
26/// @returns Output signal.
27std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, double ratio);
28
29/// Interpolates input signal to produce output signal.
30/// @param input The signal to interpolate.
31/// @param input_rate The sample rate of input.
32/// @param output_rate The desired sample rate of the output.
33/// @returns Output signal.
34inline std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
35 u32 input_rate, u32 output_rate) {
36 const double ratio = static_cast<double>(input_rate) / static_cast<double>(output_rate);
37 return Interpolate(state, std::move(input), ratio);
38}
39
40/// Nintendo Switchs DSP resampling algorithm. Based on a single channel
41void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size_t sample_count);
42
43} // namespace AudioCore