1
/*******************************************/
3
Linearly Interpolating Delay Line
4
Object by Perry R. Cook 1995-96.
5
Added methods by Julius Smith, 2000.
7
This one uses a delay line of maximum
8
length specified on creation, and
9
linearly interpolates fractional
10
length. It is designed to be more
11
efficient if the delay length is not
14
/*******************************************/
20
// Default max delay length set to 2047.
22
inputs = (MY_FLOAT *) malloc(length * sizeof(MY_FLOAT));
25
outPoint = length >> 1;
26
currentDelay = outPoint;
29
DLineL :: DLineL(long max_length)
32
inputs = (MY_FLOAT *) malloc(length * sizeof(MY_FLOAT));
35
outPoint = length >> 1;
36
currentDelay = outPoint;
44
void DLineL :: clear()
47
for (i=0;i<length;i++) inputs[i] = (MY_FLOAT) 0.0;
48
lastOutput = (MY_FLOAT) 0;
51
void DLineL :: setDelay(MY_FLOAT lag)
57
printf("DLineL: Delay length too big.\n");
58
printf("Setting to maximum length of %ld.\n",length-1);
59
// force delay to max_length
60
outPointer = inPoint + 1;
61
currentDelay = length - 1;
65
outPointer = inPoint - lag;
70
// modulo maximum length
74
outPoint = (long) outPointer;
76
alpha = outPointer - outPoint;
77
omAlpha = (MY_FLOAT) 1.0 - alpha;
80
MY_FLOAT DLineL :: delay(void)
85
MY_FLOAT DLineL :: energy(void)
88
register MY_FLOAT e = 0;
89
if (inPoint>=outPoint) {
90
for (i=outPoint;i<inPoint;i++) {
91
register MY_FLOAT t = inputs[i];
95
for (i=outPoint;i<length;i++) {
96
register MY_FLOAT t = inputs[i];
99
for (i=0;i<inPoint;i++) {
100
register MY_FLOAT t = inputs[i];
107
long DLineL :: currentInPoint(void)
112
long DLineL :: currentOutPoint(void)
117
MY_FLOAT DLineL :: contentsAt(int n)
121
if (i>= length) i = length-1;
124
"DLineL: contentsAt(%d) overflows length %ld delay line\n",
130
MY_FLOAT DLineL :: contentsAtNowMinus(int n)
132
/* "Now" is always where inPoint points which is not yet written. */
133
/* outPoint points to "now - delay". Thus, valid values for n are 1 to delay. */
136
if (i>length) i = length;
139
"DLineL: contentsAtNowMinus(%d) overflows length %ld delay line\n"
140
"Clipped\n", n,length);
143
if (ndx < 0) { /* Check for wraparound */
145
if (ndx < 0 || ndx >= length)
146
fprintf(stderr,"DLineL: contentsAtNowMinus(): can't happen\n");
151
MY_FLOAT DLineL :: tick(MY_FLOAT sample)
153
inputs[inPoint++] = sample;
155
// Check for end condition
156
if (inPoint == length)
159
// First 1/2 of interpolation
160
lastOutput = inputs[outPoint++] * omAlpha;
161
// Check for end condition
162
if (outPoint<length) {
163
// Second 1/2 of interpolation
164
lastOutput += inputs[outPoint] * alpha;
166
else { // if at end ...
167
// Second 1/2 of interpolation
168
lastOutput += inputs[0] * alpha;