mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added digital delay line
This commit is contained in:
parent
10a8fc6867
commit
27e8a40e1b
2 changed files with 37 additions and 0 deletions
|
|
@ -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
33
delay.hh
Normal 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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue