Voss Connection Detection  1
Detect a connector click using realtime code on Bela hardware
conndetect.h
Go to the documentation of this file.
1 
4 #pragma once
5 #include "config.h"
6 #include "buffer.h"
7 #include <Bela.h>
8 #include <cmath>
9 
10 class Features;
11 class Classifier;
12 class TimeDelay;
13 
14 template <us ncols> class LogFile;
15 class Gui;
16 
17 
32 enum class FeatureType: int {
39 
41 
44  WAMP_MICT,
45  TM3_MICT,
46  ZC_MICT,
47 
50  WAMP_MICW,
51  TM3_MICW,
52  ZC_MICW,
53 
55  WAMP_VPU,
56  TM3_VPU,
57  ZC_VPU,
58 
60 
61  AVG_IMU_ABS_ROT, // Average value of the IMU rotation speed vector length
62  MAX_IMU_ABS_HP_ACC, // Maximum value of the high-pass filtered
63  // accelerometer vector length
64 
65  PEDAL,
66  CLASS,
68 };
74 const char* const logFileHeader = "HP_8k_PEAKdB_MICT, HP_8k_PEAKdB_MICW, LP_500_PEAKdB_MICT, LP_500_PEAKdB_MICW, HP_2k_PEAKdB_VPU, LP_500_PEAKdB_VPU, HP_2k_PEAKFREQ_MICT, KURTOSIS_MICT, INVERSE_FREQ_VARIANCE_MICT, WAMP_MICT, TM3_MICT, ZC_MICT, KURTOSIS_MICW, INVERSE_FREQ_VARIANCE_MICW, WAMP_MICW, TM3_MICW, ZC_MICW, KURTOSIS_VPU, WAMP_VPU, TM3_VPU, ZC_VPU, TIMEDELAY_MICW_MICT, AVG_IMU_ABS_ROT, MAX_IMU_ABS_HP_ACC, PEDAL, CLASS";
75 
77 
78 typedef std::array<float, (us) NUMBER_FEATURES> ComputedFeatures;
79 
83 class ConnDetect {
84 
85  LogFile<NUMBER_FEATURES> *_logfile = nullptr;
86  FilteredDataBuffer *_bufs[2];
87  bool _connDetected = false;
88  AuxiliaryTask _detect_task;
89  Features* _features;
90  Classifier* _classifier;
91  TimeDelay* _timedelay;
92 
93  friend void raw_conndetect_auxtask_callback(void *);
94 
99  public:
106  bool connectionDetected();
107 
116  ConnDetect(BelaContext *context);
117  ~ConnDetect();
123  void addFilteredFrame(const FilteredFrame &filteredframe);
124 
125  private:
129  void auxTaskCallback();
137  void processFullBuffer(const FilteredData& data);
138 
139 };
140 
logFileHeader
const char *const logFileHeader
Please be VERY SURE to keep this in sync with the list above, otherwise LARGE MISTAKES will be made.
Definition: conndetect.h:74
ConnDetect::ConnDetect
ConnDetect(BelaContext *context)
Initalize the connection detector.
Definition: conndetect.cpp:68
ConnDetect::addFilteredFrame
void addFilteredFrame(const FilteredFrame &filteredframe)
Add a new filtered frame of data to the buffer the detector.
Definition: conndetect.cpp:101
FeatureType::TM3_MICW
@ TM3_MICW
FeatureType::ZC_MICW
@ ZC_MICW
NUMBER_FEATURES
const us NUMBER_FEATURES
Definition: conndetect.h:76
FeatureType::KURTOSIS_VPU
@ KURTOSIS_VPU
ConnDetect::connectionDetected
bool connectionDetected()
The write task.
Definition: conndetect.cpp:120
FeatureType
FeatureType
These are the features extracted from the filtered data. They should be self-explaining regarding the...
Definition: conndetect.h:32
FeatureType::MAX_IMU_ABS_HP_ACC
@ MAX_IMU_ABS_HP_ACC
FeatureType::LP_500_PEAKdB_VPU
@ LP_500_PEAKdB_VPU
FeatureType::HP_8k_PEAKdB_MICT
@ HP_8k_PEAKdB_MICT
TimeDelay
Time delay determination between two signals, based on cross-correlation and windowing of the data.
Definition: timedelay.h:12
LogFile
A class for opening a logfile, and writing data to a log.
Definition: conndetect.h:14
FeatureType::LP_500_PEAKdB_MICT
@ LP_500_PEAKdB_MICT
FeatureType::TM3_MICT
@ TM3_MICT
FeatureType::KURTOSIS_MICT
@ KURTOSIS_MICT
ConnDetect::raw_conndetect_auxtask_callback
friend void raw_conndetect_auxtask_callback(void *)
Definition: conndetect.cpp:63
FeatureType::TIMEDELAY_MICW_MICT
@ TIMEDELAY_MICW_MICT
ConnDetect
The main connection detection class.
Definition: conndetect.h:83
FeatureType::KURTOSIS_MICW
@ KURTOSIS_MICW
Classifier
Classifier class, performs the connection detection on given features.
Definition: classifier.h:17
FeatureType::AVG_IMU_ABS_ROT
@ AVG_IMU_ABS_ROT
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
FeatureType::TM3_VPU
@ TM3_VPU
FeatureType::HP_8k_PEAKdB_MICW
@ HP_8k_PEAKdB_MICW
FeatureType::WAMP_MICW
@ WAMP_MICW
buffer.h
FeatureType::ZC_MICT
@ ZC_MICT
FeatureType::WAMP_MICT
@ WAMP_MICT
ComputedFeatures
std::array< float,(us) NUMBER_FEATURES > ComputedFeatures
Definition: conndetect.h:78
FeatureType::ZC_VPU
@ ZC_VPU
FeatureType::INVERSE_FREQ_VARIANCE_MICW
@ INVERSE_FREQ_VARIANCE_MICW
FilteredData
array< Channel, NUMBER_FILTERED_CHANNELS > FilteredData
Definition: buffer.h:16
us
unsigned int us
Used to much to not abbreviate.
Definition: config.h:38
FeatureType::INVERSE_FREQ_VARIANCE_MICT
@ INVERSE_FREQ_VARIANCE_MICT
Features
This class provides the calculations of single-signal features, computed from a single channel with l...
Definition: conndetect_features.h:18
ConnDetect::~ConnDetect
~ConnDetect()
Definition: conndetect.cpp:90
FeatureType::HP_2k_PEAKdB_VPU
@ HP_2k_PEAKdB_VPU
config.h
Configuration parameters for connection detection.
FeatureType::LP_500_PEAKdB_MICW
@ LP_500_PEAKdB_MICW
FilteredDataBuffer
Class containing filtered data. It is responsible for aggregating signal samples at the full audio sa...
Definition: buffer.h:24
FeatureType::HP_2k_PEAKFREQ_MICT
@ HP_2k_PEAKFREQ_MICT
FeatureType::CLASS
@ CLASS
FeatureType::PEDAL
@ PEDAL
FeatureType::WAMP_VPU
@ WAMP_VPU
FeatureType::NumberOfFeatures
@ NumberOfFeatures