-
Notifications
You must be signed in to change notification settings - Fork 7
/
read_from_file.c
70 lines (61 loc) · 1.5 KB
/
read_from_file.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
#include <sndfile.h>
#include "feature.h"
static void print_usage
(
void
)
{
printf("\nUsage : ./alarm-detector [input sound file] [winsize (secs)] [stepsize (secs)]\n");
}
int main
(
int argc,
char *argv[]
)
{
char *infilename = NULL;
SNDFILE *infile = NULL;
SF_INFO sfinfo;
double win = 0.0;
double step = 0.0;
int winsize = 0;
int stepsize = 0;
int frameidx = 0;
int readcount = 0;
short *clip = NULL;
if(argc != 4)
{
print_usage();
return EXIT_FAILURE;
}
memset(&sfinfo, 0, sizeof(sfinfo));
infilename = argv[1];
if((infile = sf_open(infilename, SFM_READ, &sfinfo)) == NULL)
{
printf ("Not able to open input sound file %s.\n", infilename);
puts (sf_strerror (NULL));
return EXIT_FAILURE;
}
win = atof(argv[2]);
step = atof(argv[3]);
winsize = (int)(win * sfinfo.samplerate);
stepsize = (int)(step * sfinfo.samplerate);
clip = (short *)malloc(winsize * sizeof(short));
feature_extraction_init(sfinfo.samplerate, winsize);
while(1)
{
sf_seek(infile, frameidx * stepsize, SEEK_SET);
readcount = sf_readf_short(infile, clip, winsize);
if(readcount != winsize)
{
break;
}
printf("-%d-\n", frameidx);
feature_extraction_main(clip, frameidx);
++frameidx;
}
feature_extraction_release();
sf_close(infile);
free(clip);
return 0 ;
}