bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 14 | #ifdef WEBRTC_AEC_DEBUG_DUMP |
| 15 | #include <stdio.h> |
| 16 | #endif |
| 17 | |
bjornv@webrtc.org | 2c1f9d4 | 2013-03-04 23:47:39 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/aec/aec_core.h" |
| 19 | #include "webrtc/modules/audio_processing/utility/ring_buffer.h" |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 20 | #include "webrtc/typedefs.h" |
| 21 | |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 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. |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 24 | enum { |
| 25 | kExtendedNumPartitions = 32 |
| 26 | }; |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 27 | static const int kNormalNumPartitions = 12; |
| 28 | |
bjornv@webrtc.org | 0e098e0 | 2014-04-28 11:42:27 +0000 | [diff] [blame^] | 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 | |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 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; |
andrew@webrtc.org | fe8ba4d | 2013-07-31 08:13:08 +0000 | [diff] [blame] | 44 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 101eb2c | 2013-02-25 17:07:35 +0000 | [diff] [blame] | 62 | RingBuffer* nearFrBuf; |
| 63 | RingBuffer* outFrBuf; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 64 | |
andrew@webrtc.org | 101eb2c | 2013-02-25 17:07:35 +0000 | [diff] [blame] | 65 | RingBuffer* nearFrBufH; |
| 66 | RingBuffer* outFrBufH; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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]; |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 77 | float* noisePow; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 78 | |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 79 | float xfBuf[2][kExtendedNumPartitions * PART_LEN1]; // farend fft buffer |
| 80 | float wfBuf[2][kExtendedNumPartitions * PART_LEN1]; // filter fft |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 81 | complex_t sde[PART_LEN1]; // cross-psd of nearend and error |
| 82 | complex_t sxd[PART_LEN1]; // cross-psd of farend and nearend |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 83 | // Farend windowed fft buffer. |
| 84 | complex_t xfwBuf[kExtendedNumPartitions * PART_LEN1]; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 101eb2c | 2013-02-25 17:07:35 +0000 | [diff] [blame] | 101 | RingBuffer* far_buf; |
| 102 | RingBuffer* far_buf_windowed; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 103 | int system_delay; // Current system delay buffered in AEC. |
| 104 | |
| 105 | int mult; // sampling frequency multiple |
| 106 | int sampFreq; |
pbos@webrtc.org | 211b771 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 107 | uint32_t seed; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 108 | |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 109 | float normal_mu; // stepsize |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 110 | float normal_error_threshold; // error threshold |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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 |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 127 | int freq_avg_ic; // initial bin for averaging nlp gain |
| 128 | int flag_Hband_cn; // for comfort noise |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | e1b0595 | 2014-04-23 13:20:07 +0000 | [diff] [blame] | 136 | int reported_delay_enabled; // 0 = disabled, otherwise enabled. |
andrew@webrtc.org | ad80fde | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 142 | #ifdef WEBRTC_AEC_DEBUG_DUMP |
andrew@webrtc.org | 101eb2c | 2013-02-25 17:07:35 +0000 | [diff] [blame] | 143 | RingBuffer* far_time_buf; |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 144 | FILE* farFile; |
| 145 | FILE* nearFile; |
| 146 | FILE* outFile; |
| 147 | FILE* outLinearFile; |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 148 | #endif |
| 149 | }; |
| 150 | |
bjornv@webrtc.org | ed1c7f4 | 2013-02-21 16:12:24 +0000 | [diff] [blame] | 151 | typedef void (*WebRtcAec_FilterFar_t)(AecCore* aec, float yf[2][PART_LEN1]); |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 152 | extern WebRtcAec_FilterFar_t WebRtcAec_FilterFar; |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 153 | typedef void (*WebRtcAec_ScaleErrorSignal_t)(AecCore* aec, |
| 154 | float ef[2][PART_LEN1]); |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 155 | extern WebRtcAec_ScaleErrorSignal_t WebRtcAec_ScaleErrorSignal; |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 156 | typedef void (*WebRtcAec_FilterAdaptation_t)(AecCore* aec, |
| 157 | float* fft, |
| 158 | float ef[2][PART_LEN1]); |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 159 | extern WebRtcAec_FilterAdaptation_t WebRtcAec_FilterAdaptation; |
andrew@webrtc.org | f50f118 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 160 | typedef void (*WebRtcAec_OverdriveAndSuppress_t)(AecCore* aec, |
| 161 | float hNl[PART_LEN1], |
| 162 | const float hNlFb, |
| 163 | float efw[2][PART_LEN1]); |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 164 | extern WebRtcAec_OverdriveAndSuppress_t WebRtcAec_OverdriveAndSuppress; |
| 165 | |
andrew@webrtc.org | f59fce9 | 2014-02-21 00:13:31 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | c01c6c3 | 2013-02-20 22:38:47 +0000 | [diff] [blame] | 173 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ |