2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_
14 #include "webrtc/common_audio/wav_writer.h"
15 #include "webrtc/modules/audio_processing/aec/aec_common.h"
16 #include "webrtc/modules/audio_processing/aec/aec_core.h"
17 #include "webrtc/modules/audio_processing/utility/ring_buffer.h"
18 #include "webrtc/typedefs.h"
20 // Number of partitions for the extended filter mode. The first one is an enum
21 // to be used in array declarations, as it represents the maximum filter length.
23 kExtendedNumPartitions = 32
25 static const int kNormalNumPartitions = 12;
27 // Delay estimator constants, used for logging.
35 kHistorySizeBlocks = kMaxDelayBlocks + kLookaheadBlocks
38 // Extended filter adaptation parameters.
39 // TODO(ajm): No narrowband tuning yet.
40 static const float kExtendedMu = 0.4f;
41 static const float kExtendedErrorThreshold = 1.0e-6f;
43 typedef struct PowerLevel {
54 int farBufWritePos, farBufReadPos;
57 int inSamples, outSamples;
60 RingBuffer* nearFrBuf;
63 RingBuffer* nearFrBufH;
64 RingBuffer* outFrBufH;
66 float dBuf[PART_LEN2]; // nearend
67 float eBuf[PART_LEN2]; // error
69 float dBufH[PART_LEN2]; // nearend
71 float xPow[PART_LEN1];
72 float dPow[PART_LEN1];
73 float dMinPow[PART_LEN1];
74 float dInitMinPow[PART_LEN1];
77 float xfBuf[2][kExtendedNumPartitions * PART_LEN1]; // farend fft buffer
78 float wfBuf[2][kExtendedNumPartitions * PART_LEN1]; // filter fft
79 complex_t sde[PART_LEN1]; // cross-psd of nearend and error
80 complex_t sxd[PART_LEN1]; // cross-psd of farend and nearend
81 // Farend windowed fft buffer.
82 complex_t xfwBuf[kExtendedNumPartitions * PART_LEN1];
84 float sx[PART_LEN1], sd[PART_LEN1], se[PART_LEN1]; // far, near, error psd
86 float hNlFbMin, hNlFbLocalMin;
88 int hNlNewMin, hNlMinCtr;
89 float overDrive, overDriveSm;
91 float outBuf[PART_LEN];
94 short stNearState, echoState;
100 RingBuffer* far_buf_windowed;
101 int system_delay; // Current system delay buffered in AEC.
103 int mult; // sampling frequency multiple
107 float normal_mu; // stepsize
108 float normal_error_threshold; // error threshold
113 PowerLevel nearlevel;
114 PowerLevel linoutlevel;
115 PowerLevel nlpoutlevel;
124 // Quantities to control H band scaling for SWB input
125 int freq_avg_ic; // initial bin for averaging nlp gain
126 int flag_Hband_cn; // for comfort noise
127 float cn_scale_Hband; // scale for comfort noise in H band
129 int delay_histogram[kHistorySizeBlocks];
130 int delay_logging_enabled;
131 void* delay_estimator_farend;
132 void* delay_estimator;
134 int reported_delay_enabled; // 0 = disabled, otherwise enabled.
135 // 1 = extended filter mode enabled, 0 = disabled.
136 int extended_filter_enabled;
137 // Runtime selection of number of filter partitions.
140 #ifdef WEBRTC_AEC_DEBUG_DUMP
141 // Sequence number of this AEC instance, so that different instances can
142 // choose different dump file names.
145 // Number of times we've restarted dumping; used to pick new dump file names
147 int debug_dump_count;
149 RingBuffer* far_time_buf;
150 rtc_WavFile* farFile;
151 rtc_WavFile* nearFile;
152 rtc_WavFile* outFile;
153 rtc_WavFile* outLinearFile;
157 typedef void (*WebRtcAec_FilterFar_t)(AecCore* aec, float yf[2][PART_LEN1]);
158 extern WebRtcAec_FilterFar_t WebRtcAec_FilterFar;
159 typedef void (*WebRtcAec_ScaleErrorSignal_t)(AecCore* aec,
160 float ef[2][PART_LEN1]);
161 extern WebRtcAec_ScaleErrorSignal_t WebRtcAec_ScaleErrorSignal;
162 typedef void (*WebRtcAec_FilterAdaptation_t)(AecCore* aec,
164 float ef[2][PART_LEN1]);
165 extern WebRtcAec_FilterAdaptation_t WebRtcAec_FilterAdaptation;
166 typedef void (*WebRtcAec_OverdriveAndSuppress_t)(AecCore* aec,
167 float hNl[PART_LEN1],
169 float efw[2][PART_LEN1]);
170 extern WebRtcAec_OverdriveAndSuppress_t WebRtcAec_OverdriveAndSuppress;
172 typedef void (*WebRtcAec_ComfortNoise_t)(AecCore* aec,
173 float efw[2][PART_LEN1],
174 complex_t* comfortNoiseHband,
175 const float* noisePow,
176 const float* lambda);
177 extern WebRtcAec_ComfortNoise_t WebRtcAec_ComfortNoise;
179 typedef void (*WebRtcAec_SubbandCoherence_t)(AecCore* aec,
180 float efw[2][PART_LEN1],
181 float xfw[2][PART_LEN1],
185 extern WebRtcAec_SubbandCoherence_t WebRtcAec_SubbandCoherence;
187 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_