blob: cea13b8b5e9ed4e4340cb95d38555a798d9934d3 [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
Yves Gerey665174f2018-06-19 15:03:05 +020017enum { AecmFalse = 0, AecmTrue };
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19// Errors
Yves Gerey665174f2018-06-19 15:03:05 +020020#define AECM_UNSPECIFIED_ERROR 12000
21#define AECM_UNSUPPORTED_FUNCTION_ERROR 12001
22#define AECM_UNINITIALIZED_ERROR 12002
23#define AECM_NULL_POINTER_ERROR 12003
24#define AECM_BAD_PARAMETER_ERROR 12004
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26// Warnings
Yves Gerey665174f2018-06-19 15:03:05 +020027#define AECM_BAD_PARAMETER_WARNING 12100
niklase@google.com470e71d2011-07-07 08:21:25 +000028
29typedef struct {
Yves Gerey665174f2018-06-19 15:03:05 +020030 int16_t cngMode; // AECM_FALSE, AECM_TRUE (default)
31 int16_t echoMode; // 0, 1, 2, 3 (default), 4
niklase@google.com470e71d2011-07-07 08:21:25 +000032} AecmConfig;
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/*
39 * Allocates the memory needed by the AECM. The memory needs to be
40 * initialized separately using the WebRtcAecm_Init() function.
Bjorn Volckera7437942015-05-28 15:58:42 +020041 * Returns a pointer to the instance and a nullptr at failure.
niklase@google.com470e71d2011-07-07 08:21:25 +000042 */
Bjorn Volckera7437942015-05-28 15:58:42 +020043void* WebRtcAecm_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45/*
46 * This function releases the memory allocated by WebRtcAecm_Create()
47 *
48 * Inputs Description
49 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000050 * void* aecmInst Pointer to the AECM instance
niklase@google.com470e71d2011-07-07 08:21:25 +000051 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020052void WebRtcAecm_Free(void* aecmInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000053
54/*
55 * Initializes an AECM instance.
56 *
57 * Inputs Description
58 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000059 * void* aecmInst Pointer to the AECM instance
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000060 * int32_t sampFreq Sampling frequency of data
niklase@google.com470e71d2011-07-07 08:21:25 +000061 *
62 * Outputs Description
63 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000064 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080065 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000066 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000067int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
niklase@google.com470e71d2011-07-07 08:21:25 +000068
69/*
70 * Inserts an 80 or 160 sample block of data into the farend buffer.
71 *
72 * Inputs Description
73 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000074 * void* aecmInst Pointer to the AECM instance
75 * int16_t* farend In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +000076 * farend signal
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000077 * int16_t nrOfSamples Number of samples in farend buffer
niklase@google.com470e71d2011-07-07 08:21:25 +000078 *
79 * Outputs Description
80 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000081 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080082 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000083 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000084int32_t WebRtcAecm_BufferFarend(void* aecmInst,
85 const int16_t* farend,
Peter Kastingdce40cf2015-08-24 14:52:23 -070086 size_t nrOfSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
88/*
peahc12be392015-11-09 23:53:50 -080089 * Reports any errors that would arise when buffering a farend buffer.
90 *
91 * Inputs Description
92 * -------------------------------------------------------------------
93 * void* aecmInst Pointer to the AECM instance
94 * int16_t* farend In buffer containing one frame of
95 * farend signal
96 * int16_t nrOfSamples Number of samples in farend buffer
97 *
98 * Outputs Description
99 * -------------------------------------------------------------------
100 * int32_t return 0: OK
101 * 1200-12004,12100: error/warning
102 */
103int32_t WebRtcAecm_GetBufferFarendError(void* aecmInst,
104 const int16_t* farend,
105 size_t nrOfSamples);
106
107/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 * Runs the AECM on an 80 or 160 sample blocks of data.
109 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000110 * Inputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000111 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000112 * void* aecmInst Pointer to the AECM instance
113 * int16_t* nearendNoisy In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 * reference nearend+echo signal. If
115 * noise reduction is active, provide
116 * the noisy signal here.
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000117 * int16_t* nearendClean In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 * nearend+echo signal. If noise
119 * reduction is active, provide the
120 * clean signal here. Otherwise pass a
121 * NULL pointer.
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000122 * int16_t nrOfSamples Number of samples in nearend buffer
123 * int16_t msInSndCardBuf Delay estimate for sound card and
niklase@google.com470e71d2011-07-07 08:21:25 +0000124 * system buffers
125 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000126 * Outputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000127 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000128 * int16_t* out Out buffer, one frame of processed nearend
129 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800130 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000131 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000132int32_t WebRtcAecm_Process(void* aecmInst,
133 const int16_t* nearendNoisy,
134 const int16_t* nearendClean,
135 int16_t* out,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700136 size_t nrOfSamples,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000137 int16_t msInSndCardBuf);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
139/*
140 * This function enables the user to set certain parameters on-the-fly
141 *
142 * Inputs Description
143 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000144 * void* aecmInst Pointer to the AECM instance
145 * AecmConfig config Config instance that contains all
niklase@google.com470e71d2011-07-07 08:21:25 +0000146 * properties to be set
147 *
148 * Outputs Description
149 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000150 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800151 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000152 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000153int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
155/*
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000156 * This function enables the user to set the echo path on-the-fly.
157 *
158 * Inputs Description
159 * -------------------------------------------------------------------
160 * void* aecmInst Pointer to the AECM instance
161 * void* echo_path Pointer to the echo path to be set
ajm@google.com22e65152011-07-18 18:03:01 +0000162 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000163 *
164 * Outputs Description
165 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000166 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800167 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000168 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000169int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
170 const void* echo_path,
171 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000172
173/*
174 * This function enables the user to get the currently used echo path
175 * on-the-fly
176 *
177 * Inputs Description
178 * -------------------------------------------------------------------
179 * void* aecmInst Pointer to the AECM instance
180 * void* echo_path Pointer to echo path
ajm@google.com22e65152011-07-18 18:03:01 +0000181 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000182 *
183 * Outputs Description
184 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000185 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800186 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000187 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000188int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
189 void* echo_path,
190 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000191
192/*
193 * This function enables the user to get the echo path size in bytes
194 *
195 * Outputs Description
196 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000197 * size_t return Size in bytes
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000198 */
ajm@google.com22e65152011-07-18 18:03:01 +0000199size_t WebRtcAecm_echo_path_size_bytes();
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000200
niklase@google.com470e71d2011-07-07 08:21:25 +0000201#ifdef __cplusplus
202}
203#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200204#endif // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_