You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  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. #ifndef MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
  12. #include <string.h> // Provide access to size_t.
  13. #include <vector>
  14. #include "absl/types/optional.h"
  15. namespace webrtc {
  16. class Histogram {
  17. public:
  18. // Creates histogram with capacity |num_buckets| and |forget_factor| in Q15.
  19. Histogram(size_t num_buckets,
  20. int forget_factor,
  21. absl::optional<double> start_forget_weight = absl::nullopt);
  22. virtual ~Histogram();
  23. // Resets the histogram to the default start distribution.
  24. virtual void Reset();
  25. // Add entry in bucket |index|.
  26. virtual void Add(int index);
  27. // Calculates the quantile at |probability| (in Q30) of the histogram
  28. // distribution.
  29. virtual int Quantile(int probability);
  30. // Apply compression or stretching to the histogram.
  31. virtual void Scale(int old_bucket_width, int new_bucket_width);
  32. // Returns the number of buckets in the histogram.
  33. virtual int NumBuckets() const;
  34. // Returns the probability for each bucket in Q30.
  35. std::vector<int> buckets() const { return buckets_; }
  36. // Made public for testing.
  37. static std::vector<int> ScaleBuckets(const std::vector<int>& buckets,
  38. int old_bucket_width,
  39. int new_bucket_width);
  40. // Accessors only intended for testing purposes.
  41. int base_forget_factor_for_testing() const { return base_forget_factor_; }
  42. int forget_factor_for_testing() const { return forget_factor_; }
  43. absl::optional<double> start_forget_weight_for_testing() const {
  44. return start_forget_weight_;
  45. }
  46. private:
  47. std::vector<int> buckets_;
  48. int forget_factor_; // Q15
  49. const int base_forget_factor_;
  50. int add_count_;
  51. const absl::optional<double> start_forget_weight_;
  52. };
  53. } // namespace webrtc
  54. #endif // MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_