blob: 66b4fe9d0c9c25ee2d117a0c143507906f8eb7a5 [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
46 // Made public for testing.
47 static std::vector<int> ScaleBuckets(const std::vector<int>& buckets,
48 int old_bucket_width,
49 int new_bucket_width);
50
51 private:
52 std::vector<int> buckets_;
53 int forget_factor_; // Q15
54 const int base_forget_factor_;
55};
56
57} // namespace webrtc
58
59#endif // MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_