1 /* 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 15 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 16 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 17 18 #include "webrtc/typedefs.h" 19 20 #define FRAME_LEN 80 21 #define PART_LEN 64 // Length of partition 22 #define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients 23 #define PART_LEN2 (PART_LEN * 2) // Length of partition * 2 24 25 typedef 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 35 enum { 36 kOffsetLevel = -100 37 }; 38 39 typedef struct Stats { 40 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; 49 } Stats; 50 51 typedef struct AecCore AecCore; 52 53 int WebRtcAec_CreateAec(AecCore** aec); 54 int WebRtcAec_FreeAec(AecCore* aec); 55 int WebRtcAec_InitAec(AecCore* aec, int sampFreq); 56 void WebRtcAec_InitAec_SSE2(void); 57 #if defined(MIPS_FPU_LE) 58 void WebRtcAec_InitAec_mips(void); 59 #endif 60 #if defined(WEBRTC_DETECT_ARM_NEON) || defined(WEBRTC_ARCH_ARM_NEON) 61 void WebRtcAec_InitAec_neon(void); 62 #endif 63 64 void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend); 65 void WebRtcAec_ProcessFrame(AecCore* aec, 66 const float* nearend, 67 const float* nearendH, 68 int knownDelay, 69 float* out, 70 float* outH); 71 72 // A helper function to call WebRtc_MoveReadPtr() for all far-end buffers. 73 // Returns the number of elements moved, and adjusts |system_delay| by the 74 // corresponding amount in ms. 75 int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements); 76 77 // Calculates the median and standard deviation among the delay estimates 78 // collected since the last call to this function. 79 int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std); 80 81 // Returns the echo state (1: echo, 0: no echo). 82 int WebRtcAec_echo_state(AecCore* self); 83 84 // Gets statistics of the echo metrics ERL, ERLE, A_NLP. 85 void WebRtcAec_GetEchoStats(AecCore* self, 86 Stats* erl, 87 Stats* erle, 88 Stats* a_nlp); 89 #ifdef WEBRTC_AEC_DEBUG_DUMP 90 void* WebRtcAec_far_time_buf(AecCore* self); 91 #endif 92 93 // Sets local configuration modes. 94 void WebRtcAec_SetConfigCore(AecCore* self, 95 int nlp_mode, 96 int metrics_mode, 97 int delay_logging); 98 99 // Non-zero enables, zero disables. 100 void WebRtcAec_enable_reported_delay(AecCore* self, int enable); 101 102 // Returns non-zero if reported delay is enabled and zero if disabled. 103 int WebRtcAec_reported_delay_enabled(AecCore* self); 104 105 // We now interpret delay correction to mean an extended filter length feature. 106 // We reuse the delay correction infrastructure to avoid changes through to 107 // libjingle. See details along with |DelayCorrection| in 108 // echo_cancellation_impl.h. Non-zero enables, zero disables. 109 void WebRtcAec_enable_delay_correction(AecCore* self, int enable); 110 111 // Returns non-zero if delay correction is enabled and zero if disabled. 112 int WebRtcAec_delay_correction_enabled(AecCore* self); 113 114 // Returns the current |system_delay|, i.e., the buffered difference between 115 // far-end and near-end. 116 int WebRtcAec_system_delay(AecCore* self); 117 118 // Sets the |system_delay| to |value|. Note that if the value is changed 119 // improperly, there can be a performance regression. So it should be used with 120 // care. 121 void WebRtcAec_SetSystemDelay(AecCore* self, int delay); 122 123 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 124