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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 // assumed to equal the last received sample. | 33 // assumed to equal the last received sample. |
34 class SmoothingFilterImpl final : public SmoothingFilter { | 34 class SmoothingFilterImpl final : public SmoothingFilter { |
35 public: | 35 public: |
36 // |init_time_ms| is initialization time. It defines a period starting from | 36 // |init_time_ms| is initialization time. It defines a period starting from |
37 // the arriving time of the first sample. During this period, the exponential | 37 // the arriving time of the first sample. During this period, the exponential |
38 // filter uses a varying time constant so that a smaller time constant will be | 38 // filter uses a varying time constant so that a smaller time constant will be |
39 // applied to the earlier samples. This is to allow the the filter to adapt to | 39 // applied to the earlier samples. This is to allow the the filter to adapt to |
40 // earlier samples quickly. After the initialization period, the time constant | 40 // earlier samples quickly. After the initialization period, the time constant |
41 // will be set to |init_time_ms| first and can be changed through | 41 // will be set to |init_time_ms| first and can be changed through |
42 // |SetTimeConstantMs|. | 42 // |SetTimeConstantMs|. |
43 SmoothingFilterImpl(int init_time_ms, const Clock* clock); | 43 explicit SmoothingFilterImpl(int init_time_ms); |
44 ~SmoothingFilterImpl() override; | 44 ~SmoothingFilterImpl() override; |
45 | 45 |
46 void AddSample(float sample) override; | 46 void AddSample(float sample) override; |
47 rtc::Optional<float> GetAverage() override; | 47 rtc::Optional<float> GetAverage() override; |
48 bool SetTimeConstantMs(int time_constant_ms) override; | 48 bool SetTimeConstantMs(int time_constant_ms) override; |
49 | 49 |
50 // Methods used for unittests. | 50 // Methods used for unittests. |
51 float alpha() const { return alpha_; } | 51 float alpha() const { return alpha_; } |
52 | 52 |
53 private: | 53 private: |
54 void UpdateAlpha(int time_constant_ms); | 54 void UpdateAlpha(int time_constant_ms); |
55 void ExtrapolateLastSample(int64_t time_ms); | 55 void ExtrapolateLastSample(int64_t time_ms); |
56 | 56 |
57 const int init_time_ms_; | 57 const int init_time_ms_; |
58 const float init_factor_; | 58 const float init_factor_; |
59 const float init_const_; | 59 const float init_const_; |
60 const Clock* const clock_; | |
61 | 60 |
62 rtc::Optional<int64_t> init_end_time_ms_; | 61 rtc::Optional<int64_t> init_end_time_ms_; |
63 float last_sample_; | 62 float last_sample_; |
64 float alpha_; | 63 float alpha_; |
65 float state_; | 64 float state_; |
66 int64_t last_state_time_ms_; | 65 int64_t last_state_time_ms_; |
67 | 66 |
68 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SmoothingFilterImpl); | 67 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SmoothingFilterImpl); |
69 }; | 68 }; |
70 | 69 |
71 } // namespace webrtc | 70 } // namespace webrtc |
72 | 71 |
73 #endif // WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ | 72 #endif // WEBRTC_COMMON_AUDIO_SMOOTHING_FILTER_H_ |
OLD | NEW |