xref: /third_party/pulseaudio/speex/libspeexdsp/testecho.c (revision 53a5a1b3)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/pulseaudio/speex/libspeexdsp/
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include "speex/speex_echo.h"
6#include "speex/speex_preprocess.h"
7#include <stdio.h>
8#include <stdlib.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12
13
14#define NN 128
15#define TAIL 1024
16
17int main(int argc, char **argv)
18{
19   FILE *echo_fd, *ref_fd, *e_fd;
20   short echo_buf[NN], ref_buf[NN], e_buf[NN];
21   SpeexEchoState *st;
22   SpeexPreprocessState *den;
23   int sampleRate = 8000;
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 = fopen(argv[2], "rb");
31   ref_fd  = fopen(argv[1],  "rb");
32   e_fd    = fopen(argv[3], "wb");
33
34   st = speex_echo_state_init(NN, TAIL);
35   den = speex_preprocess_state_init(NN, sampleRate);
36   speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate);
37   speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st);
38
39   while (!feof(ref_fd) && !feof(echo_fd))
40   {
41      fread(ref_buf, sizeof(short), NN, ref_fd);
42      fread(echo_buf, sizeof(short), NN, echo_fd);
43      speex_echo_cancellation(st, ref_buf, echo_buf, e_buf);
44      speex_preprocess_run(den, e_buf);
45      fwrite(e_buf, sizeof(short), NN, e_fd);
46   }
47   speex_echo_state_destroy(st);
48   speex_preprocess_state_destroy(den);
49   fclose(e_fd);
50   fclose(echo_fd);
51   fclose(ref_fd);
52   return 0;
53}
54

Indexes created Thu Nov 07 10:32:03 CST 2024