Voss Connection Detection
1
Detect a connector click using realtime code on Bela hardware
|
Go to the documentation of this file.
15 #define WRITE_TO_DISK 1
60 typedef unsigned int us;
61 #define max(a, b) (((a) > (b) ? a : b))
65 conndetect->auxTaskCallback();
69 _features =
new Features(context->analogSampleRate);
70 if(!_features)
throw std::runtime_error(
"Unallocated features");
78 _timedelay =
new TimeDelay(context->analogSampleRate);
80 #if WRITE_TO_DISK == 1
83 if(!_logfile)
throw std::runtime_error(
"Could not create log file");
88 "Conndetect_auxtask_callback",
this);
95 #if WRITE_TO_DISK == 1
104 for (
auto buf : _bufs) {
105 if (!(buf->full())) {
106 buf->addFilteredFrame(frame);
111 if(nbufs_full == 1) {
112 Bela_scheduleAuxiliaryTask(_detect_task);
114 else if (nbufs_full == 2) {
115 std::cerr <<
"Two buffers full. Houston we have too much load!" << endl;
122 void ConnDetect::auxTaskCallback() {
123 for (
auto buf : _bufs) {
125 processFullBuffer((buf->data));
130 void ConnDetect::processFullBuffer(
const FilteredData &data) {
144 ft[(int) f::HP_8k_PEAKdB_MICT] = _features->
peak_dB();
147 ft[(int) f::HP_8k_PEAKdB_MICW] = _features->
peak_dB();
150 ft[(int) f::LP_500_PEAKdB_MICT] = _features->
peak_dB();
153 ft[(int) f::LP_500_PEAKdB_MICW] = _features->
peak_dB();
156 ft[(int) f::HP_2k_PEAKdB_VPU] = _features->
peak_dB();
159 ft[(int) f::LP_500_PEAKdB_VPU] = _features->
peak_dB();
162 ft[(int) f::HP_2k_PEAKFREQ_MICT] = _features->
peak_freq();
166 ft[(int) f::KURTOSIS_MICT] = _features->
kurtosis();
168 ft[(int) f::TM3_MICT] = _features->
TM3();
171 ft[(int) f::ZC_MICT] = _features->
zc(
ZC_T);
175 ft[(int) f::KURTOSIS_MICW] = _features->
kurtosis();
177 ft[(int) f::TM3_MICW] = _features->
TM3();
180 ft[(int) f::ZC_MICW] = _features->
zc(
ZC_W);
184 ft[(int) f::KURTOSIS_VPU] = _features->
kurtosis();
186 ft[(int) f::TM3_VPU] = _features->
TM3();
201 cerr <<
"Detected pedal push" << _connDetected << endl;
203 ft[(int) f::PEDAL] = pedal;
206 _connDetected = _classifier->
classify(ft);
207 ft[(int) f::CLASS] = _connDetected;
209 cerr <<
"Detected connection" << endl;
212 #if WRITE_TO_DISK == 1
const char *const logFileHeader
Please be VERY SURE to keep this in sync with the list above, otherwise LARGE MISTAKES will be made.
bool classify(const ComputedFeatures &ft)
Perform classification, i.e. detect the threshold.
const float WAMP_LT
Willson amplitude L-definition. For the thumb mic.
ConnDetect(BelaContext *context)
Initalize the connection detector.
void addFilteredFrame(const FilteredFrame &filteredframe)
Add a new filtered frame of data to the buffer the detector.
bool connectionDetected()
The write task.
FeatureType
These are the features extracted from the filtered data. They should be self-explaining regarding the...
float TM3()
Temporal moment 3, defined as.
const float SAMPLING_FREQUENCY
This is the exact sampling frequency of the system. Do not change!
Configuration parameters for connection detection based on thresholds. Note that these values are "in...
Time delay determination between two signals, based on cross-correlation and windowing of the data.
const us FILT_RAW_MICT
The number of buffers that require some processing. This is not equal to the number of sensors,...
float wamp(float wampl)
Willson amplitude. Counts the number of difss in amplitude that have an absolute change in value larg...
static float maximum(const Channel &i)
Find the maximum value in a strictly positive array. No checks on positiveness are done!
friend void raw_conndetect_auxtask_callback(void *)
The main connection detection class.
float inverse_variance()
Inverse of the variance in the center frequency, defined as:
const float WAMP_LW
Willson amplitude L-definition. For the wrist mic.
array< float, NUMBER_FILTERED_CHANNELS > FilteredFrame
An array containing data with length corresponding to a single processed frame. Its length correspond...
float peak_freq()
Compute the frequency at which the spectrum has the most power. It is defined as:
void log(const std::array< float, num_cols > &data)
Log the data to the file.
std::array< float,(us) NUMBER_FEATURES > ComputedFeatures
array< Channel, NUMBER_FILTERED_CHANNELS > FilteredData
const float ZC_T
Zero-crossings L-definition. For the thumb mic.
void setChannel(const Channel &channel)
Set channel data to operate on. BORROWS the data on which it operates, be carefull not to delete the ...
This class provides the calculations of single-signal features, computed from a single channel with l...
float determineDelay(const Channel &mic1, const Channel &mic2)
Determine the delay between two microphone signals. A positive signal means that mic 1 comes [t] time...
Configuration parameters for connection detection.
const float WAMP_LVPU
Willson amplitude L-definition. For the VPU.
Class containing filtered data. It is responsible for aggregating signal samples at the full audio sa...
us timeStamp
Storage for statistics data.
float kurtosis()
Compute the kurtosis , scaled. It is defined as:
const float ZC_VPU
Zero-crossings L-definition. For the VPU.
void raw_conndetect_auxtask_callback(void *raw_ptr)
const char *const logFileName
The filename containing logged data. If you change this, please also update the file ....
float zc(float zc_l)
Compute zero-crossings with a difference larger than zcl.
static float hasNonZero(const Channel &i)
Find a nonzero in the array.
float peak_dB()
Compute the peak level in dB (full scale, normalized to 1). The equation is:
const float ZC_W
Zero-crossings L-definition. For the wrist mic.
static float average(const Channel &i)
Compute the average of a channel value.