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
|
|
|
|
|
along with PulseAudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
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 {
|
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;
|
|
|
|
|
uint32_t blocksize;
|
|
|
|
|
pa_sample_spec sample_spec;
|
2011-11-04 16:38:30 +05:30
|
|
|
pa_bool_t agc;
|
2011-09-19 13:41:13 +05:30
|
|
|
} webrtc;
|
|
|
|
|
#endif
|
2010-09-06 15:51:20 +05:30
|
|
|
/* each canceller-specific structure goes here */
|
|
|
|
|
} priv;
|
2011-10-07 16:28:11 +05:30
|
|
|
|
|
|
|
|
/* Set this if canceller can do drift compensation. Also see set_drift()
|
|
|
|
|
* below */
|
|
|
|
|
pa_bool_t 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. */
|
2010-09-21 20:42:32 +05:30
|
|
|
pa_bool_t (*init) (pa_core *c,
|
|
|
|
|
pa_echo_canceller *ec,
|
2010-09-06 22:23:51 +05:30
|
|
|
pa_sample_spec *source_ss,
|
|
|
|
|
pa_channel_map *source_map,
|
|
|
|
|
pa_sample_spec *sink_ss,
|
|
|
|
|
pa_channel_map *sink_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 */
|
|
|
|
|
void pa_echo_canceller_get_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
|
|
|
|
|
void pa_echo_canceller_set_capture_volume(pa_echo_canceller *ec, pa_cvolume *v);
|
|
|
|
|
|
2012-07-24 10:16:56 +02:00
|
|
|
/* Null canceller functions */
|
|
|
|
|
pa_bool_t pa_null_ec_init(pa_core *c, pa_echo_canceller *ec,
|
|
|
|
|
pa_sample_spec *source_ss, pa_channel_map *source_map,
|
|
|
|
|
pa_sample_spec *sink_ss, pa_channel_map *sink_map,
|
2012-12-20 11:33:04 +01:00
|
|
|
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 */
|
2010-09-21 20:42:32 +05:30
|
|
|
pa_bool_t pa_speex_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2010-09-06 22:23:51 +05:30
|
|
|
pa_sample_spec *source_ss, pa_channel_map *source_map,
|
|
|
|
|
pa_sample_spec *sink_ss, pa_channel_map *sink_map,
|
2012-12-20 11:33:04 +01:00
|
|
|
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 */
|
2010-09-21 20:42:32 +05:30
|
|
|
pa_bool_t pa_adrian_ec_init(pa_core *c, pa_echo_canceller *ec,
|
2010-09-07 13:43:58 +05:30
|
|
|
pa_sample_spec *source_ss, pa_channel_map *source_map,
|
|
|
|
|
pa_sample_spec *sink_ss, pa_channel_map *sink_map,
|
2012-12-20 11:33:04 +01:00
|
|
|
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
|
|
|
|
|
pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
|
|
|
|
|
pa_sample_spec *source_ss, pa_channel_map *source_map,
|
|
|
|
|
pa_sample_spec *sink_ss, pa_channel_map *sink_map,
|
2012-12-20 11:33:04 +01:00
|
|
|
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 */
|