gain_change_calculator.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2017 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_MIXER_GAIN_CHANGE_CALCULATOR_H_
  11. #define MODULES_AUDIO_MIXER_GAIN_CHANGE_CALCULATOR_H_
  12. #include <stdint.h>
  13. #include "api/array_view.h"
  14. namespace webrtc {
  15. class GainChangeCalculator {
  16. public:
  17. // The 'out' signal is assumed to be produced from 'in' by applying
  18. // a smoothly varying gain. This method computes variations of the
  19. // gain and handles special cases when the samples are small.
  20. float CalculateGainChange(rtc::ArrayView<const int16_t> in,
  21. rtc::ArrayView<const int16_t> out);
  22. float LatestGain() const;
  23. private:
  24. void CalculateGain(rtc::ArrayView<const int16_t> in,
  25. rtc::ArrayView<const int16_t> out,
  26. rtc::ArrayView<float> gain);
  27. float CalculateDifferences(rtc::ArrayView<const float> values);
  28. float last_value_ = 0.f;
  29. float last_reliable_gain_ = 1.0f;
  30. };
  31. } // namespace webrtc
  32. #endif // MODULES_AUDIO_MIXER_GAIN_CHANGE_CALCULATOR_H_