Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | */ |
| 20 | #ifndef __PJMEDIA_ECHO_H__ |
| 21 | #define __PJMEDIA_ECHO_H__ |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * @file echo.h |
| 26 | * @brief Echo Cancellation API. |
| 27 | */ |
| 28 | #include <pjmedia/types.h> |
| 29 | |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * @defgroup PJMEDIA_Echo_Cancel Accoustic Echo Cancellation API |
| 34 | * @ingroup PJMEDIA_PORT |
| 35 | * @brief Echo Cancellation API. |
| 36 | * @{ |
| 37 | * |
| 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. |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | PJ_BEGIN_DECL |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * Opaque type for PJMEDIA Echo Canceller state. |
| 51 | */ |
| 52 | typedef struct pjmedia_echo_state pjmedia_echo_state; |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Echo cancellation options. |
| 57 | */ |
| 58 | typedef enum pjmedia_echo_flag |
| 59 | { |
| 60 | /** |
| 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. |
| 64 | */ |
| 65 | PJMEDIA_ECHO_DEFAULT= 0, |
| 66 | |
| 67 | /** |
| 68 | * Force to use Speex AEC as the backend echo canceller algorithm. |
| 69 | * This setting is mutually exclusive with PJMEDIA_ECHO_SIMPLE. |
| 70 | */ |
| 71 | PJMEDIA_ECHO_SPEEX = 1, |
| 72 | |
| 73 | /** |
| 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. |
| 78 | */ |
| 79 | PJMEDIA_ECHO_SIMPLE = 2, |
| 80 | |
| 81 | /** |
| 82 | * For internal use. |
| 83 | */ |
| 84 | PJMEDIA_ECHO_ALGO_MASK = 15, |
| 85 | |
| 86 | /** |
| 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. |
| 90 | */ |
| 91 | PJMEDIA_ECHO_NO_LOCK = 16, |
| 92 | |
| 93 | /** |
| 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. |
| 97 | */ |
| 98 | PJMEDIA_ECHO_USE_SIMPLE_FIFO = 32, |
| 99 | |
| 100 | /** |
| 101 | * If PJMEDIA_ECHO_USE_SW_ECHO flag is specified, software echo canceller |
| 102 | * will be used instead of device EC. |
| 103 | */ |
| 104 | PJMEDIA_ECHO_USE_SW_ECHO = 64 |
| 105 | |
| 106 | } pjmedia_echo_flag; |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Create the echo canceller. |
| 113 | * |
| 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 |
| 120 | * is not known. |
| 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 |
| 124 | * cancellation. |
| 125 | * See #pjmedia_echo_flag for other options. |
| 126 | * @param p_echo Pointer to receive the Echo Canceller state. |
| 127 | * |
| 128 | * @return PJ_SUCCESS on success, or the appropriate status. |
| 129 | */ |
| 130 | PJ_DECL(pj_status_t) pjmedia_echo_create(pj_pool_t *pool, |
| 131 | unsigned clock_rate, |
| 132 | unsigned samples_per_frame, |
| 133 | unsigned tail_ms, |
| 134 | unsigned latency_ms, |
| 135 | unsigned options, |
| 136 | pjmedia_echo_state **p_echo ); |
| 137 | |
| 138 | /** |
| 139 | * Create multi-channel the echo canceller. |
| 140 | * |
| 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 |
| 148 | * is not known. |
| 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 |
| 152 | * cancellation. |
| 153 | * See #pjmedia_echo_flag for other options. |
| 154 | * @param p_echo Pointer to receive the Echo Canceller state. |
| 155 | * |
| 156 | * @return PJ_SUCCESS on success, or the appropriate status. |
| 157 | */ |
| 158 | PJ_DECL(pj_status_t) pjmedia_echo_create2(pj_pool_t *pool, |
| 159 | unsigned clock_rate, |
| 160 | unsigned channel_count, |
| 161 | unsigned samples_per_frame, |
| 162 | unsigned tail_ms, |
| 163 | unsigned latency_ms, |
| 164 | unsigned options, |
| 165 | pjmedia_echo_state **p_echo ); |
| 166 | |
| 167 | /** |
| 168 | * Destroy the Echo Canceller. |
| 169 | * |
| 170 | * @param echo The Echo Canceller. |
| 171 | * |
| 172 | * @return PJ_SUCCESS on success. |
| 173 | */ |
| 174 | PJ_DECL(pj_status_t) pjmedia_echo_destroy(pjmedia_echo_state *echo ); |
| 175 | |
| 176 | |
| 177 | /** |
| 178 | * Reset the echo canceller. |
| 179 | * |
| 180 | * @param echo The Echo Canceller. |
| 181 | * |
| 182 | * @return PJ_SUCCESS on success. |
| 183 | */ |
| 184 | PJ_DECL(pj_status_t) pjmedia_echo_reset(pjmedia_echo_state *echo ); |
| 185 | |
| 186 | |
| 187 | /** |
| 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(). |
| 191 | * |
| 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 |
| 196 | * number of samples. |
| 197 | * |
| 198 | * @return PJ_SUCCESS on success. |
| 199 | */ |
| 200 | PJ_DECL(pj_status_t) pjmedia_echo_playback(pjmedia_echo_state *echo, |
| 201 | pj_int16_t *play_frm ); |
| 202 | |
| 203 | |
| 204 | /** |
| 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. |
| 209 | * |
| 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 |
| 216 | * number of samples. |
| 217 | * @param options Echo cancellation options, reserved for future use. |
| 218 | * Put zero for now. |
| 219 | * |
| 220 | * @return PJ_SUCCESS on success. |
| 221 | */ |
| 222 | PJ_DECL(pj_status_t) pjmedia_echo_capture(pjmedia_echo_state *echo, |
| 223 | pj_int16_t *rec_frm, |
| 224 | unsigned options ); |
| 225 | |
| 226 | |
| 227 | /** |
| 228 | * Perform echo cancellation. |
| 229 | * |
| 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 |
| 238 | * number of samples. |
| 239 | * @param options Echo cancellation options, reserved for future use. |
| 240 | * Put zero for now. |
| 241 | * @param reserved Reserved for future use, put NULL for now. |
| 242 | * |
| 243 | * @return PJ_SUCCESS on success. |
| 244 | */ |
| 245 | PJ_DECL(pj_status_t) pjmedia_echo_cancel( pjmedia_echo_state *echo, |
| 246 | pj_int16_t *rec_frm, |
| 247 | const pj_int16_t *play_frm, |
| 248 | unsigned options, |
| 249 | void *reserved ); |
| 250 | |
| 251 | |
| 252 | PJ_END_DECL |
| 253 | |
| 254 | /** |
| 255 | * @} |
| 256 | */ |
| 257 | |
| 258 | |
| 259 | #endif /* __PJMEDIA_ECHO_H__ */ |
| 260 | |