forked from BauhausUniversity/EasyListener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfft_average.h
68 lines (54 loc) · 1.33 KB
/
fft_average.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* 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
*/
#ifndef fft_average_h_
#define fft_average_h_
#include <vector>
using namespace std;
#include "fft256_f32.h"
#include "PointND.h"
class FFTAverage : public FeatureExtractor
{
public:
FFTAverage(): _new_feature_data_available(false), _frame_num(0)
{
for(int i=0; i<_fft.getNumOfBins(); i++)
{
_fft_sum.push_back(0);
_current_feature_vector.push_back(0);
}
};
float getFeature(unsigned int feature_idx) {
return _fft_sum[feature_idx];
}
PointND getCurrentFeatureVector() {
return _current_feature_vector;
}
void setCurrentFeatureVector();
int16_t getNumOfFeatures() {
return _fft.getNumOfBins();
}
void process(int16_t *audio_data, uint16_t frame_num);
void reset();
bool newFeatureDataAvailable(); // check for new sound feature data
uint16_t getFrameNum() {return _frame_num;}
virtual ~FFTAverage(){}
private:
FFT256F32 _fft;
std::vector<float> _fft_sum;
int _block_count;
int _min_number_of_blocks;
volatile bool _new_feature_data_available;
PointND _current_feature_vector;
uint16_t _frame_num;
};
#endif