1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include "speex_echo.h"
12 #include "speex_preprocess.h"
13 
14 
15 #define NN 160
16 
main(int argc,char ** argv)17 int main(int argc, char **argv)
18 {
19    int echo_fd, ref_fd, e_fd;
20    spx_int32_t noise[NN+1];
21    short echo_buf[NN], ref_buf[NN], e_buf[NN];
22    SpeexEchoState *st;
23    SpeexPreprocessState *den;
24 
25    if (argc != 4)
26    {
27       fprintf (stderr, "testecho mic_signal.sw speaker_signal.sw output.sw\n");
28       exit(1);
29    }
30    echo_fd = open (argv[2], O_RDONLY);
31    ref_fd  = open (argv[1],  O_RDONLY);
32    e_fd    = open (argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0644);
33 
34    st = speex_echo_state_init(NN, 8*NN);
35    den = speex_preprocess_state_init(NN, 8000);
36 
37    while (read(ref_fd, ref_buf, NN*2))
38    {
39       read(echo_fd, echo_buf, NN*2);
40       speex_echo_cancel(st, ref_buf, echo_buf, e_buf, noise);
41       /*speex_preprocess(den, e_buf, noise);*/
42       write(e_fd, e_buf, NN*2);
43    }
44    speex_echo_state_destroy(st);
45    speex_preprocess_state_destroy(den);
46    close(e_fd);
47    close(echo_fd);
48    close(ref_fd);
49    return 0;
50 }
51