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 | |
Niels Möller | 65ec0fc | 2018-05-21 11:46:20 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 16 | namespace webrtc { |
| 17 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 18 | constexpr float kMinFloatS16Value = -32768.f; |
| 19 | constexpr float kMaxFloatS16Value = 32767.f; |
Alex Loiko | 9917c4a | 2018-04-04 14:16:10 +0200 | [diff] [blame] | 20 | constexpr float kMaxAbsFloatS16Value = 32768.0f; |
Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 21 | |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 22 | constexpr size_t kFrameDurationMs = 10; |
| 23 | constexpr size_t kSubFramesInFrame = 20; |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 24 | constexpr size_t kMaximalNumberOfSamplesPerChannel = 480; |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 25 | |
| 26 | constexpr float kAttackFilterConstant = 0.f; |
| 27 | |
Alex Loiko | cab48c3 | 2018-04-04 17:43:31 +0200 | [diff] [blame] | 28 | // Adaptive digital gain applier settings below. |
| 29 | constexpr float kMaxGainChangePerSecondDb = 3.f; |
| 30 | constexpr float kMaxGainChangePerFrameDb = |
| 31 | kMaxGainChangePerSecondDb * kFrameDurationMs / 1000.f; |
| 32 | constexpr float kHeadroomDbfs = 1.f; |
| 33 | constexpr float kMaxGainDb = 30.f; |
Alex Loiko | 95141d9 | 2018-04-20 15:28:45 +0200 | [diff] [blame] | 34 | constexpr float kInitialAdaptiveDigitalGainDb = 8.f; |
Alex Loiko | 93e5750 | 2018-10-01 16:28:47 +0200 | [diff] [blame] | 35 | // At what limiter levels should we start decreasing the adaptive digital gain. |
| 36 | constexpr float kLimiterThresholdForAgcGainDbfs = -kHeadroomDbfs; |
Alex Loiko | cab48c3 | 2018-04-04 17:43:31 +0200 | [diff] [blame] | 37 | |
| 38 | // This parameter must be tuned together with the noise estimator. |
| 39 | constexpr float kMaxNoiseLevelDbfs = -50.f; |
| 40 | |
Alex Loiko | 2ffafa8 | 2018-07-06 15:35:42 +0200 | [diff] [blame] | 41 | // This is the threshold for speech. Speech frames are used for updating the |
| 42 | // speech level, measuring the amount of speech, and decide when to allow target |
| 43 | // gain reduction. |
Alex Loiko | 5701162 | 2018-12-10 15:15:59 +0100 | [diff] [blame] | 44 | constexpr float kVadConfidenceThreshold = 0.9f; |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 45 | |
| 46 | // The amount of 'memory' of the Level Estimator. Decides leak factors. |
Alex Loiko | 5701162 | 2018-12-10 15:15:59 +0100 | [diff] [blame] | 47 | constexpr size_t kFullBufferSizeMs = 1200; |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 48 | constexpr float kFullBufferLeakFactor = 1.f - 1.f / kFullBufferSizeMs; |
| 49 | |
| 50 | constexpr float kInitialSpeechLevelEstimateDbfs = -30.f; |
| 51 | |
Alex Loiko | 9917c4a | 2018-04-04 14:16:10 +0200 | [diff] [blame] | 52 | // Saturation Protector settings. |
Alex Loiko | 4bb1e4a | 2018-10-05 11:06:14 +0200 | [diff] [blame] | 53 | float GetInitialSaturationMarginDb(); |
| 54 | float GetExtraSaturationMarginOffsetDb(); |
Alex Loiko | 1e48e80 | 2018-03-28 09:45:29 +0200 | [diff] [blame] | 55 | |
Alex Loiko | db6af36 | 2018-06-20 14:14:18 +0200 | [diff] [blame] | 56 | constexpr size_t kPeakEnveloperSuperFrameLengthMs = 400; |
| 57 | static_assert(kFullBufferSizeMs % kPeakEnveloperSuperFrameLengthMs == 0, |
| 58 | "Full buffer size should be a multiple of super frame length for " |
| 59 | "optimal Saturation Protector performance."); |
Alex Loiko | 9917c4a | 2018-04-04 14:16:10 +0200 | [diff] [blame] | 60 | |
| 61 | constexpr size_t kPeakEnveloperBufferSize = |
| 62 | kFullBufferSizeMs / kPeakEnveloperSuperFrameLengthMs + 1; |
| 63 | |
| 64 | // This value is 10 ** (-1/20 * frame_size_ms / satproc_attack_ms), |
| 65 | // where satproc_attack_ms is 5000. |
| 66 | constexpr float kSaturationProtectorAttackConstant = 0.9988493699365052f; |
| 67 | |
| 68 | // This value is 10 ** (-1/20 * frame_size_ms / satproc_decay_ms), |
| 69 | // where satproc_decay_ms is 1000. |
| 70 | constexpr float kSaturationProtectorDecayConstant = 0.9997697679981565f; |
| 71 | |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 72 | // This is computed from kDecayMs by |
| 73 | // 10 ** (-1/20 * subframe_duration / kDecayMs). |
| 74 | // |subframe_duration| is |kFrameDurationMs / kSubFramesInFrame|. |
| 75 | // kDecayMs is defined in agc2_testing_common.h |
| 76 | constexpr float kDecayFilterConstant = 0.9998848773724686f; |
| 77 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 78 | // Number of interpolation points for each region of the limiter. |
| 79 | // These values have been tuned to limit the interpolated gain curve error given |
| 80 | // the limiter parameters and allowing a maximum error of +/- 32768^-1. |
| 81 | constexpr size_t kInterpolatedGainCurveKneePoints = 22; |
| 82 | constexpr size_t kInterpolatedGainCurveBeyondKneePoints = 10; |
| 83 | constexpr size_t kInterpolatedGainCurveTotalPoints = |
| 84 | kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints; |
| 85 | |
Alex Loiko | e36e8bb | 2018-02-16 11:54:07 +0100 | [diff] [blame] | 86 | } // namespace webrtc |
| 87 | |
| 88 | #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_ |