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

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

Issue 2582043002: Fixing init time error in smoothing filter. (Closed)
Patch Set: fixing Created 3 years, 12 months 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
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "webrtc/common_audio/smoothing_filter.h" 11 #include "webrtc/common_audio/smoothing_filter.h"
12 12
13 #include <cmath> 13 #include <cmath>
14 14
15 namespace webrtc { 15 namespace webrtc {
16 16
17 SmoothingFilterImpl::SmoothingFilterImpl(int init_time_ms_, const Clock* clock) 17 SmoothingFilterImpl::SmoothingFilterImpl(int init_time_ms, const Clock* clock)
minyue-webrtc 2016/12/21 14:10:17 this was an old error, no actual problem, but bad
18 : init_time_ms_(init_time_ms_), 18 : init_time_ms_(init_time_ms),
19 // Duing the initalization time, we use an increasing alpha. Specifically, 19 // Duing the initalization time, we use an increasing alpha. Specifically,
20 // alpha(n) = exp(pow(init_factor_, n)), 20 // alpha(n) = exp(pow(init_factor_, n)),
21 // where |init_factor_| is chosen such that 21 // where |init_factor_| is chosen such that
22 // alpha(init_time_ms_) = exp(-1.0f / init_time_ms_), 22 // alpha(init_time_ms_) = exp(-1.0f / init_time_ms_),
23 init_factor_(pow(init_time_ms_, 1.0f / init_time_ms_)), 23 init_factor_(pow(init_time_ms_, 1.0f / init_time_ms_)),
24 // |init_const_| is to a factor to help the calculation during 24 // |init_const_| is to a factor to help the calculation during
25 // initialization phase. 25 // initialization phase.
26 init_const_(1.0f / (init_time_ms_ - 26 init_const_(1.0f / (init_time_ms_ -
27 pow(init_time_ms_, 1.0f - 1.0f / init_time_ms_))), 27 pow(init_time_ms_, 1.0f - 1.0f / init_time_ms_))),
28 clock_(clock) { 28 clock_(clock) {
29 RTC_DCHECK_GT(init_time_ms_, 1);
29 UpdateAlpha(init_time_ms_); 30 UpdateAlpha(init_time_ms_);
30 } 31 }
31 32
32 SmoothingFilterImpl::~SmoothingFilterImpl() = default; 33 SmoothingFilterImpl::~SmoothingFilterImpl() = default;
33 34
34 void SmoothingFilterImpl::AddSample(float sample) { 35 void SmoothingFilterImpl::AddSample(float sample) {
35 const int64_t now_ms = clock_->TimeInMilliseconds(); 36 const int64_t now_ms = clock_->TimeInMilliseconds();
36 37
37 if (!first_sample_time_ms_) { 38 if (!first_sample_time_ms_) {
38 // This is equivalent to assuming the filter has been receiving the same 39 // This is equivalent to assuming the filter has been receiving the same
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // &= \exp\left(\frac{\gamma^m - \gamma^n}{1 - \gamma} \right) 117 // &= \exp\left(\frac{\gamma^m - \gamma^n}{1 - \gamma} \right)
117 // \end{align} 118 // \end{align}
118 // We know $\gamma = T^\frac{1}{T}$, where $T$ denotes init\_time\_ms\_. Then 119 // We know $\gamma = T^\frac{1}{T}$, where $T$ denotes init\_time\_ms\_. Then
119 // $1 - \gamma$ approaches zero when $T$ increases. This can cause numerical 120 // $1 - \gamma$ approaches zero when $T$ increases. This can cause numerical
120 // difficulties. We multiply $T$ to both numerator and denominator in the 121 // difficulties. We multiply $T$ to both numerator and denominator in the
121 // fraction. See. 122 // fraction. See.
122 // \begin{align} 123 // \begin{align}
123 // \frac{\gamma^m - \gamma^n}{1 - \gamma} 124 // \frac{\gamma^m - \gamma^n}{1 - \gamma}
124 // &= \frac{T^\frac{T-m}{T} - T^\frac{T-n}{T}}{T - T^{1-\frac{1}{T}}} 125 // &= \frac{T^\frac{T-m}{T} - T^\frac{T-n}{T}}{T - T^{1-\frac{1}{T}}}
125 // \end{align} 126 // \end{align}
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698