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/speex_echo.h"
12 #include "speex/speex_preprocess.h"
13 
14 
15 #define NN 160
16 
main()17 int main()
18 {
19    int echo_fd, ref_fd, e_fd;
20    float noise[NN+1];
21    short echo_buf[NN], ref_buf[NN], e_buf[NN];
22    SpeexEchoState *st;
23    SpeexPreprocessState *den;
24 
25    echo_fd = open ("play.sw", O_RDONLY);
26    ref_fd  = open ("rec.sw",  O_RDONLY);
27    e_fd    = open ("echo.sw", O_WRONLY | O_CREAT | O_TRUNC, 0644);
28 
29    st = speex_echo_state_init(NN, 8*NN);
30    den = speex_preprocess_state_init(NN, 8000);
31 
32    while (read(ref_fd, ref_buf, NN*2))
33    {
34       read(echo_fd, echo_buf, NN*2);
35       speex_echo_cancel(st, ref_buf, echo_buf, e_buf, noise);
36       speex_preprocess(den, e_buf, noise);
37       write(e_fd, e_buf, NN*2);
38    }
39    speex_echo_state_destroy(st);
40    speex_preprocess_state_destroy(den);
41    close(e_fd);
42    close(echo_fd);
43    close(ref_fd);
44    return 0;
45 }
46