1
/* $Id: echo.h 4082 2012-04-24 13:09:14Z bennylp $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_ECHO_H__
21
#define __PJMEDIA_ECHO_H__
26
* @brief Echo Cancellation API.
28
#include <pjmedia/types.h>
33
* @defgroup PJMEDIA_Echo_Cancel Accoustic Echo Cancellation API
34
* @ingroup PJMEDIA_PORT
35
* @brief Echo Cancellation API.
38
* This section describes API to perform echo cancellation to audio signal.
39
* There may be multiple echo canceller implementation in PJMEDIA, ranging
40
* from simple echo suppressor to a full Accoustic Echo Canceller/AEC. By
41
* using this API, application should be able to use which EC backend to
42
* use base on the requirement and capability of the platform.
50
* Opaque type for PJMEDIA Echo Canceller state.
52
typedef struct pjmedia_echo_state pjmedia_echo_state;
56
* Echo cancellation options.
58
typedef enum pjmedia_echo_flag
61
* Use any available backend echo canceller algorithm. This is
62
* the default settings. This setting is mutually exclusive with
63
* PJMEDIA_ECHO_SIMPLE and PJMEDIA_ECHO_SPEEX.
65
PJMEDIA_ECHO_DEFAULT= 0,
68
* Force to use Speex AEC as the backend echo canceller algorithm.
69
* This setting is mutually exclusive with PJMEDIA_ECHO_SIMPLE.
71
PJMEDIA_ECHO_SPEEX = 1,
74
* If PJMEDIA_ECHO_SIMPLE flag is specified during echo canceller
75
* creation, then a simple echo suppressor will be used instead of
76
* an accoustic echo cancellation. This setting is mutually exclusive
77
* with PJMEDIA_ECHO_SPEEX.
79
PJMEDIA_ECHO_SIMPLE = 2,
84
PJMEDIA_ECHO_ALGO_MASK = 15,
87
* If PJMEDIA_ECHO_NO_LOCK flag is specified, no mutex will be created
88
* for the echo canceller, but application will guarantee that echo
89
* canceller will not be called by different threads at the same time.
91
PJMEDIA_ECHO_NO_LOCK = 16,
94
* If PJMEDIA_ECHO_USE_SIMPLE_FIFO flag is specified, the delay buffer
95
* created for the echo canceller will use simple FIFO mechanism, i.e.
96
* without using WSOLA to expand and shrink audio samples.
98
PJMEDIA_ECHO_USE_SIMPLE_FIFO = 32,
101
* If PJMEDIA_ECHO_USE_SW_ECHO flag is specified, software echo canceller
102
* will be used instead of device EC.
104
PJMEDIA_ECHO_USE_SW_ECHO = 64
112
* Create the echo canceller.
114
* @param pool Pool to allocate memory.
115
* @param clock_rate Media clock rate/sampling rate.
116
* @param samples_per_frame Number of samples per frame.
117
* @param tail_ms Tail length, miliseconds.
118
* @param latency_ms Total lacency introduced by playback and
119
* recording device. Set to zero if the latency
121
* @param options Options. If PJMEDIA_ECHO_SIMPLE is specified,
122
* then a simple echo suppressor implementation
123
* will be used instead of an accoustic echo
125
* See #pjmedia_echo_flag for other options.
126
* @param p_echo Pointer to receive the Echo Canceller state.
128
* @return PJ_SUCCESS on success, or the appropriate status.
130
PJ_DECL(pj_status_t) pjmedia_echo_create(pj_pool_t *pool,
132
unsigned samples_per_frame,
136
pjmedia_echo_state **p_echo );
139
* Create multi-channel the echo canceller.
141
* @param pool Pool to allocate memory.
142
* @param clock_rate Media clock rate/sampling rate.
143
* @param channel_count Number of channels.
144
* @param samples_per_frame Number of samples per frame.
145
* @param tail_ms Tail length, miliseconds.
146
* @param latency_ms Total lacency introduced by playback and
147
* recording device. Set to zero if the latency
149
* @param options Options. If PJMEDIA_ECHO_SIMPLE is specified,
150
* then a simple echo suppressor implementation
151
* will be used instead of an accoustic echo
153
* See #pjmedia_echo_flag for other options.
154
* @param p_echo Pointer to receive the Echo Canceller state.
156
* @return PJ_SUCCESS on success, or the appropriate status.
158
PJ_DECL(pj_status_t) pjmedia_echo_create2(pj_pool_t *pool,
160
unsigned channel_count,
161
unsigned samples_per_frame,
165
pjmedia_echo_state **p_echo );
168
* Destroy the Echo Canceller.
170
* @param echo The Echo Canceller.
172
* @return PJ_SUCCESS on success.
174
PJ_DECL(pj_status_t) pjmedia_echo_destroy(pjmedia_echo_state *echo );
178
* Reset the echo canceller.
180
* @param echo The Echo Canceller.
182
* @return PJ_SUCCESS on success.
184
PJ_DECL(pj_status_t) pjmedia_echo_reset(pjmedia_echo_state *echo );
188
* Let the Echo Canceller know that a frame has been played to the speaker.
189
* The Echo Canceller will keep the frame in its internal buffer, to be used
190
* when cancelling the echo with #pjmedia_echo_capture().
192
* @param echo The Echo Canceller.
193
* @param play_frm Sample buffer containing frame to be played
194
* (or has been played) to the playback device.
195
* The frame must contain exactly samples_per_frame
198
* @return PJ_SUCCESS on success.
200
PJ_DECL(pj_status_t) pjmedia_echo_playback(pjmedia_echo_state *echo,
201
pj_int16_t *play_frm );
205
* Let the Echo Canceller know that a frame has been captured from the
206
* microphone. The Echo Canceller will cancel the echo from the captured
207
* signal, using the internal buffer (supplied by #pjmedia_echo_playback())
208
* as the FES (Far End Speech) reference.
210
* @param echo The Echo Canceller.
211
* @param rec_frm On input, it contains the input signal (captured
212
* from microphone) which echo is to be removed.
213
* Upon returning this function, this buffer contain
214
* the processed signal with the echo removed.
215
* The frame must contain exactly samples_per_frame
217
* @param options Echo cancellation options, reserved for future use.
220
* @return PJ_SUCCESS on success.
222
PJ_DECL(pj_status_t) pjmedia_echo_capture(pjmedia_echo_state *echo,
228
* Perform echo cancellation.
230
* @param echo The Echo Canceller.
231
* @param rec_frm On input, it contains the input signal (captured
232
* from microphone) which echo is to be removed.
233
* Upon returning this function, this buffer contain
234
* the processed signal with the echo removed.
235
* @param play_frm Sample buffer containing frame to be played
236
* (or has been played) to the playback device.
237
* The frame must contain exactly samples_per_frame
239
* @param options Echo cancellation options, reserved for future use.
241
* @param reserved Reserved for future use, put NULL for now.
243
* @return PJ_SUCCESS on success.
245
PJ_DECL(pj_status_t) pjmedia_echo_cancel( pjmedia_echo_state *echo,
247
const pj_int16_t *play_frm,
259
#endif /* __PJMEDIA_ECHO_H__ */