diff options
author | MerryMage <MerryMage@users.noreply.github.com> | 2018-08-12 20:32:16 +0200 |
---|---|---|
committer | MerryMage <MerryMage@users.noreply.github.com> | 2018-08-13 12:26:50 +0200 |
commit | 56300f2928a4eb982cf686f9e920d6e1e3b59356 (patch) | |
tree | 7e4e84a417622be69ed6af3a716df88e9a2b9584 /src/audio_core/algorithm/filter.h | |
parent | Merge pull request #1028 from ogniK5377/aoa (diff) | |
download | yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar.gz yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar.bz2 yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar.lz yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar.xz yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.tar.zst yuzu-56300f2928a4eb982cf686f9e920d6e1e3b59356.zip |
Diffstat (limited to 'src/audio_core/algorithm/filter.h')
-rw-r--r-- | src/audio_core/algorithm/filter.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/audio_core/algorithm/filter.h b/src/audio_core/algorithm/filter.h new file mode 100644 index 000000000..a41beef98 --- /dev/null +++ b/src/audio_core/algorithm/filter.h @@ -0,0 +1,62 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> +#include <vector> +#include "common/common_types.h" + +namespace AudioCore { + +/// Digital biquad filter: +/// +/// b0 + b1 z^-1 + b2 z^-2 +/// H(z) = ------------------------ +/// a0 + a1 z^-1 + b2 z^-2 +class Filter { +public: + /// Creates a low-pass filter. + /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0. + /// @param Q Determines the quality factor of this filter. + static Filter LowPass(double cutoff, double Q = 0.7071); + + /// Passthrough filter. + Filter(); + + Filter(double a0, double a1, double a2, double b0, double b1, double b2); + + void Process(std::vector<s16>& signal); + +private: + static constexpr size_t channel_count = 2; + + /// Coefficients are in normalized form (a0 = 1.0). + double a1, a2, b0, b1, b2; + /// Input History + std::array<std::array<double, channel_count>, 3> in; + /// Output History + std::array<std::array<double, channel_count>, 3> out; +}; + +/// Cascade filters to build up higher-order filters from lower-order ones. +class CascadingFilter { +public: + /// Creates a cascading low-pass filter. + /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0. + /// @param cascade_size Number of biquads in cascade. + static CascadingFilter LowPass(double cutoff, size_t cascade_size); + + /// Passthrough. + CascadingFilter(); + + explicit CascadingFilter(std::vector<Filter> filters); + + void Process(std::vector<s16>& signal); + +private: + std::vector<Filter> filters; +}; + +} // namespace AudioCore |