From f440728644ad3698ffd6af1abcfcc07aad5793c3 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 8 Aug 2023 23:10:02 -0400 Subject: initial commit * combine all source files into this monorepo * convert all third-party source packages into submodules * small fixes due to changes in latest third-part packages --- gui/examples/7_iir_echo.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 gui/examples/7_iir_echo.cpp (limited to 'gui/examples/7_iir_echo.cpp') diff --git a/gui/examples/7_iir_echo.cpp b/gui/examples/7_iir_echo.cpp new file mode 100644 index 0000000..75bf56e --- /dev/null +++ b/gui/examples/7_iir_echo.cpp @@ -0,0 +1,30 @@ +/** + * 7_iir_echo.cpp + * Written by Clyne Sullivan. + * + * This filter produces an echo of the given input. There are two parameters: + * alpha controls the feedback gain, and D controls the echo/delay length. + */ + +Sample* process_data(Samples samples) +{ + constexpr float alpha = 0.75; + constexpr unsigned int D = 100; + + static Samples output; + static Sample prev[D]; // prev[0] = output[0 - D] + + // Do calculations with previous output + for (unsigned int i = 0; i < D; i++) + output[i] = samples[i] + alpha * (prev[i] - 2048); + + // Do calculations with current samples + for (unsigned int i = D; i < SIZE; i++) + output[i] = samples[i] + alpha * (output[i - D] - 2048); + + // Save outputs for next computation + for (unsigned int i = 0; i < D; i++) + prev[i] = output[SIZE - (D - i)]; + + return output; +} -- cgit v1.2.3