/* * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "modules/audio_coding/neteq/histogram.h" #include <algorithm> #include <cstdlib> #include <numeric> #include "absl/types/optional.h" #include "rtc_base/checks.h" #include "rtc_base/numerics/safe_conversions.h" namespace webrtc { Histogram::Histogram(size_t num_buckets, int forget_factor, absl::optional<double> start_forget_weight) : … { … } Histogram::~Histogram() { … } // Each element in the vector is first multiplied by the forgetting factor // `forget_factor_`. Then the vector element indicated by `iat_packets` is then // increased (additive) by 1 - `forget_factor_`. This way, the probability of // `value` is slightly increased, while the sum of the histogram remains // constant (=1). // Due to inaccuracies in the fixed-point arithmetic, the histogram may no // longer sum up to 1 (in Q30) after the update. To correct this, a correction // term is added or subtracted from the first element (or elements) of the // vector. // The forgetting factor `forget_factor_` is also updated. When the DelayManager // is reset, the factor is set to 0 to facilitate rapid convergence in the // beginning. With each update of the histogram, the factor is increased towards // the steady-state value `base_forget_factor_`. void Histogram::Add(int value) { … } int Histogram::Quantile(int probability) { … } // Set the histogram vector to an exponentially decaying distribution // buckets_[i] = 0.5^(i+1), i = 0, 1, 2, ... // buckets_ is in Q30. void Histogram::Reset() { … } int Histogram::NumBuckets() const { … } } // namespace webrtc