ref: 1bf0296869c7184e538b0f602e19a2f3fff735ed
parent: 1c3d6bee053043ecae4f2af527e2c31f5a3f6960
author: Matthew Wang <mjw7@princeton.edu>
date: Wed Jun 17 12:00:24 EDT 2020
removed freeFromPool function and stored a pointer to the correct mempool in objects so free() functions will now automatically use the correct mempool
--- a/TestPlugin/Source/MyTest.cpp
+++ b/TestPlugin/Source/MyTest.cpp
@@ -58,7 +58,6 @@
tMinBLEPTable_init(&minblep, zeroCrossings, overSamplingRatio);
tMBSaw_init(&saw, &minblep);
- tMBSaw_free(&saw);
tMBPulse_init(&pulse, &minblep);
@@ -95,9 +94,9 @@
// if (phasor->phaseDidReset) tMBPulse_sync(&pulse, 0.0f);
// if (phasor->phaseDidReset) tMBTriangle_sync(&tri, 0.0f);
-// return tMBSaw_tick(&saw);
+ return tMBSaw_tick(&saw);
// return tMBPulse_tick(&pulse);
- return tMBTriangle_tick(&tri);
+// return tMBTriangle_tick(&tri);
}
int firstFrame = 1;
--- a/leaf/Inc/leaf-analysis.h
+++ b/leaf/Inc/leaf-analysis.h
@@ -34,6 +34,7 @@
/* Envelope Follower */
typedef struct _tEnvelopeFollower
{
+ tMempool mempool;
float y;
float a_thresh;
float d_coeff;
@@ -43,10 +44,9 @@
typedef _tEnvelopeFollower* tEnvelopeFollower;
void tEnvelopeFollower_init (tEnvelopeFollower* const, float attackThreshold, float decayCoeff);
- void tEnvelopeFollower_free (tEnvelopeFollower* const);
void tEnvelopeFollower_initToPool (tEnvelopeFollower* const, float attackThreshold, float decayCoeff, tMempool* const);
- void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const, tMempool* const);
-
+ void tEnvelopeFollower_free (tEnvelopeFollower* const);
+
float tEnvelopeFollower_tick (tEnvelopeFollower* const, float x);
int tEnvelopeFollower_decayCoeff (tEnvelopeFollower* const, float decayCoeff);
int tEnvelopeFollower_attackThresh (tEnvelopeFollower* const, float attackThresh);
@@ -55,6 +55,7 @@
/* Zero Crossing Detector */
typedef struct _tZeroCrossing {
+ tMempool mempool;
int count;
int maxWindowSize;
int currentWindowSize;
@@ -68,9 +69,8 @@
typedef _tZeroCrossing* tZeroCrossing;
void tZeroCrossing_init (tZeroCrossing* const, int maxWindowSize);
- void tZeroCrossing_free (tZeroCrossing* const);
void tZeroCrossing_initToPool (tZeroCrossing* const, int maxWindowSize, tMempool* const);
- void tZeroCrossing_freeFromPool (tZeroCrossing* const, tMempool* const);
+ void tZeroCrossing_free (tZeroCrossing* const);
float tZeroCrossing_tick (tZeroCrossing* const, float input);
void tZeroCrossing_setWindow (tZeroCrossing* const, float windowSize);
@@ -78,7 +78,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* PowerEnvelopeFollower */
- typedef struct _tPowerFollower {
+ typedef struct _tPowerFollower
+ {
+ tMempool mempool;
float factor, oneminusfactor;
float curr;
@@ -87,9 +89,8 @@
typedef _tPowerFollower* tPowerFollower;
void tPowerFollower_init (tPowerFollower* const, float factor);
- void tPowerFollower_free (tPowerFollower* const);
void tPowerFollower_initToPool (tPowerFollower* const, float factor, tMempool* const);
- void tPowerFollower_freeFromPool (tPowerFollower* const, tMempool* const);
+ void tPowerFollower_free (tPowerFollower* const);
float tPowerFollower_tick (tPowerFollower* const, float input);
float tPowerFollower_sample (tPowerFollower* const);
@@ -105,6 +106,7 @@
typedef struct _tEnvPD
{
+ tMempool mempool;
float buf[ENV_WINDOW_SIZE + INITVSTAKEN];
uint16_t x_phase; /* number of points since last output */
uint16_t x_period; /* requested period of output */
@@ -120,9 +122,8 @@
typedef _tEnvPD* tEnvPD;
void tEnvPD_init (tEnvPD* const, int windowSize, int hopSize, int blockSize);
- void tEnvPD_free (tEnvPD* const);
void tEnvPD_initToPool (tEnvPD* const, int windowSize, int hopSize, int blockSize, tMempool* const);
- void tEnvPD_freeFromPool (tEnvPD* const, tMempool* const);
+ void tEnvPD_free (tEnvPD* const);
float tEnvPD_tick (tEnvPD* const);
void tEnvPD_processBlock (tEnvPD* const, float* in);
@@ -137,6 +138,8 @@
typedef struct _tAttackDetection
{
+ tMempool mempool;
+
float env;
//Attack & Release times in msec
@@ -159,9 +162,8 @@
typedef _tAttackDetection* tAttackDetection;
void tAttackDetection_init (tAttackDetection* const, int blocksize, int atk, int rel);
- void tAttackDetection_free (tAttackDetection* const);
void tAttackDetection_initToPool (tAttackDetection* const, int blocksize, int atk, int rel, tMempool* const);
- void tAttackDetection_freeFromPool (tAttackDetection* const, tMempool* const);
+ void tAttackDetection_free (tAttackDetection* const);
// set expected input blocksize
void tAttackDetection_setBlocksize (tAttackDetection* const, int size);
@@ -193,6 +195,8 @@
typedef struct _tSNAC
{
+ tMempool mempool;
+
float* inputbuf;
float* processbuf;
float* spectrumbuf;
@@ -212,9 +216,8 @@
typedef _tSNAC* tSNAC;
void tSNAC_init (tSNAC* const, int overlaparg);
- void tSNAC_free (tSNAC* const);
void tSNAC_initToPool (tSNAC* const, int overlaparg, tMempool* const);
- void tSNAC_freeFromPool (tSNAC* const, tMempool* const);
+ void tSNAC_free (tSNAC* const);
void tSNAC_ioSamples (tSNAC *s, float *in, float *out, int size);
void tSNAC_setOverlap (tSNAC *s, int lap);
@@ -236,6 +239,8 @@
// Period detection
typedef struct _tPeriodDetection
{
+ tMempool mempool;
+
tEnvPD env;
tSNAC snac;
float* inBuffer;
@@ -272,9 +277,8 @@
typedef _tPeriodDetection* tPeriodDetection;
void tPeriodDetection_init (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize);
- void tPeriodDetection_free (tPeriodDetection* const);
void tPeriodDetection_initToPool (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize, tMempool* const);
- void tPeriodDetection_freeFromPool (tPeriodDetection* const, tMempool* const);
+ void tPeriodDetection_free (tPeriodDetection* const);
float tPeriodDetection_tick (tPeriodDetection* const, float sample);
float tPeriodDetection_getPeriod (tPeriodDetection* const);
--- a/leaf/Inc/leaf-delay.h
+++ b/leaf/Inc/leaf-delay.h
@@ -31,6 +31,8 @@
/* Non-interpolating delay, reimplemented from STK (Cook and Scavone). */
typedef struct _tDelay
{
+ tMempool mempool;
+
float gain;
float* buff;
@@ -45,9 +47,8 @@
typedef _tDelay* tDelay;
void tDelay_init (tDelay* const, uint32_t delay, uint32_t maxDelay);
- void tDelay_free (tDelay* const);
void tDelay_initToPool (tDelay* const, uint32_t delay, uint32_t maxDelay, tMempool* const);
- void tDelay_freeFromPool (tDelay* const, tMempool* const);
+ void tDelay_free (tDelay* const);
void tDelay_clear (tDelay* const);
int tDelay_setDelay (tDelay* const, uint32_t delay);
@@ -64,6 +65,8 @@
/* Linearly-interpolating delay, reimplemented from STK (Cook and Scavone). */
typedef struct _tLinearDelay
{
+ tMempool mempool;
+
float gain;
float* buff;
@@ -82,9 +85,9 @@
typedef _tLinearDelay* tLinearDelay;
void tLinearDelay_init (tLinearDelay* const, float delay, uint32_t maxDelay);
- void tLinearDelay_free (tLinearDelay* const);
void tLinearDelay_initToPool (tLinearDelay* const, float delay, uint32_t maxDelay, tMempool* const);
- void tLinearDelay_freeFromPool(tLinearDelay* const, tMempool* const);
+ void tLinearDelay_free (tLinearDelay* const);
+
void tLinearDelay_clear (tLinearDelay* const dl);
int tLinearDelay_setDelay (tLinearDelay* const, float delay);
float tLinearDelay_getDelay (tLinearDelay* const);
@@ -104,6 +107,8 @@
/* Hermite-interpolating delay, created by adapting STK linear delay with Hermite interpolation */
typedef struct _tHermiteDelay
{
+ tMempool mempool;
+
float gain;
float* buff;
@@ -116,15 +121,14 @@
float delay;
float alpha, omAlpha;
-
} _tHermiteDelay;
typedef _tHermiteDelay* tHermiteDelay;
void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay);
- void tHermiteDelay_free (tHermiteDelay* const dl);
void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp);
- void tHermiteDelay_freeFromPool (tHermiteDelay* const dl, tMempool* const mp);
+ void tHermiteDelay_free (tHermiteDelay* const dl);
+
void tHermiteDelay_clear (tHermiteDelay* const dl);
float tHermiteDelay_tick (tHermiteDelay* const dl, float input);
void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input);
@@ -145,6 +149,8 @@
/* Allpass-interpolating delay, reimplemented from STK (Cook and Scavone). */
typedef struct _tAllpassDelay
{
+ tMempool mempool;
+
float gain;
float* buff;
@@ -165,9 +171,8 @@
typedef _tAllpassDelay* tAllpassDelay;
void tAllpassDelay_init (tAllpassDelay* const, float delay, uint32_t maxDelay);
- void tAllpassDelay_free (tAllpassDelay* const);
void tAllpassDelay_initToPool (tAllpassDelay* const, float delay, uint32_t maxDelay, tMempool* const);
- void tAllpassDelay_freeFromPool(tAllpassDelay* const, tMempool* const);
+ void tAllpassDelay_free (tAllpassDelay* const);
void tAllpassDelay_clear (tAllpassDelay* const);
int tAllpassDelay_setDelay (tAllpassDelay* const, float delay);
@@ -184,6 +189,8 @@
/* Linear interpolating delay with fixed read and write pointers, variable rate. */
typedef struct _tTapeDelay
{
+ tMempool mempool;
+
float gain;
float* buff;
@@ -202,9 +209,8 @@
typedef _tTapeDelay* tTapeDelay;
void tTapeDelay_init (tTapeDelay* const, float delay, uint32_t maxDelay);
- void tTapeDelay_free (tTapeDelay* const);
void tTapeDelay_initToPool (tTapeDelay* const, float delay, uint32_t maxDelay, tMempool* const);
- void tTapeDelay_freeFromPool(tTapeDelay* const, tMempool* const);
+ void tTapeDelay_free (tTapeDelay* const);
void tTapeDelay_clear (tTapeDelay* const);
void tTapeDelay_setDelay (tTapeDelay* const, float delay);
--- a/leaf/Inc/leaf-distortion.h
+++ b/leaf/Inc/leaf-distortion.h
@@ -31,6 +31,7 @@
typedef struct _tSampleReducer
{
+ tMempool mempool;
float invRatio;
float hold;
uint32_t count;
@@ -39,9 +40,8 @@
typedef _tSampleReducer* tSampleReducer;
void tSampleReducer_init (tSampleReducer* const);
- void tSampleReducer_free (tSampleReducer* const);
void tSampleReducer_initToPool (tSampleReducer* const, tMempool* const);
- void tSampleReducer_freeFromPool (tSampleReducer* const, tMempool* const);
+ void tSampleReducer_free (tSampleReducer* const);
float tSampleReducer_tick (tSampleReducer* const, float input);
@@ -52,6 +52,7 @@
typedef struct _tOversampler
{
+ tMempool mempool;
int ratio;
float* pCoeffs;
float* upState;
@@ -63,9 +64,8 @@
typedef _tOversampler* tOversampler;
void tOversampler_init (tOversampler* const, int order, oBool extraQuality);
- void tOversampler_free (tOversampler* const);
void tOversampler_initToPool (tOversampler* const, int order, oBool extraQuality, tMempool* const);
- void tOversampler_freeFromPool (tOversampler* const, tMempool* const);
+ void tOversampler_free (tOversampler* const);
void tOversampler_upsample (tOversampler* const, float input, float* output);
float tOversampler_downsample (tOversampler* const os, float* input);
@@ -78,6 +78,8 @@
typedef struct _tLockhartWavefolder
{
+ tMempool mempool;
+
double Ln1;
double Fn1;
double xn1;
@@ -108,9 +110,8 @@
typedef _tLockhartWavefolder* tLockhartWavefolder;
void tLockhartWavefolder_init (tLockhartWavefolder* const);
- void tLockhartWavefolder_free (tLockhartWavefolder* const);
void tLockhartWavefolder_initToPool (tLockhartWavefolder* const, tMempool* const);
- void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const, tMempool* const);
+ void tLockhartWavefolder_free (tLockhartWavefolder* const);
float tLockhartWavefolder_tick (tLockhartWavefolder* const, float samp);
@@ -118,6 +119,8 @@
typedef struct _tCrusher
{
+ tMempool mempool;
+
float srr;
float mult, div;
float rnd;
@@ -132,9 +135,8 @@
typedef _tCrusher* tCrusher;
void tCrusher_init (tCrusher* const);
- void tCrusher_free (tCrusher* const);
void tCrusher_initToPool (tCrusher* const, tMempool* const);
- void tCrusher_freeFromPool (tCrusher* const, tMempool* const);
+ void tCrusher_free (tCrusher* const);
float tCrusher_tick (tCrusher* const, float input);
--- a/leaf/Inc/leaf-dynamics.h
+++ b/leaf/Inc/leaf-dynamics.h
@@ -36,6 +36,8 @@
/* Compressor */
typedef struct _tCompressor
{
+ tMempool mempool;
+
float tauAttack, tauRelease;
float T, R, W, M; // Threshold, compression Ratio, decibel Width of knee transition, decibel Make-up gain
@@ -48,9 +50,8 @@
typedef _tCompressor* tCompressor;
void tCompressor_init (tCompressor* const);
- void tCompressor_free (tCompressor* const);
void tCompressor_initToPool (tCompressor* const, tMempool* const);
- void tCompressor_freeFromPool(tCompressor* const, tMempool* const);
+ void tCompressor_free (tCompressor* const);
float tCompressor_tick (tCompressor* const, float input);
@@ -62,7 +63,9 @@
// The latter option allows for decaying strings, which can never exceed
// a specific level.
- typedef struct _tFeedbackLeveler {
+ typedef struct _tFeedbackLeveler
+ {
+ tMempool mempool;
float targetLevel; // target power level
float strength; // how strongly level difference affects the VCA
int mode; // 0 for upwards limiting only, 1 for biderctional limiting
@@ -74,9 +77,8 @@
typedef _tFeedbackLeveler* tFeedbackLeveler;
void tFeedbackLeveler_init (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode);
- void tFeedbackLeveler_free (tFeedbackLeveler* const);
void tFeedbackLeveler_initToPool (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, tMempool* const);
- void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const, tMempool* const);
+ void tFeedbackLeveler_free (tFeedbackLeveler* const);
float tFeedbackLeveler_tick (tFeedbackLeveler* const, float input);
float tFeedbackLeveler_sample (tFeedbackLeveler* const);
@@ -91,18 +93,18 @@
//Threshold with hysteresis (like Max/MSP thresh~ object)
- typedef struct _tThreshold {
+ typedef struct _tThreshold
+ {
+ tMempool mempool;
float highThresh, lowThresh;
int currentValue;
-
} _tThreshold;
typedef _tThreshold* tThreshold;
void tThreshold_init (tThreshold* const, float low, float high);
- void tThreshold_free (tThreshold* const);
void tThreshold_initToPool (tThreshold* const, float low, float high, tMempool* const);
- void tThreshold_freeFromPool(tThreshold* const, tMempool* const);
+ void tThreshold_free (tThreshold* const);
int tThreshold_tick (tThreshold* const, float input);
void tThreshold_setLow (tThreshold* const, float low);
--- a/leaf/Inc/leaf-effects.h
+++ b/leaf/Inc/leaf-effects.h
@@ -29,6 +29,8 @@
typedef struct _tTalkbox
{
+ tMempool mempool;
+
float param[NUM_TALKBOX_PARAM];
int bufsize;
@@ -56,9 +58,8 @@
typedef _tTalkbox* tTalkbox;
void tTalkbox_init (tTalkbox* const, int bufsize);
- void tTalkbox_free (tTalkbox* const);
void tTalkbox_initToPool (tTalkbox* const, int bufsize, tMempool* const);
- void tTalkbox_freeFromPool (tTalkbox* const, tMempool* const);
+ void tTalkbox_free (tTalkbox* const);
float tTalkbox_tick (tTalkbox* const, float synth, float voice);
float tTalkbox_tickFrozen (tTalkbox* const voc, float synth, float voice);
@@ -78,6 +79,8 @@
typedef struct _tTalkboxFloat
{
+ tMempool mempool;
+
float param[NUM_TALKBOX_PARAM];
int bufsize;
@@ -105,9 +108,8 @@
typedef _tTalkboxFloat* tTalkboxFloat;
void tTalkboxFloat_init (tTalkboxFloat* const, int bufsize);
- void tTalkboxFloat_free (tTalkboxFloat* const);
void tTalkboxFloat_initToPool (tTalkboxFloat* const, int bufsize, tMempool* const);
- void tTalkboxFloat_freeFromPool (tTalkboxFloat* const, tMempool* const);
+ void tTalkboxFloat_free (tTalkboxFloat* const);
float tTalkboxFloat_tick (tTalkboxFloat* const, float synth, float voice);
float tTalkboxFloat_tickFrozen (tTalkboxFloat* const voc, float synth, float voice);
@@ -130,6 +132,8 @@
typedef struct _tVocoder
{
+ tMempool mempool;
+
float param[NUM_VOCODER_PARAM];
float gain; //output level
@@ -146,9 +150,8 @@
typedef _tVocoder* tVocoder;
void tVocoder_init (tVocoder* const);
- void tVocoder_free (tVocoder* const);
void tVocoder_initToPool (tVocoder* const, tMempool* const);
- void tVocoder_freeFromPool (tVocoder* const, tMempool* const);
+ void tVocoder_free (tVocoder* const);
float tVocoder_tick (tVocoder* const, float synth, float voice);
void tVocoder_update (tVocoder* const);
@@ -160,6 +163,7 @@
typedef struct _tRosenbergGlottalPulse
{
+ tMempool mempool;
float phase;
float openLength;
float pulseLength;
@@ -166,16 +170,13 @@
float invPulseLengthMinusOpenLength;
float freq;
float inc;
-
-
} _tRosenbergGlottalPulse;
typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse;
void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const);
- void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const);
void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const, tMempool* const);
- void tRosenbergGlottalPulse_freeFromPool (tRosenbergGlottalPulse* const, tMempool* const);
+ void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const);
float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);
float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const gp);
@@ -200,6 +201,8 @@
typedef struct _tSOLAD
{
+ tMempool mempool;
+
uint16_t timeindex; // current reference time, write index
uint16_t blocksize; // signal input / output block size
float pitchfactor; // pitch factor between 0.25 and 4
@@ -216,9 +219,8 @@
typedef _tSOLAD* tSOLAD;
void tSOLAD_init (tSOLAD* const);
- void tSOLAD_free (tSOLAD* const);
void tSOLAD_initToPool (tSOLAD* const, tMempool* const);
- void tSOLAD_freeFromPool (tSOLAD* const, tMempool* const);
+ void tSOLAD_free (tSOLAD* const);
// send one block of input samples, receive one block of output samples
void tSOLAD_ioSamples (tSOLAD *w, float* in, float* out, int blocksize);
@@ -234,6 +236,8 @@
// Pitch shift
typedef struct _tPitchShift
{
+ tMempool mempool;
+
tSOLAD sola;
tHighpass hp;
tPeriodDetection* p;
@@ -255,9 +259,8 @@
typedef _tPitchShift* tPitchShift;
void tPitchShift_init (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize);
- void tPitchShift_free (tPitchShift* const);
void tPitchShift_initToPool (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize, tMempool* const);
- void tPitchShift_freeFromPool (tPitchShift* const, tMempool* const);
+ void tPitchShift_free (tPitchShift* const);
float tPitchShift_shift (tPitchShift* const);
float tPitchShift_shiftToFunc (tPitchShift* const, float (*fun)(float));
@@ -267,7 +270,8 @@
// Retune
typedef struct _tRetune
{
- tMempool* mempool;
+ tMempool mempool;
+
tPeriodDetection pd;
tPitchShift* ps;
@@ -293,9 +297,8 @@
typedef _tRetune* tRetune;
void tRetune_init (tRetune* const, int numVoices, int bufSize, int frameSize);
- void tRetune_free (tRetune* const);
void tRetune_initToPool (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
- void tRetune_freeFromPool (tRetune* const, tMempool* const);
+ void tRetune_free (tRetune* const);
float* tRetune_tick (tRetune* const, float sample);
void tRetune_setNumVoices (tRetune* const, int numVoices);
@@ -311,7 +314,8 @@
// Autotune
typedef struct _tAutotune
{
- tMempool* mempool;
+ tMempool mempool;
+
tPeriodDetection pd;
tPitchShift* ps;
@@ -337,9 +341,8 @@
typedef _tAutotune* tAutotune;
void tAutotune_init (tAutotune* const, int numVoices, int bufSize, int frameSize);
- void tAutotune_free (tAutotune* const);
void tAutotune_initToPool (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
- void tAutotune_freeFromPool (tAutotune* const, tMempool* const);
+ void tAutotune_free (tAutotune* const);
float* tAutotune_tick (tAutotune* const, float sample);
void tAutotune_setNumVoices (tAutotune* const, int numVoices);
@@ -359,6 +362,7 @@
typedef struct _tFormantShifter
{
+ tMempool mempool;
int ford;
float falph;
float flamb;
@@ -383,15 +387,13 @@
tHighpass hp2;
tFeedbackLeveler fbl1;
tFeedbackLeveler fbl2;
-
} _tFormantShifter;
typedef _tFormantShifter* tFormantShifter;
void tFormantShifter_init (tFormantShifter* const, int order);
- void tFormantShifter_free (tFormantShifter* const);
void tFormantShifter_initToPool (tFormantShifter* const, int order, tMempool* const);
- void tFormantShifter_freeFromPool (tFormantShifter* const, tMempool* const);
+ void tFormantShifter_free (tFormantShifter* const);
float tFormantShifter_tick (tFormantShifter* const, float input);
float tFormantShifter_remove (tFormantShifter* const, float input);
--- a/leaf/Inc/leaf-electrical.h
+++ b/leaf/Inc/leaf-electrical.h
@@ -48,6 +48,7 @@
typedef _tWDF* tWDF;
struct _tWDF
{
+ tMempool mempool;
WDFComponentType type;
float port_resistance_up;
float port_resistance_left;
@@ -74,9 +75,8 @@
//WDF Linear Components
void tWDF_init (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR);
- void tWDF_free (tWDF* const);
void tWDF_initToPool (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, tMempool* const);
- void tWDF_freeFromPool (tWDF* const, tMempool* const);
+ void tWDF_free (tWDF* const);
float tWDF_tick (tWDF* const, float sample, tWDF* const outputPoint, uint8_t paramsChanged);
--- a/leaf/Inc/leaf-envelopes.h
+++ b/leaf/Inc/leaf-envelopes.h
@@ -35,10 +35,12 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* Attack-Decay envelope */
- typedef struct _tEnvelope {
+ typedef struct _tEnvelope
+ {
+ tMempool mempool;
- const float *exp_buff;
- const float *inc_buff;
+ const float *exp_buff;
+ const float *inc_buff;
uint32_t buff_size;
float next;
@@ -58,9 +60,8 @@
typedef _tEnvelope* tEnvelope;
void tEnvelope_init (tEnvelope* const, float attack, float decay, int loop);
- void tEnvelope_free (tEnvelope* const);
void tEnvelope_initToPool (tEnvelope* const, float attack, float decay, int loop, tMempool* const);
- void tEnvelope_freeFromPool (tEnvelope* const, tMempool* const);
+ void tEnvelope_free (tEnvelope* const);
float tEnvelope_tick (tEnvelope* const);
void tEnvelope_setAttack (tEnvelope* const, float attack);
@@ -73,18 +74,18 @@
/* Exponential Smoother */
- typedef struct _tExpSmooth {
+ typedef struct _tExpSmooth
+ {
+ tMempool mempool;
float factor, oneminusfactor;
float curr,dest;
-
} _tExpSmooth;
typedef _tExpSmooth* tExpSmooth;
void tExpSmooth_init (tExpSmooth* const, float val, float factor);
- void tExpSmooth_free (tExpSmooth* const);
void tExpSmooth_initToPool (tExpSmooth* const, float val, float factor, tMempool* const);
- void tExpSmooth_freeFromPool (tExpSmooth* const, tMempool* const);
+ void tExpSmooth_free (tExpSmooth* const);
float tExpSmooth_tick (tExpSmooth* const);
float tExpSmooth_sample (tExpSmooth* const);
@@ -102,8 +103,10 @@
/* ADSR */
typedef struct _tADSR
{
- const float *exp_buff;
- const float *inc_buff;
+ tMempool mempool;
+
+ const float *exp_buff;
+ const float *inc_buff;
uint32_t buff_size;
float next;
@@ -117,16 +120,13 @@
float attackPhase, decayPhase, releasePhase, rampPhase;
float leakFactor;
-
-
} _tADSR;
typedef _tADSR* tADSR;
void tADSR_init (tADSR* const adsrenv, float attack, float decay, float sustain, float release);
- void tADSR_free (tADSR* const);
void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp);
- void tADSR_freeFromPool (tADSR* const, tMempool* const);
+ void tADSR_free (tADSR* const);
float tADSR_tick (tADSR* const);
void tADSR_setAttack (tADSR* const, float attack);
@@ -147,6 +147,7 @@
/* ADSR2 */
typedef struct _tADSR2
{
+ tMempool mempool;
float sampleRateInMs;
float attack;
float decay;
@@ -170,9 +171,8 @@
typedef _tADSR2* tADSR2;
void tADSR2_init (tADSR2* const, float attack, float decay, float sustain, float release);
- void tADSR2_free (tADSR2* const);
void tADSR2_initToPool (tADSR2* const, float attack, float decay, float sustain, float release, tMempool* const);
- void tADSR2_freeFromPool (tADSR2* const, tMempool* const);
+ void tADSR2_free (tADSR2* const);
float tADSR2_tick (tADSR2* const);
void tADSR2_setAttack (tADSR2* const, float attack);
@@ -199,6 +199,7 @@
/* ADSR3 */
typedef struct _tADSR3
{
+ tMempool mempool;
float sampleRateInMs;
int state;
float output;
@@ -225,9 +226,8 @@
typedef _tADSR3* tADSR3;
void tADSR3_init (tADSR3* const, float attack, float decay, float sustain, float release);
- void tADSR3_free (tADSR3* const);
void tADSR3_initToPool (tADSR3* const, float attack, float decay, float sustain, float release, tMempool* const);
- void tADSR3_freeFromPool (tADSR3* const, tMempool* const);
+ void tADSR3_free (tADSR3* const);
float tADSR3_tick (tADSR3* const);
void tADSR3_setAttack (tADSR3* const, float attack);
@@ -245,7 +245,8 @@
typedef struct _tADSR4
{
- const float *exp_buff;
+ tMempool mempool;
+ const float *exp_buff;
uint32_t buff_size;
uint32_t buff_sizeMinusOne;
float bufferSizeDividedBySampleRateInMs;
@@ -260,16 +261,13 @@
float attackPhase, decayPhase, releasePhase, rampPhase;
float leakFactor;
-
-
} _tADSR4;
typedef _tADSR4* tADSR4;
void tADSR4_init (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize);
- void tADSR4_free (tADSR4* const);
void tADSR4_initToPool (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, tMempool* const);
- void tADSR4_freeFromPool (tADSR4* const, tMempool* const);
+ void tADSR4_free (tADSR4* const);
float tADSR4_tick (tADSR4* const);
float tADSR4_tickNoInterp (tADSR4* const adsrenv);
@@ -283,7 +281,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* Ramp */
- typedef struct _tRamp {
+ typedef struct _tRamp
+ {
+ tMempool mempool;
float inc;
float inv_sr_ms;
float minimum_time;
@@ -291,15 +291,13 @@
float time;
float factor;
int samples_per_tick;
-
} _tRamp;
typedef _tRamp* tRamp;
void tRamp_init (tRamp* const, float time, int samplesPerTick);
- void tRamp_free (tRamp* const);
void tRamp_initToPool (tRamp* const, float time, int samplesPerTick, tMempool* const);
- void tRamp_freeFromPool (tRamp* const, tMempool* const);
+ void tRamp_free (tRamp* const);
float tRamp_tick (tRamp* const);
float tRamp_sample (tRamp* const);
@@ -309,7 +307,9 @@
///=============
/* Ramp Updown*/
- typedef struct _tRampUpDown {
+ typedef struct _tRampUpDown
+ {
+ tMempool mempool;
float upInc;
float downInc;
float inv_sr_ms;
@@ -318,15 +318,13 @@
float upTime;
float downTime;
int samples_per_tick;
-
} _tRampUpDown;
typedef _tRampUpDown* tRampUpDown;
void tRampUpDown_init (tRampUpDown* const, float upTime, float downTime, int samplesPerTick);
- void tRampUpDown_free (tRampUpDown* const);
void tRampUpDown_initToPool (tRampUpDown* const, float upTime, float downTime, int samplesPerTick, tMempool* const);
- void tRampUpDown_freeFromPool (tRampUpDown* const, tMempool* const);
+ void tRampUpDown_free (tRampUpDown* const);
float tRampUpDown_tick (tRampUpDown* const);
float tRampUpDown_sample (tRampUpDown* const);
@@ -338,7 +336,9 @@
///=========================
//Slide (based on Max/MSP's slide~)
- typedef struct _tSlide {
+ typedef struct _tSlide
+ {
+ tMempool mempool;
float prevOut;
float currentOut;
float prevIn;
@@ -345,15 +345,13 @@
float invUpSlide;
float invDownSlide;
float dest;
-
} _tSlide;
typedef _tSlide* tSlide;
void tSlide_init (tSlide* const, float upSlide, float downSlide);
- void tSlide_free (tSlide* const);
void tSlide_initToPool (tSlide* const, float upSlide, float downSlide, tMempool* const);
- void tSlide_freeFromPool (tSlide* const, tMempool* const);
+ void tSlide_free (tSlide* const);
void tSlide_setUpSlide (tSlide* const sl, float upSlide);
--- a/leaf/Inc/leaf-filters.h
+++ b/leaf/Inc/leaf-filters.h
@@ -33,20 +33,20 @@
/* tAllpass: Schroeder allpass. Comb-filter with feedforward and feedback. */
typedef struct _tAllpass
{
+ tMempool mempool;
+
float gain;
tLinearDelay delay;
float lastOut;
-
} _tAllpass;
typedef _tAllpass* tAllpass;
void tAllpass_init (tAllpass* const, float initDelay, uint32_t maxDelay);
- void tAllpass_free (tAllpass* const);
void tAllpass_initToPool (tAllpass* const, float initDelay, uint32_t maxDelay, tMempool* const);
- void tAllpass_freeFromPool (tAllpass* const, tMempool* const);
+ void tAllpass_free (tAllpass* const);
float tAllpass_tick (tAllpass* const, float input);
void tAllpass_setGain (tAllpass* const, float gain);
@@ -58,20 +58,18 @@
/* tOnePole: OnePole filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tOnePole
{
+ tMempool mempool;
float gain;
float a0,a1;
float b0,b1;
float lastIn, lastOut;
-
-
} _tOnePole;
typedef _tOnePole* tOnePole;
void tOnePole_init (tOnePole* const, float thePole);
- void tOnePole_free (tOnePole* const);
void tOnePole_initToPool (tOnePole* const, float thePole, tMempool* const);
- void tOnePole_freeFromPool (tOnePole* const, tMempool* const);
+ void tOnePole_free (tOnePole* const);
float tOnePole_tick (tOnePole* const, float input);
void tOnePole_setB0 (tOnePole* const, float b0);
@@ -86,6 +84,8 @@
/* TwoPole filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tTwoPole
{
+ tMempool mempool;
+
float gain;
float a0, a1, a2;
float b0;
@@ -94,15 +94,13 @@
oBool normalize;
float lastOut[2];
-
} _tTwoPole;
typedef _tTwoPole* tTwoPole;
void tTwoPole_init (tTwoPole* const);
- void tTwoPole_free (tTwoPole* const);
void tTwoPole_initToPool (tTwoPole* const, tMempool* const);
- void tTwoPole_freeFromPool (tTwoPole* const, tMempool* const);
+ void tTwoPole_free (tTwoPole* const);
float tTwoPole_tick (tTwoPole* const, float input);
void tTwoPole_setB0 (tTwoPole* const, float b0);
@@ -117,18 +115,17 @@
/* OneZero filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tOneZero
{
+ tMempool mempool;
float gain;
float b0,b1;
float lastIn, lastOut, frequency;
-
} _tOneZero;
typedef _tOneZero* tOneZero;
void tOneZero_init (tOneZero* const, float theZero);
- void tOneZero_free (tOneZero* const);
void tOneZero_initToPool (tOneZero* const, float theZero, tMempool* const);
- void tOneZero_freeFromPool (tOneZero* const, tMempool* const);
+ void tOneZero_free (tOneZero* const);
float tOneZero_tick (tOneZero* const, float input);
void tOneZero_setB0 (tOneZero* const, float b0);
@@ -143,6 +140,8 @@
/* TwoZero filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tTwoZero
{
+ tMempool mempool;
+
float gain;
float b0, b1, b2;
@@ -149,15 +148,13 @@
float frequency, radius;
float lastIn[2];
-
} _tTwoZero;
typedef _tTwoZero* tTwoZero;
void tTwoZero_init (tTwoZero* const);
- void tTwoZero_free (tTwoZero* const);
void tTwoZero_initToPool (tTwoZero* const, tMempool* const);
- void tTwoZero_freeFromPool (tTwoZero* const, tMempool* const);
+ void tTwoZero_free (tTwoZero* const);
float tTwoZero_tick (tTwoZero* const, float input);
void tTwoZero_setB0 (tTwoZero* const, float b0);
@@ -172,20 +169,20 @@
/* PoleZero filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tPoleZero
{
+ tMempool mempool;
+
float gain;
float a0,a1;
float b0,b1;
float lastIn, lastOut;
-
} _tPoleZero;
typedef _tPoleZero* tPoleZero;
void tPoleZero_init (tPoleZero* const);
- void tPoleZero_free (tPoleZero* const);
void tPoleZero_initToPool (tPoleZero* const, tMempool* const);
- void tPoleZero_freeFromPool (tPoleZero* const, tMempool* const);
+ void tPoleZero_free (tPoleZero* const);
float tPoleZero_tick (tPoleZero* const, float input);
void tPoleZero_setB0 (tPoleZero* const, float b0);
@@ -201,6 +198,8 @@
/* BiQuad filter, reimplemented from STK (Cook and Scavone). */
typedef struct _tBiQuad
{
+ tMempool mempool;
+
float gain;
float a0, a1, a2;
float b0, b1, b2;
@@ -215,9 +214,8 @@
typedef _tBiQuad* tBiQuad;
void tBiQuad_init (tBiQuad* const);
- void tBiQuad_free (tBiQuad* const);
void tBiQuad_initToPool (tBiQuad* const, tMempool* const);
- void tBiQuad_freeFromPool (tBiQuad* const, tMempool* const);
+ void tBiQuad_free (tBiQuad* const);
float tBiQuad_tick (tBiQuad* const, float input);
void tBiQuad_setB0 (tBiQuad* const, float b0);
@@ -246,20 +244,18 @@
typedef struct _tSVF
{
+ tMempool mempool;
SVFType type;
float cutoff, Q;
float ic1eq,ic2eq;
float g,k,a1,a2,a3,cH,cB,cL,cBK;
-
-
} _tSVF;
typedef _tSVF* tSVF;
void tSVF_init (tSVF* const, SVFType type, float freq, float Q);
- void tSVF_free (tSVF* const);
void tSVF_initToPool (tSVF* const, SVFType type, float freq, float Q, tMempool* const);
- void tSVF_freeFromPool (tSVF* const, tMempool* const);
+ void tSVF_free (tSVF* const);
float tSVF_tick (tSVF* const, float v0);
void tSVF_setFreq (tSVF* const, float freq);
@@ -270,19 +266,18 @@
/* Efficient State Variable Filter for 14-bit control input, [0, 4096). */
typedef struct _tEfficientSVF
{
+ tMempool mempool;
SVFType type;
float cutoff, Q;
float ic1eq,ic2eq;
float g,k,a1,a2,a3;
-
} _tEfficientSVF;
typedef _tEfficientSVF* tEfficientSVF;
void tEfficientSVF_init (tEfficientSVF* const, SVFType type, uint16_t input, float Q);
- void tEfficientSVF_free (tEfficientSVF* const);
void tEfficientSVF_initToPool (tEfficientSVF* const, SVFType type, uint16_t input, float Q, tMempool* const);
- void tEfficientSVF_freeFromPool (tEfficientSVF* const, tMempool* const);
+ void tEfficientSVF_free (tEfficientSVF* const);
float tEfficientSVF_tick (tEfficientSVF* const, float v0);
void tEfficientSVF_setFreq (tEfficientSVF* const, uint16_t controlFreq);
@@ -293,17 +288,16 @@
/* Simple Highpass filter. */
typedef struct _tHighpass
{
+ tMempool mempool;
float xs, ys, R;
float frequency;
-
} _tHighpass;
typedef _tHighpass* tHighpass;
void tHighpass_init (tHighpass* const, float freq);
- void tHighpass_free (tHighpass* const);
void tHighpass_initToPool (tHighpass* const, float freq, tMempool* const);
- void tHighpass_freeFromPool (tHighpass* const, tMempool* const);
+ void tHighpass_free (tHighpass* const);
float tHighpass_tick (tHighpass* const, float x);
void tHighpass_setFreq (tHighpass* const, float freq);
@@ -315,6 +309,8 @@
#define NUM_SVF_BW 16
typedef struct _tButterworth
{
+ tMempool mempool;
+
float gain;
int N;
@@ -323,15 +319,13 @@
tSVF high[NUM_SVF_BW];
float f1,f2;
-
} _tButterworth;
typedef _tButterworth* tButterworth;
void tButterworth_init (tButterworth* const, int N, float f1, float f2);
- void tButterworth_free (tButterworth* const);
void tButterworth_initToPool (tButterworth* const, int N, float f1, float f2, tMempool* const);
- void tButterworth_freeFromPool (tButterworth* const, tMempool* const);
+ void tButterworth_free (tButterworth* const);
float tButterworth_tick (tButterworth* const, float input);
void tButterworth_setF1 (tButterworth* const, float in);
@@ -342,6 +336,7 @@
typedef struct _tFIR
{
+ tMempool mempool;
float* past;
float* coeff;
int numTaps;
@@ -350,9 +345,8 @@
typedef _tFIR* tFIR;
void tFIR_init (tFIR* const, float* coeffs, int numTaps);
- void tFIR_free (tFIR* const);
void tFIR_initToPool (tFIR* const, float* coeffs, int numTaps, tMempool* const);
- void tFIR_freeFromPool (tFIR* const, tMempool* const);
+ void tFIR_free (tFIR* const);
float tFIR_tick (tFIR* const, float input);
@@ -362,6 +356,7 @@
typedef struct _tMedianFilter
{
+ tMempool mempool;
float* val;
int* age;
int m;
@@ -374,9 +369,8 @@
typedef _tMedianFilter* tMedianFilter;
void tMedianFilter_init (tMedianFilter* const, int size);
- void tMedianFilter_free (tMedianFilter* const);
void tMedianFilter_initToPool (tMedianFilter* const, int size, tMempool* const);
- void tMedianFilter_freeFromPool (tMedianFilter* const, tMempool* const);
+ void tMedianFilter_free (tMedianFilter* const);
float tMedianFilter_tick (tMedianFilter* const, float input);
@@ -404,6 +398,8 @@
typedef struct _tVZFilter
{
+ tMempool mempool;
+
VZFilterType type;
// state:
float s1, s2;
@@ -423,15 +419,14 @@
float sr; //local sampling rate of filter (may be different from leaf sr if oversampled)
float inv_sr;
-
} _tVZFilter;
typedef _tVZFilter* tVZFilter;
void tVZFilter_init (tVZFilter* const, VZFilterType type, float freq, float Q);
- void tVZFilter_free (tVZFilter* const);
void tVZFilter_initToPool (tVZFilter* const, VZFilterType type, float freq, float Q, tMempool* const);
- void tVZFilter_freeFromPool (tVZFilter* const, tMempool* const);
+ void tVZFilter_free (tVZFilter* const);
+
void tVZFilter_setSampleRate (tVZFilter* const, float sampleRate);
float tVZFilter_tick (tVZFilter* const, float input);
float tVZFilter_tickEfficient (tVZFilter* const vf, float in);
@@ -449,26 +444,24 @@
//diode ladder filter
typedef struct _tDiodeFilter
{
-
- float f;
- float r;
- float Vt;
- float n;
- float gamma;
- float zi;
- float g0inv;
- float g1inv;
- float g2inv;
- float s0, s1, s2, s3;
-
+ tMempool mempool;
+ float f;
+ float r;
+ float Vt;
+ float n;
+ float gamma;
+ float zi;
+ float g0inv;
+ float g1inv;
+ float g2inv;
+ float s0, s1, s2, s3;
} _tDiodeFilter;
typedef _tDiodeFilter* tDiodeFilter;
void tDiodeFilter_init (tDiodeFilter* const, float freq, float Q);
- void tDiodeFilter_free (tDiodeFilter* const);
void tDiodeFilter_initToPool (tDiodeFilter* const, float freq, float Q, tMempool* const);
- void tDiodeFilter_freeFromPool (tDiodeFilter* const, tMempool* const);
+ void tDiodeFilter_free (tDiodeFilter* const);
float tDiodeFilter_tick (tDiodeFilter* const, float input);
void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff);
--- a/leaf/Inc/leaf-instruments.h
+++ b/leaf/Inc/leaf-instruments.h
@@ -32,8 +32,9 @@
//==============================================================================
// 808 Cowbell
- typedef struct _t808Cowbell {
-
+ typedef struct _t808Cowbell
+ {
+ tMempool mempool;
tSquare p[2];
tNoise stick;
tSVF bandpassOsc;
@@ -45,15 +46,13 @@
float oscMix;
float filterCutoff;
uint8_t useStick;
-
} _t808Cowbell;
typedef _t808Cowbell* t808Cowbell;
void t808Cowbell_init (t808Cowbell* const, int useStick);
- void t808Cowbell_free (t808Cowbell* const);
void t808Cowbell_initToPool (t808Cowbell* const, int useStick, tMempool* const);
- void t808Cowbell_freeFromPool (t808Cowbell* const, tMempool* const);
+ void t808Cowbell_free (t808Cowbell* const);
float t808Cowbell_tick (t808Cowbell* const);
void t808Cowbell_on (t808Cowbell* const, float vel);
@@ -67,8 +66,9 @@
//==============================================================================
// 808 Hihat
- typedef struct _t808Hihat {
-
+ typedef struct _t808Hihat
+ {
+ tMempool mempool;
// 6 Square waves
tSquare p[6];
tNoise n;
@@ -84,15 +84,13 @@
float stretch;
float FM_amount;
float oscNoiseMix;
-
} _t808Hihat;
typedef _t808Hihat* t808Hihat;
void t808Hihat_init (t808Hihat* const);
- void t808Hihat_free (t808Hihat* const);
void t808Hihat_initToPool (t808Hihat* const, tMempool* const);
- void t808Hihat_freeFromPool (t808Hihat* const, tMempool* const);
+ void t808Hihat_free (t808Hihat* const);
float t808Hihat_tick (t808Hihat* const);
void t808Hihat_on (t808Hihat* const, float vel);
@@ -110,8 +108,9 @@
//==============================================================================
// 808 Snare
- typedef struct _t808Snare {
-
+ typedef struct _t808Snare
+ {
+ tMempool mempool;
// Tone 1, Tone 2, Noise
tTriangle tone[2]; // Tri (not yet antialiased or wavetabled)
tNoise noiseOsc;
@@ -131,15 +130,13 @@
float tone1Freq, tone2Freq;
float noiseFilterFreq;
-
} _t808Snare;
typedef _t808Snare* t808Snare;
void t808Snare_init (t808Snare* const);
- void t808Snare_free (t808Snare* const);
void t808Snare_initToPool (t808Snare* const, tMempool* const);
- void t808Snare_freeFromPool (t808Snare* const, tMempool* const);
+ void t808Snare_free (t808Snare* const);
float t808Snare_tick (t808Snare* const);
void t808Snare_on (t808Snare* const, float vel);
@@ -155,9 +152,10 @@
//==============================================================================
// 808 Kick
- typedef struct _t808Kick {
+ typedef struct _t808Kick
+ {
+ tMempool mempool;
-
tCycle tone; // Tri
tNoise noiseOsc;
tSVF toneLowpass;
@@ -174,15 +172,13 @@
float sighAmountInHz;
float chirpRatioMinusOne;
float noiseFilterFreq;
-
} _t808Kick;
typedef _t808Kick* t808Kick;
void t808Kick_init (t808Kick* const);
- void t808Kick_free (t808Kick* const);
void t808Kick_initToPool (t808Kick* const, tMempool* const);
- void t808Kick_freeFromPool (t808Kick* const, tMempool* const);
+ void t808Kick_free (t808Kick* const);
float t808Kick_tick (t808Kick* const);
void t808Kick_on (t808Kick* const, float vel);
--- a/leaf/Inc/leaf-midi.h
+++ b/leaf/Inc/leaf-midi.h
@@ -43,12 +43,12 @@
#define STACK_SIZE 128
typedef struct _tStack
{
+ tMempool mempool;
int data[STACK_SIZE];
uint16_t pos;
uint16_t size;
uint16_t capacity;
oBool ordered;
-
} _tStack;
typedef _tStack* tStack;
@@ -60,13 +60,6 @@
void tStack_init (tStack* const stack);
- //! Free a tStack from the default LEAF mempool.
- /*!
- @param stack A pointer to the tStack to be freed.
- */
- void tStack_free (tStack* const stack);
-
-
//! Initialize a tStack to a specified mempool.
/*!
@param stack A pointer to the tStack to be initialized.
@@ -75,13 +68,13 @@
void tStack_initToPool (tStack* const stack, tMempool* const pool);
- //! Free a tStack from a specified mempool.
+ //! Free a tStack from the default LEAF mempool.
/*!
@param stack A pointer to the tStack to be freed.
- @param pool A pointer to the tMempool from which the tStack should be freed.
*/
- void tStack_freeFromPool (tStack* const stack, tMempool* const pool);
+ void tStack_free (tStack* const stack);
+
//! Set the capacity of the stack.
/*!
@param stack A pointer to the relevant tStack.
@@ -171,6 +164,8 @@
/* tPoly */
typedef struct _tPoly
{
+ tMempool mempool;
+
tStack stack;
tStack orderStack;
@@ -201,7 +196,6 @@
int currentVoice;
int currentVelocity;
int maxLength;
-
} _tPoly;
typedef _tPoly* tPoly;
@@ -215,13 +209,6 @@
void tPoly_init (tPoly* const poly, int maxNumVoices);
- //! Free a tPoly from the default LEAF mempool.
- /*!
- @param poly A pointer to the tPoly to be freed.
- */
- void tPoly_free (tPoly* const poly);
-
-
//! Initialize a tPoly to a specified mempool.
/*!
@param poly A pointer to the tPoly to be initialized.
@@ -230,13 +217,13 @@
void tPoly_initToPool (tPoly* const poly, int maxNumVoices, tMempool* const pool);
- //! Free a tPoly from a specified mempool.
+ //! Free a tPoly from the default LEAF mempool.
/*!
@param poly A pointer to the tPoly to be freed.
- @param pool A pointer to the tMempool from which the tPoly should be freed.
*/
- void tPoly_freeFromPool (tPoly* const poly, tMempool* const pool);
+ void tPoly_free (tPoly* const poly);
+
//! Add a note with a given velocity to the poly handler.
/*!
@param poly A pointer to the relevant tPoly.
@@ -367,6 +354,8 @@
/* tPoly */
typedef struct _tSimplePoly
{
+ tMempool mempool;
+
tStack stack;
int numVoices;
@@ -388,13 +377,6 @@
void tSimplePoly_init (tSimplePoly* const poly, int maxNumVoices);
- //! Free a tPoly from the default LEAF mempool.
- /*!
- @param poly A pointer to the tPoly to be freed.
- */
- void tSimplePoly_free (tSimplePoly* const poly);
-
-
//! Initialize a tPoly to a specified mempool.
/*!
@param poly A pointer to the tPoly to be initialized.
@@ -403,13 +385,13 @@
void tSimplePoly_initToPool (tSimplePoly* const poly, int maxNumVoices, tMempool* const pool);
- //! Free a tPoly from a specified mempool.
+ //! Free a tPoly from the default LEAF mempool.
/*!
@param poly A pointer to the tPoly to be freed.
- @param pool A pointer to the tMempool from which the tPoly should be freed.
*/
- void tSimplePoly_freeFromPool (tSimplePoly* const poly, tMempool* const pool);
-
+ void tSimplePoly_free (tSimplePoly* const poly);
+
+
//! Add a note with a given velocity to the poly handler.
/*!
@param poly A pointer to the relevant tPoly.
--- a/leaf/Inc/leaf-oscillators.h
+++ b/leaf/Inc/leaf-oscillators.h
@@ -29,6 +29,7 @@
typedef struct _tCycle
{
+ tMempool mempool;
// Underlying phasor
float phase;
float inc,freq;
@@ -50,13 +51,6 @@
void tCycle_init (tCycle* const osc);
- //! Free a tCycle from the default LEAF mempool.
- /*!
- @param osc A pointer to the tCycle to be freed.
- */
- void tCycle_free (tCycle* const osc);
-
-
//! Initialize a tCycle to a specified mempool.
/*!
@param osc A pointer to the tCycle to be initialized.
@@ -65,12 +59,11 @@
void tCycle_initToPool (tCycle* const osc, tMempool* const pool);
- //! Free a tCycle from a specified mempool.
+ //! Free a tCycle from the default LEAF mempool.
/*!
@param osc A pointer to the tCycle to be freed.
- @param pool A pointer to the tMempool from which the tCycle should be freed.
*/
- void tCycle_freeFromPool (tCycle* const osc, tMempool* const pool);
+ void tCycle_free (tCycle* const osc);
//! Tick a tCycle oscillator.
@@ -95,6 +88,7 @@
/* tTriangle: Anti-aliased Triangle waveform using wavetable interpolation. Wavetables constructed from sine components. */
typedef struct _tTriangle
{
+ tMempool mempool;
// Underlying phasor
float phase;
float inc,freq;
@@ -118,13 +112,6 @@
void tTriangle_init (tTriangle* const osc);
- //! Free a tTriangle from the default LEAF mempool.
- /*!
- @param osc A pointer to the tTriangle to be freed.
- */
- void tTriangle_free (tTriangle* const osc);
-
-
//! Initialize a tTriangle to a specified mempool.
/*!
@param osc A pointer to the tTriangle to be initialized.
@@ -133,12 +120,11 @@
void tTriangle_initToPool (tTriangle* const osc, tMempool* const pool);
- //! Free a tTriangle from a specified mempool.
+ //! Free a tTriangle from the default LEAF mempool.
/*!
@param osc A pointer to the tTriangle to be freed.
- @param pool A pointer to the tMempool from which the tTriangle should be freed.
*/
- void tTriangle_freeFromPool (tTriangle* const osc, tMempool* const pool);
+ void tTriangle_free (tTriangle* const osc);
//! Tick a tTriangle oscillator.
@@ -163,6 +149,7 @@
/* tSquare: Anti-aliased Square waveform using wavetable interpolation. Wavetables constructed from sine components. */
typedef struct _tSquare
{
+ tMempool mempool;
// Underlying phasor
float phase;
float inc,freq;
@@ -186,13 +173,6 @@
void tSquare_init (tSquare* const osc);
- //! Free a tSquare from the default LEAF mempool.
- /*!
- @param osc A pointer to the tSquare to be freed.
- */
- void tSquare_free (tSquare* const osc);
-
-
//! Initialize a tSquare to a specified mempool.
/*!
@param osc A pointer to the tSquare to be initialized.
@@ -201,12 +181,11 @@
void tSquare_initToPool (tSquare* const osc, tMempool* const);
- //! Free a tSquare from a specified mempool.
+ //! Free a tSquare from the default LEAF mempool.
/*!
@param osc A pointer to the tSquare to be freed.
- @param pool A pointer to the tMempool from which the tSquare should be freed.
*/
- void tSquare_freeFromPool(tSquare* const osc, tMempool* const);
+ void tSquare_free (tSquare* const osc);
//! Tick a tSquare oscillator.
@@ -231,6 +210,7 @@
/* tSawtooth: Anti-aliased Sawtooth waveform using wavetable interpolation. Wavetables constructed from sine components. */
typedef struct _tSawtooth
{
+ tMempool mempool;
// Underlying phasor
float phase;
float inc,freq;
@@ -254,13 +234,6 @@
void tSawtooth_init (tSawtooth* const osc);
- //! Free a tSawtooth from the default LEAF mempool.
- /*!
- @param osc A pointer to the tSawtooth to be freed.
- */
- void tSawtooth_free (tSawtooth* const osc);
-
-
//! Initialize a tSawtooth to a specified mempool.
/*!
@param osc A pointer to the tSawtooth to be initialized.
@@ -269,12 +242,11 @@
void tSawtooth_initToPool (tSawtooth* const osc, tMempool* const pool);
- //! Free a tSawtooth from a specified mempool.
+ //! Free a tSawtooth from the default LEAF mempool.
/*!
@param osc A pointer to the tSawtooth to be freed.
- @param pool A pointer to the tMempool from which the tSawtooth should be freed.
*/
- void tSawtooth_freeFromPool (tSawtooth* const osc, tMempool* const pool);
+ void tSawtooth_free (tSawtooth* const osc);
//! Tick a tSawtooth oscillator.
@@ -298,6 +270,7 @@
typedef struct _tSine
{
+ tMempool mempool;
float* sine;
int size;
float phase;
@@ -320,13 +293,6 @@
void tSine_init (tSine* const osc, int size);
- //! Free a tSine from the default LEAF mempool.
- /*!
- @param osc A pointer to the tSine to be freed.
- */
- void tSine_free (tSine* const osc);
-
-
//! Initialize a tSine to a specified mempool.
/*!
@param osc A pointer to the tSine to be initialized.
@@ -335,12 +301,11 @@
void tSine_initToPool (tSine* const osc, int size, tMempool* const pool);
- //! Free a tSine from a specified mempool.
+ //! Free a tSine from the default LEAF mempool.
/*!
@param osc A pointer to the tSine to be freed.
- @param pool A pointer to the tMempool from which the tSine should be freed.
*/
- void tSine_freeFromPool (tSine* const osc, tMempool* const pool);
+ void tSine_free (tSine* const osc);
//! Tick a tSine oscillator.
@@ -365,6 +330,7 @@
/* tTri: Anti-aliased Triangle waveform using wavetable interpolation. */
typedef struct _tTri
{
+ tMempool mempool;
float phase;
float inc,freq;
float skew;
@@ -387,13 +353,6 @@
void tTri_init (tTri* const osc);
- //! Free a tTri from the default LEAF mempool.
- /*!
- @param osc A pointer to the tTri to be freed.
- */
- void tTri_free (tTri* const osc);
-
-
//! Initialize a tTri to a specified mempool.
/*!
@param osc A pointer to the tTri to be initialized.
@@ -402,12 +361,11 @@
void tTri_initToPool (tTri* const osc, tMempool* const pool);
- //! Free a tTri from a specified mempool.
+ //! Free a tTri from the default LEAF mempool.
/*!
@param osc A pointer to the tTri to be freed.
- @param pool A pointer to the tMempool from which the tTri should be freed.
*/
- void tTri_freeFromPool (tTri* const osc, tMempool* const pool);
+ void tTri_free (tTri* const osc);
//! Tick a tTri oscillator.
@@ -434,6 +392,7 @@
/* tPulse: Anti-aliased Square waveform. */
typedef struct _tPulse
{
+ tMempool mempool;
float phase;
float inc,freq;
float width;
@@ -455,13 +414,6 @@
void tPulse_init (tPulse* const osc);
- //! Free a tPulse from the default LEAF mempool.
- /*!
- @param osc A pointer to the tPulse to be freed.
- */
- void tPulse_free (tPulse* const osc);
-
-
//! Initialize a tPulse to a specified mempool.
/*!
@param osc A pointer to the tPulse to be initialized.
@@ -470,12 +422,11 @@
void tPulse_initToPool (tPulse* const osc, tMempool* const);
- //! Free a tPulse from a specified mempool.
+ //! Free a tPulse from the default LEAF mempool.
/*!
@param osc A pointer to the tPulse to be freed.
- @param pool A pointer to the tMempool from which the tPulse should be freed.
*/
- void tPulse_freeFromPool(tPulse* const osc, tMempool* const);
+ void tPulse_free (tPulse* const osc);
//! Tick a tPulse oscillator.
@@ -502,6 +453,7 @@
/* tSawtooth: Anti-aliased Sawtooth waveform. */
typedef struct _tSaw
{
+ tMempool mempool;
float phase;
float inc,freq;
} _tSaw;
@@ -522,13 +474,6 @@
void tSaw_init (tSaw* const osc);
- //! Free a tSaw from the default LEAF mempool.
- /*!
- @param osc A pointer to the tSaw to be freed.
- */
- void tSaw_free (tSaw* const osc);
-
-
//! Initialize a tSaw to a specified mempool.
/*!
@param osc A pointer to the tSaw to be initialized.
@@ -537,12 +482,11 @@
void tSaw_initToPool (tSaw* const osc, tMempool* const pool);
- //! Free a tSaw from a specified mempool.
+ //! Free a tSaw from the default LEAF mempool.
/*!
@param osc A pointer to the tSaw to be freed.
- @param pool A pointer to the tMempool from which the tSaw should be freed.
*/
- void tSaw_freeFromPool (tSaw* const osc, tMempool* const pool);
+ void tSaw_free (tSaw* const osc);
//! Tick a tSaw oscillator.
@@ -567,10 +511,10 @@
/* tPhasor: Aliasing phasor [0.0, 1.0) */
typedef struct _tPhasor
{
+ tMempool mempool;
float phase;
float inc,freq;
uint8_t phaseDidReset;
-
} _tPhasor;
typedef _tPhasor* tPhasor;
@@ -589,13 +533,6 @@
void tPhasor_init (tPhasor* const osc);
- //! Free a tPhasor from the default LEAF mempool.
- /*!
- @param osc A pointer to the tPhasor to be freed.
- */
- void tPhasor_free (tPhasor* const osc);
-
-
//! Initialize a tPhasor to a specified mempool.
/*!
@param osc A pointer to the tPhasor to be initialized.
@@ -604,14 +541,13 @@
void tPhasor_initToPool (tPhasor* const osc, tMempool* const);
- //! Free a tPhasor from a specified mempool.
+ //! Free a tPhasor from the default LEAF mempool.
/*!
@param osc A pointer to the tPhasor to be freed.
- @param pool A pointer to the tMempool from which the tPhasor should be freed.
*/
- void tPhasor_freeFromPool(tPhasor* const osc, tMempool* const);
+ void tPhasor_free (tPhasor* const osc);
-
+
//! Tick a tPhasor oscillator.
/*!
@param osc A pointer to the relevant tPhasor.
@@ -653,10 +589,10 @@
typedef struct _tNoise
{
+ tMempool mempool;
NoiseType type;
float pinkb0, pinkb1, pinkb2;
float(*rand)(void);
-
} _tNoise;
typedef _tNoise* tNoise;
@@ -668,13 +604,6 @@
void tNoise_init (tNoise* const noise, NoiseType type);
- //! Free a tNoise from the default LEAF mempool.
- /*!
- @param osc A pointer to the tNoise to be freed.
- */
- void tNoise_free (tNoise* const noise);
-
-
//! Initialize a tNoise to a specified mempool.
/*!
@param osc A pointer to the tNoise to be initialized.
@@ -683,12 +612,11 @@
void tNoise_initToPool (tNoise* const noise, NoiseType type, tMempool* const);
- //! Free a tNoise from a specified mempool.
+ //! Free a tNoise from the default LEAF mempool.
/*!
@param osc A pointer to the tNoise to be freed.
- @param pool A pointer to the tMempool from which the tNoise should be freed.
*/
- void tNoise_freeFromPool (tNoise* const noise, tMempool* const);
+ void tNoise_free (tNoise* const noise);
//! Tick a tNoise oscillator.
@@ -723,6 +651,8 @@
typedef struct _tNeuron
{
+ tMempool mempool;
+
tPoleZero f;
NeuronMode mode;
@@ -747,13 +677,6 @@
void tNeuron_init (tNeuron* const neuron);
- //! Free a tNeuron from the default LEAF mempool.
- /*!
- @param neuron A pointer to the tNeuron to be freed.
- */
- void tNeuron_free (tNeuron* const neuron);
-
-
//! Initialize a tNeuron to a specified mempool.
/*!
@param neuron A pointer to the tNeuron to be initialized.
@@ -762,12 +685,11 @@
void tNeuron_initToPool (tNeuron* const neuron, tMempool* const pool);
- //! Free a tNeuron from a specified mempool.
+ //! Free a tNeuron from the default LEAF mempool.
/*!
@param neuron A pointer to the tNeuron to be freed.
- @param pool A pointer to the tMempool from which the tNeuron should be freed.
*/
- void tNeuron_freeFromPool(tNeuron* const neuron, tMempool* const pool);
+ void tNeuron_free (tNeuron* const neuron);
//! Reset the neuron model.
@@ -916,7 +838,7 @@
typedef _tMinBLEPHandler* tMinBLEPHandler;
- void tMinBLEPHandler_init (tMinBLEPHandler* const minblep, tMinBLEPTable* const table, int oversamplerRatio);
+ void tMinBLEPHandler_init (tMinBLEPHandler* const minblep, tMinBLEPTable* const table);
void tMinBLEPHandler_free (tMinBLEPHandler* const minblep);
void tMinBLEPHandler_initToPool (tMinBLEPHandler* const minblep, tMinBLEPTable* const table, tMempool* const pool);
@@ -929,6 +851,8 @@
/* tMBTriangle: Anti-aliased Triangle waveform using wavetable interpolation. */
typedef struct _tMBTriangle
{
+ tMempool mempool;
+
float phase;
float inc,freq;
float skew;
@@ -954,13 +878,6 @@
void tMBTriangle_init (tMBTriangle* const osc, tMinBLEPTable* const table);
- //! Free a tMBTriangle from the default LEAF mempool.
- /*!
- @param osc A pointer to the tMBTriangle to be freed.
- */
- void tMBTriangle_free (tMBTriangle* const osc);
-
-
//! Initialize a tMBTriangle to a specified mempool.
/*!
@param osc A pointer to the tMBTriangle to be initialized.
@@ -967,14 +884,13 @@
@param pool A pointer to the tMempool to which the tMBTriangle should be initialized.
*/
void tMBTriangle_initToPool (tMBTriangle* const osc, tMinBLEPTable* const table, tMempool* const pool);
+
-
- //! Free a tMBTriangle from a specified mempool.
+ //! Free a tMBTriangle from the default LEAF mempool.
/*!
@param osc A pointer to the tMBTriangle to be freed.
- @param pool A pointer to the tMempool from which the tMBTriangle should be freed.
*/
- void tMBTriangle_freeFromPool (tMBTriangle* const osc, tMempool* const pool);
+ void tMBTriangle_free (tMBTriangle* const osc);
//! Tick a tMBTriangle oscillator.
@@ -1003,6 +919,8 @@
/* tMBPulse: Anti-aliased Square waveform. */
typedef struct _tMBPulse
{
+ tMempool mempool;
+
float phase;
float inc,freq;
float width;
@@ -1027,13 +945,6 @@
void tMBPulse_init (tMBPulse* const osc, tMinBLEPTable* const table);
- //! Free a tMBPulse from the default LEAF mempool.
- /*!
- @param osc A pointer to the tMBPulse to be freed.
- */
- void tMBPulse_free (tMBPulse* const osc);
-
-
//! Initialize a tMBPulse to a specified mempool.
/*!
@param osc A pointer to the tMBPulse to be initialized.
@@ -1042,12 +953,11 @@
void tMBPulse_initToPool (tMBPulse* const osc, tMinBLEPTable* const table, tMempool* const);
- //! Free a tMBPulse from a specified mempool.
+ //! Free a tMBPulse from the default LEAF mempool.
/*!
@param osc A pointer to the tMBPulse to be freed.
- @param pool A pointer to the tMempool from which the tMBPulse should be freed.
*/
- void tMBPulse_freeFromPool(tMBPulse* const osc, tMempool* const);
+ void tMBPulse_free (tMBPulse* const osc);
//! Tick a tMBPulse oscillator.
@@ -1077,6 +987,8 @@
/* tMBSawtooth: Anti-aliased Sawtooth waveform. */
typedef struct _tMBSaw
{
+ tMempool mempool;
+
float phase;
float inc,freq;
@@ -1100,13 +1012,6 @@
void tMBSaw_init (tMBSaw* const osc, tMinBLEPTable* const table);
- //! Free a tMBSaw from the default LEAF mempool.
- /*!
- @param osc A pointer to the tMBSaw to be freed.
- */
- void tMBSaw_free (tMBSaw* const osc);
-
-
//! Initialize a tMBSaw to a specified mempool.
/*!
@param osc A pointer to the tMBSaw to be initialized.
@@ -1115,12 +1020,11 @@
void tMBSaw_initToPool (tMBSaw* const osc, tMinBLEPTable* const table, tMempool* const pool);
- //! Free a tMBSaw from a specified mempool.
+ //! Free a tMBSaw from the default LEAF mempool.
/*!
@param osc A pointer to the tMBSaw to be freed.
- @param pool A pointer to the tMempool from which the tMBSaw should be freed.
*/
- void tMBSaw_freeFromPool (tMBSaw* const osc, tMempool* const pool);
+ void tMBSaw_free (tMBSaw* const osc);
//! Tick a tMBSaw oscillator.
--- a/leaf/Inc/leaf-physical.h
+++ b/leaf/Inc/leaf-physical.h
@@ -39,6 +39,8 @@
/* Karplus Strong model */
typedef struct _tPluck
{
+ tMempool mempool;
+
tAllpassDelay delayLine; // Allpass or Linear?? big difference...
tOneZero loopFilter;
tOnePole pickFilter;
@@ -49,15 +51,13 @@
float lastFreq;
float sr;
-
} _tPluck;
typedef _tPluck* tPluck;
void tPluck_init (tPluck* const, float lowestFrequency); //float delayBuff[DELAY_LENGTH]);
- void tPluck_free (tPluck* const);
void tPluck_initToPool (tPluck* const, float lowestFrequency, tMempool* const);
- void tPluck_freeFromPool (tPluck* const, tMempool* const);
+ void tPluck_free (tPluck* const);
float tPluck_tick (tPluck* const);
@@ -92,6 +92,8 @@
/* Stif Karplus Strong model */
typedef struct _tKarplusStrong
{
+ tMempool mempool;
+
tAllpassDelay delayLine;
tLinearDelay combDelay;
tOneZero filter;
@@ -108,15 +110,13 @@
float pickupPosition;
float lastOut;
-
} _tKarplusStrong;
typedef _tKarplusStrong* tKarplusStrong;
void tKarplusStrong_init (tKarplusStrong* const, float lowestFrequency); // float delayBuff[2][DELAY_LENGTH]);
- void tKarplusStrong_free (tKarplusStrong* const);
void tKarplusStrong_initToPool (tKarplusStrong* const, float lowestFrequency, tMempool* const);
- void tKarplusStrong_freeFromPool (tKarplusStrong* const, tMempool* const);
+ void tKarplusStrong_free (tKarplusStrong* const);
float tKarplusStrong_tick (tKarplusStrong* const);
@@ -151,7 +151,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* Simple Living String */
- typedef struct _tSimpleLivingString {
+ typedef struct _tSimpleLivingString
+ {
+ tMempool mempool;
float freq, waveLengthInSamples; // the frequency of the string, determining delay length
float dampFreq; // frequency for the bridge LP filter, in Hz
float decay; // amplitude damping factor for the string (only active in mode 0)
@@ -169,11 +171,10 @@
void tSimpleLivingString_init (tSimpleLivingString* const, float freq, float dampFreq,
float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode);
- void tSimpleLivingString_free (tSimpleLivingString* const);
void tSimpleLivingString_initToPool (tSimpleLivingString* const, float freq, float dampFreq,
float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const);
- void tSimpleLivingString_freeFromPool (tSimpleLivingString* const, tMempool* const);
+ void tSimpleLivingString_free (tSimpleLivingString* const);
float tSimpleLivingString_tick (tSimpleLivingString* const, float input);
float tSimpleLivingString_sample (tSimpleLivingString* const);
@@ -189,7 +190,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* Living String */
- typedef struct _tLivingString {
+ typedef struct _tLivingString
+ {
+ tMempool mempool;
float freq, waveLengthInSamples; // the frequency of the whole string, determining delay length
float pickPos; // the pick position, dividing the string in two, in ratio
float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj)
@@ -209,11 +212,10 @@
void tLivingString_init (tLivingString* const, float freq, float pickPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode);
- void tLivingString_free (tLivingString* const);
void tLivingString_initToPool (tLivingString* const, float freq, float pickPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const);
- void tLivingString_freeFromPool (tLivingString* const, tMempool* const);
+ void tLivingString_free (tLivingString* const);
float tLivingString_tick (tLivingString* const, float input);
float tLivingString_sample (tLivingString* const);
@@ -233,7 +235,9 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/* Complex Living String */
- typedef struct _tComplexLivingString {
+ typedef struct _tComplexLivingString
+ {
+ tMempool mempool;
float freq, waveLengthInSamples; // the frequency of the whole string, determining delay length
float pickPos; // the pick position, dividing the string, in ratio
float prepPos; // preparation position, in ratio
@@ -255,11 +259,10 @@
void tComplexLivingString_init (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode);
- void tComplexLivingString_free (tComplexLivingString* const);
void tComplexLivingString_initToPool (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const);
- void tComplexLivingString_freeFromPool (tComplexLivingString* const, tMempool* const);
+ void tComplexLivingString_free (tComplexLivingString* const);
float tComplexLivingString_tick (tComplexLivingString* const, float input);
float tComplexLivingString_sample (tComplexLivingString* const);
@@ -279,7 +282,9 @@
//Reed Table - borrowed from STK
- typedef struct _tReedTable {
+ typedef struct _tReedTable
+ {
+ tMempool mempool;
float offset, slope;
} _tReedTable;
@@ -286,9 +291,8 @@
typedef _tReedTable* tReedTable;
void tReedTable_init (tReedTable* const, float offset, float slope);
- void tReedTable_free (tReedTable* const);
void tReedTable_initToPool (tReedTable* const, float offset, float slope, tMempool* const);
- void tReedTable_freeFromPool (tReedTable* const, tMempool* const);
+ void tReedTable_free (tReedTable* const);
float tReedTable_tick (tReedTable* const, float input);
float tReedTable_tanh_tick (tReedTable* const, float input); //tanh softclip version of reed table - replacing the hard clip in original stk code
--- a/leaf/Inc/leaf-reverb.h
+++ b/leaf/Inc/leaf-reverb.h
@@ -35,6 +35,8 @@
/* PRCReverb: Reverb, reimplemented from STK (Cook and Scavone). */
typedef struct _tPRCReverb
{
+ tMempool mempool;
+
float mix, t60;
float inv_441;
@@ -45,15 +47,13 @@
float combCoeff;
float lastIn, lastOut;
-
} _tPRCReverb;
typedef _tPRCReverb* tPRCReverb;
void tPRCReverb_init (tPRCReverb* const, float t60);
- void tPRCReverb_free (tPRCReverb* const);
void tPRCReverb_initToPool (tPRCReverb* const, float t60, tMempool* const);
- void tPRCReverb_freeFromPool (tPRCReverb* const, tMempool* const);
+ void tPRCReverb_free (tPRCReverb* const);
void tPRCReverb_clear (tPRCReverb* const);
float tPRCReverb_tick (tPRCReverb* const, float input);
@@ -69,6 +69,8 @@
/* NReverb: Reverb, reimplemented from STK (Cook and Scavone). */
typedef struct _tNReverb
{
+ tMempool mempool;
+
float mix, t60;
float inv_sr, inv_441;
@@ -80,15 +82,13 @@
float lowpassState;
float lastIn, lastOut;
-
} _tNReverb;
typedef _tNReverb* tNReverb;
void tNReverb_init (tNReverb* const, float t60);
- void tNReverb_free (tNReverb* const);
void tNReverb_initToPool (tNReverb* const, float t60, tMempool* const);
- void tNReverb_freeFromPool (tNReverb* const, tMempool* const);
+ void tNReverb_free (tNReverb* const);
void tNReverb_clear (tNReverb* const);
float tNReverb_tick (tNReverb* const, float input);
@@ -104,6 +104,8 @@
typedef struct _tDattorroReverb
{
+ tMempool mempool;
+
float predelay;
float input_filter;
float feedback_filter;
@@ -143,15 +145,13 @@
tHighpass f2_hp;
tCycle f2_lfo;
-
} _tDattorroReverb;
typedef _tDattorroReverb* tDattorroReverb;
void tDattorroReverb_init (tDattorroReverb* const);
- void tDattorroReverb_free (tDattorroReverb* const);
void tDattorroReverb_initToPool (tDattorroReverb* const, tMempool* const);
- void tDattorroReverb_freeFromPool (tDattorroReverb* const, tMempool* const);
+ void tDattorroReverb_free (tDattorroReverb* const);
void tDattorroReverb_clear (tDattorroReverb* const);
float tDattorroReverb_tick (tDattorroReverb* const, float input);
--- a/leaf/Inc/leaf-sampling.h
+++ b/leaf/Inc/leaf-sampling.h
@@ -42,6 +42,8 @@
typedef struct _tBuffer
{
+ tMempool mempool;
+
float* buff;
uint32_t idx;
@@ -50,15 +52,13 @@
RecordMode mode;
int active;
-
} _tBuffer;
typedef _tBuffer* tBuffer;
void tBuffer_init (tBuffer* const, uint32_t length);
- void tBuffer_free (tBuffer* const);
void tBuffer_initToPool (tBuffer* const, uint32_t length, tMempool* const);
- void tBuffer_freeFromPool (tBuffer* const, tMempool* const);
+ void tBuffer_free (tBuffer* const);
void tBuffer_tick (tBuffer* const, float sample);
@@ -92,6 +92,8 @@
typedef struct _tSampler
{
+ tMempool mempool;
+
tBuffer samp;
tRamp gain;
@@ -119,15 +121,13 @@
float flipStart;
float flipIdx;
-
} _tSampler;
typedef _tSampler* tSampler;
void tSampler_init (tSampler* const, tBuffer* const);
- void tSampler_free (tSampler* const);
void tSampler_initToPool (tSampler* const, tBuffer* const, tMempool* const);
- void tSampler_freeFromPool (tSampler* const, tMempool* const);
+ void tSampler_free (tSampler* const);
float tSampler_tick (tSampler* const);
@@ -150,6 +150,7 @@
typedef struct _tAutoSampler
{
+ tMempool mempool;
tSampler sampler;
tEnvelopeFollower ef;
uint32_t windowSize;
@@ -163,9 +164,8 @@
typedef _tAutoSampler* tAutoSampler;
void tAutoSampler_init (tAutoSampler* const, tBuffer* const);
- void tAutoSampler_free (tAutoSampler* const);
void tAutoSampler_initToPool (tAutoSampler* const, tBuffer* const, tMempool* const);
- void tAutoSampler_freeFromPool (tAutoSampler* const, tMempool* const);
+ void tAutoSampler_free (tAutoSampler* const);
float tAutoSampler_tick (tAutoSampler* const, float input);
--- a/leaf/Src/leaf-analysis.c
+++ b/leaf/Src/leaf-analysis.c
@@ -27,15 +27,11 @@
tEnvelopeFollower_initToPool(ef, attackThreshold, decayCoeff, &leaf.mempool);
}
-void tEnvelopeFollower_free(tEnvelopeFollower* const ef)
-{
- tEnvelopeFollower_freeFromPool(ef, &leaf.mempool);
-}
-
void tEnvelopeFollower_initToPool (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp)
{
_tMempool* m = *mp;
_tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), m);
+ e->mempool = m;
e->y = 0.0f;
e->a_thresh = attackThreshold;
@@ -42,12 +38,11 @@
e->d_coeff = decayCoeff;
}
-void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const ef, tMempool* const mp)
+void tEnvelopeFollower_free (tEnvelopeFollower* const ef)
{
- _tMempool* m = *mp;
_tEnvelopeFollower* e = *ef;
- mpool_free((char*)e, m);
+ mpool_free((char*)e, e->mempool);
}
float tEnvelopeFollower_tick(tEnvelopeFollower* const ef, float x)
@@ -91,14 +86,12 @@
{
tZeroCrossing_initToPool (zc, maxWindowSize, &leaf.mempool);
}
-void tZeroCrossing_free (tZeroCrossing* const zc)
-{
- tZeroCrossing_freeFromPool (zc, &leaf.mempool);
-}
+
void tZeroCrossing_initToPool (tZeroCrossing* const zc, int maxWindowSize, tMempool* const mp)
{
_tMempool* m = *mp;
_tZeroCrossing* z = *zc = (_tZeroCrossing*) mpool_alloc(sizeof(_tZeroCrossing), m);
+ z->mempool = m;
z->count = 0;
z->maxWindowSize = maxWindowSize;
@@ -110,13 +103,13 @@
z->countBuffer = (uint16_t*) mpool_calloc(sizeof(uint16_t) * maxWindowSize, m);
}
-void tZeroCrossing_freeFromPool (tZeroCrossing* const zc, tMempool* const mp)
+void tZeroCrossing_free (tZeroCrossing* const zc)
{
- _tMempool* m = *mp;
_tZeroCrossing* z = *zc;
- mpool_free((char*)z->inBuffer, m);
- mpool_free((char*)z->countBuffer, m);
- mpool_free((char*)z, m);
+
+ mpool_free((char*)z->inBuffer, z->mempool);
+ mpool_free((char*)z->countBuffer, z->mempool);
+ mpool_free((char*)z, z->mempool);
}
//returns proportion of zero crossings within window size (0.0 would be none in window, 1.0 would be all zero crossings)
@@ -185,15 +178,11 @@
tPowerFollower_initToPool(pf, factor, &leaf.mempool);
}
-void tPowerFollower_free(tPowerFollower* const pf)
-{
- tPowerFollower_freeFromPool(pf, &leaf.mempool);
-}
-
void tPowerFollower_initToPool (tPowerFollower* const pf, float factor, tMempool* const mp)
{
_tMempool* m = *mp;
_tPowerFollower* p = *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), m);
+ p->mempool = m;
p->curr=0.0f;
p->factor=factor;
@@ -200,12 +189,11 @@
p->oneminusfactor=1.0f-factor;
}
-void tPowerFollower_freeFromPool (tPowerFollower* const pf, tMempool* const mp)
+void tPowerFollower_free (tPowerFollower* const pf)
{
- _tMempool* m = *mp;
_tPowerFollower* p = *pf;
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
int tPowerFollower_setFactor(tPowerFollower* const pf, float factor)
@@ -244,15 +232,11 @@
tEnvPD_initToPool(xpd, ws, hs, bs, &leaf.mempool);
}
-void tEnvPD_free (tEnvPD* const xpd)
-{
- tEnvPD_freeFromPool(xpd, &leaf.mempool);
-}
-
void tEnvPD_initToPool (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp)
{
_tMempool* m = *mp;
_tEnvPD* x = *xpd = (_tEnvPD*) mpool_calloc(sizeof(_tEnvPD), m);
+ x->mempool = m;
int period = hs, npoints = ws;
@@ -292,12 +276,11 @@
// ~ ~ ~ ~ ~ ~ ~ ~
}
-void tEnvPD_freeFromPool (tEnvPD* const xpd, tMempool* const mp)
+void tEnvPD_free (tEnvPD* const xpd)
{
- _tMempool* m = *mp;
_tEnvPD* x = *xpd;
- mpool_free((char*)x, m);
+ mpool_free((char*)x, x->mempool);
}
float tEnvPD_tick (tEnvPD* const xpd)
@@ -357,25 +340,20 @@
tAttackDetection_initToPool(ad, blocksize, atk, rel, &leaf.mempool);
}
-void tAttackDetection_free(tAttackDetection* const ad)
+void tAttackDetection_initToPool (tAttackDetection* const ad, int blocksize, int atk, int rel, tMempool* const mp)
{
- tAttackDetection_freeFromPool(ad, &leaf.mempool);
-}
-
-void tAttackDetection_initToPool (tAttackDetection* const ad, int blocksize, int atk, int rel, tMempool* const mp)
-{
_tMempool* m = *mp;
- *ad = (_tAttackDetection*) mpool_alloc(sizeof(_tAttackDetection), m);
+ _tAttackDetection* a = *ad = (_tAttackDetection*) mpool_alloc(sizeof(_tAttackDetection), m);
+ a->mempool = m;
atkdtk_init(ad, blocksize, atk, rel);
}
-void tAttackDetection_freeFromPool (tAttackDetection* const ad, tMempool* const mp)
+void tAttackDetection_free (tAttackDetection* const ad)
{
- _tMempool* m = *mp;
_tAttackDetection* a = *ad;
- mpool_free((char*)a, m);
+ mpool_free((char*)a, a->mempool);
}
/*******Public Functions***********/
@@ -507,15 +485,11 @@
tSNAC_initToPool(snac, overlaparg, &leaf.mempool);
}
-void tSNAC_free(tSNAC* const snac)
-{
- tSNAC_freeFromPool(snac, &leaf.mempool);
-}
-
void tSNAC_initToPool (tSNAC* const snac, int overlaparg, tMempool* const mp)
{
_tMempool* m = *mp;
_tSNAC* s = *snac = (_tSNAC*) mpool_alloc(sizeof(_tSNAC), m);
+ s->mempool = m;
s->biasfactor = DEFBIAS;
s->timeindex = 0;
@@ -534,16 +508,15 @@
tSNAC_setOverlap(snac, overlaparg);
}
-void tSNAC_freeFromPool (tSNAC* const snac, tMempool* const mp)
+void tSNAC_free (tSNAC* const snac)
{
- _tMempool* m = *mp;
_tSNAC* s = *snac;
- mpool_free((char*)s->inputbuf, m);
- mpool_free((char*)s->processbuf, m);
- mpool_free((char*)s->spectrumbuf, m);
- mpool_free((char*)s->biasbuf, m);
- mpool_free((char*)s, m);
+ mpool_free((char*)s->inputbuf, s->mempool);
+ mpool_free((char*)s->processbuf, s->mempool);
+ mpool_free((char*)s->spectrumbuf, s->mempool);
+ mpool_free((char*)s->biasbuf, s->mempool);
+ mpool_free((char*)s, s->mempool);
}
/******************************************************************************/
@@ -858,20 +831,16 @@
//===========================================================================
// PERIODDETECTION
//===========================================================================
-void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
+void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
{
tPeriodDetection_initToPool(pd, in, out, bufSize, frameSize, &leaf.mempool);
}
-void tPeriodDetection_free (tPeriodDetection* const pd)
+void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize, tMempool* const mp)
{
- tPeriodDetection_freeFromPool(pd, &leaf.mempool);
-}
-
-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_calloc(sizeof(_tPeriodDetection), m);
+ p->mempool = m;
p->inBuffer = in;
p->outBuffer = out;
@@ -898,14 +867,13 @@
p->fidelityThreshold = 0.95;
}
-void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp)
+void tPeriodDetection_free (tPeriodDetection* const pd)
{
- _tMempool* m = *mp;
_tPeriodDetection* p = *pd;
- tEnvPD_freeFromPool(&p->env, mp);
- tSNAC_freeFromPool(&p->snac, mp);
- mpool_free((char*)p, m);
+ tEnvPD_free(&p->env);
+ tSNAC_free(&p->snac);
+ mpool_free((char*)p, p->mempool);
}
float tPeriodDetection_tick (tPeriodDetection* pd, float sample)
--- a/leaf/Src/leaf-delay.c
+++ b/leaf/Src/leaf-delay.c
@@ -24,15 +24,11 @@
tDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
}
-void tDelay_free(tDelay* const dl)
-{
- tDelay_freeFromPool(dl, &leaf.mempool);
-}
-
void tDelay_initToPool (tDelay* const dl, uint32_t delay, uint32_t maxDelay, tMempool* const mp)
{
_tMempool* m = *mp;
_tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), m);
+ d->mempool = m;
d->maxDelay = maxDelay;
@@ -51,13 +47,12 @@
tDelay_setDelay(dl, d->delay);
}
-void tDelay_freeFromPool (tDelay* const dl, tMempool* const mp)
+void tDelay_free (tDelay* const dl)
{
- _tMempool* m = *mp;
_tDelay* d = *dl;
- mpool_free((char*)d->buff, m);
- mpool_free((char*)d, m);
+ mpool_free((char*)d->buff, d->mempool);
+ mpool_free((char*)d, d->mempool);
}
void tDelay_clear(tDelay* const dl)
@@ -172,15 +167,11 @@
tLinearDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
}
-void tLinearDelay_free(tLinearDelay* const dl)
+void tLinearDelay_initToPool (tLinearDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
{
- tLinearDelay_freeFromPool(dl, &leaf.mempool);
-}
-
-void tLinearDelay_initToPool (tLinearDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
-{
_tMempool* m = *mp;
_tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), m);
+ d->mempool = m;
d->maxDelay = maxDelay;
@@ -201,13 +192,12 @@
tLinearDelay_setDelay(dl, d->delay);
}
-void tLinearDelay_freeFromPool(tLinearDelay* const dl, tMempool* const mp)
+void tLinearDelay_free (tLinearDelay* const dl)
{
- _tMempool* m = *mp;
_tLinearDelay* d = *dl;
- mpool_free((char*)d->buff, m);
- mpool_free((char*)d, m);
+ mpool_free((char*)d->buff, d->mempool);
+ mpool_free((char*)d, d->mempool);
}
void tLinearDelay_clear(tLinearDelay* const dl)
@@ -365,20 +355,16 @@
/// Hermite Interpolated Delay
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
+void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
{
tHermiteDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
}
-void tHermiteDelay_free(tHermiteDelay* const dl)
+void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
{
- tHermiteDelay_freeFromPool(dl, &leaf.mempool);
-}
-
-void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
-{
_tMempool* m = *mp;
_tHermiteDelay* d = *dl = (_tHermiteDelay*) mpool_alloc(sizeof(_tHermiteDelay), m);
+ d->mempool = m;
d->maxDelay = maxDelay;
@@ -399,13 +385,12 @@
tHermiteDelay_setDelay(dl, d->delay);
}
-void tHermiteDelay_freeFromPool(tHermiteDelay* const dl, tMempool* const mp)
+void tHermiteDelay_free (tHermiteDelay* const dl)
{
- _tMempool* m = *mp;
_tHermiteDelay* d = *dl;
- mpool_free((char*)d->buff, m);
- mpool_free((char*)d, m);
+ mpool_free((char*)d->buff, d->mempool);
+ mpool_free((char*)d, d->mempool);
}
@@ -565,20 +550,16 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AllpassDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
+void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
{
tAllpassDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
}
-void tAllpassDelay_free(tAllpassDelay* const dl)
+void tAllpassDelay_initToPool (tAllpassDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
{
- tAllpassDelay_freeFromPool(dl, &leaf.mempool);
-}
-
-void tAllpassDelay_initToPool (tAllpassDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
-{
_tMempool* m = *mp;
_tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), m);
+ d->mempool = m;
d->maxDelay = maxDelay;
@@ -601,16 +582,15 @@
d->apInput = 0.0f;
}
-void tAllpassDelay_freeFromPool(tAllpassDelay* const dl, tMempool* const mp)
+void tAllpassDelay_free (tAllpassDelay* const dl)
{
- _tMempool* m = *mp;
_tAllpassDelay* d = *dl;
- mpool_free((char*)d->buff, m);
- mpool_free((char*)d, m);
+ mpool_free((char*)d->buff, d->mempool);
+ mpool_free((char*)d, d->mempool);
}
-void tAllpassDelay_clear(tAllpassDelay* const dl)
+void tAllpassDelay_clear(tAllpassDelay* const dl)
{
_tAllpassDelay* d = *dl;
for (int i = 0; i < d->maxDelay; i++)
@@ -619,7 +599,7 @@
}
}
-float tAllpassDelay_tick (tAllpassDelay* const dl, float input)
+float tAllpassDelay_tick (tAllpassDelay* const dl, float input)
{
_tAllpassDelay* d = *dl;
@@ -745,20 +725,16 @@
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
+void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
{
tTapeDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
}
-void tTapeDelay_free(tTapeDelay* const dl)
+void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
{
- tTapeDelay_freeFromPool(dl, &leaf.mempool);
-}
-
-void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
-{
_tMempool* m = *mp;
_tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), m);
+ d->mempool = m;
d->maxDelay = maxDelay;
@@ -776,16 +752,15 @@
tTapeDelay_setDelay(dl, delay);
}
-void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp)
+void tTapeDelay_free (tTapeDelay* const dl)
{
- _tMempool* m = *mp;
_tTapeDelay* d = *dl;
- mpool_free((char*)d->buff, m);
- mpool_free((char*)d, m);
+ mpool_free((char*)d->buff, d->mempool);
+ mpool_free((char*)d, d->mempool);
}
-void tTapeDelay_clear(tTapeDelay* const dl)
+void tTapeDelay_clear(tTapeDelay* const dl)
{
_tTapeDelay* d = *dl;
for (int i = 0; i < d->maxDelay; i++)
--- a/leaf/Src/leaf-distortion.c
+++ b/leaf/Src/leaf-distortion.c
@@ -23,20 +23,16 @@
//============================================================================================================
-void tSampleReducer_init(tSampleReducer* const sr)
+void tSampleReducer_init (tSampleReducer* const sr)
{
tSampleReducer_initToPool(sr, &leaf.mempool);
}
-void tSampleReducer_free (tSampleReducer* const sr)
+void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp)
{
- tSampleReducer_freeFromPool(sr, &leaf.mempool);
-}
-
-void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp)
-{
_tMempool* m = *mp;
_tSampleReducer* s = *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), m);
+ s->mempool = m;
s->invRatio = 1.0f;
s->hold = 0.0f;
@@ -43,12 +39,11 @@
s->count = 0;
}
-void tSampleReducer_freeFromPool (tSampleReducer* const sr, tMempool* const mp)
+void tSampleReducer_free (tSampleReducer* const sr)
{
- _tMempool* m = *mp;
_tSampleReducer* s = *sr;
- mpool_free((char*)s, m);
+ mpool_free((char*)s, s->mempool);
}
float tSampleReducer_tick(tSampleReducer* const sr, float input)
@@ -77,20 +72,16 @@
// Oversampler
//============================================================================================================
// Latency is equal to the phase length (numTaps / ratio)
-void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality)
+void tOversampler_init (tOversampler* const osr, int ratio, oBool extraQuality)
{
tOversampler_initToPool(osr, ratio, extraQuality, &leaf.mempool);
}
-void tOversampler_free(tOversampler* const osr)
+void tOversampler_initToPool (tOversampler* const osr, int ratio, oBool extraQuality, tMempool* const mp)
{
- tOversampler_freeFromPool(osr, &leaf.mempool);
-}
-
-void tOversampler_initToPool (tOversampler* const osr, int ratio, oBool extraQuality, tMempool* const mp)
-{
_tMempool* m = *mp;
_tOversampler* os = *osr = (_tOversampler*) mpool_alloc(sizeof(_tOversampler), m);
+ os->mempool = m;
uint8_t offset = 0;
if (extraQuality) offset = 6;
@@ -107,14 +98,13 @@
}
}
-void tOversampler_freeFromPool (tOversampler* const osr, tMempool* const mp)
+void tOversampler_free (tOversampler* const osr)
{
- _tMempool* m = *mp;
_tOversampler* os = *osr;
- mpool_free((char*)os->upState, m);
- mpool_free((char*)os->downState, m);
- mpool_free((char*)os, m);
+ mpool_free((char*)os->upState, os->mempool);
+ mpool_free((char*)os->downState, os->mempool);
+ mpool_free((char*)os, os->mempool);
}
float tOversampler_tick(tOversampler* const osr, float input, float* oversample, float (*effectTick)(float))
@@ -322,22 +312,16 @@
//from the paper: Virtual Analog Model of the Lockhart Wavefolder
//by Fabián Esqueda, Henri Pöntynen, Julian D. Parker and Stefan Bilbao
-void tLockhartWavefolder_init(tLockhartWavefolder* const wf)
+void tLockhartWavefolder_init (tLockhartWavefolder* const wf)
{
tLockhartWavefolder_initToPool (wf, &leaf.mempool);
}
-void tLockhartWavefolder_free(tLockhartWavefolder* const wf)
+void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp)
{
- _tLockhartWavefolder* w = *wf;
-
- leaf_free((char*)w);
-}
-
-void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp)
-{
_tMempool* m = *mp;
_tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), m);
+ w->mempool = m;
w->Ln1 = 0.0;
w->Fn1 = 0.0;
@@ -378,12 +362,11 @@
}
-void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const wf, tMempool* const mp)
+void tLockhartWavefolder_free (tLockhartWavefolder* const wf)
{
- _tMempool* m = *mp;
_tLockhartWavefolder* w = *wf;
- mpool_free((char*)w, m);
+ mpool_free((char*)w, w->mempool);
}
@@ -571,20 +554,16 @@
//============================================================================================================
#define SCALAR 5000.f
-void tCrusher_init (tCrusher* const cr)
+void tCrusher_init (tCrusher* const cr)
{
- tCrusher_freeFromPool(cr, &leaf.mempool);
+ tCrusher_initToPool(cr, &leaf.mempool);
}
-void tCrusher_free (tCrusher* const cr)
+void tCrusher_initToPool (tCrusher* const cr, tMempool* const mp)
{
- tCrusher_freeFromPool(cr, &leaf.mempool);
-}
-
-void tCrusher_initToPool (tCrusher* const cr, tMempool* const mp)
-{
_tMempool* m = *mp;
_tCrusher* c = *cr = (_tCrusher*) mpool_alloc(sizeof(_tCrusher), m);
+ c->mempool = m;
c->op = 4;
c->div = SCALAR;
@@ -594,15 +573,15 @@
c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
}
-void tCrusher_freeFromPool (tCrusher* const cr, tMempool* const mp)
+void tCrusher_free (tCrusher* const cr)
{
- _tMempool* m = *mp;
_tCrusher* c = *cr;
- tSampleReducer_freeFromPool(&c->sReducer, mp);
- mpool_free((char*)c, m);
+
+ tSampleReducer_free(&c->sReducer);
+ mpool_free((char*)c, c->mempool);
}
-float tCrusher_tick (tCrusher* const cr, float input)
+float tCrusher_tick (tCrusher* const cr, float input)
{
_tCrusher* c = *cr;
--- a/leaf/Src/leaf-dynamics.c
+++ b/leaf/Src/leaf-dynamics.c
@@ -41,20 +41,16 @@
return c;
}
*/
-void tCompressor_init(tCompressor* const comp)
+void tCompressor_init (tCompressor* const comp)
{
tCompressor_initToPool(comp, &leaf.mempool);
}
-void tCompressor_free(tCompressor* const comp)
+void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp)
{
- tCompressor_freeFromPool(comp, &leaf.mempool);
-}
-
-void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp)
-{
_tMempool* m = *mp;
_tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), m);
+ c->mempool = m;
c->tauAttack = 100;
c->tauRelease = 100;
@@ -67,12 +63,11 @@
c->W = 1.0f; // decibel Make-up gain
}
-void tCompressor_freeFromPool(tCompressor* const comp, tMempool* const mp)
+void tCompressor_free (tCompressor* const comp)
{
- _tMempool* m = *mp;
_tCompressor* c = *comp;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tCompressor_tick(tCompressor* const comp, float in)
@@ -126,20 +121,16 @@
/* Feedback Leveler */
-void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
+void tFeedbackLeveler_init (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
{
tFeedbackLeveler_initToPool(fb, targetLevel, factor, strength, mode, &leaf.mempool);
}
-void tFeedbackLeveler_free(tFeedbackLeveler* const fb)
+void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode, tMempool* const mp)
{
- tFeedbackLeveler_freeFromPool(fb, &leaf.mempool);
-}
-
-void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode, tMempool* const mp)
-{
_tMempool* m = *mp;
_tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), m);
+ p->mempool = m;
p->curr=0.0f;
p->targetLevel=targetLevel;
@@ -148,13 +139,12 @@
p->strength=strength;
}
-void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp)
+void tFeedbackLeveler_free (tFeedbackLeveler* const fb)
{
- _tMempool* m = *mp;
_tFeedbackLeveler* p = *fb;
- tPowerFollower_freeFromPool(&p->pwrFlw, mp);
- mpool_free((char*)p, m);
+ tPowerFollower_free(&p->pwrFlw);
+ mpool_free((char*)p, p->mempool);
}
void tFeedbackLeveler_setStrength(tFeedbackLeveler* const fb, float strength)
@@ -200,21 +190,17 @@
-void tThreshold_init(tThreshold* const th, float low, float high)
+void tThreshold_init (tThreshold* const th, float low, float high)
{
tThreshold_initToPool(th, low, high, &leaf.mempool);
}
-void tThreshold_free(tThreshold* const th)
+void tThreshold_initToPool (tThreshold* const th, float low, float high, tMempool* const mp)
{
- tThreshold_freeFromPool(th, &leaf.mempool);
-}
-
-void tThreshold_initToPool (tThreshold* const th, float low, float high, tMempool* const mp)
-{
_tMempool* m = *mp;
_tThreshold* t = *th = (_tThreshold*) mpool_alloc(sizeof(_tThreshold), m);
-
+ t->mempool = m;
+
t->highThresh = high;
t->lowThresh = low;
@@ -221,12 +207,11 @@
t->currentValue = 0;
}
-void tThreshold_freeFromPool(tThreshold* const th, tMempool* const mp)
+void tThreshold_free (tThreshold* const th)
{
- _tMempool* m = *mp;
_tThreshold* t = *th;
- mpool_free((char*)t, m);
+ mpool_free((char*)t, t->mempool);
}
int tThreshold_tick(tThreshold* const th, float in)
--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -32,20 +32,16 @@
// -JS
-void tTalkbox_init(tTalkbox* const voc, int bufsize)
+void tTalkbox_init (tTalkbox* const voc, int bufsize)
{
tTalkbox_initToPool(voc, bufsize, &leaf.mempool);
}
-void tTalkbox_free(tTalkbox* const voc)
+void tTalkbox_initToPool (tTalkbox* const voc, int bufsize, tMempool* const mp)
{
- tTalkbox_freeFromPool(voc, &leaf.mempool);
-}
-
-void tTalkbox_initToPool (tTalkbox* const voc, int bufsize, tMempool* const mp)
-{
_tMempool* m = *mp;
_tTalkbox* v = *voc = (_tTalkbox*) mpool_alloc(sizeof(_tTalkbox), m);
+ v->mempool = m;
v->param[0] = 0.5f; //wet
v->param[1] = 0.0f; //dry
@@ -71,21 +67,20 @@
tTalkbox_suspend(voc);
}
-void tTalkbox_freeFromPool (tTalkbox* const voc, tMempool* const mp)
+void tTalkbox_free (tTalkbox* const voc)
{
- _tMempool* m = *mp;
_tTalkbox* v = *voc;
- mpool_free((char*)v->buf1, m);
- mpool_free((char*)v->buf0, m);
- mpool_free((char*)v->window, m);
- mpool_free((char*)v->car1, m);
- mpool_free((char*)v->car0, m);
+ mpool_free((char*)v->buf1, v->mempool);
+ mpool_free((char*)v->buf0, v->mempool);
+ mpool_free((char*)v->window, v->mempool);
+ mpool_free((char*)v->car1, v->mempool);
+ mpool_free((char*)v->car0, v->mempool);
- mpool_free((char*)v->dl, m);
- mpool_free((char*)v->Rt, m);
- mpool_free((char*)v->k, m);
- mpool_free((char*)v, m);
+ mpool_free((char*)v->dl, v->mempool);
+ mpool_free((char*)v->Rt, v->mempool);
+ mpool_free((char*)v->k, v->mempool);
+ mpool_free((char*)v, v->mempool);
}
void tTalkbox_update(tTalkbox* const voc) ///update internal parameters...
@@ -363,20 +358,16 @@
// -JS
-void tTalkboxFloat_init(tTalkboxFloat* const voc, int bufsize)
+void tTalkboxFloat_init (tTalkboxFloat* const voc, int bufsize)
{
tTalkboxFloat_initToPool(voc, bufsize, &leaf.mempool);
}
-void tTalkboFloat_free(tTalkboxFloat* const voc)
+void tTalkboxFloat_initToPool (tTalkboxFloat* const voc, int bufsize, tMempool* const mp)
{
- tTalkboxFloat_freeFromPool(voc, &leaf.mempool);
-}
-
-void tTalkboxFloat_initToPool (tTalkboxFloat* const voc, int bufsize, tMempool* const mp)
-{
_tMempool* m = *mp;
_tTalkboxFloat* v = *voc = (_tTalkboxFloat*) mpool_alloc(sizeof(_tTalkboxFloat), m);
+ v->mempool = m;
v->param[0] = 0.5f; //wet
v->param[1] = 0.0f; //dry
@@ -402,21 +393,20 @@
tTalkboxFloat_suspend(voc);
}
-void tTalkboxFloat_freeFromPool (tTalkboxFloat* const voc, tMempool* const mp)
+void tTalkboxFloat_free (tTalkboxFloat* const voc)
{
- _tMempool* m = *mp;
_tTalkboxFloat* v = *voc;
- mpool_free((char*)v->buf1, m);
- mpool_free((char*)v->buf0, m);
- mpool_free((char*)v->window, m);
- mpool_free((char*)v->car1, m);
- mpool_free((char*)v->car0, m);
+ mpool_free((char*)v->buf1, v->mempool);
+ mpool_free((char*)v->buf0, v->mempool);
+ mpool_free((char*)v->window, v->mempool);
+ mpool_free((char*)v->car1, v->mempool);
+ mpool_free((char*)v->car0, v->mempool);
- mpool_free((char*)v->dl, m);
- mpool_free((char*)v->Rt, m);
- mpool_free((char*)v->k, m);
- mpool_free((char*)v, m);
+ mpool_free((char*)v->dl, v->mempool);
+ mpool_free((char*)v->Rt, v->mempool);
+ mpool_free((char*)v->k, v->mempool);
+ mpool_free((char*)v, v->mempool);
}
void tTalkboxFloat_update(tTalkboxFloat* const voc) ///update internal parameters...
@@ -687,20 +677,16 @@
// VOCODER
//============================================================================================================
-void tVocoder_init (tVocoder* const voc)
+void tVocoder_init (tVocoder* const voc)
{
tVocoder_initToPool(voc, &leaf.mempool);
}
-void tVocoder_free (tVocoder* const voc)
+void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp)
{
- tVocoder_freeFromPool(voc, &leaf.mempool);
-}
-
-void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp)
-{
_tMempool* m = *mp;
_tVocoder* v = *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), m);
+ v->mempool = m;
v->param[0] = 0.33f; //input select
v->param[1] = 0.50f; //output dB
@@ -714,12 +700,11 @@
tVocoder_update(voc);
}
-void tVocoder_freeFromPool (tVocoder* const voc, tMempool* const mp)
+void tVocoder_free (tVocoder* const voc)
{
- _tMempool* m = *mp;
_tVocoder* v = *voc;
- mpool_free((char*)v, m);
+ mpool_free((char*)v, v->mempool);
}
void tVocoder_update (tVocoder* const voc)
@@ -887,19 +872,16 @@
/// Glottal Pulse (Rosenberg model)
-void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const gp)
+void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const gp)
{
tRosenbergGlottalPulse_initToPool(gp, &leaf.mempool);
}
-void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const gp)
-{
- tRosenbergGlottalPulse_freeFromPool(gp, &leaf.mempool);
-}
-void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const gp, tMempool* const mp)
-{
+void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const gp, tMempool* const mp)
+{
_tMempool* m = *mp;
_tRosenbergGlottalPulse* g = *gp = (_tRosenbergGlottalPulse*) mpool_alloc(sizeof(_tRosenbergGlottalPulse), m);
+ g->mempool = m;
g->phase = 0.0f;
g->openLength = 0.0f;
@@ -909,11 +891,10 @@
}
-void tRosenbergGlottalPulse_freeFromPool (tRosenbergGlottalPulse* const gp, tMempool* const mp)
+void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const gp)
{
- _tMempool* m = *mp;
_tRosenbergGlottalPulse* g = *gp;
- mpool_free((char*)g, m);
+ mpool_free((char*)g, g->mempool);
}
float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const gp)
@@ -1021,21 +1002,16 @@
/******************************************************************************/
// init
-void tSOLAD_init(tSOLAD* const wp)
+void tSOLAD_init (tSOLAD* const wp)
{
tSOLAD_initToPool(wp, &leaf.mempool);
}
-void tSOLAD_free(tSOLAD* const wp)
+void tSOLAD_initToPool (tSOLAD* const wp, tMempool* const mp)
{
- tSOLAD_freeFromPool(wp, &leaf.mempool);
-}
-
-void tSOLAD_initToPool (tSOLAD* const wp, tMempool* const mp)
-{
_tMempool* m = *mp;
-
_tSOLAD* w = *wp = (_tSOLAD*) mpool_calloc(sizeof(_tSOLAD), m);
+ w->mempool = m;
w->pitchfactor = 1.;
w->delaybuf = (float*) mpool_calloc(sizeof(float) * (LOOPSIZE+16), m);
@@ -1043,13 +1019,12 @@
solad_init(w);
}
-void tSOLAD_freeFromPool (tSOLAD* const wp, tMempool* const mp)
+void tSOLAD_free (tSOLAD* const wp)
{
- _tMempool* m = *mp;
_tSOLAD* w = *wp;
- mpool_free((char*)w->delaybuf, m);
- mpool_free((char*)w, m);
+ mpool_free((char*)w->delaybuf, w->mempool);
+ mpool_free((char*)w, w->mempool);
}
// send one block of input samples, receive one block of output samples
@@ -1387,15 +1362,12 @@
tPitchShift_initToPool(psr, pd, out, bufSize, &leaf.mempool);
}
-void tPitchShift_free(tPitchShift* const psr)
+void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp)
{
- tPitchShift_freeFromPool(psr, &leaf.mempool);
-}
-
-void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp)
-{
_tMempool* m = *mp;
_tPitchShift* ps = *psr = (_tPitchShift*) mpool_calloc(sizeof(_tPitchShift), m);
+ ps->mempool = m;
+
_tPeriodDetection* p = *pd;
ps->p = pd;
@@ -1416,14 +1388,13 @@
tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO);
}
-void tPitchShift_freeFromPool (tPitchShift* const psr, tMempool* const mp)
+void tPitchShift_free (tPitchShift* const psr)
{
- _tMempool* m = *mp;
_tPitchShift* ps = *psr;
- tSOLAD_freeFromPool(&ps->sola, mp);
- tHighpass_freeFromPool(&ps->hp, mp);
- mpool_free((char*)ps, m);
+ tSOLAD_free(&ps->sola);
+ tHighpass_free(&ps->hp);
+ mpool_free((char*)ps, ps->mempool);
}
void tPitchShift_setPitchFactor(tPitchShift* psr, float pf)
@@ -1548,16 +1519,11 @@
tRetune_initToPool(rt, numVoices, bufSize, frameSize, &leaf.mempool);
}
-void tRetune_free(tRetune* const rt)
+void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
{
- tRetune_freeFromPool(rt, &leaf.mempool);
-}
-
-void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
-{
_tMempool* m = *mp;
_tRetune* r = *rt = (_tRetune*) mpool_alloc(sizeof(_tRetune), m);
- r->mempool = mp;
+ r->mempool = *mp;
r->bufSize = bufSize;
r->frameSize = frameSize;
@@ -1589,23 +1555,22 @@
}
}
-void tRetune_freeFromPool (tRetune* const rt, tMempool* const mp)
+void tRetune_free (tRetune* const rt)
{
- _tMempool* m = *mp;
_tRetune* r = *rt;
- tPeriodDetection_freeFromPool(&r->pd, mp);
+ tPeriodDetection_free(&r->pd);
for (int i = 0; i < r->numVoices; ++i)
{
- tPitchShift_freeFromPool(&r->ps[i], mp);
- mpool_free((char*)r->outBuffers[i], m);
+ tPitchShift_free(&r->ps[i]);
+ mpool_free((char*)r->outBuffers[i], r->mempool);
}
- mpool_free((char*)r->tickOutput, m);
- mpool_free((char*)r->pitchFactor, m);
- mpool_free((char*)r->ps, m);
- mpool_free((char*)r->inBuffer, m);
- mpool_free((char*)r->outBuffers, m);
- mpool_free((char*)r, m);
+ mpool_free((char*)r->tickOutput, r->mempool);
+ mpool_free((char*)r->pitchFactor, r->mempool);
+ mpool_free((char*)r->ps, r->mempool);
+ mpool_free((char*)r->inBuffer, r->mempool);
+ mpool_free((char*)r->outBuffers, r->mempool);
+ mpool_free((char*)r, r->mempool);
}
float* tRetune_tick(tRetune* const rt, float sample)
@@ -1628,35 +1593,10 @@
int bufSize = r->bufSize;
int frameSize = r->frameSize;
- tMempool* mempool = r->mempool;
+ tMempool mempool = r->mempool;
- tRetune_freeFromPool(rt, mempool);
- tRetune_initToPool(rt, numVoices, bufSize, frameSize, mempool);
-
- // Could this run into fragmentation problems?
- // Trying out reiniting the whole object (above) since it shouldn't be much slower anyway.
-
-// for (int i = 0; i < r->numVoices; ++i)
-// {
-// tPitchShift_freeFromPool(&r->ps[i], r->mempool);
-// mpool_free((char*)r->outBuffers[i], *r->mempool);
-// }
-// mpool_free((char*)r->tickOutput, *r->mempool);
-// mpool_free((char*)r->pitchFactor, *r->mempool);
-// mpool_free((char*)r->ps, *r->mempool);
-// mpool_free((char*)r->outBuffers, *r->mempool);
-//
-// r->numVoices = numVoices;
-//
-// r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, *r->mempool);
-// r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, *r->mempool);
-// r->pitchFactor = (float*) mpool_alloc(sizeof(float) * r->numVoices, *r->mempool);
-// r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, *r->mempool);
-// for (int i = 0; i < r->numVoices; ++i)
-// {
-// r->outBuffers[i] = (float*) mpool_alloc(sizeof(float) * r->bufSize, *r->mempool);
-// tPitchShift_initToPool(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize, r->mempool);
-// }
+ tRetune_free(rt);
+ tRetune_initToPool(rt, numVoices, bufSize, frameSize, &mempool);
}
void tRetune_setPitchFactors(tRetune* const rt, float pf)
@@ -1727,21 +1667,16 @@
// AUTOTUNE
//============================================================================================================
-void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize)
+void tAutotune_init (tAutotune* const rt, int numVoices, int bufSize, int frameSize)
{
tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &leaf.mempool);
}
-void tAutotune_free(tAutotune* const rt)
+void tAutotune_initToPool (tAutotune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
{
- tAutotune_freeFromPool(rt, &leaf.mempool);
-}
-
-void tAutotune_initToPool (tAutotune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
-{
_tMempool* m = *mp;
_tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), m);
- r->mempool = mp;
+ r->mempool = *mp;
r->bufSize = bufSize;
r->frameSize = frameSize;
@@ -1774,23 +1709,22 @@
r->shiftOn = 0;
}
-void tAutotune_freeFromPool (tAutotune* const rt, tMempool* const mp)
+void tAutotune_free (tAutotune* const rt)
{
- _tMempool* m = *mp;
_tAutotune* r = *rt;
- tPeriodDetection_freeFromPool(&r->pd, mp);
+ tPeriodDetection_free(&r->pd);
for (int i = 0; i < r->numVoices; ++i)
{
- tPitchShift_freeFromPool(&r->ps[i], mp);
- mpool_free((char*)r->outBuffers[i], m);
+ tPitchShift_free(&r->ps[i]);
+ mpool_free((char*)r->outBuffers[i], r->mempool);
}
- mpool_free((char*)r->tickOutput, m);
- mpool_free((char*)r->freq, m);
- mpool_free((char*)r->ps, m);
- mpool_free((char*)r->inBuffer, m);
- mpool_free((char*)r->outBuffers, m);
- mpool_free((char*)r, m);
+ mpool_free((char*)r->tickOutput, r->mempool);
+ mpool_free((char*)r->freq, r->mempool);
+ mpool_free((char*)r->ps, r->mempool);
+ mpool_free((char*)r->inBuffer, r->mempool);
+ mpool_free((char*)r->outBuffers, r->mempool);
+ mpool_free((char*)r, r->mempool);
}
float* tAutotune_tick(tAutotune* const rt, float sample)
@@ -1817,34 +1751,10 @@
int bufSize = r->bufSize;
int frameSize = r->frameSize;
- tMempool* mempool = r->mempool;
+ tMempool mempool = r->mempool;
- tAutotune_freeFromPool(rt, mempool);
- tAutotune_initToPool(rt, numVoices, bufSize, frameSize, mempool);
-
- // Could this run into fragmentation problems?
- // Trying out reiniting the whole object (above) since it shouldn't be much slower anyway.
-// for (int i = 0; i < r->numVoices; ++i)
-// {
-// tPitchShift_freeFromPool(&r->ps[i], r->mempool);
-// mpool_free((char*)r->outBuffers[i], *r->mempool);
-// }
-// mpool_free((char*)r->tickOutput, *r->mempool);
-// mpool_free((char*)r->freq, *r->mempool);
-// mpool_free((char*)r->ps, *r->mempool);
-// mpool_free((char*)r->outBuffers, *r->mempool);
-//
-// r->numVoices = numVoices;
-//
-// r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, *r->mempool);
-// r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, *r->mempool);
-// r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, *r->mempool);
-// r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, *r->mempool);
-// for (int i = 0; i < r->numVoices; ++i)
-// {
-// r->outBuffers[i] = (float*) mpool_alloc(sizeof(float) * r->bufSize, *r->mempool);
-// tPitchShift_initToPool(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize, r->mempool);
-// }
+ tAutotune_free(rt);
+ tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &mempool);
}
void tAutotune_setFreqs(tAutotune* const rt, float f)
@@ -1926,20 +1836,16 @@
//============================================================================================================
// algorithm from Tom Baran's autotalent code.
-void tFormantShifter_init(tFormantShifter* const fsr, int order)
+void tFormantShifter_init (tFormantShifter* const fsr, int order)
{
tFormantShifter_initToPool(fsr, order, &leaf.mempool);
}
-void tFormantShifter_free(tFormantShifter* const fsr)
+void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, tMempool* const mp)
{
- tFormantShifter_freeFromPool(fsr, &leaf.mempool);
-}
-
-void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, tMempool* const mp)
-{
_tMempool* m = *mp;
_tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), m);
+ fs->mempool = m;
fs->ford = order;
fs->fk = (float*) mpool_calloc(sizeof(float) * fs->ford, m);
@@ -1970,25 +1876,24 @@
tFeedbackLeveler_initToPool(&fs->fbl2, 0.8f, .005f, 0.125, 1, mp);
}
-void tFormantShifter_freeFromPool (tFormantShifter* const fsr, tMempool* const mp)
+void tFormantShifter_free (tFormantShifter* const fsr)
{
- _tMempool* m = *mp;
_tFormantShifter* fs = *fsr;
- mpool_free((char*)fs->fk, m);
- mpool_free((char*)fs->fb, m);
- mpool_free((char*)fs->fc, m);
- mpool_free((char*)fs->frb, m);
- mpool_free((char*)fs->frc, m);
- mpool_free((char*)fs->fsig, m);
- mpool_free((char*)fs->fsmooth, m);
- mpool_free((char*)fs->ftvec, m);
- mpool_free((char*)fs->fbuff, m);
- tHighpass_freeFromPool(&fs->hp, mp);
- tHighpass_freeFromPool(&fs->hp2, mp);
- tFeedbackLeveler_freeFromPool(&fs->fbl1, mp);
- tFeedbackLeveler_freeFromPool(&fs->fbl2, mp);
- mpool_free((char*)fs, m);
+ mpool_free((char*)fs->fk, fs->mempool);
+ mpool_free((char*)fs->fb, fs->mempool);
+ mpool_free((char*)fs->fc, fs->mempool);
+ mpool_free((char*)fs->frb, fs->mempool);
+ mpool_free((char*)fs->frc, fs->mempool);
+ mpool_free((char*)fs->fsig, fs->mempool);
+ mpool_free((char*)fs->fsmooth, fs->mempool);
+ mpool_free((char*)fs->ftvec, fs->mempool);
+ mpool_free((char*)fs->fbuff, fs->mempool);
+ tHighpass_free(&fs->hp);
+ tHighpass_free(&fs->hp2);
+ tFeedbackLeveler_free(&fs->fbl1);
+ tFeedbackLeveler_free(&fs->fbl2);
+ mpool_free((char*)fs, fs->mempool);
}
float tFormantShifter_tick(tFormantShifter* const fsr, float in)
--- a/leaf/Src/leaf-electrical.c
+++ b/leaf/Src/leaf-electrical.c
@@ -169,11 +169,6 @@
tWDF_initToPool(wdf, type, value, rL, rR, &leaf.mempool);
}
-void tWDF_free(tWDF* const wdf)
-{
- tWDF_freeFromPool(wdf, &leaf.mempool);
-}
-
void tWDF_initToPool(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, tMempool* const mp)
{
_tMempool* m = *mp;
@@ -182,12 +177,11 @@
wdf_init(wdf, type, value, rL, rR);
}
-void tWDF_freeFromPool (tWDF* const wdf, tMempool* const mp)
+void tWDF_free (tWDF* const wdf)
{
- _tMempool* m = *mp;
_tWDF* r = *wdf;
- mpool_free((char*)r, m);
+ mpool_free((char*)r, r->mempool);
}
float tWDF_tick(tWDF* const wdf, float sample, tWDF* const outputPoint, uint8_t paramsChanged)
--- a/leaf/Src/leaf-envelopes.c
+++ b/leaf/Src/leaf-envelopes.c
@@ -29,15 +29,11 @@
tEnvelope_initToPool(envlp, attack, decay, loop, &leaf.mempool);
}
-void tEnvelope_free(tEnvelope* const envlp)
-{
- tEnvelope_freeFromPool(envlp, &leaf.mempool);
-}
-
void tEnvelope_initToPool (tEnvelope* const envlp, float attack, float decay, int loop, tMempool* const mp)
{
_tMempool* m = *mp;
_tEnvelope* env = *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), m);
+ env->mempool = m;
env->exp_buff = __leaf_table_exp_decay;
env->inc_buff = __leaf_table_attack_decay_inc;
@@ -75,11 +71,10 @@
env->rampInc = env->inc_buff[rampIndex];
}
-void tEnvelope_freeFromPool (tEnvelope* const envlp, tMempool* const mp)
+void tEnvelope_free (tEnvelope* const envlp)
{
- _tMempool* m = *mp;
_tEnvelope* env = *envlp;
- mpool_free((char*)env, m);
+ mpool_free((char*)env, env->mempool);
}
void tEnvelope_setAttack(tEnvelope* const envlp, float attack)
@@ -225,15 +220,11 @@
tADSR_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
}
-void tADSR_free(tADSR* const adsrenv)
-{
- tADSR_freeFromPool(adsrenv, &leaf.mempool);
-}
-
void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
{
_tMempool* m = *mp;
_tADSR* adsr = *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), m);
+ adsr->mempool = m;
adsr->exp_buff = __leaf_table_exp_decay;
adsr->inc_buff = __leaf_table_attack_decay_inc;
@@ -291,11 +282,10 @@
adsr->leakFactor = 1.0f;
}
-void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp)
+void tADSR_free (tADSR* const adsrenv)
{
- _tMempool* m = *mp;
_tADSR* adsr = *adsrenv;
- mpool_free((char*)adsr, m);
+ mpool_free((char*)adsr, adsr->mempool);
}
void tADSR_setAttack(tADSR* const adsrenv, float attack)
@@ -513,15 +503,12 @@
tADSR2_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
}
-void tADSR2_free(tADSR2* const adsrenv)
-{
- tADSR2_freeFromPool(adsrenv, &leaf.mempool);
-}
-
void tADSR2_initToPool (tADSR2* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
{
_tMempool* m = *mp;
_tADSR2* adsr = *adsrenv = (_tADSR2*) mpool_alloc(sizeof(_tADSR2), m);
+ adsr->mempool = m;
+
adsr->sampleRateInMs = leaf.sampleRate * 0.001f;
adsr->attack = LEAF_clip(0.0f, attack * 0.001f, 1.0f);
adsr->attackLambda = powf(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME;
@@ -547,11 +534,10 @@
adsr->leakFactor = 1.0f;
}
-void tADSR2_freeFromPool (tADSR2* const adsrenv, tMempool* const mp)
+void tADSR2_free (tADSR2* const adsrenv)
{
- _tMempool* m = *mp;
_tADSR2* adsr = *adsrenv;
- mpool_free((char*)adsr, m);
+ mpool_free((char*)adsr, adsr->mempool);
}
void tADSR2_setAttack(tADSR2* const adsrenv, float attack)
@@ -669,15 +655,12 @@
tADSR3_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
}
-void tADSR3_free(tADSR3* const adsrenv)
-{
- tADSR3_freeFromPool(adsrenv, &leaf.mempool);
-}
-
void tADSR3_initToPool (tADSR3* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
{
_tMempool* m = *mp;
_tADSR3* adsr = *adsrenv = (_tADSR3*) mpool_alloc(sizeof(_tADSR3), m);
+ adsr->mempool = m;
+
adsr->sampleRateInMs = leaf.sampleRate * 0.001f;
adsr->targetRatioA = 0.3f;
adsr->targetRatioDR = 0.0001f;
@@ -705,11 +688,10 @@
adsr->leakFactor = 1.0f;
}
-void tADSR3_freeFromPool (tADSR3* const adsrenv, tMempool* const mp)
+void tADSR3_free (tADSR3* const adsrenv)
{
- _tMempool* m = *mp;
_tADSR3* adsr = *adsrenv;
- mpool_free((char*)adsr, m);
+ mpool_free((char*)adsr, adsr->mempool);
}
void tADSR3_setAttack(tADSR3* const adsrenv, float attack)
@@ -817,11 +799,6 @@
tADSR4_initToPool (adsrenv, attack, decay, sustain, release, expBuffer, bufferSize, &leaf.mempool);
}
-void tADSR4_free(tADSR4* const adsrenv)
-{
- tADSR4_freeFromPool(adsrenv, &leaf.mempool);
-}
-
//initialize with an exponential function that decays -- i.e. a call to LEAF_generate_exp(expBuffer, 0.001f, 0.0f, 1.0f, -0.0008f, EXP_BUFFER_SIZE);
//times are in ms
void tADSR4_initToPool (tADSR4* const adsrenv, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, tMempool* const mp)
@@ -828,6 +805,7 @@
{
_tMempool* m = *mp;
_tADSR4* adsr = *adsrenv = (_tADSR4*) mpool_alloc(sizeof(_tADSR4), m);
+ adsr->mempool = m;
adsr->exp_buff = expBuffer;
adsr->buff_size = bufferSize;
@@ -863,11 +841,10 @@
adsr->leakFactor = 1.0f;
}
-void tADSR4_freeFromPool (tADSR4* const adsrenv, tMempool* const mp)
+void tADSR4_free (tADSR4* const adsrenv)
{
- _tMempool* m = *mp;
_tADSR4* adsr = *adsrenv;
- mpool_free((char*)adsr, m);
+ mpool_free((char*)adsr, adsr->mempool);
}
void tADSR4_setAttack(tADSR4* const adsrenv, float attack)
@@ -1170,15 +1147,11 @@
tRamp_initToPool(r, time, samples_per_tick, &leaf.mempool);
}
-void tRamp_free(tRamp* const r)
-{
- tRamp_freeFromPool(r, &leaf.mempool);
-}
-
void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, tMempool* const mp)
{
_tMempool* m = *mp;
_tRamp* ramp = *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), m);
+ ramp->mempool = m;
ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
@@ -1198,12 +1171,11 @@
ramp->inc = (ramp->dest - ramp->curr) * ramp->factor;
}
-void tRamp_freeFromPool (tRamp* const r, tMempool* const mp)
+void tRamp_free (tRamp* const r)
{
- _tMempool* m = *mp;
_tRamp* ramp = *r;
- mpool_free((char*)ramp, m);
+ mpool_free((char*)ramp, ramp->mempool);
}
void tRamp_setTime(tRamp* const ramp, float time)
@@ -1274,15 +1246,11 @@
tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool);
}
-void tRampUpDown_free(tRampUpDown* const r)
-{
- tRampUpDown_freeFromPool(r, &leaf.mempool);
-}
-
void tRampUpDown_initToPool(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, tMempool* const mp)
{
_tMempool* m = *mp;
_tRampUpDown* ramp = *r = (_tRampUpDown*) mpool_alloc(sizeof(_tRampUpDown), m);
+ ramp->mempool = m;
ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
@@ -1312,12 +1280,11 @@
ramp->downInc = ((ramp->dest - ramp->curr) / ramp->downTime * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
}
-void tRampUpDown_freeFromPool (tRampUpDown* const r, tMempool* const mp)
+void tRampUpDown_free (tRampUpDown* const r)
{
- _tMempool* m = *mp;
_tRampUpDown* ramp = *r;
- mpool_free((char*)ramp, m);
+ mpool_free((char*)ramp, ramp->mempool);
}
void tRampUpDown_setUpTime(tRampUpDown* const ramp, float upTime)
@@ -1418,15 +1385,11 @@
tExpSmooth_initToPool(expsmooth, val, factor, &leaf.mempool);
}
-void tExpSmooth_free(tExpSmooth* const expsmooth)
-{
- tExpSmooth_freeFromPool(expsmooth, &leaf.mempool);
-}
-
void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp)
{
_tMempool* m = *mp;
_tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), m);
+ smooth->mempool = m;
smooth->curr=val;
smooth->dest=val;
@@ -1436,12 +1399,11 @@
smooth->oneminusfactor=1.0f-factor;
}
-void tExpSmooth_freeFromPool (tExpSmooth* const expsmooth, tMempool* const mp)
+void tExpSmooth_free (tExpSmooth* const expsmooth)
{
- _tMempool* m = *mp;
_tExpSmooth* smooth = *expsmooth;
- mpool_free((char*)smooth, m);
+ mpool_free((char*)smooth, smooth->mempool);
}
void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor)
@@ -1495,14 +1457,13 @@
{
tSlide_initToPool (sl, upSlide, downSlide, &leaf.mempool);
}
-void tSlide_free (tSlide* const sl)
-{
- tSlide_freeFromPool (sl, &leaf.mempool);
-}
+
void tSlide_initToPool (tSlide* const sl, float upSlide, float downSlide, tMempool* const mp)
{
_tMempool* m = *mp;
_tSlide* s = *sl = (_tSlide*) mpool_alloc(sizeof(_tSlide), m);
+ s->mempool = m;
+
s->prevIn = 0.0f;
s->currentOut = 0.0f;
s->prevOut = 0.0f;
@@ -1520,12 +1481,11 @@
s->invDownSlide = 1.0f / downSlide;
}
-void tSlide_freeFromPool (tSlide* const sl, tMempool* const mp)
+void tSlide_free (tSlide* const sl)
{
- _tMempool* m = *mp;
- _tSlide* s = *sl;
+ _tSlide* s = *sl;
- mpool_free((char*)s, m);
+ mpool_free((char*)s, s->mempool);
}
void tSlide_setUpSlide(tSlide* const sl, float upSlide)
--- a/leaf/Src/leaf-filters.c
+++ b/leaf/Src/leaf-filters.c
@@ -26,15 +26,11 @@
tAllpass_initToPool(ft, initDelay, maxDelay, &leaf.mempool);
}
-void tAllpass_free(tAllpass* const ft)
-{
- tAllpass_freeFromPool(ft, &leaf.mempool);
-}
-
void tAllpass_initToPool (tAllpass* const ft, float initDelay, uint32_t maxDelay, tMempool* const mp)
{
_tMempool* m = *mp;
_tAllpass* f = *ft = (_tAllpass*) mpool_alloc(sizeof(_tAllpass), m);
+ f->mempool = m;
f->gain = 0.7f;
@@ -43,13 +39,12 @@
tLinearDelay_initToPool(&f->delay, initDelay, maxDelay, mp);
}
-void tAllpass_freeFromPool (tAllpass* const ft, tMempool* const mp)
+void tAllpass_free (tAllpass* const ft)
{
- _tMempool* m = *mp;
_tAllpass* f = *ft;
- tLinearDelay_freeFromPool(&f->delay, mp);
- mpool_free((char*)f, m);
+ tLinearDelay_free(&f->delay);
+ mpool_free((char*)f, f->mempool);
}
void tAllpass_setDelay(tAllpass* const ft, float delay)
@@ -85,15 +80,11 @@
tOnePole_initToPool(ft, freq, &leaf.mempool);
}
-void tOnePole_free(tOnePole* const ft)
-{
- tOnePole_freeFromPool(ft, &leaf.mempool);
-}
-
void tOnePole_initToPool (tOnePole* const ft, float freq, tMempool* const mp)
{
_tMempool* m = *mp;
_tOnePole* f = *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), m);
+ f->mempool = m;
f->gain = 1.0f;
f->a0 = 1.0;
@@ -104,12 +95,11 @@
f->lastOut = 0.0f;
}
-void tOnePole_freeFromPool (tOnePole* const ft, tMempool* const mp)
+void tOnePole_free (tOnePole* const ft)
{
- _tMempool* m = *mp;
_tOnePole* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
void tOnePole_setB0(tOnePole* const ft, float b0)
@@ -179,15 +169,11 @@
tTwoPole_initToPool(ft, &leaf.mempool);
}
-void tTwoPole_free(tTwoPole* const ft)
-{
- tTwoPole_freeFromPool(ft, &leaf.mempool);
-}
-
void tTwoPole_initToPool (tTwoPole* const ft, tMempool* const mp)
{
_tMempool* m = *mp;
_tTwoPole* f = *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), m);
+ f->mempool = m;
f->gain = 1.0f;
f->a0 = 1.0;
@@ -197,12 +183,11 @@
f->lastOut[1] = 0.0f;
}
-void tTwoPole_freeFromPool (tTwoPole* const ft, tMempool* const mp)
+void tTwoPole_free (tTwoPole* const ft)
{
- _tMempool* m = *mp;
_tTwoPole* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tTwoPole_tick(tTwoPole* const ft, float input)
@@ -298,15 +283,11 @@
tOneZero_initToPool(ft, theZero, &leaf.mempool);
}
-void tOneZero_free(tOneZero* const ft)
-{
- tOneZero_freeFromPool(ft, &leaf.mempool);
-}
-
void tOneZero_initToPool (tOneZero* const ft, float theZero, tMempool* const mp)
{
_tMempool* m = *mp;
_tOneZero* f = *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), m);
+ f->mempool = m;
f->gain = 1.0f;
f->lastIn = 0.0f;
@@ -314,12 +295,11 @@
tOneZero_setZero(ft, theZero);
}
-void tOneZero_freeFromPool (tOneZero* const ft, tMempool* const mp)
+void tOneZero_free (tOneZero* const ft)
{
- _tMempool* m = *mp;
_tOneZero* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tOneZero_tick(tOneZero* const ft, float input)
@@ -407,15 +387,11 @@
tTwoZero_initToPool(ft, &leaf.mempool);
}
-void tTwoZero_free(tTwoZero* const ft)
-{
- tTwoZero_freeFromPool(ft, &leaf.mempool);
-}
-
void tTwoZero_initToPool (tTwoZero* const ft, tMempool* const mp)
{
_tMempool* m = *mp;
_tTwoZero* f = *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), m);
+ f->mempool = m;
f->gain = 1.0f;
f->lastIn[0] = 0.0f;
@@ -422,12 +398,11 @@
f->lastIn[1] = 0.0f;
}
-void tTwoZero_freeFromPool (tTwoZero* const ft, tMempool* const mp)
+void tTwoZero_free (tTwoZero* const ft)
{
- _tMempool* m = *mp;
_tTwoZero* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tTwoZero_tick(tTwoZero* const ft, float input)
@@ -506,15 +481,11 @@
tPoleZero_initToPool(pzf, &leaf.mempool);
}
-void tPoleZero_free(tPoleZero* const pzf)
-{
- tPoleZero_freeFromPool(pzf, &leaf.mempool);
-}
-
void tPoleZero_initToPool (tPoleZero* const pzf, tMempool* const mp)
{
_tMempool* m = *mp;
_tPoleZero* f = *pzf = (_tPoleZero*) mpool_alloc(sizeof(_tPoleZero), m);
+ f->mempool = m;
f->gain = 1.0f;
f->b0 = 1.0;
@@ -524,12 +495,11 @@
f->lastOut = 0.0f;
}
-void tPoleZero_freeFromPool (tPoleZero* const pzf, tMempool* const mp)
+void tPoleZero_free (tPoleZero* const pzf)
{
- _tMempool* m = *mp;
_tPoleZero* f = *pzf;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
void tPoleZero_setB0(tPoleZero* const pzf, float b0)
@@ -625,15 +595,11 @@
tBiQuad_initToPool(ft, &leaf.mempool);
}
-void tBiQuad_free(tBiQuad* const ft)
-{
- tBiQuad_freeFromPool(ft, &leaf.mempool);
-}
-
void tBiQuad_initToPool (tBiQuad* const ft, tMempool* const mp)
{
_tMempool* m = *mp;
_tBiQuad* f = *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), m);
+ f->mempool = m;
f->gain = 1.0f;
@@ -646,12 +612,11 @@
f->lastOut[1] = 0.0f;
}
-void tBiQuad_freeFromPool (tBiQuad* const ft, tMempool* const mp)
+void tBiQuad_free (tBiQuad* const ft)
{
- _tMempool* m = *mp;
_tBiQuad* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tBiQuad_tick(tBiQuad* const ft, float input)
@@ -790,15 +755,11 @@
}
-void tSVF_free(tSVF* const svff)
-{
- tSVF_freeFromPool (svff, &leaf.mempool);
-}
-
void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q, tMempool* const mp)
{
_tMempool* m = *mp;
_tSVF* svf = *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), m);
+ svf->mempool = m;
svf->type = type;
@@ -856,12 +817,11 @@
}
}
-void tSVF_freeFromPool (tSVF* const svff, tMempool* const mp)
+void tSVF_free (tSVF* const svff)
{
- _tMempool* m = *mp;
_tSVF* svf = *svff;
- mpool_free((char*)svf, m);
+ mpool_free((char*)svf, svf->mempool);
}
float tSVF_tick(tSVF* const svff, float v0)
@@ -915,15 +875,11 @@
tEfficientSVF_initToPool(svff, type, input, Q, &leaf.mempool);
}
-void tEfficientSVF_free(tEfficientSVF* const svff)
-{
- tEfficientSVF_freeFromPool(svff, &leaf.mempool);
-}
-
void tEfficientSVF_initToPool (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp)
{
_tMempool* m = *mp;
_tEfficientSVF* svf = *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), m);
+ svf->mempool = m;
svf->type = type;
@@ -937,12 +893,11 @@
svf->a3 = svf->g*svf->a2;
}
-void tEfficientSVF_freeFromPool (tEfficientSVF* const svff, tMempool* const mp)
+void tEfficientSVF_free (tEfficientSVF* const svff)
{
- _tMempool* m = *mp;
_tEfficientSVF* svf = *svff;
- mpool_free((char*)svf, m);
+ mpool_free((char*)svf, svf->mempool);
}
float tEfficientSVF_tick(tEfficientSVF* const svff, float v0)
@@ -991,15 +946,11 @@
tHighpass_initToPool(ft, freq, &leaf.mempool);
}
-void tHighpass_free(tHighpass* const ft)
-{
- tHighpass_freeFromPool(ft, &leaf.mempool);
-}
-
void tHighpass_initToPool (tHighpass* const ft, float freq, tMempool* const mp)
{
_tMempool* m = *mp;
_tHighpass* f = *ft = (_tHighpass*) mpool_calloc(sizeof(_tHighpass), m);
+ f->mempool = m;
f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
f->ys = 0.0f;
@@ -1008,12 +959,11 @@
f->frequency = freq;
}
-void tHighpass_freeFromPool (tHighpass* const ft, tMempool* const mp)
+void tHighpass_free (tHighpass* const ft)
{
- _tMempool* m = *mp;
_tHighpass* f = *ft;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
void tHighpass_setFreq(tHighpass* const ft, float freq)
@@ -1050,15 +1000,11 @@
tButterworth_initToPool(ft, N, f1, f2, &leaf.mempool);
}
-void tButterworth_free(tButterworth* const ft)
-{
- tButterworth_freeFromPool(ft, &leaf.mempool);
-}
-
void tButterworth_initToPool (tButterworth* const ft, int N, float f1, float f2, tMempool* const mp)
{
_tMempool* m = *mp;
_tButterworth* f = *ft = (_tButterworth*) mpool_alloc(sizeof(_tButterworth), m);
+ f->mempool = m;
f->f1 = f1;
f->f2 = f2;
@@ -1075,18 +1021,17 @@
}
}
-void tButterworth_freeFromPool (tButterworth* const ft, tMempool* const mp)
+void tButterworth_free (tButterworth* const ft)
{
- _tMempool* m = *mp;
_tButterworth* f = *ft;
for(int i = 0; i < f->N/2; ++i)
{
- tSVF_freeFromPool(&f->low[i], mp);
- tSVF_freeFromPool(&f->high[i], mp);
+ tSVF_free(&f->low[i]);
+ tSVF_free(&f->high[i]);
}
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tButterworth_tick(tButterworth* const ft, float samp)
@@ -1135,15 +1080,11 @@
tFIR_initToPool(firf, coeffs, numTaps, &leaf.mempool);
}
-void tFIR_free(tFIR* const firf)
-{
- tFIR_freeFromPool(firf, &leaf.mempool);
-}
-
void tFIR_initToPool (tFIR* const firf, float* coeffs, int numTaps, tMempool* const mp)
{
_tMempool* m = *mp;
_tFIR* fir = *firf = (_tFIR*) mpool_alloc(sizeof(_tFIR), m);
+ fir->mempool = m;
fir->numTaps = numTaps;
fir->coeff = coeffs;
@@ -1151,13 +1092,12 @@
for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f;
}
-void tFIR_freeFromPool (tFIR* const firf, tMempool* const mp)
+void tFIR_free (tFIR* const firf)
{
- _tMempool* m = *mp;
_tFIR* fir = *firf;
- mpool_free((char*)fir->past, m);
- mpool_free((char*)fir, m);
+ mpool_free((char*)fir->past, fir->mempool);
+ mpool_free((char*)fir, fir->mempool);
}
float tFIR_tick(tFIR* const firf, float input)
@@ -1181,14 +1121,12 @@
{
tMedianFilter_initToPool(f, size, &leaf.mempool);
}
-void tMedianFilter_free (tMedianFilter* const f)
-{
- tMedianFilter_freeFromPool(f, &leaf.mempool);
-}
+
void tMedianFilter_initToPool (tMedianFilter* const mf, int size, tMempool* const mp)
{
_tMempool* m = *mp;
_tMedianFilter* f = *mf = (_tMedianFilter*) mpool_alloc(sizeof(_tMedianFilter), m);
+ f->mempool = m;
f->size = size;
f->middlePosition = size / 2;
@@ -1203,14 +1141,13 @@
}
}
-void tMedianFilter_freeFromPool (tMedianFilter* const mf, tMempool* const mp)
+void tMedianFilter_free (tMedianFilter* const mf)
{
- _tMempool* m = *mp;
_tMedianFilter* f = *mf;
- mpool_free((char*)f->val, m);
- mpool_free((char*)f->age, m);
- mpool_free((char*)f, m);
+ mpool_free((char*)f->val, f->mempool);
+ mpool_free((char*)f->age, f->mempool);
+ mpool_free((char*)f, f->mempool);
}
float tMedianFilter_tick (tMedianFilter* const mf, float input)
@@ -1259,15 +1196,11 @@
tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool);
}
-void tVZFilter_free (tVZFilter* const vf)
-{
- tVZFilter_freeFromPool(vf, &leaf.mempool);
-}
-
void tVZFilter_initToPool (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, tMempool* const mp)
{
_tMempool* m = *mp;
_tVZFilter* f = *vf = (_tVZFilter*) mpool_alloc(sizeof(_tVZFilter), m);
+ f->mempool = m;
f->fc = freq;
f->type = type;
@@ -1280,14 +1213,12 @@
f->sr = leaf.sampleRate;
f->inv_sr = leaf.invSampleRate;
tVZFilter_calcCoeffs(vf);
-
-
}
-void tVZFilter_freeFromPool (tVZFilter* const vf, tMempool* const mp)
+
+void tVZFilter_free (tVZFilter* const vf)
{
- _tMempool* m = *mp;
_tVZFilter* f = *vf;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
void tVZFilter_setSampleRate (tVZFilter* const vf, float sampleRate)
@@ -1557,14 +1488,12 @@
tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool);
}
-void tDiodeFilter_free (tDiodeFilter* const vf)
-{
- tDiodeFilter_freeFromPool(vf, &leaf.mempool);
-}
void tDiodeFilter_initToPool (tDiodeFilter* const vf, float cutoff, float resonance, tMempool* const mp)
{
_tMempool* m = *mp;
_tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m);
+ f->mempool = m;
+
// initialization (the resonance factor is between 0 and 8 according to the article)
f->f = tan(PI * cutoff/leaf.sampleRate);
f->r = (7.f * resonance + 0.5f);
@@ -1579,14 +1508,12 @@
f->g0inv = 1.f/(2.f*f->Vt);
f->g1inv = 1.f/(2.f*f->gamma);
f->g2inv = 1.f/(6.f*f->gamma);
-
-
}
-void tDiodeFilter_freeFromPool (tDiodeFilter* const vf, tMempool* const mp)
+
+void tDiodeFilter_free (tDiodeFilter* const vf)
{
- _tMempool* m = *mp;
_tDiodeFilter* f = *vf;
- mpool_free((char*)f, m);
+ mpool_free((char*)f, f->mempool);
}
float tanhXdX(float x)
--- a/leaf/Src/leaf-instruments.c
+++ b/leaf/Src/leaf-instruments.c
@@ -23,15 +23,11 @@
t808Cowbell_initToPool(cowbellInst, useStick, &leaf.mempool);
}
-void t808Cowebell_free(t808Cowbell* const cowbellInst)
-{
- t808Cowbell_freeFromPool(cowbellInst, &leaf.mempool);
-}
-
void t808Cowbell_initToPool (t808Cowbell* const cowbellInst, int useStick, tMempool* const mp)
{
_tMempool* m = *mp;
_t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) mpool_alloc(sizeof(_t808Cowbell), m);
+ cowbell->mempool = m;
tSquare_initToPool(&cowbell->p[0], mp);
tSquare_setFreq(&cowbell->p[0], 540.0f);
@@ -58,21 +54,20 @@
cowbell->useStick = useStick;
}
-void t808Cowbell_freeFromPool (t808Cowbell* const cowbellInst, tMempool* const mp)
+void t808Cowbell_free (t808Cowbell* const cowbellInst)
{
- _tMempool* m = *mp;
_t808Cowbell* cowbell = *cowbellInst;
- tSquare_freeFromPool(&cowbell->p[0], mp);
- tSquare_freeFromPool(&cowbell->p[1], mp);
- tSVF_freeFromPool(&cowbell->bandpassOsc, mp);
- tSVF_freeFromPool(&cowbell->bandpassStick, mp);
- tEnvelope_freeFromPool(&cowbell->envGain, mp);
- tEnvelope_freeFromPool(&cowbell->envFilter, mp);
- tHighpass_freeFromPool(&cowbell->highpass, mp);
- tNoise_freeFromPool(&cowbell->stick, mp);
- tEnvelope_freeFromPool(&cowbell->envStick, mp);
- mpool_free((char*)cowbell, m);
+ tSquare_free(&cowbell->p[0]);
+ tSquare_free(&cowbell->p[1]);
+ tSVF_free(&cowbell->bandpassOsc);
+ tSVF_free(&cowbell->bandpassStick);
+ tEnvelope_free(&cowbell->envGain);
+ tEnvelope_free(&cowbell->envFilter);
+ tHighpass_free(&cowbell->highpass);
+ tNoise_free(&cowbell->stick);
+ tEnvelope_free(&cowbell->envStick);
+ mpool_free((char*)cowbell, cowbell->mempool);
}
void t808Cowbell_on(t808Cowbell* const cowbellInst, float vel)
@@ -153,15 +148,11 @@
t808Hihat_initToPool(hihatInst, &leaf.mempool);
}
-void t808Hihat_free(t808Hihat* const hihatInst)
-{
- t808Hihat_freeFromPool(hihatInst, &leaf.mempool);
-}
-
void t808Hihat_initToPool (t808Hihat* const hihatInst, tMempool* const mp)
{
_tMempool* m = *mp;
_t808Hihat* hihat = *hihatInst = (_t808Hihat*) mpool_alloc(sizeof(_t808Hihat), m);
+ hihat->mempool = m;
for (int i = 0; i < 6; i++)
{
@@ -192,28 +183,27 @@
tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq);
}
-void t808Hihat_freeFromPool (t808Hihat* const hihatInst, tMempool* const mp)
+void t808Hihat_free (t808Hihat* const hihatInst)
{
- _tMempool* m = *mp;
_t808Hihat* hihat = *hihatInst;
for (int i = 0; i < 6; i++)
{
- tSquare_freeFromPool(&hihat->p[i], mp);
+ tSquare_free(&hihat->p[i]);
}
- tNoise_freeFromPool(&hihat->stick, mp);
- tNoise_freeFromPool(&hihat->n, mp);
+ tNoise_free(&hihat->stick);
+ tNoise_free(&hihat->n);
// need to fix SVF to be generic
- tSVF_freeFromPool(&hihat->bandpassStick, mp);
- tSVF_freeFromPool(&hihat->bandpassOsc, mp);
- tEnvelope_freeFromPool(&hihat->envGain, mp);
- tEnvelope_freeFromPool(&hihat->envStick, mp);
+ tSVF_free(&hihat->bandpassStick);
+ tSVF_free(&hihat->bandpassOsc);
+ tEnvelope_free(&hihat->envGain);
+ tEnvelope_free(&hihat->envStick);
- tHighpass_freeFromPool(&hihat->highpass, mp);
+ tHighpass_free(&hihat->highpass);
- mpool_free((char*)hihat, m);
+ mpool_free((char*)hihat, hihat->mempool);
}
void t808Hihat_on(t808Hihat* const hihatInst, float vel)
@@ -326,15 +316,11 @@
t808Snare_initToPool(snareInst, &leaf.mempool);
}
-void t808Snare_free (t808Snare* const snareInst)
-{
- t808Snare_freeFromPool(snareInst, &leaf.mempool);
-}
-
void t808Snare_initToPool (t808Snare* const snareInst, tMempool* const mp)
{
_tMempool* m = *mp;
_t808Snare* snare = *snareInst = (_t808Snare*) mpool_alloc(sizeof(_t808Snare), m);
+ snare->mempool = m;
float ratio[2] = {1.0, 1.5};
for (int i = 0; i < 2; i++)
@@ -360,26 +346,25 @@
snare->noiseGain = 1.0f;
}
-void t808Snare_freeFromPool (t808Snare* const snareInst, tMempool* const mp)
+void t808Snare_free (t808Snare* const snareInst)
{
- _tMempool* m = *mp;
_t808Snare* snare = *snareInst;
for (int i = 0; i < 2; i++)
{
- tTriangle_freeFromPool(&snare->tone[i], mp);
- tSVF_freeFromPool(&snare->toneLowpass[i], mp);
- tEnvelope_freeFromPool(&snare->toneEnvOsc[i], mp);
- tEnvelope_freeFromPool(&snare->toneEnvGain[i], mp);
- tEnvelope_freeFromPool(&snare->toneEnvFilter[i], mp);
+ tTriangle_free(&snare->tone[i]);
+ tSVF_free(&snare->toneLowpass[i]);
+ tEnvelope_free(&snare->toneEnvOsc[i]);
+ tEnvelope_free(&snare->toneEnvGain[i]);
+ tEnvelope_free(&snare->toneEnvFilter[i]);
}
- tNoise_freeFromPool(&snare->noiseOsc, mp);
- tSVF_freeFromPool(&snare->noiseLowpass, mp);
- tEnvelope_freeFromPool(&snare->noiseEnvGain, mp);
- tEnvelope_freeFromPool(&snare->noiseEnvFilter, mp);
+ tNoise_free(&snare->noiseOsc);
+ tSVF_free(&snare->noiseLowpass);
+ tEnvelope_free(&snare->noiseEnvGain);
+ tEnvelope_free(&snare->noiseEnvFilter);
- mpool_free((char*)snare, m);
+ mpool_free((char*)snare, snare->mempool);
}
void t808Snare_on(t808Snare* const snareInst, float vel)
@@ -478,15 +463,11 @@
t808Kick_initToPool(kickInst, &leaf.mempool);
}
-void t808Kick_free (t808Kick* const kickInst)
-{
- t808Kick_freeFromPool(kickInst, &leaf.mempool);
-}
-
void t808Kick_initToPool (t808Kick* const kickInst, tMempool* const mp)
{
_tMempool* m = *mp;
_t808Kick* kick = *kickInst = (_t808Kick*) mpool_alloc(sizeof(_t808Kick), m);
+ kick->mempool = m;
tCycle_initToPool(&kick->tone, mp);
kick->toneInitialFreq = 40.0f;
@@ -502,20 +483,19 @@
kick->noiseGain = 0.3f;
}
-void t808Kick_freeFromPool (t808Kick* const kickInst, tMempool* const mp)
+void t808Kick_free (t808Kick* const kickInst)
{
- _tMempool* m = *mp;
_t808Kick* kick = *kickInst;
- tCycle_freeFromPool(&kick->tone, mp);
- tSVF_freeFromPool(&kick->toneLowpass, mp);
- tEnvelope_freeFromPool(&kick->toneEnvOscChirp, mp);
- tEnvelope_freeFromPool(&kick->toneEnvOscSigh, mp);
- tEnvelope_freeFromPool(&kick->toneEnvGain, mp);
- tNoise_freeFromPool(&kick->noiseOsc, mp);
- tEnvelope_freeFromPool(&kick->noiseEnvGain, mp);
+ tCycle_free(&kick->tone);
+ tSVF_free(&kick->toneLowpass);
+ tEnvelope_free(&kick->toneEnvOscChirp);
+ tEnvelope_free(&kick->toneEnvOscSigh);
+ tEnvelope_free(&kick->toneEnvGain);
+ tNoise_free(&kick->noiseOsc);
+ tEnvelope_free(&kick->noiseEnvGain);
- mpool_free((char*)kick, m);
+ mpool_free((char*)kick, kick->mempool);
}
float t808Kick_tick (t808Kick* const kickInst)
--- a/leaf/Src/leaf-midi.c
+++ b/leaf/Src/leaf-midi.c
@@ -25,15 +25,11 @@
tStack_initToPool(stack, &leaf.mempool);
}
-void tStack_free(tStack* const stack)
-{
- tStack_freeFromPool(stack, &leaf.mempool);
-}
-
void tStack_initToPool (tStack* const stack, tMempool* const mp)
{
_tMempool* m = *mp;
_tStack* ns = *stack = (_tStack*) mpool_alloc(sizeof(_tStack), m);
+ ns->mempool = m;
ns->ordered = OFALSE;
ns->size = 0;
@@ -43,12 +39,11 @@
for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1;
}
-void tStack_freeFromPool (tStack* const stack, tMempool* const mp)
+void tStack_free (tStack* const stack)
{
- _tMempool* m = *mp;
_tStack* ns = *stack;
- mpool_free((char*)ns, m);
+ mpool_free((char*)ns, ns->mempool);
}
// If stack contains note, returns index. Else returns -1;
@@ -266,15 +261,11 @@
tPoly_initToPool(polyh, maxNumVoices, &leaf.mempool);
}
-void tPoly_free(tPoly* const polyh)
-{
- tPoly_freeFromPool(polyh, &leaf.mempool);
-}
-
void tPoly_initToPool (tPoly* const polyh, int maxNumVoices, tMempool* const mp)
{
_tMempool* m = *mp;
_tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), m);
+ poly->mempool = m;
poly->numVoices = maxNumVoices;
poly->maxNumVoices = maxNumVoices;
@@ -317,26 +308,25 @@
poly->pitchGlideIsActive = OFALSE;
}
-void tPoly_freeFromPool (tPoly* const polyh, tMempool* const mp)
+void tPoly_free (tPoly* const polyh)
{
- _tMempool* m = *mp;
_tPoly* poly = *polyh;
for (int i = 0; i < poly->maxNumVoices; i++)
{
- tRamp_freeFromPool(&poly->ramps[i], mp);
- mpool_free((char*)poly->voices[i], m);
+ tRamp_free(&poly->ramps[i]);
+ mpool_free((char*)poly->voices[i], poly->mempool);
}
- tRamp_freeFromPool(&poly->pitchBendRamp, mp);
- tStack_freeFromPool(&poly->stack, mp);
- tStack_freeFromPool(&poly->orderStack, mp);
+ tRamp_free(&poly->pitchBendRamp);
+ tStack_free(&poly->stack);
+ tStack_free(&poly->orderStack);
- mpool_free((char*)poly->voices, m);
- mpool_free((char*)poly->ramps, m);
- mpool_free((char*)poly->rampVals, m);
- mpool_free((char*)poly->firstReceived, m);
+ mpool_free((char*)poly->voices, poly->mempool);
+ mpool_free((char*)poly->ramps, poly->mempool);
+ mpool_free((char*)poly->rampVals, poly->mempool);
+ mpool_free((char*)poly->firstReceived, poly->mempool);
- mpool_free((char*)poly, m);
+ mpool_free((char*)poly, poly->mempool);
}
void tPoly_tickPitch(tPoly* polyh)
@@ -627,15 +617,11 @@
tSimplePoly_initToPool(polyh, maxNumVoices, &leaf.mempool);
}
-void tSimplePoly_free(tSimplePoly* const polyh)
-{
- tSimplePoly_freeFromPool(polyh, &leaf.mempool);
-}
-
void tSimplePoly_initToPool (tSimplePoly* const polyh, int maxNumVoices, tMempool* const mp)
{
_tMempool* m = *mp;
_tSimplePoly* poly = *polyh = (_tSimplePoly*) mpool_alloc(sizeof(_tSimplePoly), m);
+ poly->mempool = m;
poly->numVoices = maxNumVoices;
poly->maxNumVoices = maxNumVoices;
@@ -658,18 +644,17 @@
}
-void tSimplePoly_freeFromPool (tSimplePoly* const polyh, tMempool* const mp)
+void tSimplePoly_free (tSimplePoly* const polyh)
{
- _tMempool* m = *mp;
_tSimplePoly* poly = *polyh;
for (int i = 0; i < poly->maxNumVoices; i++)
{
- mpool_free((char*)poly->voices[i], m);
+ mpool_free((char*)poly->voices[i], poly->mempool);
}
- tStack_freeFromPool(&poly->stack, mp);
- mpool_free((char*)poly->voices, m);
- mpool_free((char*)poly, m);
+ tStack_free(&poly->stack);
+ mpool_free((char*)poly->voices, poly->mempool);
+ mpool_free((char*)poly, poly->mempool);
}
int tSimplePoly_noteOn(tSimplePoly* const polyh, int note, uint8_t vel)
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -22,27 +22,21 @@
tCycle_initToPool(cy, &leaf.mempool);
}
-void tCycle_free(tCycle* const cy)
-{
- tCycle_freeFromPool(cy, &leaf.mempool);
-}
-
void tCycle_initToPool (tCycle* const cy, tMempool* const mp)
{
_tMempool* m = *mp;
_tCycle* c = *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
-
}
-void tCycle_freeFromPool (tCycle* const cy, tMempool* const mp)
+void tCycle_free (tCycle* const cy)
{
- _tMempool* m = *mp;
_tCycle* c = *cy;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
void tCycle_setFreq(tCycle* const cy, float freq)
@@ -79,7 +73,6 @@
samp1 = __leaf_table_sinewave[intPart];
return (samp0 + (samp1 - samp0) * fracPart);
-
}
void tCycleSampleRateChanged (tCycle* const cy)
@@ -96,15 +89,11 @@
tTriangle_initToPool(cy, &leaf.mempool);
}
-void tTriangle_free(tTriangle* const cy)
-{
- tTriangle_freeFromPool(cy, &leaf.mempool);
-}
-
void tTriangle_initToPool (tTriangle* const cy, tMempool* const mp)
{
_tMempool* m = *mp;
_tTriangle* c = *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -111,12 +100,11 @@
tTriangle_setFreq(cy, 220);
}
-void tTriangle_freeFromPool (tTriangle* const cy, tMempool* const mp)
+void tTriangle_free (tTriangle* const cy)
{
- _tMempool* m = *mp;
_tTriangle* c = *cy;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
void tTriangle_setFreq(tTriangle* const cy, float freq)
@@ -170,15 +158,11 @@
tSquare_initToPool(cy, &leaf.mempool);
}
-void tSquare_free(tSquare* const cy)
-{
- tSquare_freeFromPool(cy, &leaf.mempool);
-}
-
void tSquare_initToPool (tSquare* const cy, tMempool* const mp)
{
_tMempool* m = *mp;
_tSquare* c = *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -185,12 +169,11 @@
tSquare_setFreq(cy, 220);
}
-void tSquare_freeFromPool(tSquare* const cy, tMempool* const mp)
+void tSquare_free (tSquare* const cy)
{
- _tMempool* m = *mp;
_tSquare* c = *cy;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
void tSquare_setFreq(tSquare* const cy, float freq)
@@ -243,15 +226,11 @@
tSawtooth_initToPool(cy, &leaf.mempool);
}
-void tSawtooth_free(tSawtooth* const cy)
-{
- tSawtooth_freeFromPool(cy, &leaf.mempool);
-}
-
void tSawtooth_initToPool (tSawtooth* const cy, tMempool* const mp)
{
_tMempool* m = *mp;
_tSawtooth* c = *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -258,12 +237,11 @@
tSawtooth_setFreq(cy, 220);
}
-void tSawtooth_freeFromPool (tSawtooth* const cy, tMempool* const mp)
+void tSawtooth_free (tSawtooth* const cy)
{
- _tMempool* m = *mp;
_tSawtooth* c = *cy;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
void tSawtooth_setFreq(tSawtooth* const cy, float freq)
@@ -316,15 +294,11 @@
tSine_initToPool(cy, size, &leaf.mempool);
}
-void tSine_free(tSine* const cy)
-{
- tSine_freeFromPool(cy, &leaf.mempool);
-}
-
void tSine_initToPool (tSine* const cy, int size, tMempool* const mp)
{
_tMempool* m = *mp;
_tSine* c = *cy = (_tSine*) mpool_alloc(sizeof(_tSine), m);
+ c->mempool = m;
c->size = size;
c->sine = (float*) mpool_alloc(sizeof(float) * c->size, m);
@@ -333,13 +307,12 @@
c->phase = 0.0f;
}
-void tSine_freeFromPool (tSine* const cy, tMempool* const mp)
+void tSine_free (tSine* const cy)
{
- _tMempool* m = *mp;
_tSine* c = *cy;
- mpool_free((char*)c->sine, m);
- mpool_free((char*)c, m);
+ mpool_free((char*)c->sine, c->mempool);
+ mpool_free((char*)c, c->mempool);
}
void tSine_setFreq(tSine* const cy, float freq)
@@ -392,15 +365,11 @@
tTri_initToPool(osc, &leaf.mempool);
}
-void tTri_free (tTri* const osc)
-{
- tTri_freeFromPool(osc, &leaf.mempool);
-}
-
void tTri_initToPool (tTri* const osc, tMempool* const mp)
{
_tMempool* m = *mp;
_tTri* c = *osc = (_tTri*) mpool_alloc(sizeof(_tTri), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -408,12 +377,11 @@
c->lastOut = 0.0f;
}
-void tTri_freeFromPool (tTri* const cy, tMempool* const mp)
+void tTri_free (tTri* const cy)
{
- _tMempool* m = *mp;
_tTri* c = *cy;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tTri_tick (tTri* const osc)
@@ -472,15 +440,11 @@
tPulse_initToPool(osc, &leaf.mempool);
}
-void tPulse_free (tPulse* const osc)
-{
- tPulse_freeFromPool(osc, &leaf.mempool);
-}
-
void tPulse_initToPool (tPulse* const osc, tMempool* const mp)
{
_tMempool* m = *mp;
_tPulse* c = *osc = (_tPulse*) mpool_alloc(sizeof(_tPulse), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -487,12 +451,11 @@
c->width = 0.5f;
}
-void tPulse_freeFromPool(tPulse* const osc, tMempool* const mp)
+void tPulse_free (tPulse* const osc)
{
- _tMempool* m = *mp;
_tPulse* c = *osc;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tPulse_tick (tPulse* const osc)
@@ -537,26 +500,21 @@
tSaw_initToPool(osc, &leaf.mempool);
}
-void tSaw_free (tSaw* const osc)
-{
- tSaw_freeFromPool(osc, &leaf.mempool);
-}
-
void tSaw_initToPool (tSaw* const osc, tMempool* const mp)
{
_tMempool* m = *mp;
_tSaw* c = *osc = (_tSaw*) mpool_alloc(sizeof(_tSaw), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
}
-void tSaw_freeFromPool (tSaw* const osc, tMempool* const mp)
+void tSaw_free (tSaw* const osc)
{
- _tMempool* m = *mp;
_tSaw* c = *osc;
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tSaw_tick (tSaw* const osc)
@@ -598,15 +556,11 @@
tPhasor_initToPool(ph, &leaf.mempool);
}
-void tPhasor_free(tPhasor* const ph)
-{
- tPhasor_freeFromPool(ph, &leaf.mempool);
-}
-
void tPhasor_initToPool (tPhasor* const ph, tMempool* const mp)
{
_tMempool* m = *mp;
_tPhasor* p = *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), m);
+ p->mempool = m;
p->phase = 0.0f;
p->inc = 0.0f;
@@ -613,12 +567,11 @@
p->phaseDidReset = 0;
}
-void tPhasor_freeFromPool(tPhasor* const ph, tMempool* const mp)
+void tPhasor_free (tPhasor* const ph)
{
- _tMempool* m = *mp;
_tPhasor* p = *ph;
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
void tPhasor_setFreq(tPhasor* const ph, float freq)
@@ -653,26 +606,21 @@
tNoise_initToPool(ns, type, &leaf.mempool);
}
-void tNoise_free(tNoise* const ns)
-{
- tNoise_freeFromPool(ns, &leaf.mempool);
-}
-
void tNoise_initToPool (tNoise* const ns, NoiseType type, tMempool* const mp)
{
_tMempool* m = *mp;
_tNoise* n = *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), m);
+ n->mempool = m;
n->type = type;
n->rand = leaf.random;
}
-void tNoise_freeFromPool (tNoise* const ns, tMempool* const mp)
+void tNoise_free (tNoise* const ns)
{
- _tMempool* m = *mp;
_tNoise* n = *ns;
- mpool_free((char*)n, m);
+ mpool_free((char*)n, n->mempool);
}
float tNoise_tick(tNoise* const ns)
@@ -709,15 +657,11 @@
tNeuron_initToPool(nr, &leaf.mempool);
}
-void tNeuron_free(tNeuron* const nr)
-{
- tNeuron_freeFromPool(nr, &leaf.mempool);
-}
-
void tNeuron_initToPool (tNeuron* const nr, tMempool* const mp)
{
_tMempool* m = *mp;
_tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), m);
+ n->mempool = m;
tPoleZero_initToPool(&n->f, mp);
@@ -746,13 +690,12 @@
n->rate[2] = n->gL/n->C;
}
-void tNeuron_freeFromPool(tNeuron* const nr, tMempool* const mp)
+void tNeuron_free (tNeuron* const nr)
{
- _tMempool* m = *mp;
_tNeuron* n = *nr;
tPoleZero_free(&n->f);
- mpool_free((char*)n, m);
+ mpool_free((char*)n, n->mempool);
}
void tNeuron_reset(tNeuron* const nr)
@@ -1096,8 +1039,9 @@
}
-
-
+// good values for this are:
+// zeroCrossings = 16
+// oversamplerRatio = 32 (or 64 for slightly better antialiasing, but higher memory usage)
void tMinBLEPTable_init (tMinBLEPTable* const minblep, int zeroCrossings, int oversamplerRatio)
{
tMinBLEPTable_initToPool(minblep, zeroCrossings, oversamplerRatio, &leaf.mempool);
@@ -1200,9 +1144,7 @@
}
-
-
-void tMinBLEPHandler_init (tMinBLEPHandler* const minblep, tMinBLEPTable* const table, int oversamplerRatio)
+void tMinBLEPHandler_init (tMinBLEPHandler* const minblep, tMinBLEPTable* const table)
{
tMinBLEPHandler_initToPool(minblep, table, &leaf.mempool);
}
@@ -1371,15 +1313,11 @@
tMBTriangle_initToPool(osc, table, &leaf.mempool);
}
-void tMBTriangle_free (tMBTriangle* const osc)
-{
- tMBTriangle_freeFromPool(osc, &leaf.mempool);
-}
-
void tMBTriangle_initToPool (tMBTriangle* const osc, tMinBLEPTable* const table, tMempool* const mp)
{
_tMempool* m = *mp;
_tMBTriangle* c = *osc = (_tMBTriangle*) mpool_alloc(sizeof(_tMBTriangle), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -1390,15 +1328,14 @@
tHighpass_initToPool(&c->dcBlock, 5.0f, mp);
}
-void tMBTriangle_freeFromPool (tMBTriangle* const cy, tMempool* const mp)
+void tMBTriangle_free (tMBTriangle* const cy)
{
- _tMempool* m = *mp;
_tMBTriangle* c = *cy;
tMinBLEPHandler_free(&c->minBlep);
- tHighpass_freeFromPool(&c->dcBlock, mp);
+ tHighpass_free(&c->dcBlock);
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tMBTriangle_tick (tMBTriangle* const osc)
@@ -1511,15 +1448,11 @@
tMBPulse_initToPool(osc, table, &leaf.mempool);
}
-void tMBPulse_free (tMBPulse* const osc)
-{
- tMBPulse_freeFromPool(osc, &leaf.mempool);
-}
-
void tMBPulse_initToPool (tMBPulse* const osc, tMinBLEPTable* const table, tMempool* const mp)
{
_tMempool* m = *mp;
_tMBPulse* c = *osc = (_tMBPulse*) mpool_alloc(sizeof(_tMBPulse), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -1529,15 +1462,14 @@
tHighpass_initToPool(&c->dcBlock, 10.0f, mp);
}
-void tMBPulse_freeFromPool(tMBPulse* const osc, tMempool* const mp)
+void tMBPulse_free (tMBPulse* const osc)
{
- _tMempool* m = *mp;
_tMBPulse* c = *osc;
tMinBLEPHandler_free(&c->minBlep);
- tHighpass_freeFromPool(&c->dcBlock, mp);
+ tHighpass_free(&c->dcBlock);
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tMBPulse_tick (tMBPulse* const osc)
@@ -1609,15 +1541,11 @@
tMBSaw_initToPool(osc, table, &leaf.mempool);
}
-void tMBSaw_free (tMBSaw* const osc)
-{
- tMBSaw_freeFromPool(osc, &leaf.mempool);
-}
-
void tMBSaw_initToPool (tMBSaw* const osc, tMinBLEPTable* const table, tMempool* const mp)
{
_tMempool* m = *mp;
_tMBSaw* c = *osc = (_tMBSaw*) mpool_alloc(sizeof(_tMBSaw), m);
+ c->mempool = m;
c->inc = 0.0f;
c->phase = 0.0f;
@@ -1626,15 +1554,14 @@
tHighpass_initToPool(&c->dcBlock, 10.0f, mp);
}
-void tMBSaw_freeFromPool (tMBSaw* const osc, tMempool* const mp)
+void tMBSaw_free (tMBSaw* const osc)
{
- _tMempool* m = *mp;
_tMBSaw* c = *osc;
tMinBLEPHandler_free(&c->minBlep);
- tHighpass_freeFromPool(&c->dcBlock, mp);
+ tHighpass_free(&c->dcBlock);
- mpool_free((char*)c, m);
+ mpool_free((char*)c, c->mempool);
}
float tMBSaw_tick (tMBSaw* const osc)
--- a/leaf/Src/leaf-physical.c
+++ b/leaf/Src/leaf-physical.c
@@ -22,15 +22,11 @@
tPluck_initToPool(pl, lowestFrequency, &leaf.mempool);
}
-void tPluck_free (tPluck* const pl)
-{
- tPluck_freeFromPool(pl, &leaf.mempool);
-}
-
void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* const mp)
{
_tMempool* m = *mp;
_tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), m);
+ p->mempool = m;
if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
@@ -46,17 +42,16 @@
tPluck_setFrequency(pl, 220.0f);
}
-void tPluck_freeFromPool (tPluck* const pl, tMempool* const mp)
+void tPluck_free (tPluck* const pl)
{
- _tMempool* m = *mp;
_tPluck* p = *pl;
- tNoise_freeFromPool(&p->noise, mp);
- tOnePole_freeFromPool(&p->pickFilter, mp);
- tOneZero_freeFromPool(&p->loopFilter, mp);
- tAllpassDelay_freeFromPool(&p->delayLine, mp);
+ tNoise_free(&p->noise);
+ tOnePole_free(&p->pickFilter);
+ tOneZero_free(&p->loopFilter);
+ tAllpassDelay_free(&p->delayLine);
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
float tPluck_getLastOut (tPluck* const pl)
@@ -142,15 +137,11 @@
tKarplusStrong_initToPool(pl, lowestFrequency, &leaf.mempool);
}
-void tKarplusStrong_free (tKarplusStrong* const pl)
-{
- tKarplusStrong_freeFromPool(pl, &leaf.mempool);
-}
-
void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequency, tMempool* const mp)
{
_tMempool* m = *mp;
_tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), m);
+ p->mempool = m;
if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
@@ -179,22 +170,21 @@
tKarplusStrong_setFrequency( pl, 220.0f );
}
-void tKarplusStrong_freeFromPool (tKarplusStrong* const pl, tMempool* const mp)
+void tKarplusStrong_free (tKarplusStrong* const pl)
{
- _tMempool* m = *mp;
_tKarplusStrong* p = *pl;
- tAllpassDelay_freeFromPool(&p->delayLine, mp);
- tLinearDelay_freeFromPool(&p->combDelay, mp);
- tOneZero_freeFromPool(&p->filter, mp);
- tNoise_freeFromPool(&p->noise, mp);
+ tAllpassDelay_free(&p->delayLine);
+ tLinearDelay_free(&p->combDelay);
+ tOneZero_free(&p->filter);
+ tNoise_free(&p->noise);
for (int i = 0; i < 4; i++)
{
- tBiQuad_freeFromPool(&p->biquad[i], mp);
+ tBiQuad_free(&p->biquad[i]);
}
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
float tKarplusStrong_getLastOut (tKarplusStrong* const pl)
@@ -361,11 +351,6 @@
tSimpleLivingString_initToPool(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
}
-void tSimpleLivingString_free(tSimpleLivingString* const pl)
-{
- tSimpleLivingString_freeFromPool(pl, &leaf.mempool);
-}
-
void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float freq, float dampFreq,
float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const mp)
@@ -372,6 +357,7 @@
{
_tMempool* m = *mp;
_tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), m);
+ p->mempool = m;
p->curr=0.0f;
tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
@@ -385,18 +371,17 @@
p->levMode=levMode;
}
-void tSimpleLivingString_freeFromPool (tSimpleLivingString* const pl, tMempool* const mp)
+void tSimpleLivingString_free (tSimpleLivingString* const pl)
{
- _tMempool* m = *mp;
_tSimpleLivingString* p = *pl;
- tExpSmooth_freeFromPool(&p->wlSmooth, mp);
- tLinearDelay_freeFromPool(&p->delayLine, mp);
- tOnePole_freeFromPool(&p->bridgeFilter, mp);
- tHighpass_freeFromPool(&p->DCblocker, mp);
- tFeedbackLeveler_freeFromPool(&p->fbLev, mp);
+ tExpSmooth_free(&p->wlSmooth);
+ tLinearDelay_free(&p->delayLine);
+ tOnePole_free(&p->bridgeFilter);
+ tHighpass_free(&p->DCblocker);
+ tFeedbackLeveler_free(&p->fbLev);
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
void tSimpleLivingString_setFreq(tSimpleLivingString* const pl, float freq)
@@ -483,11 +468,6 @@
tLivingString_initToPool(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
}
-void tLivingString_free(tLivingString* const pl)
-{
- tLivingString_freeFromPool(pl, &leaf.mempool);
-}
-
void tLivingString_initToPool (tLivingString* const pl, float freq, float pickPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const mp)
@@ -494,6 +474,7 @@
{
_tMempool* m = *mp;
_tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), m);
+ p->mempool = m;
p->curr=0.0f;
tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
@@ -524,27 +505,26 @@
p->levMode=levMode;
}
-void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp)
+void tLivingString_free (tLivingString* const pl)
{
- _tMempool* m = *mp;
_tLivingString* p = *pl;
- tExpSmooth_freeFromPool(&p->wlSmooth, mp);
- tExpSmooth_freeFromPool(&p->ppSmooth, mp);
- tLinearDelay_freeFromPool(&p->delLF, mp);
- tLinearDelay_freeFromPool(&p->delUF, mp);
- tLinearDelay_freeFromPool(&p->delUB, mp);
- tLinearDelay_freeFromPool(&p->delLB, mp);
- tOnePole_freeFromPool(&p->bridgeFilter, mp);
- tOnePole_freeFromPool(&p->nutFilter, mp);
- tOnePole_freeFromPool(&p->prepFilterU, mp);
- tOnePole_freeFromPool(&p->prepFilterL, mp);
- tHighpass_freeFromPool(&p->DCblockerU, mp);
- tHighpass_freeFromPool(&p->DCblockerL, mp);
- tFeedbackLeveler_freeFromPool(&p->fbLevU, mp);
- tFeedbackLeveler_freeFromPool(&p->fbLevL, mp);
+ tExpSmooth_free(&p->wlSmooth);
+ tExpSmooth_free(&p->ppSmooth);
+ tLinearDelay_free(&p->delLF);
+ tLinearDelay_free(&p->delUF);
+ tLinearDelay_free(&p->delUB);
+ tLinearDelay_free(&p->delLB);
+ tOnePole_free(&p->bridgeFilter);
+ tOnePole_free(&p->nutFilter);
+ tOnePole_free(&p->prepFilterU);
+ tOnePole_free(&p->prepFilterL);
+ tHighpass_free(&p->DCblockerU);
+ tHighpass_free(&p->DCblockerL);
+ tFeedbackLeveler_free(&p->fbLevU);
+ tFeedbackLeveler_free(&p->fbLevL);
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
void tLivingString_setFreq(tLivingString* const pl, float freq)
@@ -680,11 +660,6 @@
tComplexLivingString_initToPool(pl, freq, pickPos, prepPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
}
-void tComplexLivingString_free(tComplexLivingString* const pl)
-{
- tComplexLivingString_freeFromPool(pl, &leaf.mempool);
-}
-
void tComplexLivingString_initToPool (tComplexLivingString* const pl, float freq, float pickPos, float prepPos, float prepIndex,
float dampFreq, float decay, float targetLev, float levSmoothFactor,
float levStrength, int levMode, tMempool* const mp)
@@ -691,6 +666,7 @@
{
_tMempool* m = *mp;
_tComplexLivingString* p = *pl = (_tComplexLivingString*) mpool_alloc(sizeof(_tComplexLivingString), m);
+ p->mempool = m;
p->curr=0.0f;
tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
@@ -730,30 +706,29 @@
p->levMode=levMode;
}
-void tComplexLivingString_freeFromPool (tComplexLivingString* const pl, tMempool* const mp)
+void tComplexLivingString_free (tComplexLivingString* const pl)
{
- _tMempool* m = *mp;
_tComplexLivingString* p = *pl;
- tExpSmooth_freeFromPool(&p->wlSmooth, mp);
- tExpSmooth_freeFromPool(&p->pickPosSmooth, mp);
- tExpSmooth_freeFromPool(&p->prepPosSmooth, mp);
- tLinearDelay_freeFromPool(&p->delLF, mp);
- tLinearDelay_freeFromPool(&p->delMF, mp);
- tLinearDelay_freeFromPool(&p->delUF, mp);
- tLinearDelay_freeFromPool(&p->delUB, mp);
- tLinearDelay_freeFromPool(&p->delMB, mp);
- tLinearDelay_freeFromPool(&p->delLB, mp);
- tOnePole_freeFromPool(&p->bridgeFilter, mp);
- tOnePole_freeFromPool(&p->nutFilter, mp);
- tOnePole_freeFromPool(&p->prepFilterU, mp);
- tOnePole_freeFromPool(&p->prepFilterL, mp);
- tHighpass_freeFromPool(&p->DCblockerU, mp);
- tHighpass_freeFromPool(&p->DCblockerL, mp);
- tFeedbackLeveler_freeFromPool(&p->fbLevU, mp);
- tFeedbackLeveler_freeFromPool(&p->fbLevL, mp);
+ tExpSmooth_free(&p->wlSmooth);
+ tExpSmooth_free(&p->pickPosSmooth);
+ tExpSmooth_free(&p->prepPosSmooth);
+ tLinearDelay_free(&p->delLF);
+ tLinearDelay_free(&p->delMF);
+ tLinearDelay_free(&p->delUF);
+ tLinearDelay_free(&p->delUB);
+ tLinearDelay_free(&p->delMB);
+ tLinearDelay_free(&p->delLB);
+ tOnePole_free(&p->bridgeFilter);
+ tOnePole_free(&p->nutFilter);
+ tOnePole_free(&p->prepFilterU);
+ tOnePole_free(&p->prepFilterL);
+ tHighpass_free(&p->DCblockerU);
+ tHighpass_free(&p->DCblockerL);
+ tFeedbackLeveler_free(&p->fbLevU);
+ tFeedbackLeveler_free(&p->fbLevL);
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
void tComplexLivingString_setFreq(tComplexLivingString* const pl, float freq)
@@ -922,26 +897,21 @@
tReedTable_initToPool(pm, offset, slope, &leaf.mempool);
}
-void tReedTable_free (tReedTable* const pm)
-{
- tReedTable_freeFromPool(pm, &leaf.mempool);
-}
-
void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp)
{
_tMempool* m = *mp;
_tReedTable* p = *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), m);
+ p->mempool = m;
p->offset = offset;
p->slope = slope;
}
-void tReedTable_freeFromPool (tReedTable* const pm, tMempool* const mp)
+void tReedTable_free (tReedTable* const pm)
{
- _tMempool* m = *mp;
_tReedTable* p = *pm;
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
float tReedTable_tick (tReedTable* const pm, float input)
--- a/leaf/Src/leaf-reverb.c
+++ b/leaf/Src/leaf-reverb.c
@@ -24,15 +24,11 @@
tPRCReverb_initToPool(rev, t60, &leaf.mempool);
}
-void tPRCReverb_free(tPRCReverb* const rev)
-{
- tPRCReverb_freeFromPool(rev, &leaf.mempool);
-}
-
void tPRCReverb_initToPool (tPRCReverb* const rev, float t60, tMempool* const mp)
{
_tMempool* m = *mp;
_tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), m);
+ r->mempool = m;
if (t60 <= 0.0f) t60 = 0.001f;
@@ -66,15 +62,14 @@
r->mix = 0.5f;
}
-void tPRCReverb_freeFromPool (tPRCReverb* const rev, tMempool* const mp)
+void tPRCReverb_free (tPRCReverb* const rev)
{
- _tMempool* m = *mp;
_tPRCReverb* r = *rev;
- tDelay_freeFromPool(&r->allpassDelays[0], mp);
- tDelay_freeFromPool(&r->allpassDelays[1], mp);
- tDelay_freeFromPool(&r->combDelay, mp);
- mpool_free((char*)r, m);
+ tDelay_free(&r->allpassDelays[0]);
+ tDelay_free(&r->allpassDelays[1]);
+ tDelay_free(&r->combDelay);
+ mpool_free((char*)r, r->mempool);
}
void tPRCRevert_clear(tPRCReverb* const rev)
@@ -150,15 +145,11 @@
tNReverb_initToPool(rev, t60, &leaf.mempool);
}
-void tNReverb_free(tNReverb* const rev)
-{
- tNReverb_freeFromPool(rev, &leaf.mempool);
-}
-
void tNReverb_initToPool (tNReverb* const rev, float t60, tMempool* const mp)
{
_tMempool* m = *mp;
_tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), m);
+ r->mempool = m;
if (t60 <= 0.0f) t60 = 0.001f;
@@ -198,22 +189,21 @@
r->mix = 0.3f;
}
-void tNReverb_freeFromPool (tNReverb* const rev, tMempool* const mp)
+void tNReverb_free (tNReverb* const rev)
{
- _tMempool* m = *mp;
_tNReverb* r = *rev;
for (int i = 0; i < 6; i++)
{
- tLinearDelay_freeFromPool(&r->combDelays[i], mp);
+ tLinearDelay_free(&r->combDelays[i]);
}
for (int i = 0; i < 8; i++)
{
- tLinearDelay_freeFromPool(&r->allpassDelays[i], mp);
+ tLinearDelay_free(&r->allpassDelays[i]);
}
- mpool_free((char*)r, m);
+ mpool_free((char*)r, r->mempool);
}
void tNReverb_setT60(tNReverb* const rev, float t60)
@@ -377,15 +367,11 @@
tDattorroReverb_initToPool(rev, &leaf.mempool);
}
-void tDattorroReverb_free (tDattorroReverb* const rev)
-{
- tDattorroReverb_freeFromPool(rev, &leaf.mempool);
-}
-
void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* const mp)
{
_tMempool* m = *mp;
_tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), m);
+ r->mempool = m;
r->size_max = 2.0f;
r->size = 1.f;
@@ -444,47 +430,46 @@
tDattorroReverb_setFeedbackGain(rev, 0.4f);
}
-void tDattorroReverb_freeFromPool (tDattorroReverb* const rev, tMempool* const mp)
+void tDattorroReverb_free (tDattorroReverb* const rev)
{
- _tMempool* m = *mp;
_tDattorroReverb* r = *rev;
// INPUT
- tTapeDelay_freeFromPool(&r->in_delay, mp);
- tOnePole_freeFromPool(&r->in_filter, mp);
+ tTapeDelay_free(&r->in_delay);
+ tOnePole_free(&r->in_filter);
for (int i = 0; i < 4; i++)
{
- tAllpass_freeFromPool(&r->in_allpass[i], mp);
+ tAllpass_free(&r->in_allpass[i]);
}
// FEEDBACK 1
- tAllpass_freeFromPool(&r->f1_allpass, mp);
+ tAllpass_free(&r->f1_allpass);
- tTapeDelay_freeFromPool(&r->f1_delay_1, mp);
- tTapeDelay_freeFromPool(&r->f1_delay_2, mp);
- tTapeDelay_freeFromPool(&r->f1_delay_3, mp);
+ tTapeDelay_free(&r->f1_delay_1);
+ tTapeDelay_free(&r->f1_delay_2);
+ tTapeDelay_free(&r->f1_delay_3);
- tOnePole_freeFromPool(&r->f1_filter, mp);
+ tOnePole_free(&r->f1_filter);
- tHighpass_freeFromPool(&r->f1_hp, mp);
+ tHighpass_free(&r->f1_hp);
- tCycle_freeFromPool(&r->f1_lfo, mp);
+ tCycle_free(&r->f1_lfo);
// FEEDBACK 2
- tAllpass_freeFromPool(&r->f2_allpass, mp);
+ tAllpass_free(&r->f2_allpass);
- tTapeDelay_freeFromPool(&r->f2_delay_1, mp);
- tTapeDelay_freeFromPool(&r->f2_delay_2, mp);
- tTapeDelay_freeFromPool(&r->f2_delay_3, mp);
+ tTapeDelay_free(&r->f2_delay_1);
+ tTapeDelay_free(&r->f2_delay_2);
+ tTapeDelay_free(&r->f2_delay_3);
- tOnePole_freeFromPool(&r->f2_filter, mp);
+ tOnePole_free(&r->f2_filter);
- tHighpass_freeFromPool(&r->f2_hp, mp);
+ tHighpass_free(&r->f2_hp);
- tCycle_freeFromPool(&r->f2_lfo, mp);
+ tCycle_free(&r->f2_lfo);
- mpool_free((char*)r, m);
+ mpool_free((char*)r, r->mempool);
}
void tDattorroReverb_clear (tDattorroReverb* const rev)
--- a/leaf/Src/leaf-sampling.c
+++ b/leaf/Src/leaf-sampling.c
@@ -29,15 +29,11 @@
tBuffer_initToPool(sb, length, &leaf.mempool);
}
-void tBuffer_free (tBuffer* const sb)
-{
- tBuffer_freeFromPool(sb, &leaf.mempool);
-}
-
void tBuffer_initToPool (tBuffer* const sb, uint32_t length, tMempool* const mp)
{
_tMempool* m = *mp;
_tBuffer* s = *sb = (_tBuffer*) mpool_alloc(sizeof(_tBuffer), m);
+ s->mempool = m;
s->buff = (float*) mpool_alloc( sizeof(float) * length, m);
@@ -48,13 +44,12 @@
s->mode = RecordOneShot;
}
-void tBuffer_freeFromPool (tBuffer* const sb, tMempool* const mp)
+void tBuffer_free (tBuffer* const sb)
{
- _tMempool* m = *mp;
_tBuffer* s = *sb;
- mpool_free((char*)s->buff, m);
- mpool_free((char*)s, m);
+ mpool_free((char*)s->buff, s->mempool);
+ mpool_free((char*)s, s->mempool);
}
void tBuffer_tick (tBuffer* const sb, float sample)
@@ -176,15 +171,12 @@
tSampler_initToPool(sp, b, &leaf.mempool);
}
-void tSampler_free (tSampler* const sp)
-{
- tSampler_freeFromPool(sp, &leaf.mempool);
-}
-
void tSampler_initToPool(tSampler* const sp, tBuffer* const b, tMempool* const mp)
{
_tMempool* m = *mp;
_tSampler* p = *sp = (_tSampler*) mpool_alloc(sizeof(_tSampler), m);
+ p->mempool = m;
+
_tBuffer* s = *b;
p->samp = s;
@@ -219,13 +211,12 @@
p->flipIdx = -1;
}
-void tSampler_freeFromPool (tSampler* const sp, tMempool* const mp)
+void tSampler_free (tSampler* const sp)
{
- _tMempool* m = *mp;
_tSampler* p = *sp;
- tRamp_freeFromPool(&p->gain, mp);
+ tRamp_free(&p->gain);
- mpool_free((char*)p, m);
+ mpool_free((char*)p, p->mempool);
}
void tSampler_setSample (tSampler* const sp, tBuffer* const b)
@@ -769,15 +760,11 @@
tAutoSampler_initToPool(as, b, &leaf.mempool);
}
-void tAutoSampler_free (tAutoSampler* const as)
-{
- tAutoSampler_freeFromPool(as, &leaf.mempool);
-}
-
void tAutoSampler_initToPool (tAutoSampler* const as, tBuffer* const b, tMempool* const mp)
{
_tMempool* m = *mp;
_tAutoSampler* a = *as = (_tAutoSampler*) mpool_alloc(sizeof(_tAutoSampler), m);
+ a->mempool = m;
tBuffer_setRecordMode(b, RecordOneShot);
tSampler_initToPool(&a->sampler, b, mp);
@@ -785,15 +772,14 @@
tEnvelopeFollower_initToPool(&a->ef, 0.05f, 0.9999f, mp);
}
-void tAutoSampler_freeFromPool (tAutoSampler* const as, tMempool* const mp)
+void tAutoSampler_free (tAutoSampler* const as)
{
- _tMempool* m = *mp;
_tAutoSampler* a = *as;
- tEnvelopeFollower_freeFromPool(&a->ef, mp);
- tSampler_freeFromPool(&a->sampler, mp);
+ tEnvelopeFollower_free(&a->ef);
+ tSampler_free(&a->sampler);
- mpool_free((char*)a, m);
+ mpool_free((char*)a, a->mempool);
}
float tAutoSampler_tick (tAutoSampler* const as, float input)