forked from giuliomoro/tiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RampGenerator.h
70 lines (56 loc) · 1.82 KB
/
RampGenerator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*** RampGenerator.h ***/
/* RampGenerator.h */
#ifndef RAMPGENERATOR_H_
#define RAMPGENERATOR_H_
//struct RampConfig;
class RampGenerator {
public:
RampGenerator();
~RampGenerator();
void config(int numReadings, float thresholdToTrigger, float amountBelowPeak, float rolloffRate, float readings[], int index, float avrTotal, float average, int previousSample, float peakValue, int triggered, float line, float amps, int ADSRStates, int sampleCount, int attack, int debounceSampleCount, int debounceThresh, int onsetFinished, int debounce, int startPlaying);
float processRamp(float in, float thresholdToTrigger,float amountBelowPeak, float rolloffRate);
private:
int numReadings;
float thresholdToTrigger;
float amountBelowPeak;
float rolloffRate;
/* Average */
float readings[50]; // array to store readings from the analog input
int index; // index of the current reading
float avrTotal; // running total
float average; // the average
/* -------------------- */
/* Onset Detection */
int previousSample; // Value of the sensor the last time around
float peakValue;
int triggered;
int startPlaying;
/* -------------------- */
/* Envelope Trigger */
float line;
float amps;
int ADSRStates;
int sampleCount;
enum {
kStateOff = 0,
kStateAttack
};
int attack;
/* -------------------- */
/* Debounce */
int debounceSampleCount; // Sample counter for avoiding double onsets
int debounceThresh; //1500 Duration in samples of window in which a second onset can't be triggered (equates to a trill of ~22Hz)
int onsetFinished;
int debounce;
/* -------------------- */
/* DC OFFSET FILTER */
float prevReadingDCOffset;
float prevPiezoReading;
float readingDCOffset;
float R;
/* ----------------- */
float piezoAmp;
// DEBUG
float peakValueDebug;
};
#endif /* RAMPGENERATOR_H_ */