Mercurial > hg > beaglert
annotate projects/d-box/FeedbackOscillator.h @ 43:4cd9a8ca5745 staging
Fixed bug that was causing pointer corruption
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 19 May 2015 16:54:10 +0100 |
parents | 8a575ba3ab52 |
children | be427da6fb9c |
rev | line source |
---|---|
andrewm@0 | 1 /* |
andrewm@0 | 2 * FeedbackOscillator.h |
andrewm@0 | 3 * |
andrewm@0 | 4 * Created on: June 8, 2014 |
andrewm@0 | 5 * Author: Andrew McPherson |
andrewm@0 | 6 */ |
andrewm@0 | 7 |
andrewm@0 | 8 #ifndef FEEDBACKOSCILLATOR_H |
andrewm@0 | 9 #define FEEDBACKOSCILLATOR_H |
andrewm@0 | 10 |
andrewm@0 | 11 #include <stdint.h> |
andrewm@0 | 12 |
andrewm@0 | 13 class FeedbackOscillator |
andrewm@0 | 14 { |
andrewm@0 | 15 public: |
andrewm@0 | 16 FeedbackOscillator(); |
andrewm@0 | 17 ~FeedbackOscillator(); |
andrewm@0 | 18 |
andrewm@0 | 19 // Initialise the settings for the feedback oscillator |
andrewm@0 | 20 void initialise(int maxTableSize, float hpfCutoffFrequency, float matrixSampleRate); |
andrewm@0 | 21 |
andrewm@0 | 22 // Process one sample and store the output value |
andrewm@0 | 23 // Returns the length of table to interpolate; or 0 if nothing to process further |
andrewm@0 | 24 int process(uint16_t input, uint16_t *output); |
andrewm@0 | 25 |
andrewm@0 | 26 float *wavetable() { return wavetableRead; } |
andrewm@0 | 27 |
andrewm@0 | 28 private: |
andrewm@0 | 29 float coeffs[3]; // Coefficients of first-order high-pass filter |
andrewm@0 | 30 float lastInput; // last input sample for HPF |
andrewm@0 | 31 float lastOutput; // last output sample of HPF |
andrewm@0 | 32 bool triggered; // whether we are currently saving samples |
andrewm@0 | 33 bool canTrigger; // whether we are able to begin saving samples |
andrewm@0 | 34 int wavetableMaxLength; // how long the stored wavetable can be |
andrewm@0 | 35 int sampleCount; // how many samples have elapsed |
andrewm@0 | 36 int lastTriggerCount; // sample count when we last triggered |
andrewm@0 | 37 |
andrewm@0 | 38 float *wavetable1, *wavetable2; // Two wavetables where we record samples |
andrewm@0 | 39 float *wavetableRead, *wavetableWrite; // Pointers to the above wavetables |
andrewm@0 | 40 int wavetableWritePointer; // Where we are currently writing |
andrewm@0 | 41 }; |
andrewm@0 | 42 |
andrewm@0 | 43 #endif |