Gustaf Ullberg | 8406c43 | 2018-06-19 12:31:33 +0200 | [diff] [blame] | 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 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 14 | #include <stddef.h> |
Gustaf Ullberg | 8406c43 | 2018-06-19 12:31:33 +0200 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| 17 | #include "api/array_view.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | namespace aec3 { |
| 21 | |
| 22 | class MovingAverage { |
| 23 | public: |
| 24 | // Creates an instance of MovingAverage that accepts inputs of length num_elem |
| 25 | // and averages over mem_len inputs. |
| 26 | MovingAverage(size_t num_elem, size_t mem_len); |
| 27 | ~MovingAverage(); |
| 28 | |
| 29 | // Computes the average of input and mem_len-1 previous inputs and stores the |
| 30 | // result in output. |
| 31 | void Average(rtc::ArrayView<const float> input, rtc::ArrayView<float> output); |
| 32 | |
| 33 | private: |
| 34 | const size_t num_elem_; |
| 35 | const size_t mem_len_; |
| 36 | const float scaling_; |
| 37 | std::vector<float> memory_; |
| 38 | size_t mem_index_; |
| 39 | }; |
| 40 | |
| 41 | } // namespace aec3 |
| 42 | } // namespace webrtc |
| 43 | |
| 44 | #endif // MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ |