#if !defined(__DELAY_H) #define __DELAY_H //Simple delay line class. Uses allpass interpolation to implement fractional delays if requested. //Note: this class has no error checking. delayLength must always be <= maxDelay-1. #define SAMPLE double class Delay { public: //Constructor Delay(unsigned long maxDelayIn, double delayLengthIn); //Destructor ~Delay(); //Takes in a value, returns the next output and increments pointers SAMPLE tick(SAMPLE inSample); //Utility fns void setDelayLength(double delayLengthIn); double getDelayLength() { return (delayLengthInt + delta); }; unsigned long getMaxDelay() { return maxDelay; }; SAMPLE getNextOut() { return -eta*lastOut + eta*delayLine[readIndex] + allpassState; }; SAMPLE getLastOut() { return lastOut; }; void clear(); //Fills the delay line with white noise void fillWithWhiteNoise(int velocity); private: //Delay line properties unsigned long maxDelay; unsigned long delayLengthInt; //Integer part of the delay length //Fractional delay variables double eta; //Allpass feed-forward / feedback gain double delta; //Fractional delay desired SAMPLE allpassState; //Memory variables SAMPLE* delayLine; SAMPLE lastOut; unsigned long writeIndex; unsigned long readIndex; }; #endif