shithub: leaf

Download patch

ref: 8eb793224654456f4a219abb4be6d434bd247c51
parent: 765bd487689586be946653397bcaf6d08cdbd4cc
parent: b8628af4ceadb4749cd557e6bd3057c2639f3c97
author: spiricom <jeff@snyderphonics.com>
date: Sat Jan 25 07:53:27 EST 2020

fixed linear interpolater, added hermite interpolation, fixed issues in formant shifter

binary files a/.DS_Store b/.DS_Store differ
binary files a/LEAF/.DS_Store b/LEAF/.DS_Store differ
--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -75,8 +75,12 @@
     
     void mpool_create (char* memory, size_t size, mpool_t* pool);
     
+<<<<<<< HEAD
     void* mpool_alloc(size_t size, mpool_t* pool);
     void* mpool_allocAndClear(size_t asize, mpool_t* pool);
+=======
+    void *mpool_alloc(size_t size, mpool_t* pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     void mpool_free(void* ptr, mpool_t* pool);
     
     size_t mpool_get_size(mpool_t* pool);
@@ -85,7 +89,10 @@
     void leaf_pool_init(char* memory, size_t size);
     
     void* leaf_alloc(size_t size);
+<<<<<<< HEAD
     void* leaf_allocAndClear(size_t size);
+=======
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     void leaf_free(void* ptr);
     
     size_t leaf_pool_get_size(void);
--- a/LEAF/Src/leaf-analysis.c
+++ b/LEAF/Src/leaf-analysis.c
@@ -254,6 +254,57 @@
     mpool_free(x, m->pool);
 }
 
+void    tEnvPD_initToPool       (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp)
+{
+    _tMempool* m = *mp;
+    _tEnvPD* x = *xpd = (_tEnvPD*) mpool_alloc(sizeof(_tEnvPD), m->pool);
+    
+    int period = hs, npoints = ws;
+    
+    int i;
+    
+    if (npoints < 1) npoints = 1024;
+    if (period < 1) period = npoints/2;
+    if (period < npoints / MAXOVERLAP + 1)
+        period = npoints / MAXOVERLAP + 1;
+    
+    x->x_npoints = npoints;
+    x->x_phase = 0;
+    x->x_period = period;
+    
+    x->windowSize = npoints;
+    x->hopSize = period;
+    x->blockSize = bs;
+    
+    for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0;
+    for (i = 0; i < npoints; i++)
+        x->buf[i] = (1.0f - cosf((2 * PI * i) / npoints))/npoints;
+    for (; i < npoints+INITVSTAKEN; i++) x->buf[i] = 0;
+    
+    x->x_f = 0;
+    
+    x->x_allocforvs = INITVSTAKEN;
+    
+    // ~ ~ ~ dsp ~ ~ ~
+    if (x->x_period % x->blockSize)
+    {
+        x->x_realperiod = x->x_period + x->blockSize - (x->x_period % x->blockSize);
+    }
+    else
+    {
+        x->x_realperiod = x->x_period;
+    }
+    // ~ ~ ~ ~ ~ ~ ~ ~
+}
+
+void    tEnvPD_freeFromPool     (tEnvPD* const xpd, tMempool* const mp)
+{
+    _tMempool* m = *mp;
+    _tEnvPD* x = *xpd;
+    
+    mpool_free(x, m->pool);
+}
+
 float tEnvPD_tick (tEnvPD* const xpd)
 {
     _tEnvPD* x = *xpd;
@@ -505,10 +556,17 @@
     s->minrms = DEFMINRMS;
     s->framesize = SNAC_FRAME_SIZE;
     
+<<<<<<< HEAD
     s->inputbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, m->pool);
     s->processbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2), m->pool);
     s->spectrumbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2), m->pool);
     s->biasbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, m->pool);
+=======
+    s->inputbuf = (float*) mpool_alloc(sizeof(float) * SNAC_FRAME_SIZE, m->pool);
+    s->processbuf = (float*) mpool_alloc(sizeof(float) * (SNAC_FRAME_SIZE * 2), m->pool);
+    s->spectrumbuf = (float*) mpool_alloc(sizeof(float) * (SNAC_FRAME_SIZE / 2), m->pool);
+    s->biasbuf = (float*) mpool_alloc(sizeof(float) * SNAC_FRAME_SIZE, m->pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     
     snac_biasbuf(snac);
     tSNAC_setOverlap(snac, overlaparg);
@@ -841,6 +899,126 @@
 void    tPeriodDetection_init    (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
 {
     _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_allocAndClear(sizeof(_tPeriodDetection));
+    
+    p->inBuffer = in;
+    p->outBuffer = out;
+    p->bufSize = bufSize;
+    p->frameSize = frameSize;
+    p->framesPerBuffer = p->bufSize / p->frameSize;
+    p->curBlock = 1;
+    p->lastBlock = 0;
+    p->index = 0;
+    
+    p->hopSize = DEFHOPSIZE;
+    p->windowSize = DEFWINDOWSIZE;
+    p->fba = FBA;
+    
+    tEnvPD_init(&p->env, p->windowSize, p->hopSize, p->frameSize);
+    
+    tSNAC_init(&p->snac, DEFOVERLAP);
+    
+    p->timeConstant = DEFTIMECONSTANT;
+    p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
+}
+
+void tPeriodDetection_free (tPeriodDetection* const pd)
+{
+    _tPeriodDetection* p = *pd;
+    
+    tEnvPD_free(&p->env);
+    tSNAC_free(&p->snac);
+    leaf_free(p);
+}
+
+void    tPeriodDetection_initToPool  (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize, tMempool* const mp)
+{
+    _tMempool* m = *mp;
+    _tPeriodDetection* p = *pd = (_tPeriodDetection*) mpool_alloc(sizeof(_tPeriodDetection), m->pool);
+    
+    p->inBuffer = in;
+    p->outBuffer = out;
+    p->bufSize = bufSize;
+    p->frameSize = frameSize;
+    p->framesPerBuffer = p->bufSize / p->frameSize;
+    p->curBlock = 1;
+    p->lastBlock = 0;
+    p->index = 0;
+    
+    p->hopSize = DEFHOPSIZE;
+    p->windowSize = DEFWINDOWSIZE;
+    p->fba = FBA;
+    
+    tEnvPD_initToPool(&p->env, p->windowSize, p->hopSize, p->frameSize, mp);
+    
+    tSNAC_initToPool(&p->snac, DEFOVERLAP, mp);
+    
+    p->timeConstant = DEFTIMECONSTANT;
+    p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
+}
+
+void    tPeriodDetection_freeFromPool       (tPeriodDetection* const pd, tMempool* const mp)
+{
+    _tMempool* m = *mp;
+    _tPeriodDetection* p = *pd;
+    
+    tEnvPD_freeFromPool(&p->env, mp);
+    tSNAC_freeFromPool(&p->snac, mp);
+    mpool_free(p, m->pool);
+}
+
+float tPeriodDetection_findPeriod (tPeriodDetection* pd, float sample)
+{
+    _tPeriodDetection* p = *pd;
+    
+    int i, iLast;
+    
+    i = (p->curBlock*p->frameSize);
+    iLast = (p->lastBlock*p->frameSize)+p->index;
+    
+    p->i = i;
+    p->iLast = iLast;
+    
+    p->inBuffer[i+p->index] = sample;
+    
+    p->index++;
+    p->indexstore = p->index;
+    if (p->index >= p->frameSize)
+    {
+        p->index = 0;
+        
+        tEnvPD_processBlock(&p->env, &(p->inBuffer[i]));
+        
+        tSNAC_ioSamples(&p->snac, &(p->inBuffer[i]), &(p->outBuffer[i]), p->frameSize);
+        p->period = tSNAC_getPeriod(&p->snac);
+        
+        p->curBlock++;
+        if (p->curBlock >= p->framesPerBuffer) p->curBlock = 0;
+        p->lastBlock++;
+        if (p->lastBlock >= p->framesPerBuffer) p->lastBlock = 0;
+    }
+    
+    // changed from period to p->period
+    return p->period;
+}
+
+void tPeriodDetection_setHopSize(tPeriodDetection* pd, int hs)
+{
+    _tPeriodDetection* p = *pd;
+    p->hopSize = hs;
+}
+
+void tPeriodDetection_setWindowSize(tPeriodDetection* pd, int ws)
+{
+    _tPeriodDetection* p = *pd;
+    p->windowSize = ws;
+}
+
+//===========================================================================
+// PERIODDETECTION
+//===========================================================================
+void    tPeriodDetection_init    (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
+{
+    _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_alloc(sizeof(_tPeriodDetection));
     
     p->inBuffer = in;
     p->outBuffer = out;
--- a/LEAF/Src/leaf-delay.c
+++ b/LEAF/Src/leaf-delay.c
@@ -241,6 +241,7 @@
     mpool_free(d, m->pool);
 }
 
+<<<<<<< HEAD
 
 void    tLinearDelay_clear(tLinearDelay* const dl)
 {
@@ -253,6 +254,8 @@
 
 }
 
+=======
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
 float   tLinearDelay_tick (tLinearDelay* const dl, float input)
 {
     _tLinearDelay* d = *dl;
--- a/LEAF/Src/leaf-effects.c
+++ b/LEAF/Src/leaf-effects.c
@@ -506,10 +506,17 @@
 // init
 void     tSOLAD_init(tSOLAD* const wp)
 {
+<<<<<<< HEAD
     _tSOLAD* w = *wp = (_tSOLAD*) leaf_allocAndClear(sizeof(_tSOLAD));
     
     w->pitchfactor = 1.;
     w->delaybuf = (float*) leaf_allocAndClear(sizeof(float) * (LOOPSIZE+16));
+=======
+    _tSOLAD* w = *wp = (_tSOLAD*) leaf_alloc(sizeof(_tSOLAD));
+    
+    w->pitchfactor = 1.;
+    w->delaybuf = (float*) leaf_alloc(sizeof(float) * (LOOPSIZE+16));
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     solad_init(w);
 }
 
@@ -524,10 +531,17 @@
 void    tSOLAD_initToPool       (tSOLAD* const wp, tMempool* const mp)
 {
     _tMempool* m = *mp;
+<<<<<<< HEAD
     _tSOLAD* w = *wp = (_tSOLAD*) mpool_allocAndClear(sizeof(_tSOLAD), m->pool);
     
     w->pitchfactor = 1.;
     w->delaybuf = (float*) mpool_allocAndClear(sizeof(float) * (LOOPSIZE+16), m->pool);
+=======
+    _tSOLAD* w = *wp = (_tSOLAD*) mpool_alloc(sizeof(_tSOLAD), m->pool);
+    
+    w->pitchfactor = 1.;
+    w->delaybuf = (float*) mpool_alloc(sizeof(float) * (LOOPSIZE+16), m->pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     solad_init(w);
 }
 
@@ -905,7 +919,11 @@
 void    tPitchShift_initToPool      (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp)
 {
     _tMempool* m = *mp;
+<<<<<<< HEAD
     _tPitchShift* ps = *psr = (_tPitchShift*) mpool_allocAndClear(sizeof(_tPitchShift), m->pool);
+=======
+    _tPitchShift* ps = *psr = (_tPitchShift*) mpool_alloc(sizeof(_tPitchShift), m->pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     _tPeriodDetection* p = *pd;
     
     ps->p = pd;
@@ -1055,14 +1073,23 @@
 
 void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize)
 {
+<<<<<<< HEAD
     _tRetune* r = *rt = (_tRetune*) leaf_allocAndClear(sizeof(_tRetune));
+=======
+    _tRetune* r = *rt = (_tRetune*) leaf_alloc(sizeof(_tRetune));
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     
     r->bufSize = bufSize;
     r->frameSize = frameSize;
     r->numVoices = numVoices;
     
+<<<<<<< HEAD
     r->inBuffer = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize);
     r->outBuffers = (float**) leaf_allocAndClear(sizeof(float*) * r->numVoices);
+=======
+    r->inBuffer = (float*) leaf_alloc(sizeof(float) * r->bufSize);
+    r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     
     r->hopSize = DEFHOPSIZE;
     r->windowSize = DEFWINDOWSIZE;
@@ -1071,6 +1098,7 @@
     
     r->inputPeriod = 0.0f;
     
+<<<<<<< HEAD
     r->ps = (tPitchShift*) leaf_allocAndClear(sizeof(tPitchShift) * r->numVoices);
     r->pitchFactor = (float*) leaf_allocAndClear(sizeof(float) * r->numVoices);
     r->tickOutput = (float*) leaf_allocAndClear(sizeof(float) * r->numVoices);
@@ -1077,6 +1105,14 @@
     for (int i = 0; i < r->numVoices; ++i)
     {
         r->outBuffers[i] = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize);
+=======
+    r->ps = (tPitchShift*) leaf_alloc(sizeof(tPitchShift) * r->numVoices);
+    r->pitchFactor = (float*) leaf_alloc(sizeof(float) * r->numVoices);
+    r->tickOutput = (float*) leaf_alloc(sizeof(float) * r->numVoices);
+    for (int i = 0; i < r->numVoices; ++i)
+    {
+        r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     }
     
     tPeriodDetection_init(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize);
@@ -1114,8 +1150,13 @@
     r->frameSize = frameSize;
     r->numVoices = numVoices;
     
+<<<<<<< HEAD
     r->inBuffer = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, m->pool);
     r->outBuffers = (float**) mpool_allocAndClear(sizeof(float*) * r->numVoices, m->pool);
+=======
+    r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, m->pool);
+    r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, m->pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     
     r->hopSize = DEFHOPSIZE;
     r->windowSize = DEFWINDOWSIZE;
@@ -1124,6 +1165,7 @@
     
     r->inputPeriod = 0.0f;
     
+<<<<<<< HEAD
     r->ps = (tPitchShift*) mpool_allocAndClear(sizeof(tPitchShift) * r->numVoices, m->pool);
     r->pitchFactor = (float*) mpool_allocAndClear(sizeof(float) * r->numVoices, m->pool);
     r->tickOutput = (float*) mpool_allocAndClear(sizeof(float) * r->numVoices, m->pool);
@@ -1130,6 +1172,14 @@
     for (int i = 0; i < r->numVoices; ++i)
     {
         r->outBuffers[i] = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, m->pool);
+=======
+    r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, m->pool);
+    r->pitchFactor = (float*) mpool_alloc(sizeof(float) * r->numVoices, m->pool);
+    r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, m->pool);
+    for (int i = 0; i < r->numVoices; ++i)
+    {
+        r->outBuffers[i] = (float*) mpool_alloc(sizeof(float) * r->bufSize, m->pool);
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     }
     
     tPeriodDetection_initToPool(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize, mp);
@@ -1287,6 +1337,7 @@
     for (int i = 0; i < r->numVoices; ++i)
     {
         r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize);
+<<<<<<< HEAD
     }
     
     tPeriodDetection_init(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize);
@@ -1296,6 +1347,17 @@
         tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize);
     }
     
+=======
+    }
+    
+    tPeriodDetection_init(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize);
+    
+    for (int i = 0; i < r->numVoices; ++i)
+    {
+        tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize);
+    }
+    
+>>>>>>> b8628af4ceadb4749cd557e6bd3057c2639f3c97
     r->inputPeriod = 0.0f;
 }
 
--- a/LEAF_JUCEPlugin/Source/PluginProcessor.cpp
+++ b/LEAF_JUCEPlugin/Source/PluginProcessor.cpp
@@ -57,8 +57,8 @@
 
 void OopsAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
 {
-    const int totalNumInputChannels  = getTotalNumInputChannels();
-    const int totalNumOutputChannels = getTotalNumOutputChannels();
+   const int totalNumInputChannels  = getTotalNumInputChannels();
+   const int totalNumOutputChannels = getTotalNumOutputChannels();
     
     for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
         buffer.clear (i, 0, buffer.getNumSamples());
@@ -88,8 +88,8 @@
     }
     
 
-    const float* inPointerL = buffer.getReadPointer (0);
-    const float* inPointerR = buffer.getReadPointer (1);
+   const float* inPointerL = buffer.getReadPointer (0);
+   const float* inPointerR = buffer.getReadPointer (1);
     
     float* outPointerL = buffer.getWritePointer( 0);
     float* outPointerR = buffer.getWritePointer( 1);
--- a/LEAF_JUCEPlugin/Source/PluginProcessor.h
+++ b/LEAF_JUCEPlugin/Source/PluginProcessor.h
@@ -39,7 +39,7 @@
     bool hasEditor() const override;
 
     //==============================================================================
-    const String getName() const override;
+   const String getName() const override;
 
     bool acceptsMidi() const override;
     bool producesMidi() const override;
@@ -49,7 +49,7 @@
     int getNumPrograms() override;
     int getCurrentProgram() override;
     void setCurrentProgram (int index) override;
-    const String getProgramName (int index) override;
+   const String getProgramName (int index) override;
     void changeProgramName (int index, const String& newName) override;
 
     //==============================================================================