added digital delay line

This commit is contained in:
Ahmet Inan 2020-04-19 14:02:32 +02:00
commit 27e8a40e1b
2 changed files with 37 additions and 0 deletions

View file

@ -123,6 +123,10 @@ TYPE out[NUM];
fwd(out, history(another_value));
```
### [delay.hh](delay.hh)
A [Digital delay line](https://en.wikipedia.org/wiki/Digital_delay_line) can be used to align signals with different delays - after filtering, for example.
### [calculus.hh](calculus.hh)
Some [calculus](https://en.wikipedia.org/wiki/Calculus) functions:

33
delay.hh Normal file
View file

@ -0,0 +1,33 @@
/*
Digital delay line
Copyright 2020 Ahmet Inan <inan@aicodix.de>
*/
#pragma once
namespace DSP {
template <typename TYPE, int NUM>
class Delay
{
TYPE buf[NUM];
int pos;
public:
Delay() : pos(0)
{
for (int i = 0; i < NUM; ++i)
buf[i] = 0;
}
TYPE operator () (TYPE input)
{
TYPE tmp = buf[pos];
buf[pos] = input;
if (++pos >= NUM)
pos = 0;
return tmp;
}
};
}