-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.c
78 lines (58 loc) · 1.5 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "fooid.h"
#include "sndfile.h"
int main(int argc, char ** argv)
{
if (argc < 2)
{
printf("Usage: ./test filename.wav\n");
return 0;
}
SF_INFO * sfinfo = malloc(sizeof(*sfinfo));
SNDFILE * file = sf_open(argv[1], SFM_READ, sfinfo);
print_file_info(sfinfo);
t_fooid * fooid = fp_init(sfinfo->samplerate, sfinfo->channels);
short * data = malloc(sizeof(short) * sfinfo->channels * sfinfo->samplerate);
int centiseconds = 0;
while (1)
{
sf_count_t items_read = sf_read_short(file, data, sfinfo->channels * sfinfo->samplerate);
if (items_read == 0)
{
break;
}
centiseconds += 100 * sfinfo->channels * sfinfo->samplerate / items_read;
int result = fp_feed_short(fooid, data, items_read);
if (result < 0)
{
printf("Error!\n");
break;
}
}
unsigned char * buffer = malloc(fp_getsize(fooid));
int result = fp_calculate(fooid, centiseconds, buffer);
if (result < 0)
{
printf("Failed to calculate fingerprint\n");
}
else
{
int i;
for (i = 0; i < fp_getsize(fooid); i++)
{
if (!(i % 32))
{
printf("\n");
}
printf("%02x ", (int) buffer[i]);
}
printf("\n");
}
free(buffer);
fp_free(fooid);
free(data);
free(sfinfo);
return 0;
}