moving_average.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2018 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_PROCESSING_AEC3_MOVING_AVERAGE_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_
  12. #include <stddef.h>
  13. #include <vector>
  14. #include "api/array_view.h"
  15. namespace webrtc {
  16. namespace aec3 {
  17. class MovingAverage {
  18. public:
  19. // Creates an instance of MovingAverage that accepts inputs of length num_elem
  20. // and averages over mem_len inputs.
  21. MovingAverage(size_t num_elem, size_t mem_len);
  22. ~MovingAverage();
  23. // Computes the average of input and mem_len-1 previous inputs and stores the
  24. // result in output.
  25. void Average(rtc::ArrayView<const float> input, rtc::ArrayView<float> output);
  26. private:
  27. const size_t num_elem_;
  28. const size_t mem_len_;
  29. const float scaling_;
  30. std::vector<float> memory_;
  31. size_t mem_index_;
  32. };
  33. } // namespace aec3
  34. } // namespace webrtc
  35. #endif // MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_