blob: ee780524dedff4f0f94086641d0bb1f2bfe62e06 [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
Niels Möllera12c42a2018-07-25 16:05:48 +020014#include <stddef.h>
15#include <stdint.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000016
Per Åhgrenbe36db12020-03-20 16:45:09 +010017namespace webrtc {
18
Yves Gerey665174f2018-06-19 15:03:05 +020019enum { AecmFalse = 0, AecmTrue };
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21// Errors
Yves Gerey665174f2018-06-19 15:03:05 +020022#define AECM_UNSPECIFIED_ERROR 12000
23#define AECM_UNSUPPORTED_FUNCTION_ERROR 12001
24#define AECM_UNINITIALIZED_ERROR 12002
25#define AECM_NULL_POINTER_ERROR 12003
26#define AECM_BAD_PARAMETER_ERROR 12004
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28// Warnings
Yves Gerey665174f2018-06-19 15:03:05 +020029#define AECM_BAD_PARAMETER_WARNING 12100
niklase@google.com470e71d2011-07-07 08:21:25 +000030
31typedef struct {
Yves Gerey665174f2018-06-19 15:03:05 +020032 int16_t cngMode; // AECM_FALSE, AECM_TRUE (default)
33 int16_t echoMode; // 0, 1, 2, 3 (default), 4
niklase@google.com470e71d2011-07-07 08:21:25 +000034} AecmConfig;
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*
41 * Allocates the memory needed by the AECM. The memory needs to be
42 * initialized separately using the WebRtcAecm_Init() function.
Bjorn Volckera7437942015-05-28 15:58:42 +020043 * Returns a pointer to the instance and a nullptr at failure.
niklase@google.com470e71d2011-07-07 08:21:25 +000044 */
Bjorn Volckera7437942015-05-28 15:58:42 +020045void* WebRtcAecm_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000046
47/*
48 * This function releases the memory allocated by WebRtcAecm_Create()
49 *
50 * Inputs Description
51 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000052 * void* aecmInst Pointer to the AECM instance
niklase@google.com470e71d2011-07-07 08:21:25 +000053 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020054void WebRtcAecm_Free(void* aecmInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56/*
57 * Initializes an AECM instance.
58 *
59 * Inputs Description
60 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000061 * void* aecmInst Pointer to the AECM instance
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000062 * int32_t sampFreq Sampling frequency of data
niklase@google.com470e71d2011-07-07 08:21:25 +000063 *
64 * Outputs Description
65 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000066 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080067 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000068 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000069int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
niklase@google.com470e71d2011-07-07 08:21:25 +000070
71/*
72 * Inserts an 80 or 160 sample block of data into the farend buffer.
73 *
74 * Inputs Description
75 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000076 * void* aecmInst Pointer to the AECM instance
77 * int16_t* farend In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +000078 * farend signal
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000079 * int16_t nrOfSamples Number of samples in farend buffer
niklase@google.com470e71d2011-07-07 08:21:25 +000080 *
81 * Outputs Description
82 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000083 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080084 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000085 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000086int32_t WebRtcAecm_BufferFarend(void* aecmInst,
87 const int16_t* farend,
Peter Kastingdce40cf2015-08-24 14:52:23 -070088 size_t nrOfSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000089
90/*
peahc12be392015-11-09 23:53:50 -080091 * Reports any errors that would arise when buffering a farend buffer.
92 *
93 * Inputs Description
94 * -------------------------------------------------------------------
95 * void* aecmInst Pointer to the AECM instance
96 * int16_t* farend In buffer containing one frame of
97 * farend signal
98 * int16_t nrOfSamples Number of samples in farend buffer
99 *
100 * Outputs Description
101 * -------------------------------------------------------------------
102 * int32_t return 0: OK
103 * 1200-12004,12100: error/warning
104 */
105int32_t WebRtcAecm_GetBufferFarendError(void* aecmInst,
106 const int16_t* farend,
107 size_t nrOfSamples);
108
109/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 * Runs the AECM on an 80 or 160 sample blocks of data.
111 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000112 * Inputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000114 * void* aecmInst Pointer to the AECM instance
115 * int16_t* nearendNoisy In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 * reference nearend+echo signal. If
117 * noise reduction is active, provide
118 * the noisy signal here.
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000119 * int16_t* nearendClean In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000120 * nearend+echo signal. If noise
121 * reduction is active, provide the
122 * clean signal here. Otherwise pass a
123 * NULL pointer.
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000124 * int16_t nrOfSamples Number of samples in nearend buffer
125 * int16_t msInSndCardBuf Delay estimate for sound card and
niklase@google.com470e71d2011-07-07 08:21:25 +0000126 * system buffers
127 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000128 * Outputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000129 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000130 * int16_t* out Out buffer, one frame of processed nearend
131 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800132 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000133 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000134int32_t WebRtcAecm_Process(void* aecmInst,
135 const int16_t* nearendNoisy,
136 const int16_t* nearendClean,
137 int16_t* out,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700138 size_t nrOfSamples,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000139 int16_t msInSndCardBuf);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
141/*
142 * This function enables the user to set certain parameters on-the-fly
143 *
144 * Inputs Description
145 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000146 * void* aecmInst Pointer to the AECM instance
147 * AecmConfig config Config instance that contains all
niklase@google.com470e71d2011-07-07 08:21:25 +0000148 * properties to be set
149 *
150 * Outputs Description
151 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000152 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800153 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000154 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000155int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
157/*
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000158 * This function enables the user to set the echo path on-the-fly.
159 *
160 * Inputs Description
161 * -------------------------------------------------------------------
162 * void* aecmInst Pointer to the AECM instance
163 * void* echo_path Pointer to the echo path to be set
ajm@google.com22e65152011-07-18 18:03:01 +0000164 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000165 *
166 * Outputs Description
167 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000168 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800169 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000170 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000171int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
172 const void* echo_path,
173 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000174
175/*
176 * This function enables the user to get the currently used echo path
177 * on-the-fly
178 *
179 * Inputs Description
180 * -------------------------------------------------------------------
181 * void* aecmInst Pointer to the AECM instance
182 * void* echo_path Pointer to echo path
ajm@google.com22e65152011-07-18 18:03:01 +0000183 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000184 *
185 * Outputs Description
186 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000187 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800188 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000189 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000190int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
191 void* echo_path,
192 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000193
194/*
195 * This function enables the user to get the echo path size in bytes
196 *
197 * Outputs Description
198 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000199 * size_t return Size in bytes
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000200 */
ajm@google.com22e65152011-07-18 18:03:01 +0000201size_t WebRtcAecm_echo_path_size_bytes();
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000202
niklase@google.com470e71d2011-07-07 08:21:25 +0000203#ifdef __cplusplus
204}
205#endif
Per Åhgrenbe36db12020-03-20 16:45:09 +0100206
207} // namespace webrtc
208
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200209#endif // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_