]> code.delx.au - pulseaudio/blob - src/modules/echo-cancel/echo-cancel.h
echo-cancel: Add infrastructure for cancellers to do AGC
[pulseaudio] / 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 #include <speex/speex_echo.h>
35 #include <speex/speex_preprocess.h>
36 #include "adrian.h"
37
38 /* Common data structures */
39
40 typedef struct pa_echo_canceller_msg pa_echo_canceller_msg;
41
42 typedef struct pa_echo_canceller_params pa_echo_canceller_params;
43
44 struct pa_echo_canceller_params {
45 union {
46 struct {
47 SpeexEchoState *state;
48 SpeexPreprocessState *pp_state;
49 } speex;
50 struct {
51 uint32_t blocksize;
52 AEC *aec;
53 } adrian;
54 #ifdef HAVE_WEBRTC
55 struct {
56 /* This is a void* so that we don't have to convert this whole file
57 * to C++ linkage. apm is a pointer to an AudioProcessing object */
58 void *apm;
59 uint32_t blocksize;
60 pa_sample_spec sample_spec;
61 } webrtc;
62 #endif
63 /* each canceller-specific structure goes here */
64 } priv;
65
66 /* Set this if canceller can do drift compensation. Also see set_drift()
67 * below */
68 pa_bool_t drift_compensation;
69 };
70
71 typedef struct pa_echo_canceller pa_echo_canceller;
72
73 struct pa_echo_canceller {
74 /* Initialise canceller engine. */
75 pa_bool_t (*init) (pa_core *c,
76 pa_echo_canceller *ec,
77 pa_sample_spec *source_ss,
78 pa_channel_map *source_map,
79 pa_sample_spec *sink_ss,
80 pa_channel_map *sink_map,
81 uint32_t *blocksize,
82 const char *args);
83
84 /* You should have only one of play()+record() or run() set. The first
85 * works under the assumption that you'll handle buffering and matching up
86 * samples yourself. If you set run(), module-echo-cancel will handle
87 * synchronising the playback and record streams. */
88
89 /* Feed the engine 'blocksize' playback bytes.. */
90 void (*play) (pa_echo_canceller *ec, const uint8_t *play);
91 /* Feed the engine 'blocksize' record bytes. blocksize processed bytes are
92 * returned in out. */
93 void (*record) (pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
94 /* Feed the engine blocksize playback and record streams, with a reasonable
95 * effort at keeping the two in sync. blocksize processed bytes are
96 * returned in out. */
97 void (*run) (pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
98
99 /* Optional callback to set the drift, expressed as the ratio of the
100 * difference in number of playback and capture samples to the number of
101 * capture samples, for some instant of time. This is used only if the
102 * canceller signals that it supports drift compensation, and is called
103 * before record(). The actual implementation needs to derive drift based
104 * on point samples -- the individual values are not accurate enough to use
105 * as-is. */
106 /* NOTE: the semantics of this function might change in the future. */
107 void (*set_drift) (pa_echo_canceller *ec, float drift);
108
109 /* Free up resources. */
110 void (*done) (pa_echo_canceller *ec);
111
112 /* Structure with common and engine-specific canceller parameters. */
113 pa_echo_canceller_params params;
114
115 /* msgobject that can be used to send messages back to the main thread */
116 pa_echo_canceller_msg *msg;
117 };
118
119 /* Functions to be used by the canceller analog gain control routines */
120 void pa_echo_canceller_get_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
121 void pa_echo_canceller_set_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
122
123 /* Speex canceller functions */
124 pa_bool_t pa_speex_ec_init(pa_core *c, pa_echo_canceller *ec,
125 pa_sample_spec *source_ss, pa_channel_map *source_map,
126 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
127 uint32_t *blocksize, const char *args);
128 void pa_speex_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
129 void pa_speex_ec_done(pa_echo_canceller *ec);
130
131 /* Adrian Andre's echo canceller */
132 pa_bool_t pa_adrian_ec_init(pa_core *c, pa_echo_canceller *ec,
133 pa_sample_spec *source_ss, pa_channel_map *source_map,
134 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
135 uint32_t *blocksize, const char *args);
136 void pa_adrian_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
137 void pa_adrian_ec_done(pa_echo_canceller *ec);
138
139 #ifdef HAVE_WEBRTC
140 /* WebRTC canceller functions */
141 PA_C_DECL_BEGIN
142 pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
143 pa_sample_spec *source_ss, pa_channel_map *source_map,
144 pa_sample_spec *sink_ss, pa_channel_map *sink_map,
145 uint32_t *blocksize, const char *args);
146 void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play);
147 void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
148 void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift);
149 void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
150 void pa_webrtc_ec_done(pa_echo_canceller *ec);
151 PA_C_DECL_END
152 #endif
153
154 #endif /* fooechocancelhfoo */