arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
MovingAverage.h
1
2#include "Collections/List.h"
3
4namespace audio_tools {
5
13template <class N>
15 public:
16 MovingAverage(size_t size) {
17 setSize(size);
18 }
19
20 void add(N value) {
21 if (this->values.size() == this->size) {
22 this->values.pop_front();
23 }
24 this->values.push_back(value);
25 }
26
27 float average() {
28 float sum = 0;
29 for (int i = 0; i < this->values.size(); i++) {
30 sum += this->values[i];
31 }
32 return sum / this->values.size();
33 }
34
36 void setSize(size_t size) {
37 this->size = size;
38 }
39
40 protected:
41 List<N> values;
42 size_t size = 0;;
43};
44
45} // namespace audio_tools
Double linked list.
Definition List.h:18
Caclulates the moving average of a number of values.
Definition MovingAverage.h:14
void setSize(size_t size)
Defines the number of values.
Definition MovingAverage.h:36
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10