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