ref: d407705c944d54e7655ae15773af8a2034db048c
parent: 9171062fdeebb30bfe9ef1e5c5c688db55f8aac9
author: Matthew Wang <Matthew@nat-oitwireless-inside-vapornet100-10-9-8-255.princeton.edu>
date: Thu Aug 22 06:39:18 EDT 2019
reduced mempool size and removed variable count
--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -1,5 +1,5 @@
-/*==============================================================================
-
+/*==============================================================================
+
In short, mpool is distributed under so called "BSD license",
Copyright (c) 2009-2010 Tatsuhiko Kubo <cubicdaiya@gmail.com>
@@ -29,32 +29,32 @@
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
written by C99 style
==============================================================================*/
#ifndef LEAF_MPOOL_H_INCLUDED
-#define LEAF_MPOOL_H_INCLUDED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+#define LEAF_MPOOL_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//==============================================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdbool.h>
-
+#include <stdbool.h>
+
//==============================================================================
-
-#define MPOOL_POOL_SIZE 500000
-
-#define MPOOL_ALIGN_SIZE (8)
+#define MPOOL_POOL_SIZE 50000
+
+#define MPOOL_ALIGN_SIZE (8)
+
//#define size_t unsigned long
/**
@@ -92,18 +92,18 @@
size_t leaf_pool_get_size(void);
size_t leaf_pool_get_used(void);
-void* leaf_pool_get_pool(void);
-
-void leaf_mempool_overrun(void);
-
+void* leaf_pool_get_pool(void);
+
+void leaf_mempool_overrun(void);
+
//==============================================================================
-
-#ifdef __cplusplus
-}
+
+#ifdef __cplusplus
+}
#endif
-#endif // LEAF_MPOOL_H
-
+#endif // LEAF_MPOOL_H
+
//==============================================================================
--- a/LEAF/Src/leaf-delay.c
+++ b/LEAF/Src/leaf-delay.c
@@ -61,7 +61,7 @@
int tDelay_setDelay (tDelay* const d, uint32_t delay)
{
- d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
+ d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
// read chases write
@@ -161,15 +161,15 @@
d->buff[d->inPoint] = input * d->gain;
// Increment input pointer modulo length.
- if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
-
-
- uint32_t idx = (uint32_t) d->outPoint;
-
- d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
- d->buff[idx],
- d->buff[(idx + 1) % d->maxDelay],
- d->buff[(idx + 2) % d->maxDelay],
+ if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
+
+
+ uint32_t idx = (uint32_t) d->outPoint;
+
+ d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
+ d->buff[idx],
+ d->buff[(idx + 1) % d->maxDelay],
+ d->buff[(idx + 2) % d->maxDelay],
d->alpha);
// Increment output pointer modulo length
@@ -203,7 +203,7 @@
}
int tDelayL_setDelay (tDelayL* const d, float delay)
-{
+{
d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
float outPointer = d->inPoint - d->delay;
@@ -226,20 +226,20 @@
float tap = (float) d->inPoint - tapDelay - 1.f;
// Check for wraparound.
- while ( tap < 0.f ) tap += (float)d->maxDelay;
-
- float alpha = tap - (int)tap;
- float omAlpha = 1.f - alpha;
-
- int ptx = (int) tap;
-
- // First 1/2 of interpolation
- float samp = d->buff[ptx] * omAlpha;
-
- // Second 1/2 of interpolation
- if ((ptx + 1) < d->maxDelay)
- samp += d->buff[ptx+1] * d->alpha;
- else
+ while ( tap < 0.f ) tap += (float)d->maxDelay;
+
+ float alpha = tap - (int)tap;
+ float omAlpha = 1.f - alpha;
+
+ int ptx = (int) tap;
+
+ // First 1/2 of interpolation
+ float samp = d->buff[ptx] * omAlpha;
+
+ // Second 1/2 of interpolation
+ if ((ptx + 1) < d->maxDelay)
+ samp += d->buff[ptx+1] * d->alpha;
+ else
samp += d->buff[0] * d->alpha;
return samp;
@@ -345,7 +345,7 @@
int tDelayA_setDelay (tDelayA* const d, float delay)
{
- d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
+ d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
// outPoint chases inPoint
@@ -431,142 +431,140 @@
float tDelayA_getGain (tDelayA* const d)
{
return d->gain;
-}
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
-{
- d->maxDelay = maxDelay;
-
- d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
-
- d->gain = 1.0f;
-
- d->lastIn = 0.0f;
- d->lastOut = 0.0f;
-
- d->idx = 0.0f;
- d->inc = 1.0f;
- d->inPoint = 0;
-
- tTapeDelay_setDelay(d, delay);
-}
-
-void tTapeDelay_free(tTapeDelay* const d)
-{
- leaf_free(d->buff);
- leaf_free(d);
-}
-
-int count = 0;
-
-//#define SMOOTH_FACTOR 10.f
-
-float tTapeDelay_tick (tTapeDelay* const d, float input)
-{
- d->buff[d->inPoint] = input * d->gain;
-
- // Increment input pointer modulo length.
- if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
-
- int idx = (int) d->idx;
- float alpha = d->idx - idx;
-
- d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
- d->buff[idx],
- d->buff[(idx + 1) % d->maxDelay],
- d->buff[(idx + 2) % d->maxDelay],
- alpha);
-
- float diff = (d->inPoint - d->idx);
- while (diff < 0.f) diff += d->maxDelay;
-
- d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
-
- d->idx += d->inc;
-
- if (d->idx >= d->maxDelay) d->idx = 0.0f;
-
- return d->lastOut;
-}
-
-
-void tTapeDelay_setRate(tTapeDelay* const d, float rate)
-{
- d->inc = rate;
-}
-
-int tTapeDelay_setDelay (tTapeDelay* const d, float delay)
-{
- d->delay = LEAF_clip(1.f, delay, d->maxDelay);
-
- return 0;
-}
-
-float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)
-{
- float tap = (float) d->inPoint - tapDelay - 1.f;
-
- // Check for wraparound.
- while ( tap < 0.f ) tap += (float)d->maxDelay;
-
- int idx = (int) tap;
-
- float alpha = tap - idx;
-
- float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
- d->buff[idx],
- d->buff[(idx + 1) % d->maxDelay],
- d->buff[(idx + 2) % d->maxDelay],
- alpha);
-
- return samp;
-
-}
-
-void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)
-{
- int32_t tap = d->inPoint - tapDelay - 1;
-
- // Check for wraparound.
- while ( tap < 0 ) tap += d->maxDelay;
-
- d->buff[tap] = value;
-}
-
-float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)
-{
- int32_t tap = d->inPoint - tapDelay - 1;
-
- // Check for wraparound.
- while ( tap < 0 ) tap += d->maxDelay;
-
- return (d->buff[tap] += value);
-}
-
-float tTapeDelay_getDelay (tTapeDelay *d)
-{
- return d->delay;
-}
-
-float tTapeDelay_getLastOut (tTapeDelay* const d)
-{
- return d->lastOut;
-}
-
-float tTapeDelay_getLastIn (tTapeDelay* const d)
-{
- return d->lastIn;
-}
-
-void tTapeDelay_setGain (tTapeDelay* const d, float gain)
-{
- if (gain < 0.0f) d->gain = 0.0f;
- else d->gain = gain;
-}
-
-float tTapeDelay_getGain (tTapeDelay* const d)
-{
- return d->gain;
+}
+
+// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
+void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
+{
+ d->maxDelay = maxDelay;
+
+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
+
+ d->gain = 1.0f;
+
+ d->lastIn = 0.0f;
+ d->lastOut = 0.0f;
+
+ d->idx = 0.0f;
+ d->inc = 1.0f;
+ d->inPoint = 0;
+
+ tTapeDelay_setDelay(d, delay);
+}
+
+void tTapeDelay_free(tTapeDelay* const d)
+{
+ leaf_free(d->buff);
+ leaf_free(d);
+}
+
+//#define SMOOTH_FACTOR 10.f
+
+float tTapeDelay_tick (tTapeDelay* const d, float input)
+{
+ d->buff[d->inPoint] = input * d->gain;
+
+ // Increment input pointer modulo length.
+ if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
+
+ int idx = (int) d->idx;
+ float alpha = d->idx - idx;
+
+ d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
+ d->buff[idx],
+ d->buff[(idx + 1) % d->maxDelay],
+ d->buff[(idx + 2) % d->maxDelay],
+ alpha);
+
+ float diff = (d->inPoint - d->idx);
+ while (diff < 0.f) diff += d->maxDelay;
+
+ d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
+
+ d->idx += d->inc;
+
+ if (d->idx >= d->maxDelay) d->idx = 0.0f;
+
+ return d->lastOut;
+}
+
+
+void tTapeDelay_setRate(tTapeDelay* const d, float rate)
+{
+ d->inc = rate;
+}
+
+int tTapeDelay_setDelay (tTapeDelay* const d, float delay)
+{
+ d->delay = LEAF_clip(1.f, delay, d->maxDelay);
+
+ return 0;
+}
+
+float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)
+{
+ float tap = (float) d->inPoint - tapDelay - 1.f;
+
+ // Check for wraparound.
+ while ( tap < 0.f ) tap += (float)d->maxDelay;
+
+ int idx = (int) tap;
+
+ float alpha = tap - idx;
+
+ float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
+ d->buff[idx],
+ d->buff[(idx + 1) % d->maxDelay],
+ d->buff[(idx + 2) % d->maxDelay],
+ alpha);
+
+ return samp;
+
+}
+
+void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)
+{
+ int32_t tap = d->inPoint - tapDelay - 1;
+
+ // Check for wraparound.
+ while ( tap < 0 ) tap += d->maxDelay;
+
+ d->buff[tap] = value;
+}
+
+float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)
+{
+ int32_t tap = d->inPoint - tapDelay - 1;
+
+ // Check for wraparound.
+ while ( tap < 0 ) tap += d->maxDelay;
+
+ return (d->buff[tap] += value);
+}
+
+float tTapeDelay_getDelay (tTapeDelay *d)
+{
+ return d->delay;
+}
+
+float tTapeDelay_getLastOut (tTapeDelay* const d)
+{
+ return d->lastOut;
+}
+
+float tTapeDelay_getLastIn (tTapeDelay* const d)
+{
+ return d->lastIn;
+}
+
+void tTapeDelay_setGain (tTapeDelay* const d, float gain)
+{
+ if (gain < 0.0f) d->gain = 0.0f;
+ else d->gain = gain;
+}
+
+float tTapeDelay_getGain (tTapeDelay* const d)
+{
+ return d->gain;
}