leaf-distortion.h
1 /*==============================================================================
2 
3  leaf-distortion.h
4  Created: 25 Oct 2019 10:23:28am
5  Author: Matthew Wang
6 
7  ==============================================================================*/
8 
9 #ifndef LEAF_DISTORTION_H_INCLUDED
10 #define LEAF_DISTORTION_H_INCLUDED
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16  //==============================================================================
17 
18 #include "leaf-global.h"
19 #include "leaf-mempool.h"
20 #include "leaf-math.h"
21 
30  //==============================================================================
31 
62  typedef struct _tSampleReducer
63  {
64 
65  tMempool mempool;
66  float invRatio;
67  float hold;
68  uint32_t count;
69  } _tSampleReducer;
70 
71  typedef _tSampleReducer* tSampleReducer;
72 
73  void tSampleReducer_init (tSampleReducer* const, LEAF* const leaf);
74  void tSampleReducer_initToPool (tSampleReducer* const, tMempool* const);
75  void tSampleReducer_free (tSampleReducer* const);
76 
77  float tSampleReducer_tick (tSampleReducer* const, float input);
78  void tSampleReducer_setRatio (tSampleReducer* const, float ratio);
79 
80  //==============================================================================
81 
120  typedef struct _tOversampler
121  {
122 
123  tMempool mempool;
124  int ratio;
125  float* pCoeffs;
126  float* upState;
127  float* downState;
128  int numTaps;
129  int phaseLength;
130  } _tOversampler;
131 
132  typedef _tOversampler* tOversampler;
133 
134  void tOversampler_init (tOversampler* const, int order, int extraQuality, LEAF* const leaf);
135  void tOversampler_initToPool (tOversampler* const, int order, int extraQuality, tMempool* const);
136  void tOversampler_free (tOversampler* const);
137 
138  void tOversampler_upsample (tOversampler* const, float input, float* output);
139  float tOversampler_downsample (tOversampler* const os, float* input);
140  float tOversampler_tick (tOversampler* const, float input, float* oversample, float (*effectTick)(float));
141  int tOversampler_getLatency (tOversampler* const os);
142 
143  //==============================================================================
144 
171  typedef struct _tLockhartWavefolder
172  {
173 
174  tMempool mempool;
175 
176  double Ln1;
177  double Fn1;
178  double xn1;
179 
180  double RL;
181  double R;
182  double VT;
183  double Is;
184 
185  double a;
186  double b;
187  double d;
188 
189  // Antialiasing error threshold
190  double AAthresh;
191  double half_a;
192  double longthing;
193 
194  double LambertThresh, w, expw, p, r, s, myerr;
195  double l;
196  double u, Ln, Fn;
197  double tempsDenom;
198  double tempErrDenom;
199  double tempOutDenom;
200 
201  } _tLockhartWavefolder;
202 
203  typedef _tLockhartWavefolder* tLockhartWavefolder;
204 
205  void tLockhartWavefolder_init (tLockhartWavefolder* const, LEAF* const leaf);
206  void tLockhartWavefolder_initToPool (tLockhartWavefolder* const, tMempool* const);
207  void tLockhartWavefolder_free (tLockhartWavefolder* const);
208 
209  float tLockhartWavefolder_tick (tLockhartWavefolder* const, float samp);
210 
211  //==============================================================================
212 
259  typedef struct _tCrusher
260  {
261 
262  tMempool mempool;
263 
264  float srr;
265  float mult, div;
266  float rnd;
267 
268  uint32_t op; //which bitwise operation (0-7)
269 
270  float gain;
271  tSampleReducer sReducer;
272 
273  } _tCrusher;
274 
275  typedef _tCrusher* tCrusher;
276 
277  void tCrusher_init (tCrusher* const, LEAF* const leaf);
278  void tCrusher_initToPool (tCrusher* const, tMempool* const);
279  void tCrusher_free (tCrusher* const);
280 
281  float tCrusher_tick (tCrusher* const, float input);
282  void tCrusher_setOperation (tCrusher* const, float op);
283  void tCrusher_setQuality (tCrusher* const, float val);
284  void tCrusher_setRound (tCrusher* const, float rnd);
285  void tCrusher_setSamplingRatio (tCrusher* const, float ratio);
286 
287  //==============================================================================
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif // LEAF_DISTORTION_H_INCLUDED
294 
295 //==============================================================================
296 
297 
tSampleReducer_init
void tSampleReducer_init(tSampleReducer *const, LEAF *const leaf)
Initialize a tSampleReducer to the default mempool of a LEAF instance.
Definition: leaf-distortion.c:25
tLockhartWavefolder_initToPool
void tLockhartWavefolder_initToPool(tLockhartWavefolder *const, tMempool *const)
Initialize a tLockhartWavefolder to a specified mempool.
Definition: leaf-distortion.c:321
tSampleReducer_initToPool
void tSampleReducer_initToPool(tSampleReducer *const, tMempool *const)
Initialize a tSampleReducer to a specified mempool.
Definition: leaf-distortion.c:30
tLockhartWavefolder_tick
float tLockhartWavefolder_tick(tLockhartWavefolder *const, float samp)
Definition: leaf-distortion.c:462
tOversampler_init
void tOversampler_init(tOversampler *const, int order, int extraQuality, LEAF *const leaf)
Initialize a tOversampler to the default mempool of a LEAF instance.
Definition: leaf-distortion.c:75
tCrusher_setSamplingRatio
void tCrusher_setSamplingRatio(tCrusher *const, float ratio)
Definition: leaf-distortion.c:634
tCrusher_setRound
void tCrusher_setRound(tCrusher *const, float rnd)
Definition: leaf-distortion.c:628
tCrusher_tick
float tCrusher_tick(tCrusher *const, float input)
Definition: leaf-distortion.c:585
tLockhartWavefolder_init
void tLockhartWavefolder_init(tLockhartWavefolder *const, LEAF *const leaf)
Initialize a tLockhartWavefolder to the default mempool of a LEAF instance.
Definition: leaf-distortion.c:316
tCrusher_setOperation
void tCrusher_setOperation(tCrusher *const, float op)
Definition: leaf-distortion.c:609
tSampleReducer_setRatio
void tSampleReducer_setRatio(tSampleReducer *const, float ratio)
Definition: leaf-distortion.c:62
tOversampler_free
void tOversampler_free(tOversampler *const)
Free a tOversampler from its mempool.
Definition: leaf-distortion.c:101
tCrusher_initToPool
void tCrusher_initToPool(tCrusher *const, tMempool *const)
Initialize a tCrusher to a specified mempool.
Definition: leaf-distortion.c:563
tOversampler_downsample
float tOversampler_downsample(tOversampler *const os, float *input)
Definition: leaf-distortion.c:217
tOversampler_upsample
void tOversampler_upsample(tOversampler *const, float input, float *output)
Definition: leaf-distortion.c:124
tOversampler_tick
float tOversampler_tick(tOversampler *const, float input, float *oversample, float(*effectTick)(float))
Definition: leaf-distortion.c:110
tCrusher_free
void tCrusher_free(tCrusher *const)
Free a tCrusher from its mempool.
Definition: leaf-distortion.c:577
tSampleReducer_tick
float tSampleReducer_tick(tSampleReducer *const, float input)
Definition: leaf-distortion.c:48
tCrusher_setQuality
void tCrusher_setQuality(tCrusher *const, float val)
Definition: leaf-distortion.c:616
tOversampler_initToPool
void tOversampler_initToPool(tOversampler *const, int order, int extraQuality, tMempool *const)
Initialize a tOversampler to a specified mempool.
Definition: leaf-distortion.c:80
LEAF
Struct for an instance of LEAF.
Definition: leaf-global.h:31
tOversampler_getLatency
int tOversampler_getLatency(tOversampler *const os)
Definition: leaf-distortion.c:301
tLockhartWavefolder_free
void tLockhartWavefolder_free(tLockhartWavefolder *const)
Free a tLockhartWavefolder from its mempool.
Definition: leaf-distortion.c:366
tCrusher_init
void tCrusher_init(tCrusher *const, LEAF *const leaf)
Initialize a tCrusher to the default mempool of a LEAF instance.
Definition: leaf-distortion.c:558
tSampleReducer_free
void tSampleReducer_free(tSampleReducer *const)
Free a tSampleReducer from its mempool.
Definition: leaf-distortion.c:41