leaf-dynamics.h
1 /*==============================================================================
2 
3  leaf-dynamics.h
4  Created: 30 Nov 2018 11:57:05am
5  Author: airship
6 
7  ==============================================================================*/
8 
9 #ifndef LEAF_DYNAMICS_H_INCLUDED
10 #define LEAF_DYNAMICS_H_INCLUDED
11 
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17  //==============================================================================
18 
19 #include "leaf-global.h"
20 #include "leaf-math.h"
21 #include "leaf-mempool.h"
22 #include "leaf-analysis.h"
23 
32  //==============================================================================
33 
60  typedef struct _tCompressor
61  {
62 
63  tMempool mempool;
64 
65  float tauAttack, tauRelease;
66  float T, R, W, M; // Threshold, compression Ratio, decibel Width of knee transition, decibel Make-up gain
67 
68  float x_G[2], y_G[2], x_T[2], y_T[2];
69 
70  int isActive;
71 
72  } _tCompressor;
73 
74  typedef _tCompressor* tCompressor;
75 
76  void tCompressor_init (tCompressor* const, LEAF* const leaf);
77  void tCompressor_initToPool (tCompressor* const, tMempool* const);
78  void tCompressor_free (tCompressor* const);
79 
80  float tCompressor_tick (tCompressor* const, float input);
81 
82 
131  typedef struct _tFeedbackLeveler
132  {
133 
134  tMempool mempool;
135  float targetLevel; // target power level
136  float strength; // how strongly level difference affects the VCA
137  int mode; // 0 for upwards limiting only, 1 for biderctional limiting
138  float curr;
139  tPowerFollower pwrFlw; // internal power follower needed for level tracking
140 
141  } _tFeedbackLeveler;
142 
143  typedef _tFeedbackLeveler* tFeedbackLeveler;
144 
145  void tFeedbackLeveler_init (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, LEAF* const leaf);
146  void tFeedbackLeveler_initToPool (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, tMempool* const);
147  void tFeedbackLeveler_free (tFeedbackLeveler* const);
148 
149  float tFeedbackLeveler_tick (tFeedbackLeveler* const, float input);
150  float tFeedbackLeveler_sample (tFeedbackLeveler* const);
151  void tFeedbackLeveler_setTargetLevel (tFeedbackLeveler* const, float TargetLevel);
152  void tFeedbackLeveler_setFactor (tFeedbackLeveler* const, float factor);
153  void tFeedbackLeveler_setMode (tFeedbackLeveler* const, int mode); // 0 for upwards limiting only, 1 for biderctional limiting
154  void tFeedbackLeveler_setStrength (tFeedbackLeveler* const, float strength);
155 
156 
157  //==============================================================================
158 
159 
194  typedef struct _tThreshold
195  {
196 
197  tMempool mempool;
198  float highThresh, lowThresh;
199  int currentValue;
200  } _tThreshold;
201 
202  typedef _tThreshold* tThreshold;
203 
204  void tThreshold_init (tThreshold* const, float low, float high, LEAF* const leaf);
205  void tThreshold_initToPool (tThreshold* const, float low, float high, tMempool* const);
206  void tThreshold_free (tThreshold* const);
207 
208  int tThreshold_tick (tThreshold* const, float input);
209  void tThreshold_setLow (tThreshold* const, float low);
210  void tThreshold_setHigh (tThreshold* const, float high);
211 
212 
213 
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif // LEAF_DYNAMICS_H_INCLUDED
221 
222 //==============================================================================
223 
tFeedbackLeveler_free
void tFeedbackLeveler_free(tFeedbackLeveler *const)
Free a tFeedbackLeveler from its mempool.
Definition: leaf-dynamics.c:143
tFeedbackLeveler_setMode
void tFeedbackLeveler_setMode(tFeedbackLeveler *const, int mode)
Definition: leaf-dynamics.c:164
tFeedbackLeveler_tick
float tFeedbackLeveler_tick(tFeedbackLeveler *const, float input)
Definition: leaf-dynamics.c:170
tCompressor_initToPool
void tCompressor_initToPool(tCompressor *const, tMempool *const)
Initialize a tCompressor to a specified mempool.
Definition: leaf-dynamics.c:49
tThreshold_initToPool
void tThreshold_initToPool(tThreshold *const, float low, float high, tMempool *const)
Initialize a tThreshold to a specified mempool.
Definition: leaf-dynamics.c:199
tFeedbackLeveler_sample
float tFeedbackLeveler_sample(tFeedbackLeveler *const)
Definition: leaf-dynamics.c:179
tCompressor_tick
float tCompressor_tick(tCompressor *const, float input)
Definition: leaf-dynamics.c:73
tFeedbackLeveler_initToPool
void tFeedbackLeveler_initToPool(tFeedbackLeveler *const, float targetLevel, float factor, float strength, int mode, tMempool *const)
Initialize a tFeedbackLeveler to a specified mempool.
Definition: leaf-dynamics.c:130
tThreshold_init
void tThreshold_init(tThreshold *const, float low, float high, LEAF *const leaf)
Initialize a tThreshold to the default mempool of a LEAF instance.
Definition: leaf-dynamics.c:194
tFeedbackLeveler_init
void tFeedbackLeveler_init(tFeedbackLeveler *const, float targetLevel, float factor, float strength, int mode, LEAF *const leaf)
Initialize a tFeedbackLeveler to the default mempool of a LEAF instance.
Definition: leaf-dynamics.c:125
tFeedbackLeveler_setStrength
void tFeedbackLeveler_setStrength(tFeedbackLeveler *const, float strength)
Definition: leaf-dynamics.c:151
tCompressor_free
void tCompressor_free(tCompressor *const)
Free a tCompressor from its mempool.
Definition: leaf-dynamics.c:66
tThreshold_setLow
void tThreshold_setLow(tThreshold *const, float low)
Definition: leaf-dynamics.c:234
tFeedbackLeveler_setFactor
void tFeedbackLeveler_setFactor(tFeedbackLeveler *const, float factor)
Definition: leaf-dynamics.c:158
tThreshold_setHigh
void tThreshold_setHigh(tThreshold *const, float high)
Definition: leaf-dynamics.c:241
tThreshold_tick
int tThreshold_tick(tThreshold *const, float input)
Definition: leaf-dynamics.c:218
tCompressor_init
void tCompressor_init(tCompressor *const, LEAF *const leaf)
Initialize a tCompressor to the default mempool of a LEAF instance.
Definition: leaf-dynamics.c:44
LEAF
Struct for an instance of LEAF.
Definition: leaf-global.h:31
tFeedbackLeveler_setTargetLevel
void tFeedbackLeveler_setTargetLevel(tFeedbackLeveler *const, float TargetLevel)
Definition: leaf-dynamics.c:186
tThreshold_free
void tThreshold_free(tThreshold *const)
Free a tThreshold from its mempool.
Definition: leaf-dynamics.c:211