comparison intercom/aec_test.cpp @ 2:13be24d74cd2

import intercom-0.4.1
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 09:57:52 +0200
parents
children 22a74b01a099
comparison
equal deleted inserted replaced
1:9cadc470e3da 2:13be24d74cd2
1 /* aec_test.cpp
2 *
3 * Copyright (C) DFS Deutsche Flugsicherung (2004). All Rights Reserved.
4 *
5 * Test stub for Acoustic Echo Cancellation NLMS-pw algorithm
6 * Author: Andre Adrian, DFS Deutsche Flugsicherung
7 * <Andre.Adrian@dfs.de>
8 *
9 * fortune says:
10 * It's never as good as it feels, and it's never as bad as it seems.
11 *
12 * compile
13 c++ -DWIDEB=2 -O2 -o aec_test aec_test.cpp aec.cpp tcp.cpp -lm
14 *
15 * Version 1.3 set/get ambient in dB
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <math.h>
21 #include <string.h>
22
23 #include "tcp.h"
24 #include "aec.h"
25
26 #define TAPS (40*WIDEB*8)
27
28 typedef signed short MONO;
29
30 typedef struct {
31 signed short l;
32 signed short r;
33 } STEREO;
34
35 float dB2q(float dB)
36 {
37 /* Dezibel to Ratio */
38 return powf(10.0f, dB / 20.0f);
39 }
40
41 float q2dB(float q)
42 {
43 /* Ratio to Dezibel */
44 return 20.0f * log10f(q);
45 }
46
47
48 /* Read a raw audio file (8KHz sample frequency, 16bit PCM, stereo)
49 * from stdin, echo cancel it and write it to stdout
50 */
51 int main(int argc, char *argv[])
52 {
53 STEREO inbuf[TAPS], outbuf[TAPS];
54 float visualize;
55
56 fprintf(stderr, "usage: aec_test [ambient in dB] <in.raw >out.raw\n");
57
58 AEC aec;
59
60 if (argc >= 2) {
61 aec.setambient(MAXPCM*dB2q(atof(argv[1])));
62 }
63
64 int taps;
65 float ambient;
66 while (taps = fread(inbuf, sizeof(STEREO), TAPS, stdin)) {
67 int i;
68 for (i = 0; i < taps; ++i) {
69 int s0 = inbuf[i].l; /* left channel microphone */
70 int s1 = inbuf[i].r; /* right channel speaker */
71
72 /* and do NLMS */
73 s0 = aec.doAEC(s0, s1);
74
75 /* output one internal variable */
76 // visualize = 16 * aec.hangover;
77 visualize = 32000 * aec.stepsize;
78
79 outbuf[i].l = (short)(visualize); /* left channel */
80 outbuf[i].r = s0; /* right channel echo cancelled mic */
81 }
82
83 fwrite(outbuf, sizeof(STEREO), taps, stdout);
84 }
85 ambient = aec.getambient();
86 float ambientdB = q2dB(ambient / 32767.0f);
87 fprintf(stderr, "Ambient = %2.0f dB\n", ambientdB);
88 fflush(NULL);
89
90 return 0;
91 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.