OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 /* The slope of in Q13*/ | 35 /* The slope of in Q13*/ |
36 static const int16_t kSlope2[8] = {2063, 1731, 1452, 1218, 1021, 857, 597, 337}; | 36 static const int16_t kSlope2[8] = {2063, 1731, 1452, 1218, 1021, 857, 597, 337}; |
37 | 37 |
38 /* The offset in Q14 */ | 38 /* The offset in Q14 */ |
39 static const int16_t kOffset2[8] = {18432, 18379, 18290, 18177, 18052, 17920, 17
670, | 39 static const int16_t kOffset2[8] = {18432, 18379, 18290, 18177, 18052, 17920, 17
670, |
40 17286}; | 40 17286}; |
41 | 41 |
42 static const int16_t kMuteGuardTimeMs = 8000; | 42 static const int16_t kMuteGuardTimeMs = 8000; |
43 static const int16_t kInitCheck = 42; | 43 static const int16_t kInitCheck = 42; |
44 static const int16_t kNumSubframes = 10; | 44 static const size_t kNumSubframes = 10; |
45 | 45 |
46 /* Default settings if config is not used */ | 46 /* Default settings if config is not used */ |
47 #define AGC_DEFAULT_TARGET_LEVEL 3 | 47 #define AGC_DEFAULT_TARGET_LEVEL 3 |
48 #define AGC_DEFAULT_COMP_GAIN 9 | 48 #define AGC_DEFAULT_COMP_GAIN 9 |
49 /* This is the target level for the analog part in ENV scale. To convert to RMS
scale you | 49 /* This is the target level for the analog part in ENV scale. To convert to RMS
scale you |
50 * have to add OFFSET_ENV_TO_RMS. | 50 * have to add OFFSET_ENV_TO_RMS. |
51 */ | 51 */ |
52 #define ANALOG_TARGET_LEVEL 11 | 52 #define ANALOG_TARGET_LEVEL 11 |
53 #define ANALOG_TARGET_LEVEL_2 5 // ANALOG_TARGET_LEVEL / 2 | 53 #define ANALOG_TARGET_LEVEL_2 5 // ANALOG_TARGET_LEVEL / 2 |
54 /* Offset between RMS scale (analog part) and ENV scale (digital part). This val
ue actually | 54 /* Offset between RMS scale (analog part) and ENV scale (digital part). This val
ue actually |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 * targetLevelTable = fprintf('%d,\t%d,\t%d,\t%d,\n', round((32767*10.^(-(0:63)'
/20)).^2*16/2^7) */ | 105 * targetLevelTable = fprintf('%d,\t%d,\t%d,\t%d,\n', round((32767*10.^(-(0:63)'
/20)).^2*16/2^7) */ |
106 | 106 |
107 static const int32_t kTargetLevelTable[64] = {134209536, 106606424, 84680493, 67
264106, | 107 static const int32_t kTargetLevelTable[64] = {134209536, 106606424, 84680493, 67
264106, |
108 53429779, 42440782, 33711911, 26778323, 21270778, 16895980, 13420954, 10
660642, | 108 53429779, 42440782, 33711911, 26778323, 21270778, 16895980, 13420954, 10
660642, |
109 8468049, 6726411, 5342978, 4244078, 3371191, 2677832, 2127078, 1689598,
1342095, | 109 8468049, 6726411, 5342978, 4244078, 3371191, 2677832, 2127078, 1689598,
1342095, |
110 1066064, 846805, 672641, 534298, 424408, 337119, 267783, 212708, 168960,
134210, | 110 1066064, 846805, 672641, 534298, 424408, 337119, 267783, 212708, 168960,
134210, |
111 106606, 84680, 67264, 53430, 42441, 33712, 26778, 21271, 16896, 13421, 1
0661, 8468, | 111 106606, 84680, 67264, 53430, 42441, 33712, 26778, 21271, 16896, 13421, 1
0661, 8468, |
112 6726, 5343, 4244, 3371, 2678, 2127, 1690, 1342, 1066, 847, 673, 534, 424
, 337, 268, | 112 6726, 5343, 4244, 3371, 2678, 2127, 1690, 1342, 1066, 847, 673, 534, 424
, 337, 268, |
113 213, 169, 134, 107, 85, 67}; | 113 213, 169, 134, 107, 85, 67}; |
114 | 114 |
115 int WebRtcAgc_AddMic(void *state, int16_t* const* in_mic, int16_t num_bands, | 115 int WebRtcAgc_AddMic(void *state, int16_t* const* in_mic, size_t num_bands, |
116 int16_t samples) | 116 size_t samples) |
117 { | 117 { |
118 int32_t nrg, max_nrg, sample, tmp32; | 118 int32_t nrg, max_nrg, sample, tmp32; |
119 int32_t *ptr; | 119 int32_t *ptr; |
120 uint16_t targetGainIdx, gain; | 120 uint16_t targetGainIdx, gain; |
121 int16_t i, n, L, tmp16, tmp_speech[16]; | 121 size_t i; |
| 122 int16_t n, L, tmp16, tmp_speech[16]; |
122 LegacyAgc* stt; | 123 LegacyAgc* stt; |
123 stt = (LegacyAgc*)state; | 124 stt = (LegacyAgc*)state; |
124 | 125 |
125 if (stt->fs == 8000) { | 126 if (stt->fs == 8000) { |
126 L = 8; | 127 L = 8; |
127 if (samples != 80) { | 128 if (samples != 80) { |
128 return -1; | 129 return -1; |
129 } | 130 } |
130 } else { | 131 } else { |
131 L = 16; | 132 L = 16; |
(...skipping 25 matching lines...) Expand all Loading... |
157 } else if (stt->gainTableIdx > targetGainIdx) | 158 } else if (stt->gainTableIdx > targetGainIdx) |
158 { | 159 { |
159 stt->gainTableIdx--; | 160 stt->gainTableIdx--; |
160 } | 161 } |
161 | 162 |
162 /* Q12 */ | 163 /* Q12 */ |
163 gain = kGainTableAnalog[stt->gainTableIdx]; | 164 gain = kGainTableAnalog[stt->gainTableIdx]; |
164 | 165 |
165 for (i = 0; i < samples; i++) | 166 for (i = 0; i < samples; i++) |
166 { | 167 { |
167 int j; | 168 size_t j; |
168 for (j = 0; j < num_bands; ++j) | 169 for (j = 0; j < num_bands; ++j) |
169 { | 170 { |
170 sample = (in_mic[j][i] * gain) >> 12; | 171 sample = (in_mic[j][i] * gain) >> 12; |
171 if (sample > 32767) | 172 if (sample > 32767) |
172 { | 173 { |
173 in_mic[j][i] = 32767; | 174 in_mic[j][i] = 32767; |
174 } else if (sample < -32768) | 175 } else if (sample < -32768) |
175 { | 176 { |
176 in_mic[j][i] = -32768; | 177 in_mic[j][i] = -32768; |
177 } else | 178 } else |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 { | 243 { |
243 stt->inQueue = 2; | 244 stt->inQueue = 2; |
244 } | 245 } |
245 | 246 |
246 /* call VAD (use low band only) */ | 247 /* call VAD (use low band only) */ |
247 WebRtcAgc_ProcessVad(&stt->vadMic, in_mic[0], samples); | 248 WebRtcAgc_ProcessVad(&stt->vadMic, in_mic[0], samples); |
248 | 249 |
249 return 0; | 250 return 0; |
250 } | 251 } |
251 | 252 |
252 int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, int16_t samples) | 253 int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, size_t samples) |
253 { | 254 { |
254 LegacyAgc* stt; | 255 LegacyAgc* stt; |
255 stt = (LegacyAgc*)state; | 256 stt = (LegacyAgc*)state; |
256 | 257 |
257 if (stt == NULL) | 258 if (stt == NULL) |
258 { | 259 { |
259 return -1; | 260 return -1; |
260 } | 261 } |
261 | 262 |
262 if (stt->fs == 8000) | 263 if (stt->fs == 8000) |
(...skipping 10 matching lines...) Expand all Loading... |
273 } | 274 } |
274 } else | 275 } else |
275 { | 276 { |
276 return -1; | 277 return -1; |
277 } | 278 } |
278 | 279 |
279 return WebRtcAgc_AddFarendToDigital(&stt->digitalAgc, in_far, samples); | 280 return WebRtcAgc_AddFarendToDigital(&stt->digitalAgc, in_far, samples); |
280 } | 281 } |
281 | 282 |
282 int WebRtcAgc_VirtualMic(void *agcInst, int16_t* const* in_near, | 283 int WebRtcAgc_VirtualMic(void *agcInst, int16_t* const* in_near, |
283 int16_t num_bands, int16_t samples, int32_t micLevelIn, | 284 size_t num_bands, size_t samples, int32_t micLevelIn, |
284 int32_t *micLevelOut) | 285 int32_t *micLevelOut) |
285 { | 286 { |
286 int32_t tmpFlt, micLevelTmp, gainIdx; | 287 int32_t tmpFlt, micLevelTmp, gainIdx; |
287 uint16_t gain; | 288 uint16_t gain; |
288 int16_t ii, j; | 289 size_t ii, j; |
289 LegacyAgc* stt; | 290 LegacyAgc* stt; |
290 | 291 |
291 uint32_t nrg; | 292 uint32_t nrg; |
292 int16_t sampleCntr; | 293 size_t sampleCntr; |
293 uint32_t frameNrg = 0; | 294 uint32_t frameNrg = 0; |
294 uint32_t frameNrgLimit = 5500; | 295 uint32_t frameNrgLimit = 5500; |
295 int16_t numZeroCrossing = 0; | 296 int16_t numZeroCrossing = 0; |
296 const int16_t kZeroCrossingLowLim = 15; | 297 const int16_t kZeroCrossingLowLim = 15; |
297 const int16_t kZeroCrossingHighLim = 20; | 298 const int16_t kZeroCrossingHighLim = 20; |
298 | 299 |
299 stt = (LegacyAgc*)agcInst; | 300 stt = (LegacyAgc*)agcInst; |
300 | 301 |
301 /* | 302 /* |
302 * Before applying gain decide if this is a low-level signal. | 303 * Before applying gain decide if this is a low-level signal. |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 { | 1126 { |
1126 stt->micVol = stt->minOutput; | 1127 stt->micVol = stt->minOutput; |
1127 } | 1128 } |
1128 | 1129 |
1129 *outMicLevel = WEBRTC_SPL_MIN(stt->micVol, stt->maxAnalog) >> stt->scale; | 1130 *outMicLevel = WEBRTC_SPL_MIN(stt->micVol, stt->maxAnalog) >> stt->scale; |
1130 | 1131 |
1131 return 0; | 1132 return 0; |
1132 } | 1133 } |
1133 | 1134 |
1134 int WebRtcAgc_Process(void *agcInst, const int16_t* const* in_near, | 1135 int WebRtcAgc_Process(void *agcInst, const int16_t* const* in_near, |
1135 int16_t num_bands, int16_t samples, | 1136 size_t num_bands, size_t samples, |
1136 int16_t* const* out, int32_t inMicLevel, | 1137 int16_t* const* out, int32_t inMicLevel, |
1137 int32_t *outMicLevel, int16_t echo, | 1138 int32_t *outMicLevel, int16_t echo, |
1138 uint8_t *saturationWarning) | 1139 uint8_t *saturationWarning) |
1139 { | 1140 { |
1140 LegacyAgc* stt; | 1141 LegacyAgc* stt; |
1141 | 1142 |
1142 stt = (LegacyAgc*)agcInst; | 1143 stt = (LegacyAgc*)agcInst; |
1143 | 1144 |
1144 // | 1145 // |
1145 if (stt == NULL) | 1146 if (stt == NULL) |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 #endif | 1510 #endif |
1510 return -1; | 1511 return -1; |
1511 } else | 1512 } else |
1512 { | 1513 { |
1513 #ifdef WEBRTC_AGC_DEBUG_DUMP | 1514 #ifdef WEBRTC_AGC_DEBUG_DUMP |
1514 fprintf(stt->fpt, "\n"); | 1515 fprintf(stt->fpt, "\n"); |
1515 #endif | 1516 #endif |
1516 return 0; | 1517 return 0; |
1517 } | 1518 } |
1518 } | 1519 } |
OLD | NEW |