blob: 1c560f91c9c821152d00c74063cd3c49db95b349 [file] [log] [blame]
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +00001/*
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.orgc01c6c32013-02-20 22:38:47 +000014#ifdef WEBRTC_AEC_DEBUG_DUMP
15#include <stdio.h>
16#endif
17
bjornv@webrtc.org2c1f9d42013-03-04 23:47:39 +000018#include "webrtc/modules/audio_processing/aec/aec_core.h"
19#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000020#include "webrtc/typedefs.h"
21
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000022// 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.orgf50f1182013-10-08 23:41:42 +000024enum {
25 kExtendedNumPartitions = 32
26};
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000027static const int kNormalNumPartitions = 12;
28
bjornv@webrtc.org0e098e02014-04-28 11:42:27 +000029// Delay estimator constants, used for logging.
30enum {
31 kMaxDelayBlocks = 60
32};
33enum {
34 kLookaheadBlocks = 15
35};
36enum {
37 kHistorySizeBlocks = kMaxDelayBlocks + kLookaheadBlocks
38};
39
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000040// Extended filter adaptation parameters.
41// TODO(ajm): No narrowband tuning yet.
42static const float kExtendedMu = 0.4f;
43static const float kExtendedErrorThreshold = 1.0e-6f;
andrew@webrtc.orgfe8ba4d2013-07-31 08:13:08 +000044
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000045typedef 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
55struct AecCore {
56 int farBufWritePos, farBufReadPos;
57
58 int knownDelay;
59 int inSamples, outSamples;
60 int delayEstCtr;
61
andrew@webrtc.org101eb2c2013-02-25 17:07:35 +000062 RingBuffer* nearFrBuf;
63 RingBuffer* outFrBuf;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000064
andrew@webrtc.org101eb2c2013-02-25 17:07:35 +000065 RingBuffer* nearFrBufH;
66 RingBuffer* outFrBufH;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000067
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.orgf50f1182013-10-08 23:41:42 +000077 float* noisePow;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000078
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +000079 float xfBuf[2][kExtendedNumPartitions * PART_LEN1]; // farend fft buffer
80 float wfBuf[2][kExtendedNumPartitions * PART_LEN1]; // filter fft
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000081 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.orgad80fde2013-09-25 23:17:38 +000083 // Farend windowed fft buffer.
84 complex_t xfwBuf[kExtendedNumPartitions * PART_LEN1];
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +000085
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.org101eb2c2013-02-25 17:07:35 +0000101 RingBuffer* far_buf;
102 RingBuffer* far_buf_windowed;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000103 int system_delay; // Current system delay buffered in AEC.
104
105 int mult; // sampling frequency multiple
106 int sampFreq;
pbos@webrtc.org211b7712013-04-10 07:50:54 +0000107 uint32_t seed;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000108
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +0000109 float normal_mu; // stepsize
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +0000110 float normal_error_threshold; // error threshold
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000111
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.orgf50f1182013-10-08 23:41:42 +0000127 int freq_avg_ic; // initial bin for averaging nlp gain
128 int flag_Hband_cn; // for comfort noise
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000129 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.orge1b05952014-04-23 13:20:07 +0000136 int reported_delay_enabled; // 0 = disabled, otherwise enabled.
andrew@webrtc.orgad80fde2013-09-25 23:17:38 +0000137 // 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.orgc01c6c32013-02-20 22:38:47 +0000142#ifdef WEBRTC_AEC_DEBUG_DUMP
andrew@webrtc.org101eb2c2013-02-25 17:07:35 +0000143 RingBuffer* far_time_buf;
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +0000144 FILE* farFile;
145 FILE* nearFile;
146 FILE* outFile;
147 FILE* outLinearFile;
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000148#endif
149};
150
bjornv@webrtc.orged1c7f42013-02-21 16:12:24 +0000151typedef void (*WebRtcAec_FilterFar_t)(AecCore* aec, float yf[2][PART_LEN1]);
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000152extern WebRtcAec_FilterFar_t WebRtcAec_FilterFar;
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +0000153typedef void (*WebRtcAec_ScaleErrorSignal_t)(AecCore* aec,
154 float ef[2][PART_LEN1]);
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000155extern WebRtcAec_ScaleErrorSignal_t WebRtcAec_ScaleErrorSignal;
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +0000156typedef void (*WebRtcAec_FilterAdaptation_t)(AecCore* aec,
157 float* fft,
158 float ef[2][PART_LEN1]);
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000159extern WebRtcAec_FilterAdaptation_t WebRtcAec_FilterAdaptation;
andrew@webrtc.orgf50f1182013-10-08 23:41:42 +0000160typedef void (*WebRtcAec_OverdriveAndSuppress_t)(AecCore* aec,
161 float hNl[PART_LEN1],
162 const float hNlFb,
163 float efw[2][PART_LEN1]);
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000164extern WebRtcAec_OverdriveAndSuppress_t WebRtcAec_OverdriveAndSuppress;
165
andrew@webrtc.orgf59fce92014-02-21 00:13:31 +0000166typedef void (*WebRtcAec_ComfortNoise_t)(AecCore* aec,
167 float efw[2][PART_LEN1],
168 complex_t* comfortNoiseHband,
169 const float* noisePow,
170 const float* lambda);
171extern WebRtcAec_ComfortNoise_t WebRtcAec_ComfortNoise;
172
bjornv@webrtc.orgc01c6c32013-02-20 22:38:47 +0000173#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_