-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathfingerprint.h
105 lines (90 loc) · 2.18 KB
/
fingerprint.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
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
/**-------------------------/// fingerprint audio \\\---------------------------
*
* <b>fingerprint audio</b>
* @version :
* @since : 2015 2月 07
*
* @description :
* To extract features of songs.
* @usage :
*
* @author : 'Jiahui Yu' | yjh199511 gmail.com
* @copyright
* @TODO :
*
*--------------------------\\\ fingerprint audio ///---------------------------*/
#ifndef FINGERPRINT_H
#define FINGERPRINT_H
#include <iostream>
#include <math.h>
#include <fftw3.h>
#include <assert.h>
#include <wav.h>
#include <hash.h>
#include <stdint.h>
#define FRAME_SIZE 512
#define FRAME_HEIGHT FRAME_SIZE/2
#define FRAME_HOP 256
#define LOW_FREQ 20
#define PAIR_OFFSET 5
#define PAIR_DX 63
#define PAIR_DY 31
#define Gauss_Var 30
#define PI 3.1415926
#define MAX_FEATURE_PER_FRAME 5
#define MAX_PAIR_PER_FEATURE 32
#define f2_f1_max 32
#define MIN_THRESHOLD 0.15
#define MALLOC(arr, m, type) {\
arr = (type *)malloc((m) * sizeof(type));\
assert(arr != NULL);\
}
#define MALLOC2D(arr, m, n, type) {\
arr = (type **)malloc((m)*sizeof(type*));\
assert(arr!=NULL);\
for (int i = 0; i < (m); i++){\
arr[i] = (type *)malloc((n)*sizeof(type));\
assert(arr[i]!=NULL);\
}\
}
#define FREE(p) {\
assert(p != NULL);\
free(p);\
p = NULL;\
}
#define FREE2D(arr, m) {\
for (int i = 0; i < (m); i++){\
FREE(arr[i]);\
}\
FREE(arr);\
}\
#define max(a, b) (((a)>(b))?(a):(b))
#define max3(a,b,c) max(max((a),(b)),(c))
class TExtractFeature{
private:
fftw_complex *fftw_in, *fftw_out;
fftw_plan fftw_p;
float *threshold;
float **spectrum;
float *Gauss;
float *Gauss_base;
float *Hamming;
float *peak;
int **feature;
int frame_num;
int *search;
float decay_factor;
public:
TExtractFeature();
~TExtractFeature();
void UnInit();
void ExtractPair(const char *filename, THash &hash, int offset, float decay, int Id, int mode);
int Wav2Spectrum(const char *filename, int offset);
int Spectrum2Feature();
int Feature2PairInsert(THash &hash, int Id);
int Feature2PairSearch(THash &hash);
void Init();
int AddSearch(int frame, int freq);
int NotExtremum(int j, float Arr[]);
};
#endif