| OLD | NEW |
| (Empty) |
| 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 #include <memory> | |
| 15 | |
| 16 extern "C" { | |
| 17 #include "webrtc/common_audio/ring_buffer.h" | |
| 18 } | |
| 19 #include "webrtc/base/constructormagic.h" | |
| 20 #include "webrtc/common_audio/wav_file.h" | |
| 21 #include "webrtc/modules/audio_processing/aec/aec_common.h" | |
| 22 #include "webrtc/modules/audio_processing/aec/aec_core.h" | |
| 23 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
| 24 #include "webrtc/modules/audio_processing/utility/block_mean_calculator.h" | |
| 25 #include "webrtc/typedefs.h" | |
| 26 | |
| 27 namespace webrtc { | |
| 28 | |
| 29 // Number of partitions for the extended filter mode. The first one is an enum | |
| 30 // to be used in array declarations, as it represents the maximum filter length. | |
| 31 enum { kExtendedNumPartitions = 32 }; | |
| 32 static const int kNormalNumPartitions = 12; | |
| 33 | |
| 34 // Delay estimator constants, used for logging and delay compensation if | |
| 35 // if reported delays are disabled. | |
| 36 enum { kLookaheadBlocks = 15 }; | |
| 37 enum { | |
| 38 // 500 ms for 16 kHz which is equivalent with the limit of reported delays. | |
| 39 kHistorySizeBlocks = 125 | |
| 40 }; | |
| 41 | |
| 42 typedef struct PowerLevel { | |
| 43 PowerLevel(); | |
| 44 | |
| 45 BlockMeanCalculator framelevel; | |
| 46 BlockMeanCalculator averagelevel; | |
| 47 float minlevel; | |
| 48 } PowerLevel; | |
| 49 | |
| 50 class DivergentFilterFraction { | |
| 51 public: | |
| 52 DivergentFilterFraction(); | |
| 53 | |
| 54 // Reset. | |
| 55 void Reset(); | |
| 56 | |
| 57 void AddObservation(const PowerLevel& nearlevel, | |
| 58 const PowerLevel& linoutlevel, | |
| 59 const PowerLevel& nlpoutlevel); | |
| 60 | |
| 61 // Return the latest fraction. | |
| 62 float GetLatestFraction() const; | |
| 63 | |
| 64 private: | |
| 65 // Clear all values added. | |
| 66 void Clear(); | |
| 67 | |
| 68 size_t count_; | |
| 69 size_t occurrence_; | |
| 70 float fraction_; | |
| 71 | |
| 72 RTC_DISALLOW_COPY_AND_ASSIGN(DivergentFilterFraction); | |
| 73 }; | |
| 74 | |
| 75 typedef struct CoherenceState { | |
| 76 complex_t sde[PART_LEN1]; // cross-psd of nearend and error | |
| 77 complex_t sxd[PART_LEN1]; // cross-psd of farend and nearend | |
| 78 float sx[PART_LEN1], sd[PART_LEN1], se[PART_LEN1]; // far, near, error psd | |
| 79 } CoherenceState; | |
| 80 | |
| 81 struct AecCore { | |
| 82 explicit AecCore(int instance_index); | |
| 83 ~AecCore(); | |
| 84 | |
| 85 std::unique_ptr<ApmDataDumper> data_dumper; | |
| 86 | |
| 87 CoherenceState coherence_state; | |
| 88 | |
| 89 int farBufWritePos, farBufReadPos; | |
| 90 | |
| 91 int knownDelay; | |
| 92 int inSamples, outSamples; | |
| 93 int delayEstCtr; | |
| 94 | |
| 95 RingBuffer* nearFrBuf; | |
| 96 RingBuffer* outFrBuf; | |
| 97 | |
| 98 RingBuffer* nearFrBufH[NUM_HIGH_BANDS_MAX]; | |
| 99 RingBuffer* outFrBufH[NUM_HIGH_BANDS_MAX]; | |
| 100 | |
| 101 float dBuf[PART_LEN2]; // nearend | |
| 102 float eBuf[PART_LEN2]; // error | |
| 103 | |
| 104 float dBufH[NUM_HIGH_BANDS_MAX][PART_LEN2]; // nearend | |
| 105 | |
| 106 float xPow[PART_LEN1]; | |
| 107 float dPow[PART_LEN1]; | |
| 108 float dMinPow[PART_LEN1]; | |
| 109 float dInitMinPow[PART_LEN1]; | |
| 110 float* noisePow; | |
| 111 | |
| 112 float xfBuf[2][kExtendedNumPartitions * PART_LEN1]; // farend fft buffer | |
| 113 float wfBuf[2][kExtendedNumPartitions * PART_LEN1]; // filter fft | |
| 114 // Farend windowed fft buffer. | |
| 115 complex_t xfwBuf[kExtendedNumPartitions * PART_LEN1]; | |
| 116 | |
| 117 float hNs[PART_LEN1]; | |
| 118 float hNlFbMin, hNlFbLocalMin; | |
| 119 float hNlXdAvgMin; | |
| 120 int hNlNewMin, hNlMinCtr; | |
| 121 float overDrive; | |
| 122 float overdrive_scaling; | |
| 123 int nlp_mode; | |
| 124 float outBuf[PART_LEN]; | |
| 125 int delayIdx; | |
| 126 | |
| 127 short stNearState, echoState; | |
| 128 short divergeState; | |
| 129 | |
| 130 int xfBufBlockPos; | |
| 131 | |
| 132 RingBuffer* far_time_buf; | |
| 133 | |
| 134 int system_delay; // Current system delay buffered in AEC. | |
| 135 | |
| 136 int mult; // sampling frequency multiple | |
| 137 int sampFreq = 16000; | |
| 138 size_t num_bands; | |
| 139 uint32_t seed; | |
| 140 | |
| 141 float filter_step_size; // stepsize | |
| 142 float error_threshold; // error threshold | |
| 143 | |
| 144 int noiseEstCtr; | |
| 145 | |
| 146 PowerLevel farlevel; | |
| 147 PowerLevel nearlevel; | |
| 148 PowerLevel linoutlevel; | |
| 149 PowerLevel nlpoutlevel; | |
| 150 | |
| 151 int metricsMode; | |
| 152 int stateCounter; | |
| 153 Stats erl; | |
| 154 Stats erle; | |
| 155 Stats aNlp; | |
| 156 Stats rerl; | |
| 157 DivergentFilterFraction divergent_filter_fraction; | |
| 158 | |
| 159 // Quantities to control H band scaling for SWB input | |
| 160 int freq_avg_ic; // initial bin for averaging nlp gain | |
| 161 int flag_Hband_cn; // for comfort noise | |
| 162 float cn_scale_Hband; // scale for comfort noise in H band | |
| 163 | |
| 164 int delay_metrics_delivered; | |
| 165 int delay_histogram[kHistorySizeBlocks]; | |
| 166 int num_delay_values; | |
| 167 int delay_median; | |
| 168 int delay_std; | |
| 169 float fraction_poor_delays; | |
| 170 int delay_logging_enabled; | |
| 171 void* delay_estimator_farend; | |
| 172 void* delay_estimator; | |
| 173 // Variables associated with delay correction through signal based delay | |
| 174 // estimation feedback. | |
| 175 int signal_delay_correction; | |
| 176 int previous_delay; | |
| 177 int delay_correction_count; | |
| 178 int shift_offset; | |
| 179 float delay_quality_threshold; | |
| 180 int frame_count; | |
| 181 | |
| 182 // 0 = delay agnostic mode (signal based delay correction) disabled. | |
| 183 // Otherwise enabled. | |
| 184 int delay_agnostic_enabled; | |
| 185 // 1 = extended filter mode enabled, 0 = disabled. | |
| 186 int extended_filter_enabled; | |
| 187 // 1 = next generation aec mode enabled, 0 = disabled. | |
| 188 int aec3_enabled; | |
| 189 bool refined_adaptive_filter_enabled; | |
| 190 | |
| 191 // Runtime selection of number of filter partitions. | |
| 192 int num_partitions; | |
| 193 | |
| 194 // Flag that extreme filter divergence has been detected by the Echo | |
| 195 // Suppressor. | |
| 196 int extreme_filter_divergence; | |
| 197 }; | |
| 198 | |
| 199 typedef void (*WebRtcAecFilterFar)( | |
| 200 int num_partitions, | |
| 201 int x_fft_buf_block_pos, | |
| 202 float x_fft_buf[2][kExtendedNumPartitions * PART_LEN1], | |
| 203 float h_fft_buf[2][kExtendedNumPartitions * PART_LEN1], | |
| 204 float y_fft[2][PART_LEN1]); | |
| 205 extern WebRtcAecFilterFar WebRtcAec_FilterFar; | |
| 206 typedef void (*WebRtcAecScaleErrorSignal)(float mu, | |
| 207 float error_threshold, | |
| 208 float x_pow[PART_LEN1], | |
| 209 float ef[2][PART_LEN1]); | |
| 210 extern WebRtcAecScaleErrorSignal WebRtcAec_ScaleErrorSignal; | |
| 211 typedef void (*WebRtcAecFilterAdaptation)( | |
| 212 int num_partitions, | |
| 213 int x_fft_buf_block_pos, | |
| 214 float x_fft_buf[2][kExtendedNumPartitions * PART_LEN1], | |
| 215 float e_fft[2][PART_LEN1], | |
| 216 float h_fft_buf[2][kExtendedNumPartitions * PART_LEN1]); | |
| 217 extern WebRtcAecFilterAdaptation WebRtcAec_FilterAdaptation; | |
| 218 | |
| 219 typedef void (*WebRtcAecOverdrive)(float overdrive_scaling, | |
| 220 const float hNlFb, | |
| 221 float hNl[PART_LEN1]); | |
| 222 extern WebRtcAecOverdrive WebRtcAec_Overdrive; | |
| 223 | |
| 224 typedef void (*WebRtcAecSuppress)(const float hNl[PART_LEN1], | |
| 225 float efw[2][PART_LEN1]); | |
| 226 extern WebRtcAecSuppress WebRtcAec_Suppress; | |
| 227 | |
| 228 typedef void (*WebRtcAecComputeCoherence)(const CoherenceState* coherence_state, | |
| 229 float* cohde, | |
| 230 float* cohxd); | |
| 231 extern WebRtcAecComputeCoherence WebRtcAec_ComputeCoherence; | |
| 232 | |
| 233 typedef void (*WebRtcAecUpdateCoherenceSpectra)(int mult, | |
| 234 bool extended_filter_enabled, | |
| 235 float efw[2][PART_LEN1], | |
| 236 float dfw[2][PART_LEN1], | |
| 237 float xfw[2][PART_LEN1], | |
| 238 CoherenceState* coherence_state, | |
| 239 short* filter_divergence_state, | |
| 240 int* extreme_filter_divergence); | |
| 241 extern WebRtcAecUpdateCoherenceSpectra WebRtcAec_UpdateCoherenceSpectra; | |
| 242 | |
| 243 typedef int (*WebRtcAecPartitionDelay)( | |
| 244 int num_partitions, | |
| 245 float h_fft_buf[2][kExtendedNumPartitions * PART_LEN1]); | |
| 246 extern WebRtcAecPartitionDelay WebRtcAec_PartitionDelay; | |
| 247 | |
| 248 typedef void (*WebRtcAecStoreAsComplex)(const float* data, | |
| 249 float data_complex[2][PART_LEN1]); | |
| 250 extern WebRtcAecStoreAsComplex WebRtcAec_StoreAsComplex; | |
| 251 | |
| 252 typedef void (*WebRtcAecWindowData)(float* x_windowed, const float* x); | |
| 253 extern WebRtcAecWindowData WebRtcAec_WindowData; | |
| 254 | |
| 255 } // namespace webrtc | |
| 256 | |
| 257 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ | |
| OLD | NEW |