-
Notifications
You must be signed in to change notification settings - Fork 2
/
DelayLine.cpp
73 lines (56 loc) · 968 Bytes
/
DelayLine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//---------------------------------------------------------------------------
#pragma hdrstop
#include "DelayLine.h"
DelayLine::DelayLine()
{
buff = 0;
last = 0;
}
DelayLine::~DelayLine()
{
if(buff) delete [] buff;
}
void DelayLine::SetSize(int delay_size)
{
size = delay_size;
if(buff!=0) delete [] buff;
buff = new float[size];
for(int t=0;t<size;t++)
{
buff[t] = 0.0;
}
last = 0;
}
/*
float DelayLine::Delay(float x)
{
int i;
// scroll values
for(i=size-1;i>0;i--)
{
buff[i]=buff[i-1];
}
// write input
buff[0] = x;
return buff[size-1];
}
*/
float DelayLine::Delay(float x)
{
float retval = buff[last];
buff[last] = x;
last++;
if(last>=size) last = 0;
return retval;
}
float DelayLine::Average()
{
float sum=0;
for(int t=0;t<size;t++) sum+=buff[t];
return sum / ((float)size);
}
float DelayLine::FilterAverage(float x)
{
Delay(x);
return Average();
}