diff options
Diffstat (limited to 'openFrameworks')
| -rw-r--r-- | openFrameworks/ofxMaxim/libs/maximilian.cpp | 34 | ||||
| -rwxr-xr-x | openFrameworks/ofxMaxim/libs/maximilian.h | 10 |
2 files changed, 44 insertions, 0 deletions
diff --git a/openFrameworks/ofxMaxim/libs/maximilian.cpp b/openFrameworks/ofxMaxim/libs/maximilian.cpp index 3391da1..92bae0a 100644 --- a/openFrameworks/ofxMaxim/libs/maximilian.cpp +++ b/openFrameworks/ofxMaxim/libs/maximilian.cpp @@ -426,6 +426,40 @@ double maxiDelayline::dl(double input, int size, double feedback, int position) } +maxiFractionalDelay::maxiFractionalDelay ( void ) { + memset( memory, 0, delaySize*sizeof (double) ); +} + +double maxiFractionalDelay::dl ( double sig, double delayTime, double feedback ) +{ + // Set delay time + delayTime = fmin(fabs(delayTime), delaySize); + int32_t delay = delayTime; // Truncated + double fractAmount = delayTime - delay; // Fractional remainder + double truncAmount = 1.0f - fractAmount; // Inverse fractional remainder + + // Update read pointer + readPointer = writePointer - delay; + if (readPointer < 0) + readPointer += delaySize; + + int readPointerFractPart = readPointer-1; + if (readPointerFractPart < 0) + readPointerFractPart += delaySize; + + // Get interpolated sample + double y = memory[readPointer] * truncAmount + memory[readPointerFractPart] * fractAmount; + + // Write new sample + memory[writePointer] = y * feedback + sig; + + // Increment write pointer + if (++writePointer >= delaySize) + writePointer -= delaySize; + return y; +} + + //I particularly like these. cutoff between 0 and 1 double maxiFilter::lopass(double input, double cutoff) { output=outputs[0] + cutoff*(input-outputs[0]); diff --git a/openFrameworks/ofxMaxim/libs/maximilian.h b/openFrameworks/ofxMaxim/libs/maximilian.h index d2db173..c53b731 100755 --- a/openFrameworks/ofxMaxim/libs/maximilian.h +++ b/openFrameworks/ofxMaxim/libs/maximilian.h @@ -141,6 +141,16 @@ public: }; +class maxiFractionalDelay { + static const int delaySize = 88200; + double memory[delaySize]; + int writePointer = 0; + int readPointer = 0; + +public: + maxiFractionalDelay ( void ); + double dl ( double sig, double delayTime, double feedback ); +}; class maxiFilter { double gain; |
