summaryrefslogtreecommitdiff
path: root/src/mq/mq.h
blob: 611203d62343a98f849deb78d6092c724a5b814d (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
#ifndef _MQ_H
#define _MQ_H

#include <fftw3.h>
#include <math.h>

typedef double sample;

typedef struct Peak
{
    float amplitude;
    float frequency;
    float phase;
    int bin;
    struct Peak* next;
    struct Peak* prev;
} Peak;

typedef struct PeakList
{
    struct PeakList* next;
    struct PeakList* prev;
    struct Peak* peak;
} PeakList;

typedef struct MQParameters
{
    int frame_size;
    int max_peaks;
    int num_bins;
    sample peak_threshold;
    sample fundamental;
    sample matching_interval;
    sample* fft_in;
	fftw_complex* fft_out;
	fftw_plan fft_plan;
    PeakList* prev_peaks;
} MQParameters;

int init_mq(MQParameters* params);
void reset_mq(MQParameters* params);
int destroy_mq(MQParameters* params);
void delete_peak_list(PeakList* peak_list);

PeakList* sort_peaks_by_frequency(PeakList* peak_list, int num_peaks);

PeakList* find_peaks(int signal_size, sample* signal, MQParameters* params);
PeakList* track_peaks(PeakList* peak_list, MQParameters* params);
                    
#endif