2010-09-06 15:51:20 +05:30
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2010 Arun Raghavan <arun.raghavan@collabora.co.uk>
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2010-09-06 15:51:20 +05:30
|
|
|
***/
|
|
|
|
|
|
2011-08-24 10:34:19 +05:30
|
|
|
#ifndef fooechocancelhfoo
|
|
|
|
|
#define fooechocancelhfoo
|
|
|
|
|
|
2010-09-06 15:51:20 +05:30
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <pulse/sample.h>
|
|
|
|
|
#include <pulse/channelmap.h>
|
2010-09-21 20:42:32 +05:30
|
|
|
#include <pulsecore/core.h>
|
2010-09-06 15:51:20 +05:30
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
|
2011-12-11 16:07:41 +01:00
|
|
|
#ifdef HAVE_SPEEX
|
2010-09-06 15:51:20 +05:30
|
|
|
#include <speex/speex_echo.h>
|
2011-05-19 13:29:49 +05:30
|
|
|
#include <speex/speex_preprocess.h>
|
2011-12-11 16:07:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
2010-09-07 13:43:58 +05:30
|
|
|
#include "adrian.h"
|
2010-09-06 15:51:20 +05:30
|
|
|
|
|
|
|
|
/* Common data structures */
|
|
|
|
|
|
2011-11-04 16:17:26 +05:30
|
|
|
typedef struct pa_echo_canceller_msg pa_echo_canceller_msg;
|
|
|
|
|
|
2010-09-06 15:51:20 +05:30
|
|
|
typedef struct pa_echo_canceller_params pa_echo_canceller_params;
|
|
|
|
|
|
|
|
|
|
struct pa_echo_canceller_params {
|
|
|
|
|
union {
|
2012-12-20 11:33:05 +01:00
|
|
|
struct {
|
echo-cancel: Enable different sample specs for rec and out stream
Enable advanced AEC methods to use different specs (i.e., number of
channels) for rec and out stream. A typical application is beam forming
resp. multi-channel AEC, which takes multiple record channels to produce
an echo-canceled output stream.
This commit alters the EC API as follows: the EC's init() used to get
source and sink's sample spec/channel map. The new interface renamed
source to rec and sink to play and additionally passes sample spec and
channel map of the out stream. The new parameter names of init()
{rec,play,out}_{ss,map} are more intuitive and also resemble to the
parameter names known from run(). Both rec_{ss,map} and out_{ss,map} are
initialized as we knew it from source_{ss,map} before being passed to
init(). The previous EC implementations only require trivial changes,
i.e., setting rec_{ss,map} to out_{ss,map} at the end of init() in case
that out_{ss,map} is modified in init().
2013-02-18 16:31:03 +01:00
|
|
|
pa_sample_spec out_ss;
|
2012-12-20 11:33:05 +01:00
|
|
|
} null;
|
2011-12-11 16:07:41 +01:00
|
|
|
#ifdef HAVE_SPEEX
|
2010-09-06 15:51:20 +05:30
|
|
|
struct {
|
|
|
|
|
SpeexEchoState *state;
|
2011-08-25 17:47:05 +05:30
|
|
|
SpeexPreprocessState *pp_state;
|
2010-09-06 15:51:20 +05:30
|
|
|
} speex;
|
2011-12-11 16:07:41 +01:00
|
|
|
#endif
|
2011-12-11 16:07:42 +01:00
|
|
|
#ifdef HAVE_ADRIAN_EC
|
2010-09-07 13:43:58 +05:30
|
|
|
struct {
|
|
|
|
|
uint32_t blocksize;
|
|
|
|
|
AEC *aec;
|
|
|
|
|
} adrian;
|
2011-12-11 16:07:42 +01:00
|
|
|
#endif
|
2011-09-19 13:41:13 +05:30
|
|
|
#ifdef HAVE_WEBRTC
|
|
|
|
|
struct {
|
|
|
|
|
/* This is a void* so that we don't have to convert this whole file
|
|
|
|
|
* to C++ linkage. apm is a pointer to an AudioProcessing object */
|
|
|
|
|
void *apm;
|
2016-02-17 19:47:08 +05:30
|
|
|
unsigned int blocksize; /* in frames */
|
2016-02-17 19:47:10 +05:30
|
|
|
pa_sample_spec rec_ss, play_ss, out_ss;
|
2016-02-17 19:47:12 +05:30
|
|
|
float *rec_buffer[PA_CHANNELS_MAX], *play_buffer[PA_CHANNELS_MAX]; /* for deinterleaved buffers */
|
2016-02-17 19:47:00 +05:30
|
|
|
void *trace_callback;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool agc;
|
2016-02-17 19:47:02 +05:30
|
|
|
bool first;
|
2016-02-17 19:47:06 +05:30
|
|
|
unsigned int agc_start_volume;
|
2011-09-19 13:41:13 +05:30
|
|
|
} webrtc;
|
|
|
|
|
#endif
|
2010-09-06 15:51:20 +05:30
|
|
|
/* each canceller-specific structure goes here */
|
2016-02-17 19:47:06 +05:30
|
|
|
};
|
2011-10-07 16:28:11 +05:30
|
|
|
|
|
|
|
|
/* Set this if canceller can do drift compensation. Also see set_drift()
|
|
|
|
|
* below */
|
2013-06-27 19:28:09 +02:00
|
|
|
bool drift_compensation;
|
2010-09-06 15:51:20 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct pa_echo_canceller pa_echo_canceller;
|
|
|
|
|
|
|
|
|
|
struct pa_echo_canceller {
|
2011-10-07 16:28:11 +05:30
|
|
|
/* Initialise canceller engine. */
|
2013-06-28 01:03:47 +02:00
|
|
|
bool (*init) (pa_core *c,
|
2010-09-21 20:42:32 +05:30
|
|
|
pa_echo_canceller *ec,
|
echo-cancel: Enable different sample specs for rec and out stream
Enable advanced AEC methods to use different specs (i.e., number of
channels) for rec and out stream. A typical application is beam forming
resp. multi-channel AEC, which takes multiple record channels to produce
an echo-canceled output stream.
This commit alters the EC API as follows: the EC's init() used to get
source and sink's sample spec/channel map. The new interface renamed
source to rec and sink to play and additionally passes sample spec and
channel map of the out stream. The new parameter names of init()
{rec,play,out}_{ss,map} are more intuitive and also resemble to the
parameter names known from run(). Both rec_{ss,map} and out_{ss,map} are
initialized as we knew it from source_{ss,map} before being passed to
init(). The previous EC implementations only require trivial changes,
i.e., setting rec_{ss,map} to out_{ss,map} at the end of init() in case
that out_{ss,map} is modified in init().
2013-02-18 16:31:03 +01:00
|
|
|
pa_sample_spec *rec_ss,
|
|
|
|
|
pa_channel_map *rec_map,
|
|
|
|
|
pa_sample_spec *play_ss,
|
|
|
|
|
pa_channel_map *play_map,
|
|
|
|
|
pa_sample_spec *out_ss,
|
|
|
|
|
pa_channel_map *out_map,
|
2012-12-20 11:33:04 +01:00
|
|
|
uint32_t *nframes,
|
2010-09-06 22:23:51 +05:30
|
|
|
const char *args);
|
2011-10-07 16:28:11 +05:30
|
|
|
|
|
|
|
|
/* You should have only one of play()+record() or run() set. The first
|
|
|
|
|
* works under the assumption that you'll handle buffering and matching up
|
|
|
|
|
* samples yourself. If you set run(), module-echo-cancel will handle
|
|
|
|
|
* synchronising the playback and record streams. */
|
|
|
|
|
|
2012-12-20 11:33:04 +01:00
|
|
|
/* Feed the engine 'nframes' playback frames. */
|
2011-10-07 16:28:11 +05:30
|
|
|
void (*play) (pa_echo_canceller *ec, const uint8_t *play);
|
2012-12-20 11:33:04 +01:00
|
|
|
/* Feed the engine 'nframes' record frames. nframes processed frames are
|
2011-10-07 16:28:11 +05:30
|
|
|
* returned in out. */
|
|
|
|
|
void (*record) (pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
|
2012-12-20 11:33:04 +01:00
|
|
|
/* Feed the engine nframes playback and record frames, with a reasonable
|
|
|
|
|
* effort at keeping the two in sync. nframes processed frames are
|
2011-10-07 16:28:11 +05:30
|
|
|
* returned in out. */
|
2010-09-07 15:07:39 +05:30
|
|
|
void (*run) (pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
|
2011-10-07 16:28:11 +05:30
|
|
|
|
|
|
|
|
/* Optional callback to set the drift, expressed as the ratio of the
|
|
|
|
|
* difference in number of playback and capture samples to the number of
|
|
|
|
|
* capture samples, for some instant of time. This is used only if the
|
|
|
|
|
* canceller signals that it supports drift compensation, and is called
|
|
|
|
|
* before record(). The actual implementation needs to derive drift based
|
|
|
|
|
* on point samples -- the individual values are not accurate enough to use
|
|
|
|
|
* as-is. */
|
|
|
|
|
/* NOTE: the semantics of this function might change in the future. */
|
|
|
|
|
void (*set_drift) (pa_echo_canceller *ec, float drift);
|
|
|
|
|
|
|
|
|
|
/* Free up resources. */
|
2010-09-06 15:51:20 +05:30
|
|
|
void (*done) (pa_echo_canceller *ec);
|
|
|
|
|
|
2011-10-07 16:28:11 +05:30
|
|
|
/* Structure with common and engine-specific canceller parameters. */
|
2010-09-06 15:51:20 +05:30
|
|
|
pa_echo_canceller_params params;
|
2011-11-04 16:17:26 +05:30
|
|
|
|
|
|
|
|
/* msgobject that can be used to send messages back to the main thread */
|
|
|
|
|
pa_echo_canceller_msg *msg;
|
2010-09-06 15:51:20 +05:30
|
|
|
};
|
|
|
|
|
|
2011-11-04 16:17:26 +05:30
|
|
|
/* Functions to be used by the canceller analog gain control routines */
|
2016-02-25 17:58:38 +05:30
|
|
|
pa_volume_t pa_echo_canceller_get_capture_volume(pa_echo_canceller *ec);
|
|
|
|
|
void pa_echo_canceller_set_capture_volume(pa_echo_canceller *ec, pa_volume_t volume);
|
2011-11-04 16:17:26 +05:30
|
|
|
|
2013-02-13 17:26:51 +01:00
|
|
|
/* Computes EC block size in frames (rounded down to nearest power-of-2) based
|
|
|
|
|
* on sample rate and milliseconds. */
|
|
|
|
|
uint32_t pa_echo_canceller_blocksize_power2(unsigned rate, unsigned ms);
|
|
|
|
|
|
2012-07-24 10:16:56 +02:00
|
|
|
/* Null canceller functions */
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_null_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2013-06-28 01:03:47 +02:00
|
|
|
pa_sample_spec *rec_ss, pa_channel_map *rec_map,
|
|
|
|
|
pa_sample_spec *play_ss, pa_channel_map *play_map,
|
|
|
|
|
pa_sample_spec *out_ss, pa_channel_map *out_map,
|
|
|
|
|
uint32_t *nframes, const char *args);
|
2012-07-24 10:16:56 +02:00
|
|
|
void pa_null_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
|
|
|
|
|
void pa_null_ec_done(pa_echo_canceller *ec);
|
|
|
|
|
|
2011-12-11 16:07:41 +01:00
|
|
|
#ifdef HAVE_SPEEX
|
2010-09-06 15:51:20 +05:30
|
|
|
/* Speex canceller functions */
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_speex_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2013-06-28 01:03:47 +02:00
|
|
|
pa_sample_spec *rec_ss, pa_channel_map *rec_map,
|
|
|
|
|
pa_sample_spec *play_ss, pa_channel_map *play_map,
|
|
|
|
|
pa_sample_spec *out_ss, pa_channel_map *out_map,
|
|
|
|
|
uint32_t *nframes, const char *args);
|
2010-09-07 15:07:39 +05:30
|
|
|
void pa_speex_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
|
2010-09-06 15:51:20 +05:30
|
|
|
void pa_speex_ec_done(pa_echo_canceller *ec);
|
2011-12-11 16:07:41 +01:00
|
|
|
#endif
|
2010-09-07 13:43:58 +05:30
|
|
|
|
2011-12-11 16:07:42 +01:00
|
|
|
#ifdef HAVE_ADRIAN_EC
|
2010-09-07 13:43:58 +05:30
|
|
|
/* Adrian Andre's echo canceller */
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_adrian_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2013-06-28 01:03:47 +02:00
|
|
|
pa_sample_spec *rec_ss, pa_channel_map *rec_map,
|
|
|
|
|
pa_sample_spec *play_ss, pa_channel_map *play_map,
|
|
|
|
|
pa_sample_spec *out_ss, pa_channel_map *out_map,
|
|
|
|
|
uint32_t *nframes, const char *args);
|
2010-09-07 15:07:39 +05:30
|
|
|
void pa_adrian_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
|
2010-09-07 13:43:58 +05:30
|
|
|
void pa_adrian_ec_done(pa_echo_canceller *ec);
|
2011-12-11 16:07:42 +01:00
|
|
|
#endif
|
2011-08-24 10:34:19 +05:30
|
|
|
|
2011-09-19 13:41:13 +05:30
|
|
|
#ifdef HAVE_WEBRTC
|
|
|
|
|
/* WebRTC canceller functions */
|
|
|
|
|
PA_C_DECL_BEGIN
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2013-06-28 01:03:47 +02:00
|
|
|
pa_sample_spec *rec_ss, pa_channel_map *rec_map,
|
|
|
|
|
pa_sample_spec *play_ss, pa_channel_map *play_map,
|
|
|
|
|
pa_sample_spec *out_ss, pa_channel_map *out_map,
|
|
|
|
|
uint32_t *nframes, const char *args);
|
2011-10-07 16:28:11 +05:30
|
|
|
void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play);
|
|
|
|
|
void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out);
|
|
|
|
|
void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift);
|
2011-09-19 13:41:13 +05:30
|
|
|
void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out);
|
|
|
|
|
void pa_webrtc_ec_done(pa_echo_canceller *ec);
|
|
|
|
|
PA_C_DECL_END
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-24 10:34:19 +05:30
|
|
|
#endif /* fooechocancelhfoo */
|