diff options
author | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
---|---|---|
committer | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
commit | 5902a67796000c7546d07fa778b26619c4588c3a (patch) | |
tree | 1c1fa04635a3c248d07fde4dce8857885ca23952 /examples/7_iir_echo.cpp | |
parent | 1cf4908a23dc5537be0bab1089ffcaa7079d5434 (diff) | |
parent | dff847ff4455e7b8c5123167a7d01afe7c45f585 (diff) |
Merge pull request 'devel: Ready for pre-release' (#1) from devel into masterv0.1
Reviewed-on: https://code.bitgloo.com/clyne/stmdspgui/pulls/1
Diffstat (limited to 'examples/7_iir_echo.cpp')
-rw-r--r-- | examples/7_iir_echo.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/7_iir_echo.cpp b/examples/7_iir_echo.cpp new file mode 100644 index 0000000..75bf56e --- /dev/null +++ b/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; +} |