andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | 798195e | 2013-02-20 17:31:38 +0000 | [diff] [blame] | 15 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ |
| 16 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 17 | |
bjornv@webrtc.org | 0bfd5f0 | 2013-01-30 16:16:59 +0000 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 19 | |
| 20 | #define FRAME_LEN 80 |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 21 | #define PART_LEN 64 // Length of partition |
bjornv@webrtc.org | 0bfd5f0 | 2013-01-30 16:16:59 +0000 | [diff] [blame] | 22 | #define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients |
| 23 | #define PART_LEN2 (PART_LEN * 2) // Length of partition * 2 |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 24 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 35 | enum { |
| 36 | kOffsetLevel = -100 |
| 37 | }; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 38 | |
bjornv@webrtc.org | ef1346d | 2013-02-19 21:03:10 +0000 | [diff] [blame] | 39 | typedef struct Stats { |
bjornv@webrtc.org | e422fa5 | 2013-02-15 18:40:34 +0000 | [diff] [blame] | 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; |
bjornv@webrtc.org | ef1346d | 2013-02-19 21:03:10 +0000 | [diff] [blame] | 49 | } Stats; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 50 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 51 | typedef struct AecCore AecCore; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 52 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 53 | int WebRtcAec_CreateAec(AecCore** aec); |
| 54 | int WebRtcAec_FreeAec(AecCore* aec); |
| 55 | int WebRtcAec_InitAec(AecCore* aec, int sampFreq); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 56 | void WebRtcAec_InitAec_SSE2(void); |
andrew@webrtc.org | f59fce9 | 2014-02-21 00:13:31 +0000 | [diff] [blame] | 57 | #if defined(MIPS_FPU_LE) |
| 58 | void WebRtcAec_InitAec_mips(void); |
| 59 | #endif |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 60 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 61 | void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend); |
| 62 | void WebRtcAec_ProcessFrame(AecCore* aec, |
bjornv@webrtc.org | e27e49b | 2013-02-20 16:59:41 +0000 | [diff] [blame] | 63 | const short* nearend, |
| 64 | const short* nearendH, |
| 65 | int knownDelay, |
| 66 | int16_t* out, |
| 67 | int16_t* outH); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 68 | |
| 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.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 72 | int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements); |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 73 | |
bjornv@webrtc.org | d3eadf1 | 2013-02-15 15:21:02 +0000 | [diff] [blame] | 74 | // Calculates the median and standard deviation among the delay estimates |
| 75 | // collected since the last call to this function. |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 76 | int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std); |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 77 | |
bjornv@webrtc.org | 3942fd8 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 78 | // Returns the echo state (1: echo, 0: no echo). |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 79 | int WebRtcAec_echo_state(AecCore* self); |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 80 | |
bjornv@webrtc.org | e422fa5 | 2013-02-15 18:40:34 +0000 | [diff] [blame] | 81 | // Gets statistics of the echo metrics ERL, ERLE, A_NLP. |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 82 | void WebRtcAec_GetEchoStats(AecCore* self, |
| 83 | Stats* erl, |
| 84 | Stats* erle, |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 85 | Stats* a_nlp); |
bjornv@webrtc.org | 9c643ec | 2013-02-19 21:41:27 +0000 | [diff] [blame] | 86 | #ifdef WEBRTC_AEC_DEBUG_DUMP |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 87 | void* WebRtcAec_far_time_buf(AecCore* self); |
bjornv@webrtc.org | 9c643ec | 2013-02-19 21:41:27 +0000 | [diff] [blame] | 88 | #endif |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 89 | |
bjornv@webrtc.org | 191efa0 | 2013-02-20 17:09:47 +0000 | [diff] [blame] | 90 | // Sets local configuration modes. |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 91 | void WebRtcAec_SetConfigCore(AecCore* self, |
| 92 | int nlp_mode, |
| 93 | int metrics_mode, |
bjornv@webrtc.org | 191efa0 | 2013-02-20 17:09:47 +0000 | [diff] [blame] | 94 | int delay_logging); |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 95 | |
bjornv@webrtc.org | e1b0595 | 2014-04-23 13:20:07 +0000 | [diff] [blame] | 96 | // Non-zero enables, zero disables. |
| 97 | void WebRtcAec_enable_reported_delay(AecCore* self, int enable); |
| 98 | |
| 99 | // Returns non-zero if reported delay is enabled and zero if disabled. |
| 100 | int WebRtcAec_reported_delay_enabled(AecCore* self); |
| 101 | |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 102 | // 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. |
| 106 | void WebRtcAec_enable_delay_correction(AecCore* self, int enable); |
| 107 | |
| 108 | // Returns non-zero if delay correction is enabled and zero if disabled. |
| 109 | int WebRtcAec_delay_correction_enabled(AecCore* self); |
| 110 | |
bjornv@webrtc.org | 798195e | 2013-02-20 17:31:38 +0000 | [diff] [blame] | 111 | // Returns the current |system_delay|, i.e., the buffered difference between |
| 112 | // far-end and near-end. |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 113 | int WebRtcAec_system_delay(AecCore* self); |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 114 | |
bjornv@webrtc.org | 798195e | 2013-02-20 17:31:38 +0000 | [diff] [blame] | 115 | // 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.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 118 | void WebRtcAec_SetSystemDelay(AecCore* self, int delay); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 119 | |
bjornv@webrtc.org | 798195e | 2013-02-20 17:31:38 +0000 | [diff] [blame] | 120 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ |