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
22 #ifndef fooechocancelhfoo
23 #define fooechocancelhfoo
29 #include <pulse/sample.h>
30 #include <pulse/channelmap.h>
31 #include <pulsecore/core.h>
32 #include <pulsecore/macro.h>
35 #include <speex/speex_echo.h>
36 #include <speex/speex_preprocess.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
{
50 pa_sample_spec source_ss
;
54 SpeexEchoState
*state
;
55 SpeexPreprocessState
*pp_state
;
66 /* This is a void* so that we don't have to convert this whole file
67 * to C++ linkage. apm is a pointer to an AudioProcessing object */
70 pa_sample_spec sample_spec
;
74 /* each canceller-specific structure goes here */
77 /* Set this if canceller can do drift compensation. Also see set_drift()
79 pa_bool_t drift_compensation
;
82 typedef struct pa_echo_canceller pa_echo_canceller
;
84 struct pa_echo_canceller
{
85 /* Initialise canceller engine. */
86 pa_bool_t (*init
) (pa_core
*c
,
87 pa_echo_canceller
*ec
,
88 pa_sample_spec
*source_ss
,
89 pa_channel_map
*source_map
,
90 pa_sample_spec
*sink_ss
,
91 pa_channel_map
*sink_map
,
95 /* You should have only one of play()+record() or run() set. The first
96 * works under the assumption that you'll handle buffering and matching up
97 * samples yourself. If you set run(), module-echo-cancel will handle
98 * synchronising the playback and record streams. */
100 /* Feed the engine 'nframes' playback frames. */
101 void (*play
) (pa_echo_canceller
*ec
, const uint8_t *play
);
102 /* Feed the engine 'nframes' record frames. nframes processed frames are
103 * returned in out. */
104 void (*record
) (pa_echo_canceller
*ec
, const uint8_t *rec
, uint8_t *out
);
105 /* Feed the engine nframes playback and record frames, with a reasonable
106 * effort at keeping the two in sync. nframes processed frames are
107 * returned in out. */
108 void (*run
) (pa_echo_canceller
*ec
, const uint8_t *rec
, const uint8_t *play
, uint8_t *out
);
110 /* Optional callback to set the drift, expressed as the ratio of the
111 * difference in number of playback and capture samples to the number of
112 * capture samples, for some instant of time. This is used only if the
113 * canceller signals that it supports drift compensation, and is called
114 * before record(). The actual implementation needs to derive drift based
115 * on point samples -- the individual values are not accurate enough to use
117 /* NOTE: the semantics of this function might change in the future. */
118 void (*set_drift
) (pa_echo_canceller
*ec
, float drift
);
120 /* Free up resources. */
121 void (*done
) (pa_echo_canceller
*ec
);
123 /* Structure with common and engine-specific canceller parameters. */
124 pa_echo_canceller_params params
;
126 /* msgobject that can be used to send messages back to the main thread */
127 pa_echo_canceller_msg
*msg
;
130 /* Functions to be used by the canceller analog gain control routines */
131 void pa_echo_canceller_get_capture_volume(pa_echo_canceller
*ec
, pa_cvolume
*v
);
132 void pa_echo_canceller_set_capture_volume(pa_echo_canceller
*ec
, pa_cvolume
*v
);
134 /* Computes EC block size in frames (rounded down to nearest power-of-2) based
135 * on sample rate and milliseconds. */
136 uint32_t pa_echo_canceller_blocksize_power2(unsigned rate
, unsigned ms
);
138 /* Null canceller functions */
139 pa_bool_t
pa_null_ec_init(pa_core
*c
, pa_echo_canceller
*ec
,
140 pa_sample_spec
*source_ss
, pa_channel_map
*source_map
,
141 pa_sample_spec
*sink_ss
, pa_channel_map
*sink_map
,
142 uint32_t *nframes
, const char *args
);
143 void pa_null_ec_run(pa_echo_canceller
*ec
, const uint8_t *rec
, const uint8_t *play
, uint8_t *out
);
144 void pa_null_ec_done(pa_echo_canceller
*ec
);
147 /* Speex canceller functions */
148 pa_bool_t
pa_speex_ec_init(pa_core
*c
, pa_echo_canceller
*ec
,
149 pa_sample_spec
*source_ss
, pa_channel_map
*source_map
,
150 pa_sample_spec
*sink_ss
, pa_channel_map
*sink_map
,
151 uint32_t *nframes
, const char *args
);
152 void pa_speex_ec_run(pa_echo_canceller
*ec
, const uint8_t *rec
, const uint8_t *play
, uint8_t *out
);
153 void pa_speex_ec_done(pa_echo_canceller
*ec
);
156 #ifdef HAVE_ADRIAN_EC
157 /* Adrian Andre's echo canceller */
158 pa_bool_t
pa_adrian_ec_init(pa_core
*c
, pa_echo_canceller
*ec
,
159 pa_sample_spec
*source_ss
, pa_channel_map
*source_map
,
160 pa_sample_spec
*sink_ss
, pa_channel_map
*sink_map
,
161 uint32_t *nframes
, const char *args
);
162 void pa_adrian_ec_run(pa_echo_canceller
*ec
, const uint8_t *rec
, const uint8_t *play
, uint8_t *out
);
163 void pa_adrian_ec_done(pa_echo_canceller
*ec
);
167 /* WebRTC canceller functions */
169 pa_bool_t
pa_webrtc_ec_init(pa_core
*c
, pa_echo_canceller
*ec
,
170 pa_sample_spec
*source_ss
, pa_channel_map
*source_map
,
171 pa_sample_spec
*sink_ss
, pa_channel_map
*sink_map
,
172 uint32_t *nframes
, const char *args
);
173 void pa_webrtc_ec_play(pa_echo_canceller
*ec
, const uint8_t *play
);
174 void pa_webrtc_ec_record(pa_echo_canceller
*ec
, const uint8_t *rec
, uint8_t *out
);
175 void pa_webrtc_ec_set_drift(pa_echo_canceller
*ec
, float drift
);
176 void pa_webrtc_ec_run(pa_echo_canceller
*ec
, const uint8_t *rec
, const uint8_t *play
, uint8_t *out
);
177 void pa_webrtc_ec_done(pa_echo_canceller
*ec
);
181 #endif /* fooechocancelhfoo */