blob: 576cf196fa4bc264edc09889ff0f4d3a7431ebef [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_
12#define MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
andrew@webrtc.org9ae13542013-02-25 17:07:35 +000014#include <stdlib.h>
15
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000017
Yves Gerey665174f2018-06-19 15:03:05 +020018enum { AecmFalse = 0, AecmTrue };
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20// Errors
Yves Gerey665174f2018-06-19 15:03:05 +020021#define AECM_UNSPECIFIED_ERROR 12000
22#define AECM_UNSUPPORTED_FUNCTION_ERROR 12001
23#define AECM_UNINITIALIZED_ERROR 12002
24#define AECM_NULL_POINTER_ERROR 12003
25#define AECM_BAD_PARAMETER_ERROR 12004
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// Warnings
Yves Gerey665174f2018-06-19 15:03:05 +020028#define AECM_BAD_PARAMETER_WARNING 12100
niklase@google.com470e71d2011-07-07 08:21:25 +000029
30typedef struct {
Yves Gerey665174f2018-06-19 15:03:05 +020031 int16_t cngMode; // AECM_FALSE, AECM_TRUE (default)
32 int16_t echoMode; // 0, 1, 2, 3 (default), 4
niklase@google.com470e71d2011-07-07 08:21:25 +000033} AecmConfig;
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*
40 * Allocates the memory needed by the AECM. The memory needs to be
41 * initialized separately using the WebRtcAecm_Init() function.
Bjorn Volckera7437942015-05-28 15:58:42 +020042 * Returns a pointer to the instance and a nullptr at failure.
niklase@google.com470e71d2011-07-07 08:21:25 +000043 */
Bjorn Volckera7437942015-05-28 15:58:42 +020044void* WebRtcAecm_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000045
46/*
47 * This function releases the memory allocated by WebRtcAecm_Create()
48 *
49 * Inputs Description
50 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000051 * void* aecmInst Pointer to the AECM instance
niklase@google.com470e71d2011-07-07 08:21:25 +000052 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020053void WebRtcAecm_Free(void* aecmInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
55/*
56 * Initializes an AECM instance.
57 *
58 * Inputs Description
59 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000060 * void* aecmInst Pointer to the AECM instance
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000061 * int32_t sampFreq Sampling frequency of data
niklase@google.com470e71d2011-07-07 08:21:25 +000062 *
63 * Outputs Description
64 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000065 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080066 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000067 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000068int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
70/*
71 * Inserts an 80 or 160 sample block of data into the farend buffer.
72 *
73 * Inputs Description
74 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000075 * void* aecmInst Pointer to the AECM instance
76 * int16_t* farend In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +000077 * farend signal
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000078 * int16_t nrOfSamples Number of samples in farend buffer
niklase@google.com470e71d2011-07-07 08:21:25 +000079 *
80 * Outputs Description
81 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000082 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080083 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000084 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000085int32_t WebRtcAecm_BufferFarend(void* aecmInst,
86 const int16_t* farend,
Peter Kastingdce40cf2015-08-24 14:52:23 -070087 size_t nrOfSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000088
89/*
peahc12be392015-11-09 23:53:50 -080090 * Reports any errors that would arise when buffering a farend buffer.
91 *
92 * Inputs Description
93 * -------------------------------------------------------------------
94 * void* aecmInst Pointer to the AECM instance
95 * int16_t* farend In buffer containing one frame of
96 * farend signal
97 * int16_t nrOfSamples Number of samples in farend buffer
98 *
99 * Outputs Description
100 * -------------------------------------------------------------------
101 * int32_t return 0: OK
102 * 1200-12004,12100: error/warning
103 */
104int32_t WebRtcAecm_GetBufferFarendError(void* aecmInst,
105 const int16_t* farend,
106 size_t nrOfSamples);
107
108/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000109 * Runs the AECM on an 80 or 160 sample blocks of data.
110 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000111 * Inputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000113 * void* aecmInst Pointer to the AECM instance
114 * int16_t* nearendNoisy In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 * reference nearend+echo signal. If
116 * noise reduction is active, provide
117 * the noisy signal here.
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000118 * int16_t* nearendClean In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 * nearend+echo signal. If noise
120 * reduction is active, provide the
121 * clean signal here. Otherwise pass a
122 * NULL pointer.
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000123 * int16_t nrOfSamples Number of samples in nearend buffer
124 * int16_t msInSndCardBuf Delay estimate for sound card and
niklase@google.com470e71d2011-07-07 08:21:25 +0000125 * system buffers
126 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000127 * Outputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000129 * int16_t* out Out buffer, one frame of processed nearend
130 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800131 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000133int32_t WebRtcAecm_Process(void* aecmInst,
134 const int16_t* nearendNoisy,
135 const int16_t* nearendClean,
136 int16_t* out,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700137 size_t nrOfSamples,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000138 int16_t msInSndCardBuf);
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
140/*
141 * This function enables the user to set certain parameters on-the-fly
142 *
143 * Inputs Description
144 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000145 * void* aecmInst Pointer to the AECM instance
146 * AecmConfig config Config instance that contains all
niklase@google.com470e71d2011-07-07 08:21:25 +0000147 * properties to be set
148 *
149 * Outputs Description
150 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000151 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800152 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000153 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000154int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
156/*
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000157 * This function enables the user to set the echo path on-the-fly.
158 *
159 * Inputs Description
160 * -------------------------------------------------------------------
161 * void* aecmInst Pointer to the AECM instance
162 * void* echo_path Pointer to the echo path to be set
ajm@google.com22e65152011-07-18 18:03:01 +0000163 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000164 *
165 * Outputs Description
166 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000167 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800168 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000169 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000170int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
171 const void* echo_path,
172 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000173
174/*
175 * This function enables the user to get the currently used echo path
176 * on-the-fly
177 *
178 * Inputs Description
179 * -------------------------------------------------------------------
180 * void* aecmInst Pointer to the AECM instance
181 * void* echo_path Pointer to echo path
ajm@google.com22e65152011-07-18 18:03:01 +0000182 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000183 *
184 * Outputs Description
185 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000186 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800187 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000188 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000189int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
190 void* echo_path,
191 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000192
193/*
194 * This function enables the user to get the echo path size in bytes
195 *
196 * Outputs Description
197 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000198 * size_t return Size in bytes
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000199 */
ajm@google.com22e65152011-07-18 18:03:01 +0000200size_t WebRtcAecm_echo_path_size_bytes();
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000201
niklase@google.com470e71d2011-07-07 08:21:25 +0000202#ifdef __cplusplus
203}
204#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200205#endif // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_