andrewm@0: /* andrewm@0: * FeedbackOscillator.h andrewm@0: * andrewm@0: * Created on: June 8, 2014 andrewm@0: * Author: Andrew McPherson andrewm@0: */ andrewm@0: andrewm@0: #ifndef FEEDBACKOSCILLATOR_H andrewm@0: #define FEEDBACKOSCILLATOR_H andrewm@0: andrewm@0: class FeedbackOscillator andrewm@0: { andrewm@0: public: andrewm@0: FeedbackOscillator(); andrewm@0: ~FeedbackOscillator(); andrewm@0: andrewm@0: // Initialise the settings for the feedback oscillator andrewm@0: void initialise(int maxTableSize, float hpfCutoffFrequency, float matrixSampleRate); andrewm@0: andrewm@0: // Process one sample and store the output value andrewm@0: // Returns the length of table to interpolate; or 0 if nothing to process further andrewm@50: int process(float input, float *output); andrewm@0: andrewm@0: float *wavetable() { return wavetableRead; } andrewm@0: andrewm@0: private: andrewm@0: float coeffs[3]; // Coefficients of first-order high-pass filter andrewm@0: float lastInput; // last input sample for HPF andrewm@0: float lastOutput; // last output sample of HPF andrewm@0: bool triggered; // whether we are currently saving samples andrewm@0: bool canTrigger; // whether we are able to begin saving samples andrewm@0: int wavetableMaxLength; // how long the stored wavetable can be andrewm@0: int sampleCount; // how many samples have elapsed andrewm@0: int lastTriggerCount; // sample count when we last triggered andrewm@0: andrewm@0: float *wavetable1, *wavetable2; // Two wavetables where we record samples andrewm@0: float *wavetableRead, *wavetableWrite; // Pointers to the above wavetables andrewm@0: int wavetableWritePointer; // Where we are currently writing andrewm@0: }; andrewm@0: andrewm@0: #endif