diff options
author | bunnei <bunneidev@gmail.com> | 2016-03-31 02:17:52 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2016-03-31 02:17:52 +0200 |
commit | 644fbbeb13db8147ce74cfbde80f62ee492c201a (patch) | |
tree | 0c9e5ee0a8e9bb98cc2df13d5584f756c7cfeea2 /src/audio_core/hle/filter.h | |
parent | Merge pull request #1611 from ObsidianX/cfg-common-fix (diff) | |
parent | DSP: Implement audio filters (simple, biquad) (diff) | |
download | yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar.gz yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar.bz2 yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar.lz yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar.xz yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.tar.zst yuzu-644fbbeb13db8147ce74cfbde80f62ee492c201a.zip |
Diffstat (limited to 'src/audio_core/hle/filter.h')
-rw-r--r-- | src/audio_core/hle/filter.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/audio_core/hle/filter.h b/src/audio_core/hle/filter.h new file mode 100644 index 000000000..75738f600 --- /dev/null +++ b/src/audio_core/hle/filter.h @@ -0,0 +1,112 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> + +#include "audio_core/hle/common.h" +#include "audio_core/hle/dsp.h" + +#include "common/common_types.h" + +namespace DSP { +namespace HLE { + +/// Preprocessing filters. There is an independent set of filters for each Source. +class SourceFilters final { + SourceFilters() { Reset(); } + + /// Reset internal state. + void Reset(); + + /** + * Enable/Disable filters + * See also: SourceConfiguration::Configuration::simple_filter_enabled, + * SourceConfiguration::Configuration::biquad_filter_enabled. + * @param simple If true, enables the simple filter. If false, disables it. + * @param simple If true, enables the biquad filter. If false, disables it. + */ + void Enable(bool simple, bool biquad); + + /** + * Configure simple filter. + * @param config Configuration from DSP shared memory. + */ + void Configure(SourceConfiguration::Configuration::SimpleFilter config); + + /** + * Configure biquad filter. + * @param config Configuration from DSP shared memory. + */ + void Configure(SourceConfiguration::Configuration::BiquadFilter config); + + /** + * Processes a frame in-place. + * @param frame Audio samples to process. Modified in-place. + */ + void ProcessFrame(StereoFrame16& frame); + +private: + bool simple_filter_enabled; + bool biquad_filter_enabled; + + struct SimpleFilter { + SimpleFilter() { Reset(); } + + /// Resets internal state. + void Reset(); + + /** + * Configures this filter with application settings. + * @param config Configuration from DSP shared memory. + */ + void Configure(SourceConfiguration::Configuration::SimpleFilter config); + + /** + * Processes a single stereo PCM16 sample. + * @param x0 Input sample + * @return Output sample + */ + std::array<s16, 2> ProcessSample(const std::array<s16, 2>& x0); + + private: + // Configuration + s32 a1, b0; + // Internal state + std::array<s16, 2> y1; + } simple_filter; + + struct BiquadFilter { + BiquadFilter() { Reset(); } + + /// Resets internal state. + void Reset(); + + /** + * Configures this filter with application settings. + * @param config Configuration from DSP shared memory. + */ + void Configure(SourceConfiguration::Configuration::BiquadFilter config); + + /** + * Processes a single stereo PCM16 sample. + * @param x0 Input sample + * @return Output sample + */ + std::array<s16, 2> ProcessSample(const std::array<s16, 2>& x0); + + private: + // Configuration + s32 a1, a2, b0, b1, b2; + // Internal state + std::array<s16, 2> x1; + std::array<s16, 2> x2; + std::array<s16, 2> y1; + std::array<s16, 2> y2; + } biquad_filter; +}; + +} // namespace HLE +} // namespace DSP |