blob: fc8f612ac84058e0d87674bf8d425f8c01bfd3ac [file] [log] [blame]
Jakob Ivarsson1eb3d7e2019-02-21 15:42:31 +01001/*
2 * Copyright (c) 2019 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#ifndef MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
12#define MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
13
14#include <string.h> // Provide access to size_t.
15
16#include <vector>
17
18namespace webrtc {
19
20class Histogram {
21 public:
22 // Creates histogram with capacity |num_buckets| and |forget_factor| in Q15.
23 Histogram(size_t num_buckets, int forget_factor);
24
25 virtual ~Histogram();
26
27 // Resets the histogram to the default start distribution.
28 virtual void Reset();
29
30 // Add entry in bucket |index|.
31 virtual void Add(int index);
32
33 // Calculates the quantile at |probability| (in Q30) of the histogram
34 // distribution.
35 virtual int Quantile(int probability);
36
37 // Apply compression or stretching to the histogram.
38 virtual void Scale(int old_bucket_width, int new_bucket_width);
39
40 // Returns the number of buckets in the histogram.
41 virtual int NumBuckets() const;
42
43 // Returns the probability for each bucket in Q30.
44 std::vector<int> buckets() const { return buckets_; }
45
Jakob Ivarssondb42ed22019-02-27 10:08:09 +010046 int forget_factor() const { return base_forget_factor_; }
47
Jakob Ivarsson1eb3d7e2019-02-21 15:42:31 +010048 // Made public for testing.
49 static std::vector<int> ScaleBuckets(const std::vector<int>& buckets,
50 int old_bucket_width,
51 int new_bucket_width);
52
53 private:
54 std::vector<int> buckets_;
55 int forget_factor_; // Q15
56 const int base_forget_factor_;
57};
58
59} // namespace webrtc
60
61#endif // MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_