blob: 35e8f58587f0f50133148a45d73f57a4ab3911ba [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
Niels Möller65ec0fc2018-05-21 11:46:20 +020014#include <stddef.h>
15
Alex Loikoa05ee822018-02-20 15:58:36 +010016#include <cmath>
17
Alex Loikoe36e8bb2018-02-16 11:54:07 +010018namespace webrtc {
19
Alex Loikoa05ee822018-02-20 15:58:36 +010020constexpr float kMinFloatS16Value = -32768.f;
21constexpr float kMaxFloatS16Value = 32767.f;
Alex Loiko9917c4a2018-04-04 14:16:10 +020022constexpr float kMaxAbsFloatS16Value = 32768.0f;
Alex Loikoe36e8bb2018-02-16 11:54:07 +010023
Alex Loiko153f11e2018-02-16 12:39:00 +010024constexpr size_t kFrameDurationMs = 10;
25constexpr size_t kSubFramesInFrame = 20;
Alex Loikoa05ee822018-02-20 15:58:36 +010026constexpr size_t kMaximalNumberOfSamplesPerChannel = 480;
Alex Loiko153f11e2018-02-16 12:39:00 +010027
28constexpr float kAttackFilterConstant = 0.f;
29
Alex Loikocab48c32018-04-04 17:43:31 +020030// Adaptive digital gain applier settings below.
31constexpr float kMaxGainChangePerSecondDb = 3.f;
32constexpr float kMaxGainChangePerFrameDb =
33 kMaxGainChangePerSecondDb * kFrameDurationMs / 1000.f;
34constexpr float kHeadroomDbfs = 1.f;
35constexpr float kMaxGainDb = 30.f;
Alex Loiko95141d92018-04-20 15:28:45 +020036constexpr float kInitialAdaptiveDigitalGainDb = 8.f;
Alex Loikocab48c32018-04-04 17:43:31 +020037
38// This parameter must be tuned together with the noise estimator.
39constexpr float kMaxNoiseLevelDbfs = -50.f;
40
Alex Loiko2ffafa82018-07-06 15:35:42 +020041// 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 Loikodb6af362018-06-20 14:14:18 +020044constexpr float kVadConfidenceThreshold = 0.4f;
Alex Loiko1e48e802018-03-28 09:45:29 +020045
46// The amount of 'memory' of the Level Estimator. Decides leak factors.
Alex Loikodb6af362018-06-20 14:14:18 +020047constexpr size_t kFullBufferSizeMs = 1600;
Alex Loiko1e48e802018-03-28 09:45:29 +020048constexpr float kFullBufferLeakFactor = 1.f - 1.f / kFullBufferSizeMs;
49
50constexpr float kInitialSpeechLevelEstimateDbfs = -30.f;
51
Alex Loiko9917c4a2018-04-04 14:16:10 +020052// Saturation Protector settings.
Alex Loiko1e48e802018-03-28 09:45:29 +020053constexpr float kInitialSaturationMarginDb = 17.f;
54
Alex Loikodb6af362018-06-20 14:14:18 +020055constexpr size_t kPeakEnveloperSuperFrameLengthMs = 400;
56static_assert(kFullBufferSizeMs % kPeakEnveloperSuperFrameLengthMs == 0,
57 "Full buffer size should be a multiple of super frame length for "
58 "optimal Saturation Protector performance.");
Alex Loiko9917c4a2018-04-04 14:16:10 +020059
60constexpr size_t kPeakEnveloperBufferSize =
61 kFullBufferSizeMs / kPeakEnveloperSuperFrameLengthMs + 1;
62
63// This value is 10 ** (-1/20 * frame_size_ms / satproc_attack_ms),
64// where satproc_attack_ms is 5000.
65constexpr float kSaturationProtectorAttackConstant = 0.9988493699365052f;
66
67// This value is 10 ** (-1/20 * frame_size_ms / satproc_decay_ms),
68// where satproc_decay_ms is 1000.
69constexpr float kSaturationProtectorDecayConstant = 0.9997697679981565f;
70
Alex Loiko153f11e2018-02-16 12:39:00 +010071// This is computed from kDecayMs by
72// 10 ** (-1/20 * subframe_duration / kDecayMs).
73// |subframe_duration| is |kFrameDurationMs / kSubFramesInFrame|.
74// kDecayMs is defined in agc2_testing_common.h
75constexpr float kDecayFilterConstant = 0.9998848773724686f;
76
Alex Loikoa05ee822018-02-20 15:58:36 +010077// Number of interpolation points for each region of the limiter.
78// These values have been tuned to limit the interpolated gain curve error given
79// the limiter parameters and allowing a maximum error of +/- 32768^-1.
80constexpr size_t kInterpolatedGainCurveKneePoints = 22;
81constexpr size_t kInterpolatedGainCurveBeyondKneePoints = 10;
82constexpr size_t kInterpolatedGainCurveTotalPoints =
83 kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints;
84
Alex Loikoe36e8bb2018-02-16 11:54:07 +010085} // namespace webrtc
86
87#endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_