aboutsummaryrefslogtreecommitdiffstats
path: root/gui/templates/1_convolve_simple.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-10-19 21:01:53 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-10-19 21:01:53 -0400
commitf1ad9796741daa8368f4885bbce360522df24367 (patch)
tree48416337fd661d8a12e90d2d7d8fb6dbbc6aa83b /gui/templates/1_convolve_simple.cpp
parent241a089c39c77345e8e0a0c8a04301ba2271e432 (diff)
gui improvements; code templates
Diffstat (limited to 'gui/templates/1_convolve_simple.cpp')
-rw-r--r--gui/templates/1_convolve_simple.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/gui/templates/1_convolve_simple.cpp b/gui/templates/1_convolve_simple.cpp
new file mode 100644
index 0000000..0f1973d
--- /dev/null
+++ b/gui/templates/1_convolve_simple.cpp
@@ -0,0 +1,29 @@
+/**
+ * 1_convolve_simple.cpp
+ * Written by Clyne Sullivan.
+ *
+ * Computes a convolution in the simplest way possible. While the code is brief, it lacks many
+ * possible optimizations. The convolution's result will not fill the output buffer either, as the
+ * transient response is not calculated.
+ */
+
+adcsample_t *process_data(adcsample_t *samples, unsigned int size)
+{
+ // Define our output buffer. SIZE is the largest size of the 'samples' buffer.
+ static adcsample_t buffer[SIZE];
+
+ // Define our filter
+ constexpr unsigned int filter_size = 3;
+ float filter[filter_size] = {
+ 0.3333, 0.3333, 0.3333
+ };
+
+ // Begin convolving:
+ for (int n = 0; n < size - (filter_size - 1); n++) {
+ buffer[n] = 0;
+ for (int k = 0; k < filter_size; k++)
+ buffer[n] += samples[n + k] * filter[k];
+ }
+
+ return buffer;
+}