f@0
|
1 //
|
f@0
|
2 // AccessiblePeakMeter.h
|
f@0
|
3 //
|
f@0
|
4 // Author: Fiore Martin
|
f@0
|
5 // Started from IPlugMultiTargets example in WDL-OL, by Oli Larkin - https://github.com/olilarkin/wdl-ol
|
f@0
|
6 //
|
f@0
|
7 // Licensed under the Cockos WDL License, see README.txt
|
f@0
|
8 //
|
f@0
|
9
|
f@0
|
10
|
f@0
|
11 #ifndef __ACCESSIBLEPEAKMETER__
|
f@0
|
12 #define __ACCESSIBLEPEAKMETER__
|
f@0
|
13
|
f@0
|
14 #include "IPlug_include_in_plug_hdr.h"
|
f@0
|
15
|
f@0
|
16 #include "stk/include/SineWave.h"
|
f@0
|
17 #include "stk/include/Envelope.h"
|
f@0
|
18 #include "stk/include/ADSR.h"
|
f@0
|
19
|
f@0
|
20
|
f@0
|
21 class AccessiblePeakMeter : public IPlug
|
f@0
|
22 {
|
f@0
|
23 public:
|
f@0
|
24
|
f@0
|
25 AccessiblePeakMeter(IPlugInstanceInfo instanceInfo);
|
f@0
|
26 ~AccessiblePeakMeter();
|
f@0
|
27
|
f@0
|
28 void Reset();
|
f@0
|
29 void OnParamChange(int paramIdx);
|
f@0
|
30 void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames);
|
f@0
|
31 bool HostRequestingAboutBox();
|
f@0
|
32
|
f@0
|
33 private:
|
f@0
|
34 static const double DRYWET_DEFAULT;
|
f@2
|
35 static const int SONIFICATION_TYPE_DEFAULT;
|
f@0
|
36 static const double METERDECAY_DEFAULT;
|
f@0
|
37 static const double THRESHOLD_DEFAULT;
|
f@0
|
38 static const double BEEP_TIME;
|
f@0
|
39 static const double DB_RANGE;
|
f@0
|
40 static const double SONIFICATION_RANGE;
|
f@0
|
41 static const int SONIFICATION_TYPE_CLIPPING;
|
f@0
|
42 static const int SONIFICATION_TYPE_CONTINUOUS;
|
f@0
|
43 static const int MAX_CHANNELS = 2;
|
f@0
|
44 static const int NUM_PRESETS;
|
f@0
|
45 static const double MIN_SONIFICATION_FREQ;
|
f@0
|
46 static const int NUM_KNOB_FRAMES;
|
f@0
|
47 static const double CLIPPING_CEILING_SNAP;
|
f@0
|
48
|
f@0
|
49 /* parameters on GUI */
|
f@0
|
50 double mDry;
|
f@0
|
51 double mWet;
|
f@0
|
52 double mMeterDecayRate;
|
f@0
|
53 double mThreshold;
|
f@0
|
54
|
f@0
|
55 double mSampleRate;
|
f@0
|
56
|
f@0
|
57 /* paramters for peak level meter */
|
f@0
|
58 double mPrevPeak[MAX_CHANNELS];
|
f@0
|
59 int mMeterIdx[MAX_CHANNELS];
|
f@0
|
60
|
f@0
|
61 /* struct Sonification is the sonification engine. It has two substructures containing
|
f@0
|
62 data specific to each type (clipping/continuous)
|
f@0
|
63 */
|
f@0
|
64 struct Sonification {
|
f@0
|
65 int type; // type of sonification : clipping - continous
|
f@0
|
66 stk::SineWave ugen[MAX_CHANNELS]; // generator for both types of sonification
|
f@0
|
67
|
f@0
|
68 struct Continous {
|
f@0
|
69 /* this envelope is to turn off the countinuous sonification smoothly
|
f@0
|
70 without clicks. It's always 1, unless the sonification is being turned off.
|
f@0
|
71 */
|
f@0
|
72 stk::Envelope envelope[MAX_CHANNELS];
|
f@0
|
73 bool isOn[MAX_CHANNELS];
|
f@0
|
74 } continous;
|
f@0
|
75
|
f@0
|
76 struct Clipping {
|
f@0
|
77 /* max diff is used to keep the pitch more consistent over different blocks
|
f@0
|
78 with maxDiff the beep sounds better cause is not constantly pitch modulated */
|
f@0
|
79 double maxDiff[MAX_CHANNELS];
|
f@0
|
80 stk::ADSR envelope[MAX_CHANNELS];
|
f@0
|
81 } clipping;
|
f@0
|
82
|
f@0
|
83 /* resets all the ugens. When srate is less than 0, type and ugen freq are
|
f@0
|
84 not affected by resetas well as sample rate.
|
f@0
|
85 */
|
f@0
|
86 void reset(double srate = -1.0){
|
f@0
|
87
|
f@0
|
88 for (int i = 0; i < MAX_CHANNELS; i++){
|
f@0
|
89
|
f@0
|
90 ugen[i].reset();
|
f@0
|
91
|
f@0
|
92 continous.isOn[i] = true;
|
f@0
|
93 stk::Envelope & coe = continous.envelope[i];
|
f@0
|
94 coe.setValue(1.0); // setValue also sets the target to the value
|
f@0
|
95 coe.setTime(0.2);
|
f@0
|
96
|
f@0
|
97 clipping.maxDiff[i] = 0.0;
|
f@0
|
98 stk::ADSR & cle = clipping.envelope[i];
|
f@0
|
99 cle.setValue(0.0);
|
f@0
|
100 cle.setReleaseTime(BEEP_TIME);
|
f@0
|
101 cle.setAttackTime(0.01);
|
f@0
|
102 cle.setSustainLevel(1);
|
f@0
|
103
|
f@0
|
104 if (srate > 0.0){
|
f@0
|
105 ugen[i].setSampleRate(srate);
|
f@0
|
106 coe.setSampleRate(srate);
|
f@0
|
107 cle.setSampleRate(srate);
|
f@0
|
108 }
|
f@0
|
109 }
|
f@0
|
110 }
|
f@0
|
111
|
f@2
|
112 Sonification() : type(SONIFICATION_TYPE_DEFAULT) {
|
f@0
|
113 reset();
|
f@0
|
114 }
|
f@0
|
115
|
f@0
|
116 } mSonification;
|
f@0
|
117
|
f@0
|
118 /* adds continous sonification on top of the original audio signal */
|
f@0
|
119 void addContinuousSonification(double** inputs, double** outputs, int nFrames);
|
f@0
|
120 /* adds clipping sonification on top of the original audio signal */
|
f@0
|
121 void addClippingSonification(double** inputs, double** outputs, int nFrames);
|
f@0
|
122 /* for dry/wet mix */
|
f@0
|
123 inline double mix(double dry, double wet) const{
|
f@0
|
124 return dry * mDry + wet * mWet;
|
f@0
|
125 }
|
f@0
|
126 };
|
f@0
|
127
|
f@0
|
128
|
f@0
|
129 #endif //__ACCESSIBLEPEAKMETER__
|