gain_applier.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_GAIN_APPLIER_H_
  11. #define MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_
  12. #include <stddef.h>
  13. #include "modules/audio_processing/include/audio_frame_view.h"
  14. namespace webrtc {
  15. class GainApplier {
  16. public:
  17. GainApplier(bool hard_clip_samples, float initial_gain_factor);
  18. void ApplyGain(AudioFrameView<float> signal);
  19. void SetGainFactor(float gain_factor);
  20. float GetGainFactor() const { return current_gain_factor_; }
  21. private:
  22. void Initialize(size_t samples_per_channel);
  23. // Whether to clip samples after gain is applied. If 'true', result
  24. // will fit in FloatS16 range.
  25. const bool hard_clip_samples_;
  26. float last_gain_factor_;
  27. // If this value is not equal to 'last_gain_factor', gain will be
  28. // ramped from 'last_gain_factor_' to this value during the next
  29. // 'ApplyGain'.
  30. float current_gain_factor_;
  31. int samples_per_channel_ = -1;
  32. float inverse_samples_per_channel_ = -1.f;
  33. };
  34. } // namespace webrtc
  35. #endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_