-
Notifications
You must be signed in to change notification settings - Fork 4
/
fft_average.cpp
51 lines (46 loc) · 1.03 KB
/
fft_average.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* EasyListener for Teensy Audio Library
*
* (c) 2020 Clemens Wegener
* Bauhaus-Universität Weimar
* Department Interface Design
*
* This library uses machine learning to detect previously
* presented audio signals on the Teensy board.
*
* BSD license
*/
#include "fft_average.h"
bool FFTAverage::newFeatureDataAvailable()
{
__disable_irq();
bool flag = _new_feature_data_available;
if (flag){
_new_feature_data_available = false;
}
__enable_irq();
return flag;
}
void FFTAverage::process(int16_t *audio_data, uint16_t frame_num)
{
_frame_num = frame_num;
_fft.process(audio_data, frame_num);
for(int i=0; i<_fft.getNumOfBins(); i++)
{
_fft_sum[i]+=_fft.getBin(i);
}
_new_feature_data_available = true;
}
void FFTAverage::setCurrentFeatureVector()
{
for(int i=0; i<getNumOfFeatures(); i++)
{
_current_feature_vector.setDim(i, getFeature(i));
_current_feature_vector.normalize();
}
reset();
}
void FFTAverage::reset()
{
std::fill(_fft_sum.begin(),_fft_sum.end(),0);
}