File: testecho.c

package info (click to toggle)
speex 1.1.6-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,616 kB
  • ctags: 1,261
  • sloc: ansic: 15,615; sh: 8,282; makefile: 204
file content (65 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <speex/speex_echo.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <speex/speex_preprocess.h>

#define NN 160

int main()
{
   int i;
   int echo_fd, ref_fd, e_fd;
   float echo[NN], ref[NN], e[NN];
   short noise[NN];
   short echo_buf[NN], ref_buf[NN], e_buf[NN];
   SpeexEchoState *st;
   SpeexPreprocessState *den;

   echo_fd = open ("play.sw", O_RDONLY);
   ref_fd  = open ("rec.sw",  O_RDONLY);
   e_fd    = open ("echo.sw", O_WRONLY | O_CREAT | O_TRUNC, 0644);

   st = speex_echo_state_init(NN, 8*NN);
   den = speex_preprocess_state_init(NN, 8000);

   while (read(ref_fd, ref_buf, NN*2))
   {
      read(echo_fd, echo_buf, NN*2);
/*
      for (i=0;i<NN;i++)
         ref[i] = ref_buf[i];
      
      for (i=0;i<NN;i++)
         echo[i] = echo_buf[i];
*/
      speex_echo_cancel(st, ref_buf, echo_buf, e_buf, NULL);
      /*speex_denoise(den, e, noise);*/
      
 /*     for (i=0;i<NN;i++)
         e_buf[i] = e[i];
*/
      write(e_fd, e_buf, NN*2);
#if 0
      for (i=0;i<NN;i++)
         printf ("%f\n", e[i]);
#endif
   }
#if 0
   for (i=0;i<st->window_size;i++)
      printf ("%f\n", st->W[i]);
#endif
   speex_echo_state_destroy(st);
   speex_preprocess_state_destroy(den);
   close(e_fd);
   close(echo_fd);
   close(ref_fd);
   return 0;
}