blob: adb1614926e618cdbc2fb6c543c98c7987640129 [file] [log] [blame]
Alex Loikoe36e8bb2018-02-16 11:54:07 +01001/*
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
14namespace webrtc {
15
Alessio Bazzica841d74e2021-03-31 15:04:03 +020016constexpr float kMinFloatS16Value = -32768.0f;
17constexpr float kMaxFloatS16Value = 32767.0f;
Alex Loiko9917c4a2018-04-04 14:16:10 +020018constexpr float kMaxAbsFloatS16Value = 32768.0f;
Alex Loikoe36e8bb2018-02-16 11:54:07 +010019
Alessio Bazzica980c4602021-04-14 19:09:17 +020020// Minimum audio level in dBFS scale for S16 samples.
21constexpr float kMinLevelDbfs = -90.31f;
22
Alessio Bazzicab995bb82021-03-31 09:48:49 +020023constexpr int kFrameDurationMs = 10;
24constexpr int kSubFramesInFrame = 20;
25constexpr int kMaximalNumberOfSamplesPerChannel = 480;
Alex Loiko153f11e2018-02-16 12:39:00 +010026
Alex Loikocab48c32018-04-04 17:43:31 +020027// Adaptive digital gain applier settings below.
Alessio Bazzica841d74e2021-03-31 15:04:03 +020028constexpr float kHeadroomDbfs = 1.0f;
29constexpr float kMaxGainDb = 30.0f;
30constexpr float kInitialAdaptiveDigitalGainDb = 8.0f;
Alex Loiko93e57502018-10-01 16:28:47 +020031// At what limiter levels should we start decreasing the adaptive digital gain.
32constexpr float kLimiterThresholdForAgcGainDbfs = -kHeadroomDbfs;
Alex Loikocab48c32018-04-04 17:43:31 +020033
Alex Loiko2ffafa82018-07-06 15:35:42 +020034// 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 Bazzica61982a72021-04-14 16:17:09 +020037constexpr float kVadConfidenceThreshold = 0.95f;
Alex Loiko1e48e802018-03-28 09:45:29 +020038
Alessio Bazzica980c4602021-04-14 19:09:17 +020039// Adaptive digital level estimator parameters.
40// Number of milliseconds of speech frames to observe to make the estimator
41// confident.
42constexpr float kLevelEstimatorTimeToConfidenceMs = 400;
43constexpr float kLevelEstimatorLeakFactor =
44 1.0f - 1.0f / kLevelEstimatorTimeToConfidenceMs;
Alex Loiko1e48e802018-03-28 09:45:29 +020045
Alessio Bazzicac1ece012020-09-25 14:31:17 +020046// Robust VAD probability and speech decisions.
Alessio Bazzica980c4602021-04-14 19:09:17 +020047constexpr int kDefaultLevelEstimatorAdjacentSpeechFramesThreshold = 12;
Alessio Bazzicac1ece012020-09-25 14:31:17 +020048
Alex Loiko9917c4a2018-04-04 14:16:10 +020049// Saturation Protector settings.
Alessio Bazzica980c4602021-04-14 19:09:17 +020050constexpr float kSaturationProtectorInitialHeadroomDb = 20.0f;
51constexpr float kSaturationProtectorExtraHeadroomDb = 5.0f;
52constexpr int kSaturationProtectorBufferSize = 4;
Alex Loiko1e48e802018-03-28 09:45:29 +020053
Alessio Bazzica980c4602021-04-14 19:09:17 +020054// Set the initial speech level estimate so that `kInitialAdaptiveDigitalGainDb`
55// is applied at the beginning of the call.
56constexpr float kInitialSpeechLevelEstimateDbfs =
57 -kSaturationProtectorExtraHeadroomDb -
58 kSaturationProtectorInitialHeadroomDb - kInitialAdaptiveDigitalGainDb -
59 kHeadroomDbfs;
Alex Loiko153f11e2018-02-16 12:39:00 +010060
Alex Loikoa05ee822018-02-20 15:58:36 +010061// 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 Bazzicab995bb82021-03-31 09:48:49 +020064constexpr int kInterpolatedGainCurveKneePoints = 22;
65constexpr int kInterpolatedGainCurveBeyondKneePoints = 10;
66constexpr int kInterpolatedGainCurveTotalPoints =
Alex Loikoa05ee822018-02-20 15:58:36 +010067 kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints;
68
Alex Loikoe36e8bb2018-02-16 11:54:07 +010069} // namespace webrtc
70
71#endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_