SynthLab SDK
synthlabcore.h
1 #pragma once
2 
3 // *** NOTE: relative paths to SDK files ********************************************
4 // these are setup so that ModuleCore DM projects are compiled directly
5 // from the SDK itself with minimal effort
6 //
7 // You may want to adjust these to suit your particular development folder
8 // system if you only want to use parts of the SDK or plan on modifying
9 // SDK files, or need to alter the folder hierarchy for your setup.
10 //
11 // Alternatively, you may add a new "Include Path" to your compiler setup.
12 // **********************************************************************************
13 
14 #include "../../../../source/synthbase.h"
15 #include "../../../../source/synthfunctions.h"
16 
17 // -----------------------------
18 // SynthLab SDK File //
19 // for //
20 // DynamicModule //
21 // Development //
22 // ----------------------------
30 // -----------------------------------------------------------------------------
31 namespace SynthLab
32 {
98  class SynthLabCore : public ModuleCore
99  {
100  public:
102  SynthLabCore(); /* C-TOR */
103 
105  virtual ~SynthLabCore() {} /* D-TOR */
106 
108  virtual bool reset(CoreProcData& processInfo) override;
109  virtual bool update(CoreProcData& processInfo) override;
110  virtual bool render(CoreProcData& processInfo) override;
111  virtual bool doNoteOn(CoreProcData& processInfo) override;
112  virtual bool doNoteOff(CoreProcData& processInfo) override;
113 
115  virtual int32_t getState() override { return enumToInt(state); }
116  virtual bool shutdown() override;
117  virtual void setSustainOverride(bool b) override;
118 
119  protected:
120  bool noteOff = false;
121  bool retriggered = false;
122  double lastTriggerMod = 0.0;
123 
124  // --- index of contour
125  double sustainLevel = 1.0;
126  double attackTime_mSec = 1.0;
127  double decayTime_mSec = 1.0;
128  double releaseTime_mSec = 1.0;
129 
131  inline void calcAttackCoeff(double attackTime, double attackTimeScalar = 1.0)
132  {
133  // --- store for comparing so don't need to waste cycles on updates
134  attackTime_mSec = attackTime;
135 
136  // --- samples for the exponential rate
137  double samples = sampleRate*((attackTime_mSec*attackTimeScalar) / 1000.0);
138 
139  // --- coeff and base for iterative exponential calculation
140  attackCoeff = exp(-log((1.0 + attackTCO) / attackTCO) / samples);
141  attackOffset = (1.0 + attackTCO)*(1.0 - attackCoeff);
142  }
143 
145  inline void calcDecayCoeff(double decayTime, double decayTimeScalar = 1.0)
146  {
147  // --- store for comparing so don't need to waste cycles on updates
148  decayTime_mSec = decayTime;
149 
150  // --- samples for the exponential rate
151  double samples = sampleRate*((decayTime_mSec*decayTimeScalar) / 1000.0);
152 
153  // --- coeff and base for iterative exponential calculation
154  decayCoeff = exp(-log((1.0 + decayTCO) / decayTCO) / samples);
156  }
157 
159  void calcReleaseCoeff(double releaseTime, double releaseTimeScalar = 1.0)
160  {
161  // --- store for comparing so don't need to waste cycles on updates
162  releaseTime_mSec = releaseTime;
163 
164  // --- samples for the exponential rate
165  double samples = sampleRate*((releaseTime_mSec*releaseTimeScalar) / 1000.0);
166 
167  // --- coeff and base for iterative exponential calculation
168  releaseCoeff = exp(-log((1.0 + releaseTCO) / releaseTCO) / samples);
170  }
171 
172  // --- sample rate for time calculations
173  double sampleRate = 0.0;
174 
175  // --- the current output of the EG
176  double envelopeOutput = 0.0;
177 
178 
179  //--- Coefficient, offset and TCO values
180  // for each state
181  double attackCoeff = 0.0;
182  double attackOffset = 0.0;
183  double attackTCO = 0.0;
184 
185  double decayCoeff = 0.0;
186  double decayOffset = 0.0;
187  double decayTCO = 0.0;
188 
189  double releaseCoeff = 0.0;
190  double releaseOffset = 0.0;
191  double releaseTCO = 0.0;
192 
193  // --- for sustain pedal input; these two bools keep track of the override,
194  // and eventual release when the sus pedal is released after user released key
195  bool sustainOverride = false;
196  bool releasePending = false;
197 
198  // --- inc value for shutdown
199  double incShutdown = 0.0;
200 
201  // --- stage variable
202  EGState state = EGState::kOff;
203  };
204 
205 
206 
207 } // namespace
208 
double decayTCO
TCO value for calculating offset.
Definition: synthlabcore.h:187
EGState state
EG state variable.
Definition: synthlabcore.h:202
#define enumToInt(ENUM)
macro helper to cast a typed enum to an int
Definition: synthfunctions.h:251
void calcDecayCoeff(double decayTime, double decayTimeScalar=1.0)
Definition: synthlabcore.h:145
double releaseTime_mSec
rel: is a time to decay from max output to 0.0
Definition: synthlabcore.h:128
bool noteOff
for retriggering EG
Definition: synthlabcore.h:120
double attackCoeff
exponential feedback coefficient
Definition: synthlabcore.h:181
SynthLabCore()
Construction: Cores follow the same construction pattern.
Definition: synthlabcore.cpp:29
bool retriggered
for retriggering EG
Definition: synthlabcore.h:121
virtual bool shutdown() override
Shutdown handler for EG.
Definition: synthlabcore.cpp:400
virtual int32_t getState() override
Definition: synthlabcore.h:115
void calcAttackCoeff(double attackTime, double attackTimeScalar=1.0)
Definition: synthlabcore.h:131
virtual bool doNoteOff(CoreProcData &processInfo) override
Note-off handler for the ModuleCore.
Definition: synthlabcore.cpp:135
Definition: addosccore.cpp:4
virtual bool update(CoreProcData &processInfo) override
Updates the object for the next block of audio processing.
Definition: synthlabcore.cpp:79
double sampleRate
sample rate
Definition: synthlabcore.h:108
double attackTime_mSec
att: is a time duration
Definition: synthlabcore.h:126
double releaseTCO
TCO value for calculating offset.
Definition: synthlabcore.h:191
void calcReleaseCoeff(double releaseTime, double releaseTimeScalar=1.0)
Definition: synthlabcore.h:159
double releaseCoeff
exponential feedback coefficient
Definition: synthlabcore.h:189
virtual bool render(CoreProcData &processInfo) override
Renders the output of the module.
Definition: synthlabcore.cpp:98
double decayTime_mSec
dcy: is a time to decay from max output to 0.0
Definition: synthlabcore.h:127
bool sustainOverride
if true, places the EG into sustain mode
Definition: synthlabcore.h:195
double lastTriggerMod
for retriggering EG trigger detection
Definition: synthlabcore.h:122
EGState
Definition: synthlabparams.h:723
double decayTimeScalar
for MIDI modulations to decay time
Definition: synthlabcore.h:127
double envelopeOutput
the current envelope output sample
Definition: synthlabcore.h:176
double decayOffset
TCO offset to allow proper attack/decay on [1, 0].
Definition: synthlabcore.h:186
double sustainLevel
level, not time
Definition: synthlabcore.h:125
double attackTCO
TCO value for calculating offset.
Definition: synthlabcore.h:183
virtual bool doNoteOn(CoreProcData &processInfo) override
Note-on handler for the ModuleCore.
Definition: synthlabcore.cpp:116
double decayCoeff
exponential feedback coefficient
Definition: synthlabcore.h:185
virtual bool reset(CoreProcData &processInfo) override
Resets object to initialized state.
Definition: synthlabcore.cpp:61
double releaseOffset
TCO offset to allow proper attack/decay on [1, 0].
Definition: synthlabcore.h:190
virtual void setSustainOverride(bool b) override
Sustain pedal handler for EG.
Definition: synthlabcore.cpp:422
virtual ~SynthLabCore()
Definition: synthlabcore.h:105
bool releasePending
a flag set when a note off event occurs while the sustain pedal is held, telling the EG to go to the ...
Definition: synthlabcore.h:196
double incShutdown
shutdown linear incrementer
Definition: synthlabcore.h:199
This structure holds all of the information needed to call functions on a ModuleCore object...
Definition: synthbase.h:1071
double attackOffset
TCO offset to allow proper attack/decay on [1, 0].
Definition: synthlabcore.h:182
double attackTimeScalar
for MIDI modulations to attack time
Definition: synthlabcore.h:126