summaryrefslogtreecommitdiff
path: root/src/audio_core/algorithm
diff options
context:
space:
mode:
authorGravatar raven022018-09-19 19:53:11 +0800
committerGravatar GitHub2018-09-19 19:53:11 +0800
commitc8f9bbbf859c0e38cf691b64c67761382fcebfc2 (patch)
tree99529c2277a6b740a6e278985c5147fa649c5497 /src/audio_core/algorithm
parentAdd 1D sampler for TLDS - TexelFetch (Mario Rabbids) (diff)
parentMerge pull request #1348 from ogniK5377/GetImageSize (diff)
downloadyuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.gz
yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.xz
yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.zip
Merge branch 'master' into tlds
Diffstat (limited to 'src/audio_core/algorithm')
-rw-r--r--src/audio_core/algorithm/filter.cpp12
-rw-r--r--src/audio_core/algorithm/filter.h4
-rw-r--r--src/audio_core/algorithm/interpolate.cpp12
-rw-r--r--src/audio_core/algorithm/interpolate.h4
4 files changed, 16 insertions, 16 deletions
diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp
index 9fcd0614d..f65bf64f7 100644
--- a/src/audio_core/algorithm/filter.cpp
+++ b/src/audio_core/algorithm/filter.cpp
@@ -35,12 +35,12 @@ Filter::Filter(double a0, double a1, double a2, double b0, double b1, double b2)
35 : a1(a1 / a0), a2(a2 / a0), b0(b0 / a0), b1(b1 / a0), b2(b2 / a0) {} 35 : a1(a1 / a0), a2(a2 / a0), b0(b0 / a0), b1(b1 / a0), b2(b2 / a0) {}
36 36
37void Filter::Process(std::vector<s16>& signal) { 37void Filter::Process(std::vector<s16>& signal) {
38 const size_t num_frames = signal.size() / 2; 38 const std::size_t num_frames = signal.size() / 2;
39 for (size_t i = 0; i < num_frames; i++) { 39 for (std::size_t i = 0; i < num_frames; i++) {
40 std::rotate(in.begin(), in.end() - 1, in.end()); 40 std::rotate(in.begin(), in.end() - 1, in.end());
41 std::rotate(out.begin(), out.end() - 1, out.end()); 41 std::rotate(out.begin(), out.end() - 1, out.end());
42 42
43 for (size_t ch = 0; ch < channel_count; ch++) { 43 for (std::size_t ch = 0; ch < channel_count; ch++) {
44 in[0][ch] = signal[i * channel_count + ch]; 44 in[0][ch] = signal[i * channel_count + ch];
45 45
46 out[0][ch] = b0 * in[0][ch] + b1 * in[1][ch] + b2 * in[2][ch] - a1 * out[1][ch] - 46 out[0][ch] = b0 * in[0][ch] + b1 * in[1][ch] + b2 * in[2][ch] - a1 * out[1][ch] -
@@ -54,14 +54,14 @@ void Filter::Process(std::vector<s16>& signal) {
54/// Calculates the appropriate Q for each biquad in a cascading filter. 54/// Calculates the appropriate Q for each biquad in a cascading filter.
55/// @param total_count The total number of biquads to be cascaded. 55/// @param total_count The total number of biquads to be cascaded.
56/// @param index 0-index of the biquad to calculate the Q value for. 56/// @param index 0-index of the biquad to calculate the Q value for.
57static double CascadingBiquadQ(size_t total_count, size_t index) { 57static double CascadingBiquadQ(std::size_t total_count, std::size_t index) {
58 const double pole = M_PI * (2 * index + 1) / (4.0 * total_count); 58 const double pole = M_PI * (2 * index + 1) / (4.0 * total_count);
59 return 1.0 / (2.0 * std::cos(pole)); 59 return 1.0 / (2.0 * std::cos(pole));
60} 60}
61 61
62CascadingFilter CascadingFilter::LowPass(double cutoff, size_t cascade_size) { 62CascadingFilter CascadingFilter::LowPass(double cutoff, std::size_t cascade_size) {
63 std::vector<Filter> cascade(cascade_size); 63 std::vector<Filter> cascade(cascade_size);
64 for (size_t i = 0; i < cascade_size; i++) { 64 for (std::size_t i = 0; i < cascade_size; i++) {
65 cascade[i] = Filter::LowPass(cutoff, CascadingBiquadQ(cascade_size, i)); 65 cascade[i] = Filter::LowPass(cutoff, CascadingBiquadQ(cascade_size, i));
66 } 66 }
67 return CascadingFilter{std::move(cascade)}; 67 return CascadingFilter{std::move(cascade)};
diff --git a/src/audio_core/algorithm/filter.h b/src/audio_core/algorithm/filter.h
index a41beef98..3546d149b 100644
--- a/src/audio_core/algorithm/filter.h
+++ b/src/audio_core/algorithm/filter.h
@@ -30,7 +30,7 @@ public:
30 void Process(std::vector<s16>& signal); 30 void Process(std::vector<s16>& signal);
31 31
32private: 32private:
33 static constexpr size_t channel_count = 2; 33 static constexpr std::size_t channel_count = 2;
34 34
35 /// Coefficients are in normalized form (a0 = 1.0). 35 /// Coefficients are in normalized form (a0 = 1.0).
36 double a1, a2, b0, b1, b2; 36 double a1, a2, b0, b1, b2;
@@ -46,7 +46,7 @@ public:
46 /// Creates a cascading low-pass filter. 46 /// Creates a cascading low-pass filter.
47 /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0. 47 /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0.
48 /// @param cascade_size Number of biquads in cascade. 48 /// @param cascade_size Number of biquads in cascade.
49 static CascadingFilter LowPass(double cutoff, size_t cascade_size); 49 static CascadingFilter LowPass(double cutoff, std::size_t cascade_size);
50 50
51 /// Passthrough. 51 /// Passthrough.
52 CascadingFilter(); 52 CascadingFilter();
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp
index 11459821f..3aea9b0f2 100644
--- a/src/audio_core/algorithm/interpolate.cpp
+++ b/src/audio_core/algorithm/interpolate.cpp
@@ -14,7 +14,7 @@
14namespace AudioCore { 14namespace AudioCore {
15 15
16/// The Lanczos kernel 16/// The Lanczos kernel
17static double Lanczos(size_t a, double x) { 17static double Lanczos(std::size_t a, double x) {
18 if (x == 0.0) 18 if (x == 0.0)
19 return 1.0; 19 return 1.0;
20 const double px = M_PI * x; 20 const double px = M_PI * x;
@@ -37,15 +37,15 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
37 } 37 }
38 state.nyquist.Process(input); 38 state.nyquist.Process(input);
39 39
40 constexpr size_t taps = InterpolationState::lanczos_taps; 40 constexpr std::size_t taps = InterpolationState::lanczos_taps;
41 const size_t num_frames = input.size() / 2; 41 const std::size_t num_frames = input.size() / 2;
42 42
43 std::vector<s16> output; 43 std::vector<s16> output;
44 output.reserve(static_cast<size_t>(input.size() / ratio + 4)); 44 output.reserve(static_cast<std::size_t>(input.size() / ratio + 4));
45 45
46 double& pos = state.position; 46 double& pos = state.position;
47 auto& h = state.history; 47 auto& h = state.history;
48 for (size_t i = 0; i < num_frames; ++i) { 48 for (std::size_t i = 0; i < num_frames; ++i) {
49 std::rotate(h.begin(), h.end() - 1, h.end()); 49 std::rotate(h.begin(), h.end() - 1, h.end());
50 h[0][0] = input[i * 2 + 0]; 50 h[0][0] = input[i * 2 + 0];
51 h[0][1] = input[i * 2 + 1]; 51 h[0][1] = input[i * 2 + 1];
@@ -53,7 +53,7 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
53 while (pos <= 1.0) { 53 while (pos <= 1.0) {
54 double l = 0.0; 54 double l = 0.0;
55 double r = 0.0; 55 double r = 0.0;
56 for (size_t j = 0; j < h.size(); j++) { 56 for (std::size_t j = 0; j < h.size(); j++) {
57 l += Lanczos(taps, pos + j - taps + 1) * h[j][0]; 57 l += Lanczos(taps, pos + j - taps + 1) * h[j][0];
58 r += Lanczos(taps, pos + j - taps + 1) * h[j][1]; 58 r += Lanczos(taps, pos + j - taps + 1) * h[j][1];
59 } 59 }
diff --git a/src/audio_core/algorithm/interpolate.h b/src/audio_core/algorithm/interpolate.h
index c79c2eef4..edbd6460f 100644
--- a/src/audio_core/algorithm/interpolate.h
+++ b/src/audio_core/algorithm/interpolate.h
@@ -12,8 +12,8 @@
12namespace AudioCore { 12namespace AudioCore {
13 13
14struct InterpolationState { 14struct InterpolationState {
15 static constexpr size_t lanczos_taps = 4; 15 static constexpr std::size_t lanczos_taps = 4;
16 static constexpr size_t history_size = lanczos_taps * 2 - 1; 16 static constexpr std::size_t history_size = lanczos_taps * 2 - 1;
17 17
18 double current_ratio = 0.0; 18 double current_ratio = 0.0;
19 CascadingFilter nyquist; 19 CascadingFilter nyquist;