-
Notifications
You must be signed in to change notification settings - Fork 7
/
AecSample.cpp
72 lines (51 loc) · 1.89 KB
/
AecSample.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
#include <string>
#include "DTLN_AEC.h"
int main(int argc, char *argv[])
{
//lpszInputRefWave is a reference data(far end)
//lpszInputRecWave is a recording data(near end recording)
std::string lpszInputRefWave = std::string(argv[1]);
std::string lpszInputRecWave = std::string(argv[2]);
std::string lpszOutputWave = std::string(argv[3]);
FILE *lpoInputRefFile = NULL;
FILE *lpoInputRecFile = NULL;
FILE *lpoOutputFile = NULL;
short *lpsInputRefSample = NULL;
short *lpsInputRecSample = NULL;
short *lpsOutputSample = NULL;
int nReadSize, nFrameSize;
lpoInputRefFile = fopen(lpszInputRefWave.c_str(), "rb");
lpoInputRecFile = fopen(lpszInputRecWave.c_str(), "rb");
lpoOutputFile = fopen(lpszOutputWave.c_str(), "wb+");
DTLN_AEC oDtlnAec;
nFrameSize = oDtlnAec.Init();
lpsInputRefSample = new short[nFrameSize];
lpsInputRecSample = new short[nFrameSize];
lpsOutputSample = new short[nFrameSize];
//Skip wave header
fread(lpsInputRefSample, 1, 44, lpoInputRefFile);
fread(lpsInputRecSample, 1, 44, lpoInputRecFile);
while (true)
{
nReadSize = fread(lpsInputRefSample, 1, nFrameSize * sizeof(short), lpoInputRefFile);
if (nReadSize <= 0)
break;
nReadSize = fread(lpsInputRecSample, 1, nFrameSize * sizeof(short), lpoInputRecFile);
if (nReadSize <= 0)
break;
oDtlnAec.Process(lpsInputRefSample, lpsInputRecSample, lpsOutputSample);
//write PCM
fwrite(lpsOutputSample, 1, nFrameSize * sizeof(short), lpoOutputFile);
}
fclose(lpoInputRefFile);
fclose(lpoInputRecFile);
fclose(lpoOutputFile);
if (lpsInputRefSample != NULL)
delete[] lpsInputRefSample;
if (lpsInputRecSample != NULL)
delete[] lpsInputRecSample;
if (lpsOutputSample != NULL)
delete[] lpsOutputSample;
return 0;
}