Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Side by Side Diff: webrtc/common_audio/smoothing_filter.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Fix thread safety problem and changed smoothing filter. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } else { 43 } else {
44 initialized_ = true; 44 initialized_ = true;
45 filter_.UpdateBase(exp(1.0f / time_constant_ms_)); 45 filter_.UpdateBase(exp(1.0f / time_constant_ms_));
46 } 46 }
47 } 47 }
48 48
49 // The filter will do the following: 49 // The filter will do the following:
50 // float alpha = pow(base, last_update_time_ms_ - now_ms); 50 // float alpha = pow(base, last_update_time_ms_ - now_ms);
51 // filtered_ = alpha * filtered_ + (1 - alpha) * sample; 51 // filtered_ = alpha * filtered_ + (1 - alpha) * sample;
52 filter_.Apply(static_cast<float>(last_sample_time_ms_ - now_ms), sample); 52 filter_.Apply(static_cast<float>(last_sample_time_ms_ - now_ms), sample);
53 last_sample_ = sample;
53 last_sample_time_ms_ = now_ms; 54 last_sample_time_ms_ = now_ms;
54 } 55 }
55 56
56 rtc::Optional<float> SmoothingFilterImpl::GetAverage() const { 57 rtc::Optional<float> SmoothingFilterImpl::GetAverage() const {
57 float value = filter_.filtered(); 58 float value = filter_.filtered();
58 return value == rtc::ExpFilter::kValueUndefined ? rtc::Optional<float>() 59 if (value == rtc::ExpFilter::kValueUndefined)
59 : rtc::Optional<float>(value); 60 return rtc::Optional<float>();
61 int64_t now_ms = clock_->TimeInMilliseconds();
62 return rtc::Optional<float>(
minyue-webrtc 2016/12/01 11:32:50 I like the idea of making the query of average tim
63 value -
64 (value - last_sample_) *
65 (1 - exp((last_sample_time_ms_ - now_ms) / time_constant_ms_)));
60 } 66 }
61 67
62 void SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) { 68 void SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {
63 time_constant_ms_ = time_constant_ms; 69 time_constant_ms_ = time_constant_ms;
64 filter_.UpdateBase(exp(1.0f / time_constant_ms_)); 70 filter_.UpdateBase(exp(1.0f / time_constant_ms_));
65 } 71 }
66 72
67 } // namespace webrtc 73 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/smoothing_filter.h ('k') | webrtc/common_audio/smoothing_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698