15d44f53644941810d2f4f68065a96d995559418
[profile/ivi/pulseaudio.git] / src / modules / echo-cancel / echo-cancel.h
1 /***
2     This file is part of PulseAudio.
3
4     Copyright 2010 Arun Raghavan <arun.raghavan@collabora.co.uk>
5
6     PulseAudio is free software; you can redistribute it and/or modify
7     it under the terms of the GNU Lesser General Public License as published
8     by the Free Software Foundation; either version 2.1 of the License,
9     or (at your option) any later version.
10
11     PulseAudio is distributed in the hope that it will be useful, but
12     WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     General Public License for more details.
15
16     You should have received a copy of the GNU Lesser General Public License
17     along with PulseAudio; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     USA.
20 ***/
21
22 #ifndef fooechocancelhfoo
23 #define fooechocancelhfoo
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <pulse/sample.h>
30 #include <pulse/channelmap.h>
31 #include <pulsecore/core.h>
32 #include <pulsecore/macro.h>
33
34 #ifdef HAVE_SPEEX
35 #include <speex/speex_echo.h>
36 #include <speex/speex_preprocess.h>
37 #endif
38
39 #include "adrian.h"
40
41 /* Common data structures */
42
43 typedef struct pa_echo_canceller_msg pa_echo_canceller_msg;
44
45 typedef struct pa_echo_canceller_params pa_echo_canceller_params;
46
47 struct pa_echo_canceller_params {
48     union {
49 #ifdef HAVE_SPEEX
50         struct {
51             SpeexEchoState *state;
52             SpeexPreprocessState *pp_state;
53         } speex;
54 #endif
55         struct {
56             uint32_t blocksize;
57             AEC *aec;
58         } adrian;
59 #ifdef HAVE_WEBRTC
60         struct {
61             /* This is a void* so that we don't have to convert this whole file
62              * to C++ linkage. apm is a pointer to an AudioProcessing object */
63             void *apm;
64             uint32_t blocksize;
65             pa_sample_spec sample_spec;
66             pa_bool_t agc;
67         } webrtc;
68 #endif
69         /* each canceller-specific structure goes here */
70     } priv;
71
72     /* Set this if canceller can do drift compensation. Also see set_drift()
73      * below */
74     pa_bool_t drift_compensation;
75 };
76
77 typedef struct pa_echo_canceller pa_echo_canceller;
78
79 struct pa_echo_canceller {
80     /* Initialise canceller engine. */
81     pa_bool_t   (*init)                 (pa_core *c,
82                                          pa_echo_canceller *ec,
83                                          pa_sample_spec *source_ss,
84                                          pa_channel_map *source_map,
85                                          pa_sample_spec *sink_ss,
86                                          pa_channel_map *sink_map,
87                                          uint32_t *blocksize,
88                                          const char *args);
89
90     /* You should have only one of play()+record() or run() set. The first
91      * works under the assumption that you'll handle buffering and matching up
92      * samples yourself. If you set run(), module-echo-cancel will handle
93      * synchronising the playback and record streams. */
94
95     /* Feed the engine 'blocksize' playback bytes.. */
96     void        (*play)                 (pa_echo_canceller *ec, const uint8_t *play);
97     /* Feed the engine 'blocksize' record bytes. blocksize processed bytes are
98      * returned in out. */
99     void        (*record)               (pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
100     /* Feed the engine blocksize playback and record streams, with a reasonable
101      * effort at keeping the two in sync. blocksize processed bytes are
102      * returned in out. */
103     void        (*run)                  (pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
104
105     /* Optional callback to set the drift, expressed as the ratio of the
106      * difference in number of playback and capture samples to the number of
107      * capture samples, for some instant of time. This is used only if the
108      * canceller signals that it supports drift compensation, and is called
109      * before record(). The actual implementation needs to derive drift based
110      * on point samples -- the individual values are not accurate enough to use
111      * as-is. */
112     /* NOTE: the semantics of this function might change in the future. */
113     void        (*set_drift)            (pa_echo_canceller *ec, float drift);
114
115     /* Free up resources. */
116     void        (*done)                 (pa_echo_canceller *ec);
117
118     /* Structure with common and engine-specific canceller parameters. */
119     pa_echo_canceller_params params;
120
121     /* msgobject that can be used to send messages back to the main thread */
122     pa_echo_canceller_msg *msg;
123 };
124
125 /* Functions to be used by the canceller analog gain control routines */
126 void pa_echo_canceller_get_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
127 void pa_echo_canceller_set_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
128
129 #ifdef HAVE_SPEEX
130 /* Speex canceller functions */
131 pa_bool_t pa_speex_ec_init(pa_core *c, pa_echo_canceller *ec,
132                            pa_sample_spec *source_ss, pa_channel_map *source_map,
133                            pa_sample_spec *sink_ss, pa_channel_map *sink_map,
134                            uint32_t *blocksize, const char *args);
135 void pa_speex_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
136 void pa_speex_ec_done(pa_echo_canceller *ec);
137 #endif
138
139 /* Adrian Andre's echo canceller */
140 pa_bool_t pa_adrian_ec_init(pa_core *c, pa_echo_canceller *ec,
141                            pa_sample_spec *source_ss, pa_channel_map *source_map,
142                            pa_sample_spec *sink_ss, pa_channel_map *sink_map,
143                            uint32_t *blocksize, const char *args);
144 void pa_adrian_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
145 void pa_adrian_ec_done(pa_echo_canceller *ec);
146
147 #ifdef HAVE_WEBRTC
148 /* WebRTC canceller functions */
149 PA_C_DECL_BEGIN
150 pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
151                             pa_sample_spec *source_ss, pa_channel_map *source_map,
152                             pa_sample_spec *sink_ss, pa_channel_map *sink_map,
153                             uint32_t *blocksize, const char *args);
154 void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play);
155 void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
156 void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift);
157 void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
158 void pa_webrtc_ec_done(pa_echo_canceller *ec);
159 PA_C_DECL_END
160 #endif
161
162 #endif /* fooechocancelhfoo */