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