-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
73 lines (52 loc) · 1.47 KB
/
main.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
73
#include "noise_reduction/speex/speex_preprocess.h"
#include "Denoise.hpp"
#include <iostream>
#include <fstream>
#include <stdio.h>
#define FRAME_SIZE 22050
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
const char * wavReadPath = "./2.pcm";
std::fstream fin;
fin.open(wavReadPath);
if(!fin.is_open()) {
printf("can't open in file\n");
}
FILE* fpcm = fopen("./out.pcm", "wb");
int count = 0;
short nNum = 0;
short tmp = 0;
short in[FRAME_SIZE] = {0};
short out[FRAME_SIZE]={0};
SpeexPreprocessState *st;
st = speex_preprocess_state_init(80, 44100);
while(1){
fin.read((char*)&nNum, sizeof(short));
in[count] = nNum;
if ((count+1) % FRAME_SIZE == 0) {
denoise(in, FRAME_SIZE, out, st);
for (int ii = 0; ii < FRAME_SIZE; ii++) {
tmp = out[ii];
fwrite(&tmp, 2, 1, fpcm);
}
count = 0;
printf("once more\n");
}
if(fin.eof()){
denoise(in, count, out, st);
for (int ii = 0; ii < count; ii++) {
tmp = out[ii];
fwrite(&tmp, 2, 1, fpcm);
}
count = 0;
break;
}
count++;
}
fin.close();
fclose(fpcm);
speex_preprocess_state_destroy(st);
printf("Done\n");
return 0;
}