diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-05-22 13:37:49 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-05-22 13:37:49 -0400 |
commit | f211f9628854b417000192c59d6ab22b946119b1 (patch) | |
tree | 9cd7ae6cb2a6598b056087389e0497026ad9d4c5 /examples/7_iir_echo.cpp | |
parent | 660d967ec0ac79ea2a43946be4c056ef2d21ffc4 (diff) |
make helper funcs inline; drop std::span for algo
Diffstat (limited to 'examples/7_iir_echo.cpp')
-rw-r--r-- | examples/7_iir_echo.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/examples/7_iir_echo.cpp b/examples/7_iir_echo.cpp index 57e5605..75bf56e 100644 --- a/examples/7_iir_echo.cpp +++ b/examples/7_iir_echo.cpp @@ -1,9 +1,17 @@ -Sample *process_data(Samples samples) +/** + * 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 Sample output[samples.size()]; + static Samples output; static Sample prev[D]; // prev[0] = output[0 - D] // Do calculations with previous output @@ -11,12 +19,12 @@ Sample *process_data(Samples samples) output[i] = samples[i] + alpha * (prev[i] - 2048); // Do calculations with current samples - for (unsigned int i = D; i < samples.size(); i++) + 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[samples.size() - (D - i)]; + prev[i] = output[SIZE - (D - i)]; return output; } |