leaf-delay.h
1 /*==============================================================================
2 
3  leaf-delay.h
4  Created: 20 Jan 2017 12:01:24pm
5  Author: Michael R Mulshine
6 
7  ==============================================================================*/
8 
9 #ifndef LEAF_DELAY_H_INCLUDED
10 #define LEAF_DELAY_H_INCLUDED
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16  //==============================================================================
17 
18 #include "leaf-math.h"
19 #include "leaf-mempool.h"
20 
29  //==============================================================================
30 
106  typedef struct _tDelay
107  {
108  tMempool mempool;
109 
110  float gain;
111  float* buff;
112 
113  float lastOut, lastIn;
114 
115  uint32_t inPoint, outPoint;
116 
117  uint32_t delay, maxDelay;
118 
119  } _tDelay;
120 
121  typedef _tDelay* tDelay;
122 
123  void tDelay_init (tDelay* const, uint32_t delay, uint32_t maxDelay, LEAF* const leaf);
124  void tDelay_initToPool (tDelay* const, uint32_t delay, uint32_t maxDelay, tMempool* const);
125  void tDelay_free (tDelay* const);
126 
127  void tDelay_clear (tDelay* const);
128  void tDelay_setDelay (tDelay* const, uint32_t delay);
129  uint32_t tDelay_getDelay (tDelay* const);
130  void tDelay_tapIn (tDelay* const, float in, uint32_t tapDelay);
131  float tDelay_tapOut (tDelay* const, uint32_t tapDelay);
132  float tDelay_addTo (tDelay* const, float value, uint32_t tapDelay);
133  float tDelay_tick (tDelay* const, float sample);
134  float tDelay_getLastOut (tDelay* const);
135  float tDelay_getLastIn (tDelay* const);
136 
137  //==============================================================================
138 
224  typedef struct _tLinearDelay
225  {
226  tMempool mempool;
227 
228  float gain;
229  float* buff;
230 
231  float lastOut, lastIn;
232 
233  uint32_t inPoint, outPoint;
234 
235  uint32_t maxDelay;
236 
237  float delay;
238 
239  float alpha, omAlpha;
240 
241  } _tLinearDelay;
242 
243  typedef _tLinearDelay* tLinearDelay;
244 
245  void tLinearDelay_init (tLinearDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
246  void tLinearDelay_initToPool (tLinearDelay* const, float delay, uint32_t maxDelay, tMempool* const);
247  void tLinearDelay_free (tLinearDelay* const);
248 
249  void tLinearDelay_clear (tLinearDelay* const dl);
250  void tLinearDelay_setDelay (tLinearDelay* const, float delay);
251  float tLinearDelay_getDelay (tLinearDelay* const);
252  void tLinearDelay_tapIn (tLinearDelay* const, float in, uint32_t tapDelay);
253  float tLinearDelay_tapOut (tLinearDelay* const, uint32_t tapDelay);
254  float tLinearDelay_addTo (tLinearDelay* const, float value, uint32_t tapDelay);
255  float tLinearDelay_tick (tLinearDelay* const, float sample);
256  void tLinearDelay_tickIn (tLinearDelay* const, float input);
257  float tLinearDelay_tickOut (tLinearDelay* const);
258  float tLinearDelay_getLastOut (tLinearDelay* const);
259  float tLinearDelay_getLastIn (tLinearDelay* const);
260 
261 
262 
263  //==============================================================================
264 
360  typedef struct _tHermiteDelay
361  {
362  tMempool mempool;
363 
364  float gain;
365  float* buff;
366 
367  float lastOut, lastIn;
368 
369  uint32_t inPoint, outPoint;
370 
371  uint32_t maxDelay;
372 
373  float delay;
374 
375  float alpha, omAlpha;
376  } _tHermiteDelay;
377 
378  typedef _tHermiteDelay* tHermiteDelay;
379 
380  void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf);
381  void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp);
382  void tHermiteDelay_free (tHermiteDelay* const dl);
383 
384  void tHermiteDelay_clear (tHermiteDelay* const dl);
385  float tHermiteDelay_tick (tHermiteDelay* const dl, float input);
386  void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input);
387  float tHermiteDelay_tickOut (tHermiteDelay* const dl);
388  void tHermiteDelay_setDelay (tHermiteDelay* const dl, float delay);
389  float tHermiteDelay_tapOut (tHermiteDelay* const dl, uint32_t tapDelay);
390  void tHermiteDelay_tapIn (tHermiteDelay* const dl, float value, uint32_t tapDelay);
391  float tHermiteDelay_addTo (tHermiteDelay* const dl, float value, uint32_t tapDelay);
392  float tHermiteDelay_getDelay (tHermiteDelay* const dl);
393  float tHermiteDelay_getLastOut (tHermiteDelay* const dl);
394  float tHermiteDelay_getLastIn (tHermiteDelay* const dl);
395  void tHermiteDelay_setGain (tHermiteDelay* const dl, float gain);
396  float tHermiteDelay_getGain (tHermiteDelay* const dl);
397 
398 
399  //==============================================================================
400 
476  typedef struct _tAllpassDelay
477  {
478  tMempool mempool;
479 
480  float gain;
481  float* buff;
482 
483  float lastOut, lastIn;
484 
485  uint32_t inPoint, outPoint;
486 
487  uint32_t maxDelay;
488 
489  float delay;
490 
491  float alpha, omAlpha, coeff;
492 
493  float apInput;
494 
495  } _tAllpassDelay;
496 
497  typedef _tAllpassDelay* tAllpassDelay;
498 
499  void tAllpassDelay_init (tAllpassDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
500  void tAllpassDelay_initToPool (tAllpassDelay* const, float delay, uint32_t maxDelay, tMempool* const);
501  void tAllpassDelay_free (tAllpassDelay* const);
502 
503  void tAllpassDelay_clear (tAllpassDelay* const);
504  void tAllpassDelay_setDelay (tAllpassDelay* const, float delay);
505  float tAllpassDelay_getDelay (tAllpassDelay* const);
506  void tAllpassDelay_tapIn (tAllpassDelay* const, float in, uint32_t tapDelay);
507  float tAllpassDelay_tapOut (tAllpassDelay* const, uint32_t tapDelay);
508  float tAllpassDelay_addTo (tAllpassDelay* const, float value, uint32_t tapDelay);
509  float tAllpassDelay_tick (tAllpassDelay* const, float sample);
510  float tAllpassDelay_getLastOut (tAllpassDelay* const);
511  float tAllpassDelay_getLastIn (tAllpassDelay* const);
512 
513  //==============================================================================
514 
594  typedef struct _tTapeDelay
595  {
596  tMempool mempool;
597 
598  float gain;
599  float* buff;
600 
601  float lastOut, lastIn;
602 
603  uint32_t inPoint;
604 
605  uint32_t maxDelay;
606 
607  float delay, inc, idx;
608 
609  float apInput;
610 
611  } _tTapeDelay;
612 
613  typedef _tTapeDelay* tTapeDelay;
614 
615  void tTapeDelay_init (tTapeDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
616  void tTapeDelay_initToPool (tTapeDelay* const, float delay, uint32_t maxDelay, tMempool* const);
617  void tTapeDelay_free (tTapeDelay* const);
618 
619  void tTapeDelay_clear (tTapeDelay* const);
620  void tTapeDelay_setDelay (tTapeDelay* const, float delay);
621  float tTapeDelay_getDelay (tTapeDelay* const);
622  void tTapeDelay_tapIn (tTapeDelay* const, float in, uint32_t tapDelay);
623  float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay);
624  float tTapeDelay_addTo (tTapeDelay* const, float value, uint32_t tapDelay);
625  float tTapeDelay_tick (tTapeDelay* const, float sample);
626  void tTapeDelay_incrementInPoint(tTapeDelay* const dl);
627  float tTapeDelay_getLastOut (tTapeDelay* const);
628  float tTapeDelay_getLastIn (tTapeDelay* const);
629 
630  //==============================================================================
631 
681  typedef struct _tRingBuffer
682  {
683 
684  tMempool mempool;
685 
686  float* buffer;
687  unsigned int size;
688  unsigned int pos;
689  unsigned int mask;
690  } _tRingBuffer;
691 
692  typedef _tRingBuffer* tRingBuffer;
693 
694  void tRingBuffer_init (tRingBuffer* const ring, int size, LEAF* const leaf);
695  void tRingBuffer_initToPool (tRingBuffer* const ring, int size, tMempool* const mempool);
696  void tRingBuffer_free (tRingBuffer* const ring);
697 
698  void tRingBuffer_push (tRingBuffer* const ring, float val);
699  float tRingBuffer_getNewest (tRingBuffer* const ring);
700  float tRingBuffer_getOldest (tRingBuffer* const ring);
701  float tRingBuffer_get (tRingBuffer* const ring, int index);
702  int tRingBuffer_getSize (tRingBuffer* const ring);
703 
704 #ifdef __cplusplus
705 }
706 #endif
707 
708 #endif // LEAF_DELAY_H_INCLUDED
709 
710 //==============================================================================
711 
712 
tAllpassDelay_setDelay
void tAllpassDelay_setDelay(tAllpassDelay *const, float delay)
Definition: leaf-delay.c:619
tAllpassDelay_clear
void tAllpassDelay_clear(tAllpassDelay *const)
Definition: leaf-delay.c:587
tHermiteDelay_getDelay
float tHermiteDelay_getDelay(tHermiteDelay *const dl)
Definition: leaf-delay.c:511
tAllpassDelay_tapIn
void tAllpassDelay_tapIn(tAllpassDelay *const, float in, uint32_t tapDelay)
Definition: leaf-delay.c:664
tDelay_init
void tDelay_init(tDelay *const, uint32_t delay, uint32_t maxDelay, LEAF *const leaf)
Initialize a tDelay to the default mempool of a LEAF instance.
Definition: leaf-delay.c:22
tHermiteDelay_tickOut
float tHermiteDelay_tickOut(tHermiteDelay *const dl)
Definition: leaf-delay.c:435
tLinearDelay_addTo
float tLinearDelay_addTo(tLinearDelay *const, float value, uint32_t tapDelay)
Definition: leaf-delay.c:305
tHermiteDelay_setDelay
void tHermiteDelay_setDelay(tHermiteDelay *const dl, float delay)
Definition: leaf-delay.c:455
tAllpassDelay_tapOut
float tAllpassDelay_tapOut(tAllpassDelay *const, uint32_t tapDelay)
Definition: leaf-delay.c:651
tAllpassDelay_init
void tAllpassDelay_init(tAllpassDelay *const, float delay, uint32_t maxDelay, LEAF *const leaf)
Initialize a tAllpassDelay to the default mempool of a LEAF instance.
Definition: leaf-delay.c:547
tDelay_initToPool
void tDelay_initToPool(tDelay *const, uint32_t delay, uint32_t maxDelay, tMempool *const)
Initialize a tDelay to a specified mempool.
Definition: leaf-delay.c:27
tLinearDelay_clear
void tLinearDelay_clear(tLinearDelay *const dl)
Definition: leaf-delay.c:201
tHermiteDelay_tapOut
float tHermiteDelay_tapOut(tHermiteDelay *const dl, uint32_t tapDelay)
Definition: leaf-delay.c:474
tLinearDelay_tick
float tLinearDelay_tick(tLinearDelay *const, float sample)
Definition: leaf-delay.c:210
tRingBuffer_free
void tRingBuffer_free(tRingBuffer *const ring)
Free a tRingBuffer from its mempool.
Definition: leaf-delay.c:918
tHermiteDelay_getGain
float tHermiteDelay_getGain(tHermiteDelay *const dl)
Definition: leaf-delay.c:536
tHermiteDelay_init
void tHermiteDelay_init(tHermiteDelay *const dl, float delay, uint32_t maxDelay, LEAF *const leaf)
Initialize a tHermiteDelay to the default mempool of a LEAF instance.
Definition: leaf-delay.c:354
tLinearDelay_free
void tLinearDelay_free(tLinearDelay *const)
Free a tLinearDelay from its mempool.
Definition: leaf-delay.c:193
tTapeDelay_setDelay
void tTapeDelay_setDelay(tTapeDelay *const, float delay)
Definition: leaf-delay.c:812
tHermiteDelay_tickIn
void tHermiteDelay_tickIn(tHermiteDelay *const dl, float input)
Definition: leaf-delay.c:425
tTapeDelay_getLastIn
float tTapeDelay_getLastIn(tTapeDelay *const)
Definition: leaf-delay.c:877
tRingBuffer_getOldest
float tRingBuffer_getOldest(tRingBuffer *const ring)
Get the oldest value in the ring buffer.
Definition: leaf-delay.c:942
tRingBuffer_getSize
int tRingBuffer_getSize(tRingBuffer *const ring)
Get the size of the ring buffer.
Definition: leaf-delay.c:956
tDelay_addTo
float tDelay_addTo(tDelay *const, float value, uint32_t tapDelay)
Definition: leaf-delay.c:119
tHermiteDelay_initToPool
void tHermiteDelay_initToPool(tHermiteDelay *const dl, float delay, uint32_t maxDelay, tMempool *const mp)
Initialize a tHermiteDelay to a specified mempool.
Definition: leaf-delay.c:359
tRingBuffer_getNewest
float tRingBuffer_getNewest(tRingBuffer *const ring)
Get the newest value in the ring buffer.
Definition: leaf-delay.c:935
tTapeDelay_incrementInPoint
void tTapeDelay_incrementInPoint(tTapeDelay *const dl)
Definition: leaf-delay.c:798
tLinearDelay_getLastIn
float tLinearDelay_getLastIn(tLinearDelay *const)
Definition: leaf-delay.c:329
tTapeDelay_getDelay
float tTapeDelay_getDelay(tTapeDelay *const)
Definition: leaf-delay.c:865
tHermiteDelay_addTo
float tHermiteDelay_addTo(tHermiteDelay *const dl, float value, uint32_t tapDelay)
Definition: leaf-delay.c:499
tLinearDelay_setDelay
void tLinearDelay_setDelay(tLinearDelay *const, float delay)
Definition: leaf-delay.c:263
tLinearDelay_tapIn
void tLinearDelay_tapIn(tLinearDelay *const, float in, uint32_t tapDelay)
Definition: leaf-delay.c:293
tTapeDelay_init
void tTapeDelay_init(tTapeDelay *const, float delay, uint32_t maxDelay, LEAF *const leaf)
Initialize a tTapeDelay to the default mempool of a LEAF instance.
Definition: leaf-delay.c:720
tLinearDelay_init
void tLinearDelay_init(tLinearDelay *const, float delay, uint32_t maxDelay, LEAF *const leaf)
Initialize a tLinearDelay to the default mempool of a LEAF instance.
Definition: leaf-delay.c:163
tTapeDelay_free
void tTapeDelay_free(tTapeDelay *const)
Free a tTapeDelay from its mempool.
Definition: leaf-delay.c:747
tTapeDelay_clear
void tTapeDelay_clear(tTapeDelay *const)
Definition: leaf-delay.c:755
tTapeDelay_tapIn
void tTapeDelay_tapIn(tTapeDelay *const, float in, uint32_t tapDelay)
Definition: leaf-delay.c:841
tTapeDelay_addTo
float tTapeDelay_addTo(tTapeDelay *const, float value, uint32_t tapDelay)
Definition: leaf-delay.c:853
tHermiteDelay_clear
void tHermiteDelay_clear(tHermiteDelay *const dl)
Definition: leaf-delay.c:393
tLinearDelay_getDelay
float tLinearDelay_getDelay(tLinearDelay *const)
Definition: leaf-delay.c:317
tHermiteDelay_tick
float tHermiteDelay_tick(tHermiteDelay *const dl, float input)
Definition: leaf-delay.c:402
tDelay_getLastIn
float tDelay_getLastIn(tDelay *const)
Definition: leaf-delay.c:143
tDelay_tick
float tDelay_tick(tDelay *const, float sample)
Definition: leaf-delay.c:67
tDelay_getLastOut
float tDelay_getLastOut(tDelay *const)
Definition: leaf-delay.c:137
tDelay_free
void tDelay_free(tDelay *const)
Free a tDelay from its mempool.
Definition: leaf-delay.c:50
tDelay_clear
void tDelay_clear(tDelay *const)
Definition: leaf-delay.c:58
tRingBuffer_init
void tRingBuffer_init(tRingBuffer *const ring, int size, LEAF *const leaf)
Initialize a tRingBuffer to the default mempool of a LEAF instance.
Definition: leaf-delay.c:898
tAllpassDelay_getLastIn
float tAllpassDelay_getLastIn(tAllpassDelay *const)
Definition: leaf-delay.c:700
tAllpassDelay_getLastOut
float tAllpassDelay_getLastOut(tAllpassDelay *const)
Definition: leaf-delay.c:694
tDelay_tapOut
float tDelay_tapOut(tDelay *const, uint32_t tapDelay)
Definition: leaf-delay.c:94
tLinearDelay_tickIn
void tLinearDelay_tickIn(tLinearDelay *const, float input)
Definition: leaf-delay.c:234
tAllpassDelay_free
void tAllpassDelay_free(tAllpassDelay *const)
Free a tAllpassDelay from its mempool.
Definition: leaf-delay.c:579
tTapeDelay_getLastOut
float tTapeDelay_getLastOut(tTapeDelay *const)
Definition: leaf-delay.c:871
tTapeDelay_tapOut
float tTapeDelay_tapOut(tTapeDelay *const d, float tapDelay)
Definition: leaf-delay.c:818
tLinearDelay_tickOut
float tLinearDelay_tickOut(tLinearDelay *const)
Definition: leaf-delay.c:244
tHermiteDelay_getLastOut
float tHermiteDelay_getLastOut(tHermiteDelay *const dl)
Definition: leaf-delay.c:517
tLinearDelay_initToPool
void tLinearDelay_initToPool(tLinearDelay *const, float delay, uint32_t maxDelay, tMempool *const)
Initialize a tLinearDelay to a specified mempool.
Definition: leaf-delay.c:168
tAllpassDelay_tick
float tAllpassDelay_tick(tAllpassDelay *const, float sample)
Definition: leaf-delay.c:596
tHermiteDelay_free
void tHermiteDelay_free(tHermiteDelay *const dl)
Free a tHermiteDelay from its mempool.
Definition: leaf-delay.c:384
tTapeDelay_tick
float tTapeDelay_tick(tTapeDelay *const, float sample)
Definition: leaf-delay.c:766
tAllpassDelay_getDelay
float tAllpassDelay_getDelay(tAllpassDelay *const)
Definition: leaf-delay.c:688
tHermiteDelay_tapIn
void tHermiteDelay_tapIn(tHermiteDelay *const dl, float value, uint32_t tapDelay)
Definition: leaf-delay.c:487
tDelay_getDelay
uint32_t tDelay_getDelay(tDelay *const)
Definition: leaf-delay.c:131
tHermiteDelay_getLastIn
float tHermiteDelay_getLastIn(tHermiteDelay *const dl)
Definition: leaf-delay.c:523
tLinearDelay_tapOut
float tLinearDelay_tapOut(tLinearDelay *const, uint32_t tapDelay)
Definition: leaf-delay.c:282
tRingBuffer_get
float tRingBuffer_get(tRingBuffer *const ring, int index)
Get the value at an index of the buffer.
Definition: leaf-delay.c:949
LEAF
Struct for an instance of LEAF.
Definition: leaf-global.h:31
tDelay_tapIn
void tDelay_tapIn(tDelay *const, float in, uint32_t tapDelay)
Definition: leaf-delay.c:107
tLinearDelay_getLastOut
float tLinearDelay_getLastOut(tLinearDelay *const)
Definition: leaf-delay.c:323
tAllpassDelay_initToPool
void tAllpassDelay_initToPool(tAllpassDelay *const, float delay, uint32_t maxDelay, tMempool *const)
Initialize a tAllpassDelay to a specified mempool.
Definition: leaf-delay.c:552
tRingBuffer_push
void tRingBuffer_push(tRingBuffer *const ring, float val)
Push a value to the ring buffer, overwriting the oldest value if the buffer is full.
Definition: leaf-delay.c:926
tTapeDelay_initToPool
void tTapeDelay_initToPool(tTapeDelay *const, float delay, uint32_t maxDelay, tMempool *const)
Initialize a tTapeDelay to a specified mempool.
Definition: leaf-delay.c:725
tRingBuffer_initToPool
void tRingBuffer_initToPool(tRingBuffer *const ring, int size, tMempool *const mempool)
Initialize a tRingBuffer to a specified mempool.
Definition: leaf-delay.c:903
tAllpassDelay_addTo
float tAllpassDelay_addTo(tAllpassDelay *const, float value, uint32_t tapDelay)
Definition: leaf-delay.c:676
tDelay_setDelay
void tDelay_setDelay(tDelay *const, uint32_t delay)
Definition: leaf-delay.c:83
tHermiteDelay_setGain
void tHermiteDelay_setGain(tHermiteDelay *const dl, float gain)
Definition: leaf-delay.c:529