Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_ |
| 13 | |
| 14 | namespace webrtc { |
| 15 | |
Alessio Bazzica | 841d74e | 2021-03-31 15:04:03 +0200 | [diff] [blame] | 16 | constexpr float kMinFloatS16Value = -32768.0f; |
| 17 | constexpr float kMaxFloatS16Value = 32767.0f; |
Alex Loiko | 9917c4a | 2018-04-04 14:16:10 +0200 | [diff] [blame] | 18 | constexpr float kMaxAbsFloatS16Value = 32768.0f; |
Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 19 | |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 20 | // Minimum audio level in dBFS scale for S16 samples. |
| 21 | constexpr float kMinLevelDbfs = -90.31f; |
| 22 | |
Alessio Bazzica | b995bb8 | 2021-03-31 09:48:49 +0200 | [diff] [blame] | 23 | constexpr int kFrameDurationMs = 10; |
| 24 | constexpr int kSubFramesInFrame = 20; |
| 25 | constexpr int kMaximalNumberOfSamplesPerChannel = 480; |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 26 | |
Alex Loiko | cab48c3 | 2018-04-04 17:43:31 +0200 | [diff] [blame] | 27 | // Adaptive digital gain applier settings below. |
Alessio Bazzica | 841d74e | 2021-03-31 15:04:03 +0200 | [diff] [blame] | 28 | constexpr float kHeadroomDbfs = 1.0f; |
| 29 | constexpr float kMaxGainDb = 30.0f; |
| 30 | constexpr float kInitialAdaptiveDigitalGainDb = 8.0f; |
Alex Loiko | 93e5750 | 2018-10-01 16:28:47 +0200 | [diff] [blame] | 31 | // At what limiter levels should we start decreasing the adaptive digital gain. |
| 32 | constexpr float kLimiterThresholdForAgcGainDbfs = -kHeadroomDbfs; |
Alex Loiko | cab48c3 | 2018-04-04 17:43:31 +0200 | [diff] [blame] | 33 | |
Alex Loiko | 2ffafa8 | 2018-07-06 15:35:42 +0200 | [diff] [blame] | 34 | // This is the threshold for speech. Speech frames are used for updating the |
| 35 | // speech level, measuring the amount of speech, and decide when to allow target |
| 36 | // gain reduction. |
Alessio Bazzica | 61982a7 | 2021-04-14 16:17:09 +0200 | [diff] [blame] | 37 | constexpr float kVadConfidenceThreshold = 0.95f; |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 38 | |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 39 | // Adaptive digital level estimator parameters. |
| 40 | // Number of milliseconds of speech frames to observe to make the estimator |
| 41 | // confident. |
| 42 | constexpr float kLevelEstimatorTimeToConfidenceMs = 400; |
| 43 | constexpr float kLevelEstimatorLeakFactor = |
| 44 | 1.0f - 1.0f / kLevelEstimatorTimeToConfidenceMs; |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 45 | |
Alessio Bazzica | c1ece01 | 2020-09-25 14:31:17 +0200 | [diff] [blame] | 46 | // Robust VAD probability and speech decisions. |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 47 | constexpr int kDefaultLevelEstimatorAdjacentSpeechFramesThreshold = 12; |
Alessio Bazzica | c1ece01 | 2020-09-25 14:31:17 +0200 | [diff] [blame] | 48 | |
Alex Loiko | 9917c4a | 2018-04-04 14:16:10 +0200 | [diff] [blame] | 49 | // Saturation Protector settings. |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 50 | constexpr float kSaturationProtectorInitialHeadroomDb = 20.0f; |
| 51 | constexpr float kSaturationProtectorExtraHeadroomDb = 5.0f; |
| 52 | constexpr int kSaturationProtectorBufferSize = 4; |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 53 | |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 54 | // Set the initial speech level estimate so that `kInitialAdaptiveDigitalGainDb` |
| 55 | // is applied at the beginning of the call. |
| 56 | constexpr float kInitialSpeechLevelEstimateDbfs = |
| 57 | -kSaturationProtectorExtraHeadroomDb - |
| 58 | kSaturationProtectorInitialHeadroomDb - kInitialAdaptiveDigitalGainDb - |
| 59 | kHeadroomDbfs; |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 60 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 61 | // Number of interpolation points for each region of the limiter. |
| 62 | // These values have been tuned to limit the interpolated gain curve error given |
| 63 | // the limiter parameters and allowing a maximum error of +/- 32768^-1. |
Alessio Bazzica | b995bb8 | 2021-03-31 09:48:49 +0200 | [diff] [blame] | 64 | constexpr int kInterpolatedGainCurveKneePoints = 22; |
| 65 | constexpr int kInterpolatedGainCurveBeyondKneePoints = 10; |
| 66 | constexpr int kInterpolatedGainCurveTotalPoints = |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 67 | kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints; |
| 68 | |
Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 69 | } // namespace webrtc |
| 70 | |
| 71 | #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_ |