-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDelayLine.cpp
47 lines (40 loc) · 908 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
//
// DelayLine.cpp
// DSPLibrary
//
// Created by Mayank on 9/11/12.
// Copyright (c) 2012 Mayank Sanganeria. All rights reserved.
//
#include "DelayLine.h"
void DelayLine::setLength(const float withLength, float withFs)
{
length = withLength * withFs;
circularBuffer = new float[length];
clearBuffer(); // clear the buffer before we start writing into it
readHead = length*0.5;
writeHead = 0;
}
void DelayLine::clearBuffer()
{
for (int i = 0; i < length; i++) { // clear buffer
circularBuffer[(i + length) % length] = 0;
}
}
void DelayLine::advanceWriteHead()
{
writeHead = (writeHead+1)%length;
}
void DelayLine::advanceReadHead()
{
readHead = (readHead+1)%length;
}
void DelayLine::write(float withSample)
{
int x = writeHead;
circularBuffer[x] = withSample;
}
float DelayLine::read()
{
int x = readHead;
return circularBuffer[x];
}