blob: 327a5a9126d7d7276262ba713624d8d81aa26d80 [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
11/*
12 * Specifies the interface for the AEC core.
13 */
14
bjornv@webrtc.org798195e2013-02-20 17:31:38 +000015#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_
16#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000017
bjornv@webrtc.org0bfd5f02013-01-30 16:16:59 +000018#include "webrtc/typedefs.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000019
20#define FRAME_LEN 80
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +000021#define PART_LEN 64 // Length of partition
bjornv@webrtc.org0bfd5f02013-01-30 16:16:59 +000022#define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients
23#define PART_LEN2 (PART_LEN * 2) // Length of partition * 2
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000024
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000025typedef float complex_t[2];
26// For performance reasons, some arrays of complex numbers are replaced by twice
27// as long arrays of float, all the real parts followed by all the imaginary
28// ones (complex_t[SIZE] -> float[2][SIZE]). This allows SIMD optimizations and
29// is better than two arrays (one for the real parts and one for the imaginary
30// parts) as this other way would require two pointers instead of one and cause
31// extra register spilling. This also allows the offsets to be calculated at
32// compile time.
33
34// Metrics
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +000035enum {
36 kOffsetLevel = -100
37};
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000038
bjornv@webrtc.orgef1346d2013-02-19 21:03:10 +000039typedef struct Stats {
bjornv@webrtc.orge422fa52013-02-15 18:40:34 +000040 float instant;
41 float average;
42 float min;
43 float max;
44 float sum;
45 float hisum;
46 float himean;
47 int counter;
48 int hicounter;
bjornv@webrtc.orgef1346d2013-02-19 21:03:10 +000049} Stats;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000050
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000051typedef struct AecCore AecCore;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000052
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000053int WebRtcAec_CreateAec(AecCore** aec);
54int WebRtcAec_FreeAec(AecCore* aec);
55int WebRtcAec_InitAec(AecCore* aec, int sampFreq);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000056void WebRtcAec_InitAec_SSE2(void);
andrew@webrtc.orgf59fce92014-02-21 00:13:31 +000057#if defined(MIPS_FPU_LE)
58void WebRtcAec_InitAec_mips(void);
59#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000060
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000061void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend);
62void WebRtcAec_ProcessFrame(AecCore* aec,
bjornv@webrtc.orge27e49b2013-02-20 16:59:41 +000063 const short* nearend,
64 const short* nearendH,
65 int knownDelay,
66 int16_t* out,
67 int16_t* outH);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000068
69// A helper function to call WebRtc_MoveReadPtr() for all far-end buffers.
70// Returns the number of elements moved, and adjusts |system_delay| by the
71// corresponding amount in ms.
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000072int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements);
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000073
bjornv@webrtc.orgd3eadf12013-02-15 15:21:02 +000074// Calculates the median and standard deviation among the delay estimates
75// collected since the last call to this function.
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000076int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std);
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000077
bjornv@webrtc.org3942fd82013-02-15 17:01:03 +000078// Returns the echo state (1: echo, 0: no echo).
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000079int WebRtcAec_echo_state(AecCore* self);
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000080
bjornv@webrtc.orge422fa52013-02-15 18:40:34 +000081// Gets statistics of the echo metrics ERL, ERLE, A_NLP.
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +000082void WebRtcAec_GetEchoStats(AecCore* self,
83 Stats* erl,
84 Stats* erle,
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000085 Stats* a_nlp);
bjornv@webrtc.org9c643ec2013-02-19 21:41:27 +000086#ifdef WEBRTC_AEC_DEBUG_DUMP
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000087void* WebRtcAec_far_time_buf(AecCore* self);
bjornv@webrtc.org9c643ec2013-02-19 21:41:27 +000088#endif
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000089
bjornv@webrtc.org191efa02013-02-20 17:09:47 +000090// Sets local configuration modes.
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +000091void WebRtcAec_SetConfigCore(AecCore* self,
92 int nlp_mode,
93 int metrics_mode,
bjornv@webrtc.org191efa02013-02-20 17:09:47 +000094 int delay_logging);
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000095
bjornv@webrtc.orge1b05952014-04-23 13:20:07 +000096// Non-zero enables, zero disables.
97void WebRtcAec_enable_reported_delay(AecCore* self, int enable);
98
99// Returns non-zero if reported delay is enabled and zero if disabled.
100int WebRtcAec_reported_delay_enabled(AecCore* self);
101
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +0000102// We now interpret delay correction to mean an extended filter length feature.
103// We reuse the delay correction infrastructure to avoid changes through to
104// libjingle. See details along with |DelayCorrection| in
105// echo_cancellation_impl.h. Non-zero enables, zero disables.
106void WebRtcAec_enable_delay_correction(AecCore* self, int enable);
107
108// Returns non-zero if delay correction is enabled and zero if disabled.
109int WebRtcAec_delay_correction_enabled(AecCore* self);
110
bjornv@webrtc.org798195e2013-02-20 17:31:38 +0000111// Returns the current |system_delay|, i.e., the buffered difference between
112// far-end and near-end.
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000113int WebRtcAec_system_delay(AecCore* self);
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +0000114
bjornv@webrtc.org798195e2013-02-20 17:31:38 +0000115// Sets the |system_delay| to |value|. Note that if the value is changed
116// improperly, there can be a performance regression. So it should be used with
117// care.
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000118void WebRtcAec_SetSystemDelay(AecCore* self, int delay);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000119
bjornv@webrtc.org798195e2013-02-20 17:31:38 +0000120#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_