blob: e63140797e4013fc0071260e2f9452598f4c448a [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 Bonadei92ea95e2017-09-15 06:47:31 +020016#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18enum {
19 AecmFalse = 0,
20 AecmTrue
21};
22
23// Errors
24#define AECM_UNSPECIFIED_ERROR 12000
25#define AECM_UNSUPPORTED_FUNCTION_ERROR 12001
26#define AECM_UNINITIALIZED_ERROR 12002
27#define AECM_NULL_POINTER_ERROR 12003
28#define AECM_BAD_PARAMETER_ERROR 12004
29
30// Warnings
31#define AECM_BAD_PARAMETER_WARNING 12100
32
33typedef struct {
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000034 int16_t cngMode; // AECM_FALSE, AECM_TRUE (default)
35 int16_t echoMode; // 0, 1, 2, 3 (default), 4
niklase@google.com470e71d2011-07-07 08:21:25 +000036} AecmConfig;
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*
43 * Allocates the memory needed by the AECM. The memory needs to be
44 * initialized separately using the WebRtcAecm_Init() function.
Bjorn Volckera7437942015-05-28 15:58:42 +020045 * Returns a pointer to the instance and a nullptr at failure.
niklase@google.com470e71d2011-07-07 08:21:25 +000046 */
Bjorn Volckera7437942015-05-28 15:58:42 +020047void* WebRtcAecm_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000048
49/*
50 * This function releases the memory allocated by WebRtcAecm_Create()
51 *
52 * Inputs Description
53 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000054 * void* aecmInst Pointer to the AECM instance
niklase@google.com470e71d2011-07-07 08:21:25 +000055 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020056void WebRtcAecm_Free(void* aecmInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
58/*
59 * Initializes an AECM instance.
60 *
61 * Inputs Description
62 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000063 * void* aecmInst Pointer to the AECM instance
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000064 * int32_t sampFreq Sampling frequency of data
niklase@google.com470e71d2011-07-07 08:21:25 +000065 *
66 * Outputs Description
67 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000068 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080069 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000070 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000071int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
73/*
74 * Inserts an 80 or 160 sample block of data into the farend buffer.
75 *
76 * Inputs Description
77 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +000078 * void* aecmInst Pointer to the AECM instance
79 * int16_t* farend In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +000080 * farend signal
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000081 * int16_t nrOfSamples Number of samples in farend buffer
niklase@google.com470e71d2011-07-07 08:21:25 +000082 *
83 * Outputs Description
84 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000085 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -080086 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +000087 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000088int32_t WebRtcAecm_BufferFarend(void* aecmInst,
89 const int16_t* farend,
Peter Kastingdce40cf2015-08-24 14:52:23 -070090 size_t nrOfSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
92/*
peahc12be392015-11-09 23:53:50 -080093 * Reports any errors that would arise when buffering a farend buffer.
94 *
95 * Inputs Description
96 * -------------------------------------------------------------------
97 * void* aecmInst Pointer to the AECM instance
98 * int16_t* farend In buffer containing one frame of
99 * farend signal
100 * int16_t nrOfSamples Number of samples in farend buffer
101 *
102 * Outputs Description
103 * -------------------------------------------------------------------
104 * int32_t return 0: OK
105 * 1200-12004,12100: error/warning
106 */
107int32_t WebRtcAecm_GetBufferFarendError(void* aecmInst,
108 const int16_t* farend,
109 size_t nrOfSamples);
110
111/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 * Runs the AECM on an 80 or 160 sample blocks of data.
113 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000114 * Inputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000116 * void* aecmInst Pointer to the AECM instance
117 * int16_t* nearendNoisy In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 * reference nearend+echo signal. If
119 * noise reduction is active, provide
120 * the noisy signal here.
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000121 * int16_t* nearendClean In buffer containing one frame of
niklase@google.com470e71d2011-07-07 08:21:25 +0000122 * nearend+echo signal. If noise
123 * reduction is active, provide the
124 * clean signal here. Otherwise pass a
125 * NULL pointer.
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000126 * int16_t nrOfSamples Number of samples in nearend buffer
127 * int16_t msInSndCardBuf Delay estimate for sound card and
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 * system buffers
129 *
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000130 * Outputs Description
niklase@google.com470e71d2011-07-07 08:21:25 +0000131 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000132 * int16_t* out Out buffer, one frame of processed nearend
133 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800134 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000135 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000136int32_t WebRtcAecm_Process(void* aecmInst,
137 const int16_t* nearendNoisy,
138 const int16_t* nearendClean,
139 int16_t* out,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700140 size_t nrOfSamples,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000141 int16_t msInSndCardBuf);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
143/*
144 * This function enables the user to set certain parameters on-the-fly
145 *
146 * Inputs Description
147 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000148 * void* aecmInst Pointer to the AECM instance
149 * AecmConfig config Config instance that contains all
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 * properties to be set
151 *
152 * Outputs Description
153 * -------------------------------------------------------------------
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000154 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800155 * 1200-12004,12100: error/warning
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000157int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
159/*
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000160 * This function enables the user to set the echo path on-the-fly.
161 *
162 * Inputs Description
163 * -------------------------------------------------------------------
164 * void* aecmInst Pointer to the AECM instance
165 * void* echo_path Pointer to the echo path to be set
ajm@google.com22e65152011-07-18 18:03:01 +0000166 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000167 *
168 * Outputs Description
169 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000170 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800171 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000172 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000173int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
174 const void* echo_path,
175 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000176
177/*
178 * This function enables the user to get the currently used echo path
179 * on-the-fly
180 *
181 * Inputs Description
182 * -------------------------------------------------------------------
183 * void* aecmInst Pointer to the AECM instance
184 * void* echo_path Pointer to echo path
ajm@google.com22e65152011-07-18 18:03:01 +0000185 * size_t size_bytes Size in bytes of the echo path
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000186 *
187 * Outputs Description
188 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000189 * int32_t return 0: OK
peahc12be392015-11-09 23:53:50 -0800190 * 1200-12004,12100: error/warning
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000191 */
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +0000192int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
193 void* echo_path,
194 size_t size_bytes);
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000195
196/*
197 * This function enables the user to get the echo path size in bytes
198 *
199 * Outputs Description
200 * -------------------------------------------------------------------
kwiberg@webrtc.org924e81f2014-05-12 09:55:19 +0000201 * size_t return Size in bytes
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000202 */
ajm@google.com22e65152011-07-18 18:03:01 +0000203size_t WebRtcAecm_echo_path_size_bytes();
bjornv@google.comc4b939c2011-07-13 08:09:56 +0000204
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
niklase@google.com470e71d2011-07-07 08:21:25 +0000206#ifdef __cplusplus
207}
208#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200209#endif // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_