agc2_common.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_
  11. #define MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_
  12. #include <stddef.h>
  13. namespace webrtc {
  14. constexpr float kMinFloatS16Value = -32768.f;
  15. constexpr float kMaxFloatS16Value = 32767.f;
  16. constexpr float kMaxAbsFloatS16Value = 32768.0f;
  17. constexpr size_t kFrameDurationMs = 10;
  18. constexpr size_t kSubFramesInFrame = 20;
  19. constexpr size_t kMaximalNumberOfSamplesPerChannel = 480;
  20. constexpr float kAttackFilterConstant = 0.f;
  21. // Adaptive digital gain applier settings below.
  22. constexpr float kHeadroomDbfs = 1.f;
  23. constexpr float kMaxGainDb = 30.f;
  24. constexpr float kInitialAdaptiveDigitalGainDb = 8.f;
  25. // At what limiter levels should we start decreasing the adaptive digital gain.
  26. constexpr float kLimiterThresholdForAgcGainDbfs = -kHeadroomDbfs;
  27. // This is the threshold for speech. Speech frames are used for updating the
  28. // speech level, measuring the amount of speech, and decide when to allow target
  29. // gain reduction.
  30. constexpr float kVadConfidenceThreshold = 0.9f;
  31. // The amount of 'memory' of the Level Estimator. Decides leak factors.
  32. constexpr size_t kFullBufferSizeMs = 1200;
  33. constexpr float kFullBufferLeakFactor = 1.f - 1.f / kFullBufferSizeMs;
  34. constexpr float kInitialSpeechLevelEstimateDbfs = -30.f;
  35. // Robust VAD probability and speech decisions.
  36. constexpr float kDefaultSmoothedVadProbabilityAttack = 1.f;
  37. constexpr int kDefaultLevelEstimatorAdjacentSpeechFramesThreshold = 1;
  38. // Saturation Protector settings.
  39. constexpr float kDefaultInitialSaturationMarginDb = 20.f;
  40. constexpr float kDefaultExtraSaturationMarginDb = 2.f;
  41. constexpr size_t kPeakEnveloperSuperFrameLengthMs = 400;
  42. static_assert(kFullBufferSizeMs % kPeakEnveloperSuperFrameLengthMs == 0,
  43. "Full buffer size should be a multiple of super frame length for "
  44. "optimal Saturation Protector performance.");
  45. constexpr size_t kPeakEnveloperBufferSize =
  46. kFullBufferSizeMs / kPeakEnveloperSuperFrameLengthMs + 1;
  47. // This value is 10 ** (-1/20 * frame_size_ms / satproc_attack_ms),
  48. // where satproc_attack_ms is 5000.
  49. constexpr float kSaturationProtectorAttackConstant = 0.9988493699365052f;
  50. // This value is 10 ** (-1/20 * frame_size_ms / satproc_decay_ms),
  51. // where satproc_decay_ms is 1000.
  52. constexpr float kSaturationProtectorDecayConstant = 0.9997697679981565f;
  53. // This is computed from kDecayMs by
  54. // 10 ** (-1/20 * subframe_duration / kDecayMs).
  55. // |subframe_duration| is |kFrameDurationMs / kSubFramesInFrame|.
  56. // kDecayMs is defined in agc2_testing_common.h
  57. constexpr float kDecayFilterConstant = 0.9998848773724686f;
  58. // Number of interpolation points for each region of the limiter.
  59. // These values have been tuned to limit the interpolated gain curve error given
  60. // the limiter parameters and allowing a maximum error of +/- 32768^-1.
  61. constexpr size_t kInterpolatedGainCurveKneePoints = 22;
  62. constexpr size_t kInterpolatedGainCurveBeyondKneePoints = 10;
  63. constexpr size_t kInterpolatedGainCurveTotalPoints =
  64. kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints;
  65. } // namespace webrtc
  66. #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_COMMON_H_