| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 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 | 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 | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| 11 #ifndef WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 11 #ifndef WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 
| 12 #define WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 12 #define WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 
| 13 | 13 | 
| 14 #include "webrtc/base/analytics/exp_filter.h" | 14 #include "webrtc/base/analytics/exp_filter.h" | 
| 15 #include "webrtc/base/constructormagic.h" | 15 #include "webrtc/base/constructormagic.h" | 
| 16 #include "webrtc/base/optional.h" | 16 #include "webrtc/base/optional.h" | 
| 17 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.h" | 
| 18 | 18 | 
| 19 namespace webrtc { | 19 namespace webrtc { | 
| 20 | 20 | 
| 21 class SmoothingFilter { | 21 class SmoothingFilter { | 
| 22  public: | 22  public: | 
| 23   virtual ~SmoothingFilter() = default; | 23   virtual ~SmoothingFilter() = default; | 
| 24   virtual void AddSample(float sample) = 0; | 24   virtual void AddSample(float sample) = 0; | 
| 25   virtual rtc::Optional<float> GetAverage() const = 0; | 25   virtual rtc::Optional<float> GetAverage() const = 0; | 
|  | 26   virtual void SetTimeConstantMs(int time_constant_ms) = 0; | 
| 26 }; | 27 }; | 
| 27 | 28 | 
| 28 // SmoothingFilterImpl applies an exponential filter | 29 // SmoothingFilterImpl applies an exponential filter | 
| 29 //   alpha = exp(-sample_interval / time_constant); | 30 //   alpha = exp(-sample_interval / time_constant); | 
| 30 //   y[t] = alpha * y[t-1] + (1 - alpha) * sample; | 31 //   y[t] = alpha * y[t-1] + (1 - alpha) * sample; | 
| 31 class SmoothingFilterImpl final : public SmoothingFilter { | 32 class SmoothingFilterImpl final : public SmoothingFilter { | 
| 32  public: | 33  public: | 
| 33   // |time_constant_ms| is the time constant for the exponential filter. | 34   // |time_constant_ms| is the time constant for the exponential filter. | 
| 34   SmoothingFilterImpl(int time_constant_ms, const Clock* clock); | 35   SmoothingFilterImpl(int time_constant_ms, const Clock* clock); | 
| 35 | 36 | 
| 36   void AddSample(float sample) override; | 37   void AddSample(float sample) override; | 
| 37   rtc::Optional<float> GetAverage() const override; | 38   rtc::Optional<float> GetAverage() const override; | 
|  | 39   void SetTimeConstantMs(int time_constant_ms) override; | 
| 38 | 40 | 
| 39  private: | 41  private: | 
| 40   const int time_constant_ms_; | 42   int time_constant_ms_; | 
| 41   const Clock* const clock_; | 43   const Clock* const clock_; | 
| 42 | 44 | 
| 43   bool first_sample_received_; | 45   bool first_sample_received_; | 
| 44   bool initialized_; | 46   bool initialized_; | 
| 45   int64_t first_sample_time_ms_; | 47   int64_t first_sample_time_ms_; | 
| 46   int64_t last_sample_time_ms_; | 48   int64_t last_sample_time_ms_; | 
| 47   rtc::ExpFilter filter_; | 49   rtc::ExpFilter filter_; | 
| 48 | 50 | 
| 49   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SmoothingFilterImpl); | 51   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SmoothingFilterImpl); | 
| 50 }; | 52 }; | 
| 51 | 53 | 
| 52 }  // namespace webrtc | 54 }  // namespace webrtc | 
| 53 | 55 | 
| 54 #endif  // WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 56 #endif  // WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 
| OLD | NEW | 
|---|