forked from robin1001/beamforming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvad-test.cc
59 lines (46 loc) · 1.47 KB
/
vad-test.cc
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
/* Created on 2016-08-24
* Author: Zhang Binbin
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "wav.h"
#include "vad.h"
int main(int argc, char *argv[]) {
const char *usage = "Do energy vad for input wav file\n"
"Usage: vad-test wav_in_file\n";
if (argc != 2) {
printf(usage);
exit(-1);
}
WavReader reader(argv[1]);
printf("input file %s info: \n"
"sample_rate %d \n"
"channels %d \n"
"bits_per_sample_ %d \n",
argv[1],
reader.SampleRate(),
reader.NumChannel(),
reader.BitsPerSample());
int sample_rate = reader.SampleRate();
int num_sample = reader.NumSample();
float frame_len = 0.025; // 25 ms
float frame_shift = 0.01; // 10ms
int num_point_per_frame = (int)(frame_len * sample_rate);
int num_point_shift = (int)(frame_shift * sample_rate);
float *data = (float *)calloc(sizeof(float), num_sample);
// Copy first channel
for (int i = 0; i < num_sample; i++) {
data[i] = reader.Data()[i * reader.NumChannel()];
}
Vad vad;
VadInit(&vad, 1.5e7, 3, 10);
for (int i = 0; i < num_sample; i += num_point_shift) {
// last frame
if (i + num_point_per_frame > num_sample) break;
int tags = IsSpeech(&vad, data+i, num_point_per_frame) ? 1 : 0;
printf("%f %d \n", float(i) / sample_rate, tags);
}
free(data);
return 0;
}