-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpeexVAD.cpp
72 lines (66 loc) · 2.11 KB
/
SpeexVAD.cpp
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
/************************************************
*
* DM-Release@build:SpeexVAD.cpp
*
* Created on: Sep 30, 2014
* Author: Andy Huang
* Email: [email protected]
*
* All rights reserved!
*
************************************************/
#include "SpeexVAD.h"
#include <stdio.h>
SpeexVAD::SpeexVAD(int ps, int pc) :
preState(NULL), frameSize(0), probStart(ps), probContinue(pc) {
}
SpeexVAD::~SpeexVAD() {
if (preState != NULL){
speex_preprocess_state_destroy(preState);
preState = NULL;
}
}
int SpeexVAD::initialize(int framesize, unsigned int rate) {
int vad = 1;
float f;
int i = 1;
preState = speex_preprocess_state_init(framesize, rate);
if (!preState) {
printf("--- init speex failed\n");
return -1;
}
int vadProbStart = probStart;
int vadProbContinue = probContinue;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_VAD, &vad);
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_PROB_START,
&vadProbStart);
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_PROB_CONTINUE,
&vadProbContinue);
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_DENOISE, &i);
int noiseSuppress = -40;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS,
&noiseSuppress);
i = 0;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_AGC, &i);
f = 16000;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_AGC_LEVEL, &f);
i = 0;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_DEREVERB, &i);
f = .0;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
f = .0;
speex_preprocess_ctl(preState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
frameSize = framesize;
return 0;
}
bool SpeexVAD::isVoice(void *data, int samplesize) {
if (samplesize != frameSize) {
printf("!!! sample size: %d != framesize: %d\n", samplesize, frameSize);
return false;
}
spx_int16_t *ptr = (spx_int16_t *) data; // S16
if (speex_preprocess_run(preState, ptr))
return true;
else
return false;
}