1 /* 2 * Copyright (c) 2013 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ 13 14 #ifdef WEBRTC_AEC_DEBUG_DUMP 15 #include <stdio.h> 16 #endif 17 18 #include "webrtc/modules/audio_processing/aec/aec_core.h" 19 #include "webrtc/modules/audio_processing/utility/ring_buffer.h" 20 #include "webrtc/typedefs.h" 21 22 // Number of partitions for the extended filter mode. The first one is an enum 23 // to be used in array declarations, as it represents the maximum filter length. 24 enum { 25 kExtendedNumPartitions = 32 26 }; 27 static const int kNormalNumPartitions = 12; 28 29 // Delay estimator constants, used for logging. 30 enum { 31 kMaxDelayBlocks = 60 32 }; 33 enum { 34 kLookaheadBlocks = 15 35 }; 36 enum { 37 kHistorySizeBlocks = kMaxDelayBlocks + kLookaheadBlocks 38 }; 39 40 // Extended filter adaptation parameters. 41 // TODO(ajm): No narrowband tuning yet. 42 static const float kExtendedMu = 0.4f; 43 static const float kExtendedErrorThreshold = 1.0e-6f; 44 45 typedef struct PowerLevel { 46 float sfrsum; 47 int sfrcounter; 48 float framelevel; 49 float frsum; 50 int frcounter; 51 float minlevel; 52 float averagelevel; 53 } PowerLevel; 54 55 struct AecCore { 56 int farBufWritePos, farBufReadPos; 57 58 int knownDelay; 59 int inSamples, outSamples; 60 int delayEstCtr; 61 62 RingBuffer* nearFrBuf; 63 RingBuffer* outFrBuf; 64 65 RingBuffer* nearFrBufH; 66 RingBuffer* outFrBufH; 67 68 float dBuf[PART_LEN2]; // nearend 69 float eBuf[PART_LEN2]; // error 70 71 float dBufH[PART_LEN2]; // nearend 72 73 float xPow[PART_LEN1]; 74 float dPow[PART_LEN1]; 75 float dMinPow[PART_LEN1]; 76 float dInitMinPow[PART_LEN1]; 77 float* noisePow; 78 79 float xfBuf[2][kExtendedNumPartitions * PART_LEN1]; // farend fft buffer 80 float wfBuf[2][kExtendedNumPartitions * PART_LEN1]; // filter fft 81 complex_t sde[PART_LEN1]; // cross-psd of nearend and error 82 complex_t sxd[PART_LEN1]; // cross-psd of farend and nearend 83 // Farend windowed fft buffer. 84 complex_t xfwBuf[kExtendedNumPartitions * PART_LEN1]; 85 86 float sx[PART_LEN1], sd[PART_LEN1], se[PART_LEN1]; // far, near, error psd 87 float hNs[PART_LEN1]; 88 float hNlFbMin, hNlFbLocalMin; 89 float hNlXdAvgMin; 90 int hNlNewMin, hNlMinCtr; 91 float overDrive, overDriveSm; 92 int nlp_mode; 93 float outBuf[PART_LEN]; 94 int delayIdx; 95 96 short stNearState, echoState; 97 short divergeState; 98 99 int xfBufBlockPos; 100 101 RingBuffer* far_buf; 102 RingBuffer* far_buf_windowed; 103 int system_delay; // Current system delay buffered in AEC. 104 105 int mult; // sampling frequency multiple 106 int sampFreq; 107 uint32_t seed; 108 109 float normal_mu; // stepsize 110 float normal_error_threshold; // error threshold 111 112 int noiseEstCtr; 113 114 PowerLevel farlevel; 115 PowerLevel nearlevel; 116 PowerLevel linoutlevel; 117 PowerLevel nlpoutlevel; 118 119 int metricsMode; 120 int stateCounter; 121 Stats erl; 122 Stats erle; 123 Stats aNlp; 124 Stats rerl; 125 126 // Quantities to control H band scaling for SWB input 127 int freq_avg_ic; // initial bin for averaging nlp gain 128 int flag_Hband_cn; // for comfort noise 129 float cn_scale_Hband; // scale for comfort noise in H band 130 131 int delay_histogram[kHistorySizeBlocks]; 132 int delay_logging_enabled; 133 void* delay_estimator_farend; 134 void* delay_estimator; 135 136 int reported_delay_enabled; // 0 = disabled, otherwise enabled. 137 // 1 = extended filter mode enabled, 0 = disabled. 138 int extended_filter_enabled; 139 // Runtime selection of number of filter partitions. 140 int num_partitions; 141 142 #ifdef WEBRTC_AEC_DEBUG_DUMP 143 RingBuffer* far_time_buf; 144 FILE* farFile; 145 FILE* nearFile; 146 FILE* outFile; 147 FILE* outLinearFile; 148 #endif 149 }; 150 151 typedef void (*WebRtcAec_FilterFar_t)(AecCore* aec, float yf[2][PART_LEN1]); 152 extern WebRtcAec_FilterFar_t WebRtcAec_FilterFar; 153 typedef void (*WebRtcAec_ScaleErrorSignal_t)(AecCore* aec, 154 float ef[2][PART_LEN1]); 155 extern WebRtcAec_ScaleErrorSignal_t WebRtcAec_ScaleErrorSignal; 156 typedef void (*WebRtcAec_FilterAdaptation_t)(AecCore* aec, 157 float* fft, 158 float ef[2][PART_LEN1]); 159 extern WebRtcAec_FilterAdaptation_t WebRtcAec_FilterAdaptation; 160 typedef void (*WebRtcAec_OverdriveAndSuppress_t)(AecCore* aec, 161 float hNl[PART_LEN1], 162 const float hNlFb, 163 float efw[2][PART_LEN1]); 164 extern WebRtcAec_OverdriveAndSuppress_t WebRtcAec_OverdriveAndSuppress; 165 166 typedef void (*WebRtcAec_ComfortNoise_t)(AecCore* aec, 167 float efw[2][PART_LEN1], 168 complex_t* comfortNoiseHband, 169 const float* noisePow, 170 const float* lambda); 171 extern WebRtcAec_ComfortNoise_t WebRtcAec_ComfortNoise; 172 173 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ 174