shithub: leaf

Download patch

ref: 8ab6a52fdfc58365c123dbab858f2d81f1b737c6
parent: ee1acb645d0683b97bbd1f65a2e708a8aadea34d
author: Matthew Wang <Matthew@nat-oitwireless-inside-vapornet100-10-9-53-29.princeton.edu>
date: Thu Dec 12 07:30:27 EST 2019

revert internal oscillator structure to not place struct in mempool due to performance issues on vocodec (probably due to tables being in another memory region)

--- a/LEAF/Inc/leaf-oscillators.h
+++ b/LEAF/Inc/leaf-oscillators.h
@@ -1,9 +1,7 @@
 /*==============================================================================
- 
  leaf-oscillators.h
  Created: 20 Jan 2017 12:00:58pm
  Author:  Michael R Mulshine
- 
  ==============================================================================*/
 
 #ifndef LEAF_OSCILLATORS_H_INCLUDED
@@ -27,15 +25,13 @@
         float phase;
         float inc,freq;
         
-    } _tCycle;
+    } tCycle;
     
-    typedef _tCycle* tCycle;
-    
     void        tCycle_init         (tCycle*  const);
     void        tCycle_free         (tCycle*  const);
     
     float       tCycle_tick         (tCycle*  const);
-    void         tCycle_setFreq      (tCycle*  const, float freq);
+    int         tCycle_setFreq      (tCycle*  const, float freq);
     
     //==============================================================================
     
@@ -46,10 +42,8 @@
         float phase;
         float inc,freq;
         
-    } _tTriangle;
+    } tTriangle;
     
-    typedef _tTriangle* tTriangle;
-    
     void        tTriangle_init      (tTriangle*  const);
     void        tTriangle_free      (tTriangle*  const);
     
@@ -65,10 +59,8 @@
         float phase;
         float inc,freq;
         
-    } _tSquare;
+    } tSquare;
     
-    typedef _tSquare* tSquare;
-    
     void        tSquare_init        (tSquare*  const);
     void        tSquare_free        (tSquare*  const);
     
@@ -84,10 +76,8 @@
         float phase;
         float inc,freq;
         
-    } _tSawtooth;
+    } tSawtooth;
     
-    typedef _tSawtooth* tSawtooth;
-    
     void        tSawtooth_init      (tSawtooth*  const);
     void        tSawtooth_free      (tSawtooth*  const);
     
@@ -102,10 +92,8 @@
         float phase;
         float inc,freq;
         
-    } _tPhasor;
+    } tPhasor;
     
-    typedef _tPhasor* tPhasor;
-    
     void        tPhasor_init        (tPhasor*  const);
     void        tPhasor_free        (tPhasor*  const);
     
@@ -128,10 +116,8 @@
         float pinkb0, pinkb1, pinkb2;
         float(*rand)(void);
         
-    } _tNoise;
+    } tNoise;
     
-    typedef _tNoise* tNoise;
-    
     void        tNoise_init          (tNoise* const, NoiseType type);
     void        tNoise_free          (tNoise* const);
     
@@ -163,10 +149,8 @@
         float V[3];
         float P[3];
         float gK, gN, gL, C;
-    } _tNeuron;
+    } tNeuron;
     
-    typedef _tNeuron* tNeuron;
-    
     void        tNeuron_init        (tNeuron* const);
     void        tNeuron_free        (tNeuron* const);
     
@@ -192,4 +176,3 @@
 #endif  // LEAF_OSCILLATORS_H_INCLUDED
 
 //==============================================================================
-
--- a/LEAF/Src/leaf-oscillators.c
+++ b/LEAF/Src/leaf-oscillators.c
@@ -1,11 +1,9 @@
 /*==============================================================================
+ leaf-oscillators.c
+ Created: 20 Jan 2017 12:00:58pm
+ Author:  Michael R Mulshine
+ ==============================================================================*/
 
-    leaf-oscillators.c
-    Created: 20 Jan 2017 12:00:58pm
-    Author:  Michael R Mulshine
-
-==============================================================================*/
-
 #if _WIN32 || _WIN64
 
 #include "..\Inc\leaf-tables.h"
@@ -21,34 +19,29 @@
 #endif
 
 // Cycle
-void    tCycle_init(tCycle* const cy)
+void    tCycle_init(tCycle* const c)
 {
-    _tCycle* c = *cy = (_tCycle*) leaf_alloc(sizeof(_tCycle));
-    
     c->inc      =  0.0f;
     c->phase    =  0.0f;
 }
 
-void    tCycle_free(tCycle* const cy)
+void    tCycle_free(tCycle* const c)
 {
-    _tCycle* c = *cy;
-    leaf_free(c);
+    
 }
 
-void     tCycle_setFreq(tCycle* const cy, float freq)
+int     tCycle_setFreq(tCycle* const c, float freq)
 {
-    _tCycle* c = *cy;
-    
     if (freq < 0.0f) freq = 0.0f;
     
     c->freq = freq;
     c->inc = freq * leaf.invSampleRate;
+    
+    return 0;
 }
 
-float   tCycle_tick(tCycle* const cy)
+float   tCycle_tick(tCycle* const c)
 {
-    _tCycle* c = *cy;
-    
     // Phasor increment
     c->phase += c->inc;
     while (c->phase >= 1.0f) c->phase -= 1.0f;
@@ -63,39 +56,31 @@
     return (samp0 + (samp1 - samp0) * fracPart);
 }
 
-void     tCycleSampleRateChanged (tCycle* const cy)
+void     tCycleSampleRateChanged (tCycle* const c)
 {
-    _tCycle* c = *cy;
-    
     c->inc = c->freq * leaf.invSampleRate;
 }
 
 //========================================================================
 /* Triangle */
-void    tTriangle_start(tTriangle* const cy)
+void    tTriangle_start(tTriangle* const c)
 {
     
 }
 
-void   tTriangle_init(tTriangle* const cy)
+void   tTriangle_init(tTriangle* const c)
 {
-    _tTriangle* c = *cy = (_tTriangle*) leaf_alloc(sizeof(_tTriangle));
-    
     c->inc      =  0.0f;
     c->phase    =  0.0f;
 }
 
-void   tTriangle_free(tTriangle* const cy)
+void   tTriangle_free(tTriangle* const c)
 {
-    _tTriangle* c = *cy;
     
-    leaf_free(c);
 }
 
-int tTriangle_setFreq(tTriangle* const cy, float freq)
+int tTriangle_setFreq(tTriangle* const c, float freq)
 {
-    _tTriangle* c = *cy;
-    
     if (freq < 0.0f) freq = 0.0f;
     
     c->freq = freq;
@@ -105,10 +90,8 @@
 }
 
 
-float   tTriangle_tick(tTriangle* const cy)
+float   tTriangle_tick(tTriangle* const c)
 {
-    _tTriangle* c = *cy;
-    
     // Phasor increment
     c->phase += c->inc;
     while (c->phase >= 1.0f) c->phase -= 1.0f;
@@ -182,34 +165,26 @@
     return out;
 }
 
-void     tTriangleSampleRateChanged (tTriangle*  const cy)
+void     tTriangleSampleRateChanged (tTriangle*  const c)
 {
-    _tTriangle* c = *cy;
-    
     c->inc = c->freq * leaf.invSampleRate;
 }
 
 //========================================================================
 /* Square */
-void   tSquare_init(tSquare* const cy)
+void   tSquare_init(tSquare* const c)
 {
-    _tSquare* c = *cy = (_tSquare*) leaf_alloc(sizeof(_tSquare));
-    
     c->inc      =  0.0f;
     c->phase    =  0.0f;
 }
 
-void   tSquare_free(tSquare* const cy)
+void   tSquare_free(tSquare* const c)
 {
-    _tSquare* c = *cy;
     
-    leaf_free(c);
 }
 
-int     tSquare_setFreq(tSquare*  const cy, float freq)
+int     tSquare_setFreq(tSquare*  const c, float freq)
 {
-    _tSquare* c = *cy;
-    
     if (freq < 0.0f) freq = 0.0f;
     
     c->freq = freq;
@@ -218,10 +193,8 @@
     return 0;
 }
 
-float   tSquare_tick(tSquare* const cy)
+float   tSquare_tick(tSquare* const c)
 {
-    _tSquare* c = *cy;
-    
     // Phasor increment
     c->phase += c->inc;
     while (c->phase >= 1.0f) c->phase -= 1.0f;
@@ -294,34 +267,26 @@
     return out;
 }
 
-void     tSquareSampleRateChanged (tSquare*  const cy)
+void     tSquareSampleRateChanged (tSquare*  const c)
 {
-    _tSquare* c = *cy;
-    
     c->inc = c->freq * leaf.invSampleRate;
 }
 
 //=====================================================================
 // Sawtooth
-void    tSawtooth_init(tSawtooth* const cy)
+void    tSawtooth_init(tSawtooth* const c)
 {
-    _tSawtooth* c = *cy = (_tSawtooth*) leaf_alloc(sizeof(_tSawtooth));
-    
     c->inc      = 0.0f;
     c->phase    = 0.0f;
 }
 
-void    tSawtooth_free(tSawtooth* const cy)
+void    tSawtooth_free(tSawtooth* const c)
 {
-    _tSawtooth* c = *cy;
     
-    leaf_free(c);
 }
 
-int     tSawtooth_setFreq(tSawtooth* const cy, float freq)
+int     tSawtooth_setFreq(tSawtooth* const c, float freq)
 {
-    _tSawtooth* c = *cy;
-
     if (freq < 0.0f) freq = 0.0f;
     
     c->freq = freq;
@@ -330,10 +295,8 @@
     return 0;
 }
 
-float   tSawtooth_tick(tSawtooth* const cy)
+float   tSawtooth_tick(tSawtooth* const c)
 {
-    _tSawtooth* c = *cy;
-
     // Phasor increment
     c->phase += c->inc;
     while (c->phase >= 1.0f) c->phase -= 1.0f;
@@ -407,41 +370,31 @@
     return out;
 }
 
-void     tSawtoothSampleRateChanged (tSawtooth* const cy)
+void     tSawtoothSampleRateChanged (tSawtooth* const c)
 {
-    _tSawtooth* c = *cy;
-
     c->inc = c->freq * leaf.invSampleRate;
 }
 
 //========================================================================
 /* Phasor */
-void     tPhasorSampleRateChanged (tPhasor* const ph)
+void     tPhasorSampleRateChanged (tPhasor* const p)
 {
-    _tPhasor* p = *ph;
-    
     p->inc = p->freq * leaf.invSampleRate;
-}
+};
 
-void    tPhasor_init(tPhasor* const ph)
+void    tPhasor_init(tPhasor* const p)
 {
-    _tPhasor* p = *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor));
-    
     p->phase = 0.0f;
     p->inc = 0.0f;
 }
 
-void    tPhasor_free(tPhasor* const ph)
+void    tPhasor_free(tPhasor* const p)
 {
-    _tPhasor* p = *ph;
     
-    leaf_free(p);
 }
 
-int     tPhasor_setFreq(tPhasor* const ph, float freq)
+int     tPhasor_setFreq(tPhasor* const p, float freq)
 {
-    _tPhasor* p = *ph;
-    
     if (freq < 0.0f) freq = 0.0f;
     
     p->freq = freq;
@@ -450,10 +403,8 @@
     return 0;
 }
 
-float   tPhasor_tick(tPhasor* const ph)
+float   tPhasor_tick(tPhasor* const p)
 {
-    _tPhasor* p = *ph;
-    
     p->phase += p->inc;
     
     if (p->phase >= 1.0f) p->phase -= 1.0f;
@@ -462,25 +413,19 @@
 }
 
 /* Noise */
-void    tNoise_init(tNoise* const ns, NoiseType type)
+void    tNoise_init(tNoise* const n, NoiseType type)
 {
-    _tNoise* n = *ns = (_tNoise*) leaf_alloc(sizeof(_tNoise));
-    
     n->type = type;
     n->rand = leaf.random;
 }
 
-void    tNoise_free(tNoise* const ns)
+void    tNoise_free(tNoise* const n)
 {
-    _tNoise* n = *ns;
     
-    leaf_free(n);
 }
 
-float   tNoise_tick(tNoise* const ns)
+float   tNoise_tick(tNoise* const n)
 {
-    _tNoise* n = *ns;
-    
     float rand = (n->rand() * 2.0f) - 1.0f;
     
     if (n->type == PinkNoise)
@@ -501,15 +446,13 @@
 //=================================================================================
 /* Neuron */
 
-void     tNeuronSampleRateChanged(tNeuron* nr)
+void     tNeuronSampleRateChanged(tNeuron* n)
 {
     
 }
 
-void    tNeuron_init(tNeuron* const nr)
+void    tNeuron_init(tNeuron* const n)
 {
-    _tNeuron* n = *nr = (_tNeuron*) leaf_alloc(sizeof(_tNeuron));
-    
     tPoleZero_init(&n->f);
     
     tPoleZero_setBlockZero(&n->f, 0.99f);
@@ -537,17 +480,13 @@
     n->rate[2] = n->gL/n->C;
 }
 
-void    tNeuron_free(tNeuron* const nr)
+void    tNeuron_free(tNeuron* const n)
 {
-    _tNeuron* n = *nr;
-    
     tPoleZero_free(&n->f);
-    leaf_free(n);
 }
 
-void   tNeuron_reset(tNeuron* const nr)
+void   tNeuron_reset(tNeuron* const n)
 {
-    _tNeuron* n = *nr;
     
     tPoleZero_setBlockZero(&n->f, 0.99f);
     
@@ -575,61 +514,51 @@
 }
 
 
-void        tNeuron_setV1(tNeuron* const nr, float V1)
+void        tNeuron_setV1(tNeuron* const n, float V1)
 {
-    _tNeuron* n = *nr;
     n->V[0] = V1;
 }
 
 
-void        tNeuron_setV2(tNeuron* const nr, float V2)
+void        tNeuron_setV2(tNeuron* const n, float V2)
 {
-    _tNeuron* n = *nr;
     n->V[1] = V2;
 }
 
-void        tNeuron_setV3(tNeuron* const nr, float V3)
+void        tNeuron_setV3(tNeuron* const n, float V3)
 {
-    _tNeuron* n = *nr;
     n->V[2] = V3;
 }
 
-void        tNeuron_setTimeStep(tNeuron* const nr, float timeStep)
+void        tNeuron_setTimeStep(tNeuron* const n, float timeStep)
 {
-    _tNeuron* n = *nr;
     n->timeStep = timeStep;
 }
 
-void        tNeuron_setK(tNeuron* const nr, float K)
+void        tNeuron_setK(tNeuron* const n, float K)
 {
-    _tNeuron* n = *nr;
     n->gK = K;
 }
 
-void        tNeuron_setL(tNeuron* const nr, float L)
+void        tNeuron_setL(tNeuron* const n, float L)
 {
-    _tNeuron* n = *nr;
     n->gL = L;
     n->rate[2] = n->gL/n->C;
 }
 
-void        tNeuron_setN(tNeuron* const nr, float N)
+void        tNeuron_setN(tNeuron* const n, float N)
 {
-    _tNeuron* n = *nr;
     n->gN = N;
 }
 
-void        tNeuron_setC(tNeuron* const nr, float C)
+void        tNeuron_setC(tNeuron* const n, float C)
 {
-    _tNeuron* n = *nr;
     n->C = C;
     n->rate[2] = n->gL/n->C;
 }
 
-float   tNeuron_tick(tNeuron* const nr)
+float   tNeuron_tick(tNeuron* const n)
 {
-    _tNeuron* n = *nr;
-    
     float output = 0.0f;
     float voltage = n->voltage;
     
@@ -702,14 +631,12 @@
     
 }
 
-void        tNeuron_setMode  (tNeuron* const nr, NeuronMode mode)
+void        tNeuron_setMode  (tNeuron* const n, NeuronMode mode)
 {
-    _tNeuron* n = *nr;
     n->mode = mode;
 }
 
-void        tNeuron_setCurrent  (tNeuron* const nr, float current)
+void        tNeuron_setCurrent  (tNeuron* const n, float current)
 {
-    _tNeuron* n = *nr;
     n->current = current;
 }