echo-cance: Make Adrian canceller optional
[pulseaudio-raopUDP/pulseaudio-raop-alac.git] / src / modules / echo-cancel / echo-cancel.h
blob870d163e94afa1537ab447fcadba9082f7aa605f
1 /***
2 This file is part of PulseAudio.
4 Copyright 2010 Arun Raghavan <arun.raghavan@collabora.co.uk>
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.
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.
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 ***/
22 #ifndef fooechocancelhfoo
23 #define fooechocancelhfoo
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #include <pulse/sample.h>
30 #include <pulse/channelmap.h>
31 #include <pulsecore/core.h>
32 #include <pulsecore/macro.h>
34 #ifdef HAVE_SPEEX
35 #include <speex/speex_echo.h>
36 #include <speex/speex_preprocess.h>
37 #endif
39 #include "adrian.h"
41 /* Common data structures */
43 typedef struct pa_echo_canceller_msg pa_echo_canceller_msg;
45 typedef struct pa_echo_canceller_params pa_echo_canceller_params;
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 #ifdef HAVE_ADRIAN_EC
56 struct {
57 uint32_t blocksize;
58 AEC *aec;
59 } adrian;
60 #endif
61 #ifdef HAVE_WEBRTC
62 struct {
63 /* This is a void* so that we don't have to convert this whole file
64 * to C++ linkage. apm is a pointer to an AudioProcessing object */
65 void *apm;
66 uint32_t blocksize;
67 pa_sample_spec sample_spec;
68 pa_bool_t agc;
69 } webrtc;
70 #endif
71 /* each canceller-specific structure goes here */
72 } priv;
74 /* Set this if canceller can do drift compensation. Also see set_drift()
75 * below */
76 pa_bool_t drift_compensation;
79 typedef struct pa_echo_canceller pa_echo_canceller;
81 struct pa_echo_canceller {
82 /* Initialise canceller engine. */
83 pa_bool_t (*init) (pa_core *c,
84 pa_echo_canceller *ec,
85 pa_sample_spec *source_ss,
86 pa_channel_map *source_map,
87 pa_sample_spec *sink_ss,
88 pa_channel_map *sink_map,
89 uint32_t *blocksize,
90 const char *args);
92 /* You should have only one of play()+record() or run() set. The first
93 * works under the assumption that you'll handle buffering and matching up
94 * samples yourself. If you set run(), module-echo-cancel will handle
95 * synchronising the playback and record streams. */
97 /* Feed the engine 'blocksize' playback bytes.. */
98 void (*play) (pa_echo_canceller *ec, const uint8_t *play);
99 /* Feed the engine 'blocksize' record bytes. blocksize processed bytes are
100 * returned in out. */
101 void (*record) (pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
102 /* Feed the engine blocksize playback and record streams, with a reasonable
103 * effort at keeping the two in sync. blocksize processed bytes are
104 * returned in out. */
105 void (*run) (pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
107 /* Optional callback to set the drift, expressed as the ratio of the
108 * difference in number of playback and capture samples to the number of
109 * capture samples, for some instant of time. This is used only if the
110 * canceller signals that it supports drift compensation, and is called
111 * before record(). The actual implementation needs to derive drift based
112 * on point samples -- the individual values are not accurate enough to use
113 * as-is. */
114 /* NOTE: the semantics of this function might change in the future. */
115 void (*set_drift) (pa_echo_canceller *ec, float drift);
117 /* Free up resources. */
118 void (*done) (pa_echo_canceller *ec);
120 /* Structure with common and engine-specific canceller parameters. */
121 pa_echo_canceller_params params;
123 /* msgobject that can be used to send messages back to the main thread */
124 pa_echo_canceller_msg *msg;
127 /* Functions to be used by the canceller analog gain control routines */
128 void pa_echo_canceller_get_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
129 void pa_echo_canceller_set_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
131 #ifdef HAVE_SPEEX
132 /* Speex canceller functions */
133 pa_bool_t pa_speex_ec_init(pa_core *c, pa_echo_canceller *ec,
134 pa_sample_spec *source_ss, pa_channel_map *source_map,
135 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
136 uint32_t *blocksize, const char *args);
137 void pa_speex_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
138 void pa_speex_ec_done(pa_echo_canceller *ec);
139 #endif
141 #ifdef HAVE_ADRIAN_EC
142 /* Adrian Andre's echo canceller */
143 pa_bool_t pa_adrian_ec_init(pa_core *c, pa_echo_canceller *ec,
144 pa_sample_spec *source_ss, pa_channel_map *source_map,
145 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
146 uint32_t *blocksize, const char *args);
147 void pa_adrian_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
148 void pa_adrian_ec_done(pa_echo_canceller *ec);
149 #endif
151 #ifdef HAVE_WEBRTC
152 /* WebRTC canceller functions */
153 PA_C_DECL_BEGIN
154 pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
155 pa_sample_spec *source_ss, pa_channel_map *source_map,
156 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
157 uint32_t *blocksize, const char *args);
158 void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play);
159 void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
160 void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift);
161 void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
162 void pa_webrtc_ec_done(pa_echo_canceller *ec);
163 PA_C_DECL_END
164 #endif
166 #endif /* fooechocancelhfoo */