Index: webrtc/common_audio/smoothing_filter.cc |
diff --git a/webrtc/common_audio/smoothing_filter.cc b/webrtc/common_audio/smoothing_filter.cc |
index ff79ab8799e9de332ff324152e97c43947837e6a..f3dafaf3f1a6b52acc11ff0fdcc64cd1afc8a1b8 100644 |
--- a/webrtc/common_audio/smoothing_filter.cc |
+++ b/webrtc/common_audio/smoothing_filter.cc |
@@ -50,13 +50,19 @@ void SmoothingFilterImpl::AddSample(float sample) { |
// float alpha = pow(base, last_update_time_ms_ - now_ms); |
// filtered_ = alpha * filtered_ + (1 - alpha) * sample; |
filter_.Apply(static_cast<float>(last_sample_time_ms_ - now_ms), sample); |
+ last_sample_ = sample; |
last_sample_time_ms_ = now_ms; |
} |
rtc::Optional<float> SmoothingFilterImpl::GetAverage() const { |
float value = filter_.filtered(); |
- return value == rtc::ExpFilter::kValueUndefined ? rtc::Optional<float>() |
- : rtc::Optional<float>(value); |
+ if (value == rtc::ExpFilter::kValueUndefined) |
+ return rtc::Optional<float>(); |
+ int64_t now_ms = clock_->TimeInMilliseconds(); |
+ return rtc::Optional<float>( |
minyue-webrtc
2016/12/01 11:32:50
I like the idea of making the query of average tim
|
+ value - |
+ (value - last_sample_) * |
+ (1 - exp((last_sample_time_ms_ - now_ms) / time_constant_ms_))); |
} |
void SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) { |