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 /templates/3_fir.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 'templates/3_fir.cpp')
-rw-r--r-- | templates/3_fir.cpp | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/templates/3_fir.cpp b/templates/3_fir.cpp deleted file mode 100644 index 3a68500..0000000 --- a/templates/3_fir.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 3_fir.cpp - * Written by Clyne Sullivan. - * - * The below code was written for applying FIR filters. While this is still essentially an overlap- - * save convolution, other optimizations have been made to allow for larger filters to be applied - * within the available execution time. Samples are also normalized so that they center around zero. - */ - -Sample *process_data(Samples samples) -{ - static Sample buffer[samples.size()]; - - // Define the filter: - constexpr unsigned int filter_size = 3; - static float filter[filter_size] = { - // Put filter values here (note: precision will be truncated for 'float' size). - 0.3333, 0.3333, 0.3333 - }; - - // Do an overlap-save convolution - static Sample prev[filter_size]; - - for (int n = 0; n < samples.size(); n++) { - // Using a float variable for accumulation allows for better code optimization - float v = 0; - - for (int k = 0; k < filter_size; k++) { - int i = n - (filter_size - 1) + k; - - auto s = i >= 0 ? samples[i] : prev[filter_size - 1 + i]; - // Sample values are 0 to 4095. Below, the original sample is normalized to a -1.0 to - // 1.0 range for calculation. - v += (s / 2048.f - 1) * filter[k]; - } - - // Return value to sample range of 0-4095. - buffer[n] = (v + 1) * 2048.f; - } - - // Save samples for next convolution - for (int i = 0; i < filter_size; i++) - prev[i] = samples[samples.size() - filter_size + i]; - - return buffer; -} - |