arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
CoreAudio
AudioBasic
MovingAverage.h
Go to the documentation of this file.
1
2
#include "
Collections/List.h
"
3
4
namespace
audio_tools
{
5
13
template
<
class
N>
14
class
MovingAverage
{
15
public
:
16
MovingAverage
(
size_t
size
) {
17
setSize
(
size
);
18
}
19
20
void
addMeasurement
(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
calculate
() {
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
List.h
audio_tools::List
Double linked list.
Definition
List.h:18
audio_tools::List::size
size_t size()
Definition
List.h:293
audio_tools::List::pop_front
bool pop_front()
Definition
List.h:201
audio_tools::List::push_back
bool push_back(T data)
Definition
List.h:147
audio_tools::MovingAverage
Caclulates the moving average of a number of values.
Definition
MovingAverage.h:14
audio_tools::MovingAverage::calculate
float calculate()
Definition
MovingAverage.h:27
audio_tools::MovingAverage::addMeasurement
void addMeasurement(N value)
Definition
MovingAverage.h:20
audio_tools::MovingAverage::MovingAverage
MovingAverage(size_t size)
Definition
MovingAverage.h:16
audio_tools::MovingAverage::values
List< N > values
Definition
MovingAverage.h:41
audio_tools::MovingAverage::size
size_t size
Definition
MovingAverage.h:42
audio_tools::MovingAverage::setSize
void setSize(size_t size)
Defines the number of values.
Definition
MovingAverage.h:36
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
AudioCodecsBase.h:10
Generated by
1.9.8