• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "webrtc/modules/video_coding/utility/include/exp_filter.h"
12 
13 #include <math.h>
14 
15 namespace webrtc {
16 
17 void
Reset(float alpha)18 VCMExpFilter::Reset(float alpha)
19 {
20     _alpha = alpha;
21     _filtered = -1.0;
22 }
23 
24 float
Apply(float exp,float sample)25 VCMExpFilter::Apply(float exp, float sample)
26 {
27     if (_filtered == -1.0)
28     {
29         // Initialize filtered bit rates
30         _filtered = sample;
31     }
32     else if (exp == 1.0)
33     {
34         _filtered = _alpha * _filtered + (1 - _alpha) * sample;
35     }
36     else
37     {
38         float alpha = pow(_alpha, exp);
39         _filtered = alpha * _filtered + (1 - alpha) * sample;
40     }
41     if (_max != -1 && _filtered > _max)
42     {
43         _filtered = _max;
44     }
45     return _filtered;
46 }
47 
48 void
UpdateBase(float alpha)49 VCMExpFilter::UpdateBase(float alpha)
50 {
51     _alpha = alpha;
52 }
53 
54 float
Value() const55 VCMExpFilter::Value() const
56 {
57     return _filtered;
58 }
59 
60 }
61