blob: de84b2e6d13d67d0849367b89fafdb34b31bf7b2 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.orgb9d7d932012-01-25 19:21:13 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Henrik Kjellander9b72af92015-11-11 20:16:11 +010011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Peter Kastingdce40cf2015-08-24 14:52:23 -070014#include <stddef.h>
15
bjornv@webrtc.org21a2fc92013-02-15 17:01:03 +000016#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18// Errors
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000019#define AEC_UNSPECIFIED_ERROR 12000
20#define AEC_UNSUPPORTED_FUNCTION_ERROR 12001
21#define AEC_UNINITIALIZED_ERROR 12002
22#define AEC_NULL_POINTER_ERROR 12003
23#define AEC_BAD_PARAMETER_ERROR 12004
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25// Warnings
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000026#define AEC_BAD_PARAMETER_WARNING 12050
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28enum {
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000029 kAecNlpConservative = 0,
30 kAecNlpModerate,
31 kAecNlpAggressive
niklase@google.com470e71d2011-07-07 08:21:25 +000032};
33
34enum {
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000035 kAecFalse = 0,
36 kAecTrue
niklase@google.com470e71d2011-07-07 08:21:25 +000037};
38
39typedef struct {
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000040 int16_t nlpMode; // default kAecNlpModerate
41 int16_t skewMode; // default kAecFalse
42 int16_t metricsMode; // default kAecFalse
43 int delay_logging; // default kAecFalse
44 // float realSkew;
niklase@google.com470e71d2011-07-07 08:21:25 +000045} AecConfig;
46
47typedef struct {
bjornv@webrtc.orgb4cd3422013-02-15 18:40:34 +000048 int instant;
49 int average;
50 int max;
51 int min;
niklase@google.com470e71d2011-07-07 08:21:25 +000052} AecLevel;
53
54typedef struct {
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000055 AecLevel rerl;
56 AecLevel erl;
57 AecLevel erle;
58 AecLevel aNlp;
niklase@google.com470e71d2011-07-07 08:21:25 +000059} AecMetrics;
60
bjornv@webrtc.org132c15d2013-02-27 21:03:41 +000061struct AecCore;
62
niklase@google.com470e71d2011-07-07 08:21:25 +000063#ifdef __cplusplus
64extern "C" {
65#endif
66
67/*
68 * Allocates the memory needed by the AEC. The memory needs to be initialized
Bjorn Volcker9345e862015-06-10 21:43:36 +020069 * separately using the WebRtcAec_Init() function. Returns a pointer to the
70 * object or NULL on error.
niklase@google.com470e71d2011-07-07 08:21:25 +000071 */
Bjorn Volcker9345e862015-06-10 21:43:36 +020072void* WebRtcAec_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000073
74/*
75 * This function releases the memory allocated by WebRtcAec_Create().
76 *
77 * Inputs Description
78 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000079 * void* aecInst Pointer to the AEC instance
niklase@google.com470e71d2011-07-07 08:21:25 +000080 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020081void WebRtcAec_Free(void* aecInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
83/*
84 * Initializes an AEC instance.
85 *
86 * Inputs Description
87 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000088 * void* aecInst Pointer to the AEC instance
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000089 * int32_t sampFreq Sampling frequency of data
90 * int32_t scSampFreq Soundcard sampling frequency
niklase@google.com470e71d2011-07-07 08:21:25 +000091 *
92 * Outputs Description
93 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000094 * int32_t return 0: OK
95 * -1: error
niklase@google.com470e71d2011-07-07 08:21:25 +000096 */
andrew@webrtc.org13b2d462013-10-08 23:41:42 +000097int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq);
niklase@google.com470e71d2011-07-07 08:21:25 +000098
99/*
100 * Inserts an 80 or 160 sample block of data into the farend buffer.
101 *
102 * Inputs Description
103 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000104 * void* aecInst Pointer to the AEC instance
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000105 * const float* farend In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000106 * farend signal for L band
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000107 * int16_t nrOfSamples Number of samples in farend buffer
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 *
109 * Outputs Description
110 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000111 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800112 * 12000-12050: error code
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 */
andrew@webrtc.org13b2d462013-10-08 23:41:42 +0000114int32_t WebRtcAec_BufferFarend(void* aecInst,
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000115 const float* farend,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700116 size_t nrOfSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
118/*
peahc12be392015-11-09 23:53:50 -0800119 * Reports any errors that would arise if buffering a farend buffer
120 *
121 * Inputs Description
122 * -------------------------------------------------------------------
123 * void* aecInst Pointer to the AEC instance
124 * const float* farend In buffer containing one frame of
125 * farend signal for L band
126 * int16_t nrOfSamples Number of samples in farend buffer
127 *
128 * Outputs Description
129 * -------------------------------------------------------------------
130 * int32_t return 0: OK
131 * 12000-12050: error code
132 */
133int32_t WebRtcAec_GetBufferFarendError(void* aecInst,
134 const float* farend,
135 size_t nrOfSamples);
136
137/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 * Runs the echo canceller on an 80 or 160 sample blocks of data.
139 *
140 * Inputs Description
141 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000142 * void* aecInst Pointer to the AEC instance
aluebs@webrtc.orgc78d81a2015-01-21 19:10:55 +0000143 * float* const* nearend In buffer containing one frame of
144 * nearend+echo signal for each band
145 * int num_bands Number of bands in nearend buffer
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000146 * int16_t nrOfSamples Number of samples in nearend buffer
147 * int16_t msInSndCardBuf Delay estimate for sound card and
niklase@google.com470e71d2011-07-07 08:21:25 +0000148 * system buffers
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000149 * int16_t skew Difference between number of samples played
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 * and recorded at the soundcard (for clock skew
151 * compensation)
152 *
153 * Outputs Description
154 * -------------------------------------------------------------------
aluebs@webrtc.orgc78d81a2015-01-21 19:10:55 +0000155 * float* const* out Out buffer, one frame of processed nearend
156 * for each band
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000157 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800158 * 12000-12050: error code
niklase@google.com470e71d2011-07-07 08:21:25 +0000159 */
andrew@webrtc.org13b2d462013-10-08 23:41:42 +0000160int32_t WebRtcAec_Process(void* aecInst,
aluebs@webrtc.orgc78d81a2015-01-21 19:10:55 +0000161 const float* const* nearend,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700162 size_t num_bands,
aluebs@webrtc.orgc78d81a2015-01-21 19:10:55 +0000163 float* const* out,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700164 size_t nrOfSamples,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000165 int16_t msInSndCardBuf,
166 int32_t skew);
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
168/*
169 * This function enables the user to set certain parameters on-the-fly.
170 *
171 * Inputs Description
172 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000173 * void* handle Pointer to the AEC instance
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 * AecConfig config Config instance that contains all
175 * properties to be set
176 *
177 * Outputs Description
178 * -------------------------------------------------------------------
peahc12be392015-11-09 23:53:50 -0800179 * int return 0: OK
180 * 12000-12050: error code
niklase@google.com470e71d2011-07-07 08:21:25 +0000181 */
bjornv@webrtc.org47b274d2013-02-20 17:09:47 +0000182int WebRtcAec_set_config(void* handle, AecConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
184/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000185 * Gets the current echo status of the nearend signal.
186 *
187 * Inputs Description
188 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000189 * void* handle Pointer to the AEC instance
niklase@google.com470e71d2011-07-07 08:21:25 +0000190 *
191 * Outputs Description
192 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000193 * int* status 0: Almost certainly nearend single-talk
niklase@google.com470e71d2011-07-07 08:21:25 +0000194 * 1: Might not be neared single-talk
peahc12be392015-11-09 23:53:50 -0800195 * int return 0: OK
196 * 12000-12050: error code
niklase@google.com470e71d2011-07-07 08:21:25 +0000197 */
bjornv@webrtc.org21a2fc92013-02-15 17:01:03 +0000198int WebRtcAec_get_echo_status(void* handle, int* status);
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
200/*
201 * Gets the current echo metrics for the session.
202 *
203 * Inputs Description
204 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000205 * void* handle Pointer to the AEC instance
niklase@google.com470e71d2011-07-07 08:21:25 +0000206 *
207 * Outputs Description
208 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000209 * AecMetrics* metrics Struct which will be filled out with the
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 * current echo metrics.
peahc12be392015-11-09 23:53:50 -0800211 * int return 0: OK
212 * 12000-12050: error code
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 */
bjornv@webrtc.orgb4cd3422013-02-15 18:40:34 +0000214int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics);
niklase@google.com470e71d2011-07-07 08:21:25 +0000215
216/*
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000217 * Gets the current delay metrics for the session.
218 *
219 * Inputs Description
220 * -------------------------------------------------------------------
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000221 * void* handle Pointer to the AEC instance
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000222 *
223 * Outputs Description
224 * -------------------------------------------------------------------
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000225 * int* median Delay median value.
226 * int* std Delay standard deviation.
227 * float* fraction_poor_delays Fraction of the delay estimates that may
228 * cause the AEC to perform poorly.
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000229 *
peahc12be392015-11-09 23:53:50 -0800230 * int return 0: OK
231 * 12000-12050: error code
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000232 */
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000233int WebRtcAec_GetDelayMetrics(void* handle,
234 int* median,
235 int* std,
236 float* fraction_poor_delays);
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000237
bjornv@webrtc.org132c15d2013-02-27 21:03:41 +0000238// Returns a pointer to the low level AEC handle.
239//
240// Input:
241// - handle : Pointer to the AEC instance.
242//
243// Return value:
244// - AecCore pointer : NULL for error.
245//
246struct AecCore* WebRtcAec_aec_core(void* handle);
247
niklase@google.com470e71d2011-07-07 08:21:25 +0000248#ifdef __cplusplus
249}
250#endif
Henrik Kjellander9b72af92015-11-11 20:16:11 +0100251#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_