Unlike the plain delay, this code doesn't keep a read pointer. Instead, the pointer is calculated from the desired delay time and the write pointer. In general, the value we want would lie between two sample values so we take the largest valid pointer, and computer the fractional offset. The interpolated value is calculated by connecting the two known values with a straight line, multiplying the line's slope times the fractional offset, and adding that to the sample on the lower bound. To simplify the interpolation process a bit, the delayline is made one sample longer than necesary where the first point is a copy of the last.
The write step is pretty much the same as the basic delay - after getting the read value, write the incoming sample plus the read value weighted by the desired feedback level. When the write pointer reaches the end of the delay line, copy the last point to the first, and wrap the pointer to the second location of the delay line.
The code allows for the maximum delay time, feedback multiplier, and mix levels for the input and delayed signal to be specified in the constructor.
See also:
Please do not redistribute this code. In the event that it contains a bug, this will ensure that it can be fixed without the buggy copies floating around indefinitely.
Last Modified: 9/5/98
/*********************************************************
Vdelay.h - A variable delay unit with linear interpolation
Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
*********************************************************/
#ifndef VDELAY_H
#define VDELAY_H
#include "Processor.h"
class Vdelay : public Processor {
public:
Vdelay(float maxDelay, float feedback, float wetMix, float dryMix);
void Initialize(void);
void Process(void);
void Cleanup(void);
private:
float * bufferStart, * bufferEnd, feedbackGain;
float wetLevel, dryLevel, * outputSignal, * inputSignal, *LFO;
float delayLineOutput, delayTime; //delay time in milliseconds
float * delayLineStart, * delayLineEnd, * writePtr;
int i, delayLineLength;
Vdelay(Vdelay&){};
};
#endif
|
/********************************************************* Vdelay.cpp - A variable delay unit with linear interpolation Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com This code may be used and modified freely provided that credit is given to the author in any public release. Any derivative programs must be distributed freely and/or the modified source code made publicly available. All code is provided AS IS and without warranty of any kind. *********************************************************/ #include "Vdelay.h" #include |