blob: 0c6a11c63a1e556b2c2d0f7d76fbaddc3d3a1cf4 (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#ifndef _SIMPL_MQ_H
#define _SIMPL_MQ_H
#include <cstdlib>
#include <fftw3.h>
#include <math.h>
#include <string.h>
#include "base.h"
namespace simpl
{
// ---------------------------------------------------------------------------
// MQPeak
// ---------------------------------------------------------------------------
class MQPeak {
public:
float amplitude;
float frequency;
float phase;
int bin;
MQPeak* next;
MQPeak* prev;
MQPeak() {
amplitude = 0.f;
frequency = 0.f;
phase = 0.f;
bin = 0;
next = NULL;
prev = NULL;
}
};
// ---------------------------------------------------------------------------
// MQPeakList
// ---------------------------------------------------------------------------
class MQPeakList {
public:
MQPeakList* next;
MQPeakList* prev;
MQPeak* peak;
MQPeakList() {
next = NULL;
prev = NULL;
peak = NULL;
}
};
// ---------------------------------------------------------------------------
// MQParameters
// ---------------------------------------------------------------------------
class MQParameters {
public:
int frame_size;
int max_peaks;
int num_bins;
sample peak_threshold;
sample fundamental;
sample matching_interval;
sample* window;
sample* fft_in;
fftw_complex* fft_out;
fftw_plan fft_plan;
MQPeakList* prev_peaks;
MQParameters() {
frame_size = 0;
max_peaks = 0;
num_bins = 0;
peak_threshold = 0.f;
fundamental = 0.f;
matching_interval = 0.f;
window = NULL;
fft_in = NULL;
fft_out = NULL;
prev_peaks = NULL;
}
};
// ---------------------------------------------------------------------------
// MQ functions
// ---------------------------------------------------------------------------
int init_mq(MQParameters* params);
void reset_mq(MQParameters* params);
int destroy_mq(MQParameters* params);
void mq_add_peak(MQPeak* new_peak, MQPeakList* peak_list);
void delete_peak_list(MQPeakList* peak_list);
MQPeakList* mq_sort_peaks_by_frequency(MQPeakList* peak_list, int num_peaks);
MQPeakList* mq_find_peaks(int signal_size, sample* signal,
MQParameters* params);
MQPeakList* mq_track_peaks(MQPeakList* peak_list, MQParameters* params);
} // end of namespace simpl
#endif
|