Voss Connection Detection  1
Detect a connector click using realtime code on Bela hardware
filter.cpp
Go to the documentation of this file.
1 #include "filter.h"
2 #include "Bela.h"
3 #include <libraries/math_neon/math_neon.h>
4 #include <libraries/Biquad/QuadBiquad.h>
5 
6 const float sq2 = sqrtf_neon(2.0f);
7 
8 Filter::Filter(const float fs) {
9 
10  /* Initialize Biquad filters for each signal. */
11  /* ******** High-pass filter for microphones */
12  Biquad::Settings hp8k_mic_settings{
13  .fs = fs,
14  .type = Biquad::highpass,
15  .cutoff = MIC_HP_CUTON8k,
16  .q = sq2,
17  .peakGainDb = 0.0f,
18  };
19  Biquad::Settings lp_mic_settings{
20  .fs = fs,
21  .type = Biquad::lowpass,
22  .cutoff = MIC_LP_CUTOFF,
23  .q = sq2,
24  .peakGainDb = 0.0f,
25  };
26 
27  Biquad::Settings hp_acc_settings {
28  .fs = fs,
29  .type = Biquad::highpass,
30  .cutoff = ACC_HP_CUTON,
31  .q = sq2,
32  .peakGainDb = 0.0f,
33  };
34  Biquad::Settings lp_acc_settings{
35  .fs = fs,
36  .type = Biquad::lowpass,
37  .cutoff = ACC_LP_CUTOFF,
38  .q = sq2,
39  .peakGainDb = 0.0f,
40  };
41  Biquad::Settings hp2k_mic_settings{
42  .fs = fs,
43  .type = Biquad::highpass,
44  .cutoff = MIC_HP_CUTON2k,
45  .q = sq2,
46  .peakGainDb = 0.0f,
47  };
48 
49  Biquad::Settings imu_accelerometer_hp_settings{
50  .fs = fs,
51  .type = Biquad::highpass,
52  .cutoff = IMU_ACC_CUTON,
53  .q = sq2,
54  .peakGainDb = 0.0f,
55  };
56 
57  BiquadCoeffT<float> hp8k_mic_coefs(hp8k_mic_settings);
58  BiquadCoeffT<float> hp2k_mic_coefs(hp2k_mic_settings);
59  BiquadCoeffT<float> lp_mic_coefs(lp_mic_settings);
60  BiquadCoeffT<float> hp_acc_coefs(hp_acc_settings);
61  BiquadCoeffT<float> lp_acc_coefs(lp_acc_settings);
62  BiquadCoeffT<float> imu_accelerometer_hp_coefs(
63  imu_accelerometer_hp_settings);
64 
65  _filters1= new QuadBiquad();
66  _filters2= new QuadBiquad();
67  _filters3= new QuadBiquad();
68 
69  _filters1->filters.at(0) = hp8k_mic_coefs;
70  _filters1->filters.at(1) = hp8k_mic_coefs;
71 
72  /* ******** Low-pass filter for microphones */
73  _filters1->filters.at(2) = lp_mic_coefs;
74  _filters1->filters.at(3) = lp_mic_coefs;
75 
76  /* ******** High-pass and lowpass filters for VPU */
77  _filters2->filters.at(0) = hp_acc_coefs;
78  _filters2->filters.at(1) = lp_acc_coefs;
79 
80  /* ******** High-pass 2k filters for mics */
81  _filters2->filters.at(2) = hp2k_mic_coefs;
82  _filters2->filters.at(3) = hp2k_mic_coefs;
83 
84  /* IMU accelerometer high-pass */
85  _filters3->filters.at(0) = imu_accelerometer_hp_coefs;
86 
87  _filters1->update();
88  _filters2->update();
89  _filters3->update();
90 }
91 void Filter::filter(const RawFrame& rawframe,FilteredFrame& filteredframe) {
92 
97  float filters1_inout[] = {
98  // Mic samples for the 8k high-pass filter
99  rawframe[RAW_MICT],
100  rawframe[RAW_MICW],
101  // Mic samples for the 500 Hz low-pass filter
102  rawframe[RAW_MICT],
103  rawframe[RAW_MICW],
104  };
105  float filters2_inout[] = {
106  // High-pass filter 2 kHz for VPU
107  rawframe[RAW_VPU],
108  // Low-pass filter 500 Hz for VPU
109  rawframe[RAW_VPU],
110 
111  // High-pass filter 2 kHz for mic
112  rawframe[RAW_MICT],
113  rawframe[RAW_MICW]
114  };
115  float filters3_inout[] = {
116  // High-pass the IMU acceleration value.
117  rawframe[RAW_IMU_ACC],
118  0,
119  0,
120  0,
121  };
122 
124  _filters1->process(filters1_inout);
125  _filters2->process(filters2_inout);
126  _filters3->process(filters3_inout);
127 
128  filteredframe[FILT_RAW_MICT] = rawframe[RAW_MICT];
129  filteredframe[FILT_RAW_MICW] = rawframe[RAW_MICW];
130  filteredframe[FILT_RAW_VPU] = rawframe[RAW_VPU];
131 
132  filteredframe[FILT_HP8k_MICT] = filters1_inout[0];
133  filteredframe[FILT_HP8k_MICW] = filters1_inout[1];
134 
135  filteredframe[FILT_LP500_MICT] = filters1_inout[2];
136  filteredframe[FILT_LP500_MICW] = filters1_inout[3];
137 
138  filteredframe[FILT_HP2k_VPU] = filters2_inout[0];
139  filteredframe[FILT_LP500_VPU] = filters2_inout[1];
140 
141  filteredframe[FILT_HP2k_MICT] = filters2_inout[2];
142  /* filteredframe[FILT_HP2k_MICW] = filters2_inout[3]; */
143 
144  filteredframe[FILT_PEDAL] = rawframe[RAW_PEDAL];
145  filteredframe[FILT_IMU_ROT] = rawframe[RAW_IMU_ROT];
146  filteredframe[FILT_HP_IMU_ACC] = filters3_inout[0];
147 
148 }
150  delete _filters1;
151  delete _filters2;
152  delete _filters3;
153 }
FILT_HP2k_VPU
const us FILT_HP2k_VPU
Definition: filter.h:88
filter.h
ACC_HP_CUTON
const float ACC_HP_CUTON
The cut-on frequency of the high-pass filter for accelerometer data.
Definition: config.h:124
RAW_MICW
const us RAW_MICW
Definition: filter.h:41
FILT_IMU_ROT
const us FILT_IMU_ROT
Definition: filter.h:91
RAW_MICT
const us RAW_MICT
The number of channels of raw data coming from the sensors. This is currently set to 6....
Definition: filter.h:40
FILT_LP500_MICW
const us FILT_LP500_MICW
Definition: filter.h:85
Filter::~Filter
~Filter()
Definition: filter.cpp:149
FILT_RAW_MICT
const us FILT_RAW_MICT
The number of buffers that require some processing. This is not equal to the number of sensors,...
Definition: filter.h:78
RawFrame
array< float, NUMBER_RAW_CHANNELS > RawFrame
An array containing data for a raw frame.
Definition: filter.h:50
FILT_HP8k_MICT
const us FILT_HP8k_MICT
Definition: filter.h:79
FILT_RAW_MICW
const us FILT_RAW_MICW
Definition: filter.h:83
IMU_ACC_CUTON
const float IMU_ACC_CUTON
Cut-on frequency of the high-pass for the IMU accelerometer.
Definition: config.h:130
FILT_LP500_MICT
const us FILT_LP500_MICT
Definition: filter.h:81
ACC_LP_CUTOFF
const float ACC_LP_CUTOFF
Definition: config.h:125
MIC_HP_CUTON2k
const float MIC_HP_CUTON2k
The cut-on frequency of the microphone 2kHz high-pass filter.
Definition: config.h:115
FilteredFrame
array< float, NUMBER_FILTERED_CHANNELS > FilteredFrame
An array containing data with length corresponding to a single processed frame. Its length correspond...
Definition: filter.h:102
RAW_PEDAL
const us RAW_PEDAL
Definition: filter.h:45
RAW_IMU_ROT
const us RAW_IMU_ROT
Definition: filter.h:43
MIC_LP_CUTOFF
const float MIC_LP_CUTOFF
The cut-off frequency of the microphone low-pass filter.
Definition: config.h:119
FILT_PEDAL
const us FILT_PEDAL
Definition: filter.h:93
RAW_IMU_ACC
const us RAW_IMU_ACC
Definition: filter.h:44
FILT_RAW_VPU
const us FILT_RAW_VPU
Definition: filter.h:87
Filter::Filter
Filter(const float fs)
Definition: filter.cpp:8
FILT_HP_IMU_ACC
const us FILT_HP_IMU_ACC
Definition: filter.h:92
RAW_VPU
const us RAW_VPU
Definition: filter.h:42
sq2
const float sq2
Definition: filter.cpp:6
FILT_LP500_VPU
const us FILT_LP500_VPU
Definition: filter.h:89
FILT_HP8k_MICW
const us FILT_HP8k_MICW
Definition: filter.h:84
FILT_HP2k_MICT
const us FILT_HP2k_MICT
Definition: filter.h:80
MIC_HP_CUTON8k
const float MIC_HP_CUTON8k
The cut-on frequency of the microphone 8kHz high-pass filter.
Definition: config.h:111
Filter::filter
void filter(const RawFrame &rawframe, FilteredFrame &filteredframe)
Filter a single raw frame to obtain a filtered frame.
Definition: filter.cpp:91