Unified · Split
| @@ -4,25 +4,25 @@ · 3 unmodified lines | ||
| 4 | 4 | Created: 30 Nov 2018 10:24:44am |
| 5 | 5 | Author: airship |
| 6 | 6 | |
| 7 | −==============================================================================*/ | |
| 8 | − | |
| 9 | −#ifndef LEAF_808_H_INCLUDED | |
| 10 | −#define LEAF_808_H_INCLUDED | |
| 11 | − | |
| 12 | −#ifdef __cplusplus | |
| 13 | −extern "C" { | |
| 14 | −#endif | |
| 15 | − | |
| 16 | −//============================================================================== | |
| 7 | +==============================================================================*/ | |
| 8 | + | |
| 9 | +#ifndef LEAF_808_H_INCLUDED | |
| 10 | +#define LEAF_808_H_INCLUDED | |
| 11 | + | |
| 12 | +#ifdef __cplusplus | |
| 13 | +extern "C" { | |
| 14 | +#endif | |
| 15 | + | |
| 16 | +//============================================================================== | |
| 17 | 17 | |
| 18 | 18 | #include "leaf-globals.h" |
| 19 | 19 | #include "leaf-math.h" |
| 20 | 20 | |
| 21 | 21 | #include "leaf-oscillator.h" |
| 22 | 22 | #include "leaf-utilities.h" |
| 23 | −#include "leaf-filter.h" | |
| 24 | − | |
| 25 | −//============================================================================== | |
| 23 | +#include "leaf-filter.h" | |
| 24 | + | |
| 25 | +//============================================================================== | |
| 26 | 26 | |
| 27 | 27 | // 808 Cowbell |
| 28 | 28 | typedef struct _t808Cowbell { |
| @@ -50,7 +50,7 @@ void t808Cowbell_setBandpassFreq (t808Cowbell* const, float freq); · 21 unmodified lines | ||
| 50 | 50 | void t808Cowbell_setFreq (t808Cowbell* const, float freq); |
| 51 | 51 | void t808Cowbell_setOscMix (t808Cowbell* const, float oscMix); |
| 52 | 52 | |
| 53 | −//============================================================================== | |
| 53 | +//============================================================================== | |
| 54 | 54 | |
| 55 | 55 | // 808 Hihat |
| 56 | 56 | typedef struct _t808Hihat { |
| @@ -88,8 +88,8 @@ void t808Hihat_setStickBandPassQ (t808Hihat* const hihat, float Q); · 31 unmodified lines | ||
| 88 | 88 | void t808Hihat_setOscFreq (t808Hihat* const, float freq); |
| 89 | 89 | void t808Hihat_setStretch (t808Hihat* const hihat, float stretch); |
| 90 | 90 | void t808Hihat_setFM (t808Hihat* const hihat, float FM_amount); |
| 91 | − | |
| 92 | −//============================================================================== | |
| 91 | + | |
| 92 | +//============================================================================== | |
| 93 | 93 | |
| 94 | 94 | // 808 Snare |
| 95 | 95 | typedef struct _t808Snare { |
| @@ -131,7 +131,7 @@ void t808Snare_setToneNoiseMix (t808Snare* const, float toneNoiseMi · 35 unmodified lines | ||
| 131 | 131 | void t808Snare_setNoiseFilterFreq (t808Snare* const, float noiseFilterFreq); |
| 132 | 132 | void t808Snare_setNoiseFilterQ (t808Snare* const, float noiseFilterQ); |
| 133 | 133 | |
| 134 | −//============================================================================== | |
| 134 | +//============================================================================== | |
| 135 | 135 | |
| 136 | 136 | // 808 Kick |
| 137 | 137 | typedef struct _t808Kick { |
| @@ -169,16 +169,16 @@ void t808Kick_setSighAmount (t808Kick* const, float sigh); · 31 unmodified lines | ||
| 169 | 169 | void t808Kick_setChirpAmount (t808Kick* const, float chirp); |
| 170 | 170 | void t808Kick_setToneNoiseMix (t808Kick* const, float toneNoiseMix); |
| 171 | 171 | void t808Kick_setNoiseFilterFreq (t808Kick* const, float noiseFilterFreq); |
| 172 | −void t808Kick_setNoiseFilterQ (t808Kick* const, float noiseFilterQ); | |
| 173 | − | |
| 174 | −//============================================================================== | |
| 175 | − | |
| 176 | −#ifdef __cplusplus | |
| 177 | −} | |
| 178 | −#endif | |
| 179 | − | |
| 180 | −#endif // LEAF_808_H_INCLUDED | |
| 181 | − | |
| 172 | +void t808Kick_setNoiseFilterQ (t808Kick* const, float noiseFilterQ); | |
| 173 | + | |
| 174 | +//============================================================================== | |
| 175 | + | |
| 176 | +#ifdef __cplusplus | |
| 177 | +} | |
| 178 | +#endif | |
| 179 | + | |
| 180 | +#endif // LEAF_808_H_INCLUDED | |
| 181 | + | |
| 182 | 182 | //============================================================================== |
| 183 | 183 | |
| 184 | 184 | |
| @@ -64,6 +64,7 @@ struct _tWDF · 63 unmodified lines | ||
| 64 | 64 | |
| 65 | 65 | //WDF Linear Components |
| 66 | 66 | void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR); |
| 67 | +void tWDF_free(tWDF* const r); | |
| 67 | 68 | float tWDF_tick(tWDF* const r, float sample, tWDF* const outputPoint, uint8_t paramsChanged); |
| 68 | 69 | |
| 69 | 70 | void tWDF_setValue(tWDF* const r, float value); |
| @@ -4,21 +4,21 @@ · 3 unmodified lines | ||
| 4 | 4 | Created: 30 Nov 2018 11:03:37am |
| 5 | 5 | Author: airship |
| 6 | 6 | |
| 7 | −==============================================================================*/ | |
| 8 | − | |
| 9 | −#ifndef LEAF_FORMANT_H_INCLUDED | |
| 10 | −#define LEAF_FORMANT_H_INCLUDED | |
| 11 | − | |
| 12 | −#ifdef __cplusplus | |
| 13 | −extern "C" { | |
| 7 | +==============================================================================*/ | |
| 8 | + | |
| 9 | +#ifndef LEAF_FORMANT_H_INCLUDED | |
| 10 | +#define LEAF_FORMANT_H_INCLUDED | |
| 11 | + | |
| 12 | +#ifdef __cplusplus | |
| 13 | +extern "C" { | |
| 14 | 14 | #endif |
| 15 | 15 | |
| 16 | −//============================================================================== | |
| 16 | +//============================================================================== | |
| 17 | 17 | |
| 18 | 18 | #include "leaf-globals.h" |
| 19 | 19 | #include "leaf-math.h" |
| 20 | 20 | |
| 21 | −//============================================================================== | |
| 21 | +//============================================================================== | |
| 22 | 22 | |
| 23 | 23 | #define FORD 7 |
| 24 | 24 | #define FORMANT_BUFFER_SIZE 2048 |
| @@ -26,41 +26,42 @@ extern "C" { · 1 unmodified line | ||
| 26 | 26 | typedef struct _tFormantShifter |
| 27 | 27 | { |
| 28 | 28 | int ford; |
| 29 | + int bufsize; | |
| 29 | 30 | float falph; |
| 30 | 31 | float flamb; |
| 31 | − float fk[FORD]; | |
| 32 | − float fb[FORD]; | |
| 33 | − float fc[FORD]; | |
| 34 | − float frb[FORD]; | |
| 35 | − float frc[FORD]; | |
| 36 | − float fsig[FORD]; | |
| 37 | − float fsmooth[FORD]; | |
| 32 | + float* fk; | |
| 33 | + float* fb; | |
| 34 | + float* fc; | |
| 35 | + float* frb; | |
| 36 | + float* frc; | |
| 37 | + float* fsig; | |
| 38 | + float* fsmooth; | |
| 38 | 39 | float fhp; |
| 39 | 40 | float flp; |
| 40 | 41 | float flpa; |
| 41 | − float fbuff[FORD][FORMANT_BUFFER_SIZE]; | |
| 42 | − float ftvec[FORD]; | |
| 42 | + float** fbuff; | |
| 43 | + float* ftvec; | |
| 43 | 44 | float fmute; |
| 44 | 45 | float fmutealph; |
| 45 | 46 | unsigned int cbi; |
| 46 | 47 | |
| 47 | 48 | } tFormantShifter; |
| 48 | 49 | |
| 49 | −void tFormantShifter_init (tFormantShifter* const); | |
| 50 | +void tFormantShifter_init (tFormantShifter* const, int bufsize, int order); | |
| 50 | 51 | void tFormantShifter_free (tFormantShifter* const); |
| 51 | 52 | |
| 52 | 53 | float tFormantShifter_tick (tFormantShifter* const, float input, float fwarp); |
| 53 | 54 | float tFormantShifter_remove (tFormantShifter* const, float input); |
| 54 | 55 | float tFormantShifter_add (tFormantShifter* const, float input, float fwarp); |
| 55 | −void tFormantShifter_ioSamples (tFormantShifter* const, float* in, float* out, int size, float fwarp); | |
| 56 | +void tFormantShifter_ioSamples (tFormantShifter* const, float* in, float* out, int size, float fwarp); | |
| 56 | 57 | |
| 57 | −//============================================================================== | |
| 58 | − | |
| 59 | −#ifdef __cplusplus | |
| 60 | −} | |
| 61 | −#endif | |
| 62 | − | |
| 63 | −#endif // LEAF_FORMANT_H_INCLUDED | |
| 64 | − | |
| 58 | +//============================================================================== | |
| 59 | + | |
| 60 | +#ifdef __cplusplus | |
| 61 | +} | |
| 62 | +#endif | |
| 63 | + | |
| 64 | +#endif // LEAF_FORMANT_H_INCLUDED | |
| 65 | + | |
| 65 | 66 | //============================================================================== |
| 66 | 67 | |
| @@ -41,17 +41,9 @@ extern LEAF leaf; // The global instance of LEAF. · 40 unmodified lines | ||
| 41 | 41 | |
| 42 | 42 | //============================================================================== |
| 43 | 43 | |
| 44 | −#define NUM_VOICES 8 | |
| 45 | −#define NUM_SHIFTERS 4 | |
| 46 | −#define POLY_NUM_MAX_VOICES 8 | |
| 47 | −#define NUM_OSC 4 | |
| 48 | −#define INV_NUM_OSC (1.0f / NUM_OSC) | |
| 49 | 44 | #define PS_FRAME_SIZE 1024 // SNAC_FRAME_SIZE in leaf-pitch.h should match (or be smaller than?) this |
| 50 | 45 | #define ENV_WINDOW_SIZE 1024 |
| 51 | 46 | #define ENV_HOP_SIZE 256 |
| 52 | − | |
| 53 | −#define DELAY_LENGTH 16000 // The maximum delay length of all Delay/DelayL/DelayA components. | |
| 54 | − // Feel free to change to suit memory constraints or desired delay max length / functionality. | |
| 55 | 47 | |
| 56 | 48 | union unholy_t { /* a union between a float and an integer */ |
| 57 | 49 | float f; |
| @@ -75,7 +75,7 @@ typedef struct mpool_t { · 74 unmodified lines | ||
| 75 | 75 | int next; |
| 76 | 76 | } mpool_t; |
| 77 | 77 | |
| 78 | −void mpool_create (size_t size, mpool_t* pool); | |
| 78 | +void mpool_create (char* memory, size_t size, mpool_t* pool); | |
| 79 | 79 | |
| 80 | 80 | void *mpool_alloc(size_t size, mpool_t* pool); |
| 81 | 81 | void mpool_free(void* ptr, mpool_t* pool); |
| @@ -84,7 +84,7 @@ size_t mpool_get_size(mpool_t* pool); · 2 unmodified lines | ||
| 84 | 84 | size_t mpool_get_used(mpool_t* pool); |
| 85 | 85 | |
| 86 | 86 | |
| 87 | −void leaf_pool_init(size_t size); | |
| 87 | +void leaf_pool_init(char* memory, size_t size); | |
| 88 | 88 | |
| 89 | 89 | void* leaf_alloc(size_t size); |
| 90 | 90 | void leaf_free(void* ptr); |
| @@ -25,18 +25,20 @@ extern "C" { · 24 unmodified lines | ||
| 25 | 25 | /* tPoly */ |
| 26 | 26 | typedef struct _tPoly |
| 27 | 27 | { |
| 28 | − tStack* stack; | |
| 29 | − tStack* orderStack; | |
| 28 | + tStack stack; | |
| 29 | + tStack orderStack; | |
| 30 | 30 | |
| 31 | − tRamp* ramp[POLY_NUM_MAX_VOICES]; | |
| 32 | − float rampVals[POLY_NUM_MAX_VOICES]; | |
| 33 | − oBool firstReceived[POLY_NUM_MAX_VOICES]; | |
| 31 | + tRamp* ramp; | |
| 32 | + float* rampVals; | |
| 33 | + oBool* firstReceived; | |
| 34 | 34 | float glideTime; |
| 35 | 35 | oBool pitchGlideIsActive; |
| 36 | 36 | |
| 37 | 37 | int numVoices; |
| 38 | + int maxNumVoices; | |
| 38 | 39 | |
| 39 | − int voices[POLY_NUM_MAX_VOICES][2]; | |
| 40 | + //int voices[POLY_NUM_MAX_VOICES][2]; | |
| 41 | + int** voices; | |
| 40 | 42 | |
| 41 | 43 | int notes[128][2]; |
| 42 | 44 | |
| @@ -47,7 +49,7 @@ typedef struct _tPoly · 4 unmodified lines | ||
| 47 | 49 | int lastVoiceToChange; |
| 48 | 50 | |
| 49 | 51 | float pitchBend; |
| 50 | − tRamp* pitchBendRamp; | |
| 52 | + tRamp pitchBendRamp; | |
| 51 | 53 | |
| 52 | 54 | int currentNote; |
| 53 | 55 | int currentVoice; |
| @@ -57,7 +59,7 @@ typedef struct _tPoly · 3 unmodified lines | ||
| 57 | 59 | } tPoly; |
| 58 | 60 | |
| 59 | 61 | /* MPoly*/ |
| 60 | −void tPoly_init(tPoly* const, int numVoices); | |
| 62 | +void tPoly_init(tPoly* const, int maxNumVoices); | |
| 61 | 63 | void tPoly_free(tPoly* const); |
| 62 | 64 | |
| 63 | 65 | //ADDING A NOTE |
| @@ -33,6 +33,7 @@ typedef struct _tOversampler · 32 unmodified lines | ||
| 33 | 33 | } tOversampler; |
| 34 | 34 | |
| 35 | 35 | void tOversampler_init(tOversampler* const, int order, oBool extraQuality); |
| 36 | +void tOversampler_free(tOversampler* const); | |
| 36 | 37 | void tOversampler_upsample(tOversampler* const, float input, float* output); |
| 37 | 38 | float tOversampler_downsample(tOversampler *const os, float* input); |
| 38 | 39 | float tOversampler_tick(tOversampler* const, float input, float (*effectTick)(float)); |
| @@ -6,13 +6,13 @@ · 5 unmodified lines | ||
| 6 | 6 | Author: airship |
| 7 | 7 | |
| 8 | 8 | ============================================================================== |
| 9 | −*/ | |
| 10 | − | |
| 11 | −#ifndef LEAF_PITCH_H_INCLUDED | |
| 12 | −#define LEAF_PITCH_H_INCLUDED | |
| 13 | − | |
| 14 | −#ifdef __cplusplus | |
| 15 | −extern "C" { | |
| 9 | +*/ | |
| 10 | + | |
| 11 | +#ifndef LEAF_PITCH_H_INCLUDED | |
| 12 | +#define LEAF_PITCH_H_INCLUDED | |
| 13 | + | |
| 14 | +#ifdef __cplusplus | |
| 15 | +extern "C" { | |
| 16 | 16 | #endif |
| 17 | 17 | |
| 18 | 18 | //============================================================================== |
| @@ -22,8 +22,8 @@ extern "C" { · 3 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | #include "leaf-filter.h" |
| 24 | 24 | #include "leaf-utilities.h" |
| 25 | −#include "leaf.h" | |
| 26 | −//============================================================================== | |
| 25 | +#include "../leaf.h" | |
| 26 | +//============================================================================== | |
| 27 | 27 | |
| 28 | 28 | #define DEFPITCHRATIO 2.0f |
| 29 | 29 | #define DEFTIMECONSTANT 100.0f |
| @@ -32,92 +32,8 @@ extern "C" { · 2 unmodified lines | ||
| 32 | 32 | #define FBA 20 |
| 33 | 33 | #define HPFREQ 40.0f |
| 34 | 34 | |
| 35 | −//============================================================================== | |
| 36 | − | |
| 37 | −/* tSOLAD : pitch shifting algorithm that underlies tPitchShifter etc */ | |
| 38 | −#define LOOPSIZE (2048*2) // (4096*2) // loop size must be power of two | |
| 39 | −#define LOOPMASK (LOOPSIZE - 1) | |
| 40 | −#define PITCHFACTORDEFAULT 1.0f | |
| 41 | −#define INITPERIOD 64.0f | |
| 42 | −#define MAXPERIOD (float)((LOOPSIZE - w->blocksize) * 0.8f) | |
| 43 | −#define MINPERIOD 8.0f | |
| 44 | − | |
| 45 | −typedef struct _tSOLAD | |
| 46 | −{ | |
| 47 | − uint16_t timeindex; // current reference time, write index | |
| 48 | − uint16_t blocksize; // signal input / output block size | |
| 49 | − float pitchfactor; // pitch factor between 0.25 and 4 | |
| 50 | − float readlag; // read pointer's lag behind write pointer | |
| 51 | − float period; // period length in input signal | |
| 52 | − float jump; // read pointer jump length and direction | |
| 53 | − float xfadelength; // crossfade length expressed at input sample rate | |
| 54 | − float xfadevalue; // crossfade phase and value | |
| 55 | − | |
| 56 | − float* delaybuf; | |
| 57 | − | |
| 58 | −} tSOLAD; | |
| 59 | − | |
| 60 | −void tSOLAD_init (tSOLAD* const); | |
| 61 | −void tSOLAD_free (tSOLAD* const); | |
| 62 | − | |
| 63 | −// send one block of input samples, receive one block of output samples | |
| 64 | −void tSOLAD_ioSamples (tSOLAD *w, float* in, float* out, int blocksize); | |
| 65 | 35 | |
| 66 | −// set periodicity analysis data | |
| 67 | −void tSOLAD_setPeriod (tSOLAD *w, float period); | |
| 68 | − | |
| 69 | −// set pitch factor between 0.25 and 4 | |
| 70 | −void tSOLAD_setPitchFactor (tSOLAD *w, float pitchfactor); | |
| 71 | − | |
| 72 | −// force readpointer lag | |
| 73 | −void tSOLAD_setReadLag (tSOLAD *w, float readlag); | |
| 74 | − | |
| 75 | −// reset state variables | |
| 76 | −void tSOLAD_resetState (tSOLAD *w); | |
| 77 | − | |
| 78 | −//============================================================================== | |
| 79 | − | |
| 80 | −// tSNAC: period detector | |
| 81 | −#define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE | |
| 82 | −#define DEFOVERLAP 1 // default overlap | |
| 83 | −#define DEFBIAS 0.2f // default bias | |
| 84 | −#define DEFMINRMS 0.003f // default minimum RMS | |
| 85 | −#define SEEK 0.85f // seek-length as ratio of framesize | |
| 86 | − | |
| 87 | −typedef struct _tSNAC | |
| 88 | −{ | |
| 89 | − float* inputbuf; | |
| 90 | − float* processbuf; | |
| 91 | − float* spectrumbuf; | |
| 92 | − float* biasbuf; | |
| 93 | − uint16_t timeindex; | |
| 94 | − uint16_t framesize; | |
| 95 | − uint16_t overlap; | |
| 96 | − uint16_t periodindex; | |
| 97 | − | |
| 98 | − float periodlength; | |
| 99 | − float fidelity; | |
| 100 | − float biasfactor; | |
| 101 | − float minrms; | |
| 102 | − | |
| 103 | −} tSNAC; | |
| 104 | − | |
| 105 | − | |
| 106 | − | |
| 107 | − | |
| 108 | −void tSNAC_init (tSNAC* const, int overlaparg); // constructor | |
| 109 | −void tSNAC_free (tSNAC* const); // destructor | |
| 110 | − | |
| 111 | −void tSNAC_ioSamples (tSNAC *s, float *in, float *out, int size); | |
| 112 | −void tSNAC_setOverlap (tSNAC *s, int lap); | |
| 113 | −void tSNAC_setBias (tSNAC *s, float bias); | |
| 114 | −void tSNAC_setMinRMS (tSNAC *s, float rms); | |
| 115 | − | |
| 116 | −/*To get freq, perform SAMPLE_RATE/snac_getperiod() */ | |
| 117 | −float tSNAC_getPeriod (tSNAC *s); | |
| 118 | −float tSNAC_getfidelity (tSNAC *s); | |
| 119 | − | |
| 120 | −//============================================================================== | |
| 36 | +//============================================================================== | |
| 121 | 37 | |
| 122 | 38 | // Pitch shifter |
| 123 | 39 | typedef struct _tPitchShifter |
| @@ -164,7 +80,7 @@ void tPitchShifter_setHopSize (tPitchShifter* const, int hs); · 40 unmodified lines | ||
| 164 | 80 | void tPitchShifter_setWindowSize (tPitchShifter* const, int ws); |
| 165 | 81 | float tPitchShifter_getPeriod (tPitchShifter* const); |
| 166 | 82 | |
| 167 | −//============================================================================== | |
| 83 | +//============================================================================== | |
| 168 | 84 | |
| 169 | 85 | // Period detection |
| 170 | 86 | typedef struct _tPeriod |
| @@ -203,7 +119,7 @@ float tPeriod_findPeriod (tPeriod* const, float sample); · 32 unmodified lines | ||
| 203 | 119 | void tPeriod_setHopSize (tPeriod* p, int hs); |
| 204 | 120 | void tPeriod_setWindowSize (tPeriod* p, int ws); |
| 205 | 121 | |
| 206 | −//============================================================================== | |
| 122 | +//============================================================================== | |
| 207 | 123 | |
| 208 | 124 | // Pitch shift |
| 209 | 125 | typedef struct _tPitchShift |
| @@ -234,12 +150,12 @@ float tPitchShift_shiftToFunc (tPitchShift* const, float (*fun)(fl · 24 unmodified lines | ||
| 234 | 150 | float tPitchShift_shiftToFreq (tPitchShift* const, float freq); |
| 235 | 151 | void tPitchShift_setPitchFactor (tPitchShift* const, float pf); |
| 236 | 152 | |
| 237 | −//============================================================================== | |
| 238 | − | |
| 239 | −#ifdef __cplusplus | |
| 240 | −} | |
| 241 | −#endif | |
| 242 | − | |
| 243 | −#endif // LEAF_PITCH_H_INCLUDED | |
| 244 | − | |
| 153 | +//============================================================================== | |
| 154 | + | |
| 155 | +#ifdef __cplusplus | |
| 156 | +} | |
| 157 | +#endif | |
| 158 | + | |
| 159 | +#endif // LEAF_PITCH_H_INCLUDED | |
| 160 | + | |
| 245 | 161 | //============================================================================== |
| @@ -7,22 +7,22 @@ · 6 unmodified lines | ||
| 7 | 7 | ==============================================================================*/ |
| 8 | 8 | |
| 9 | 9 | #ifndef LEAF_REVERB_H_INCLUDED |
| 10 | −#define LEAF_REVERB_H_INCLUDED | |
| 11 | − | |
| 12 | −#ifdef __cplusplus | |
| 13 | −extern "C" { | |
| 10 | +#define LEAF_REVERB_H_INCLUDED | |
| 11 | + | |
| 12 | +#ifdef __cplusplus | |
| 13 | +extern "C" { | |
| 14 | 14 | #endif |
| 15 | 15 | |
| 16 | −//============================================================================== | |
| 16 | +//============================================================================== | |
| 17 | 17 | |
| 18 | 18 | #include "leaf-globals.h" |
| 19 | 19 | #include "leaf-math.h" |
| 20 | 20 | |
| 21 | −#include "leaf-delay.h" | |
| 22 | −#include "leaf-filter.h" | |
| 21 | +#include "leaf-delay.h" | |
| 22 | +#include "leaf-filter.h" | |
| 23 | 23 | #include "leaf-oscillator.h" |
| 24 | 24 | |
| 25 | −//============================================================================== | |
| 25 | +//============================================================================== | |
| 26 | 26 | |
| 27 | 27 | /* PRCRev: Reverb, reimplemented from STK (Cook and Scavone). */ |
| 28 | 28 | typedef struct _tPRCRev |
| @@ -31,8 +31,8 @@ typedef struct _tPRCRev · 2 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | float inv_441; |
| 33 | 33 | |
| 34 | − tDelay* allpassDelays[2]; | |
| 35 | − tDelay* combDelay; | |
| 34 | + tDelay allpassDelays[2]; | |
| 35 | + tDelay combDelay; | |
| 36 | 36 | float allpassCoeff; |
| 37 | 37 | float combCoeff; |
| 38 | 38 | |
| @@ -60,8 +60,8 @@ typedef struct _tNRev · 21 unmodified lines | ||
| 60 | 60 | |
| 61 | 61 | float inv_sr, inv_441; |
| 62 | 62 | |
| 63 | − tDelay* allpassDelays[8]; | |
| 64 | − tDelay* combDelays[6]; | |
| 63 | + tDelay allpassDelays[8]; | |
| 64 | + tDelay combDelays[6]; | |
| 65 | 65 | float allpassCoeff; |
| 66 | 66 | float combCoeffs[6]; |
| 67 | 67 | float lowpassState; |
| @@ -81,68 +81,68 @@ void tNRev_setT60 (tNRev* const, float t60); · 13 unmodified lines | ||
| 81 | 81 | // Set mix between dry input and wet output signal. |
| 82 | 82 | void tNRev_setMix (tNRev* const, float mix); |
| 83 | 83 | |
| 84 | −//============================================================================== | |
| 85 | − | |
| 86 | −typedef struct _tDattorro | |
| 87 | −{ | |
| 88 | − float predelay; | |
| 89 | − float input_filter; | |
| 90 | − float feedback_filter; | |
| 91 | − float feedback_gain; | |
| 92 | − float mix; | |
| 93 | − | |
| 94 | − | |
| 95 | − float size, size_max, t; | |
| 96 | − | |
| 97 | − float f1_delay_2_last, | |
| 98 | − f2_delay_2_last; | |
| 99 | − | |
| 100 | − float f1_last, | |
| 101 | − f2_last; | |
| 102 | − | |
| 103 | − // INPUT | |
| 104 | − tTapeDelay in_delay; | |
| 105 | − tOnePole in_filter; | |
| 106 | − tAllpass in_allpass[4]; | |
| 107 | − | |
| 108 | − // FEEDBACK 1 | |
| 109 | − tAllpass f1_allpass; | |
| 110 | − tTapeDelay f1_delay_1; | |
| 111 | − tOnePole f1_filter; | |
| 112 | − tTapeDelay f1_delay_2; | |
| 113 | − tTapeDelay f1_delay_3; | |
| 114 | − tHighpass f1_hp; | |
| 115 | − | |
| 116 | − tCycle f1_lfo; | |
| 117 | − | |
| 118 | − // FEEDBACK 2 | |
| 119 | − tAllpass f2_allpass; | |
| 120 | − tTapeDelay f2_delay_1; | |
| 121 | − tOnePole f2_filter; | |
| 122 | − tTapeDelay f2_delay_2; | |
| 123 | − tTapeDelay f2_delay_3; | |
| 124 | − tHighpass f2_hp; | |
| 125 | − | |
| 126 | − tCycle f2_lfo; | |
| 127 | − | |
| 128 | −} tDattorro; | |
| 129 | − | |
| 130 | −void tDattorro_init (tDattorro* const); | |
| 131 | −void tDattorro_free (tDattorro* const); | |
| 132 | − | |
| 133 | −float tDattorro_tick (tDattorro* const, float input); | |
| 134 | − | |
| 135 | −void tDattorro_setMix (tDattorro* const, float mix); | |
| 136 | −void tDattorro_setSize (tDattorro* const, float size); | |
| 137 | −void tDattorro_setInputDelay (tDattorro* const, float preDelay); | |
| 138 | −void tDattorro_setInputFilter (tDattorro* const, float freq); | |
| 139 | −void tDattorro_setFeedbackFilter (tDattorro* const, float freq); | |
| 140 | −void tDattorro_setFeedbackGain (tDattorro* const, float gain); | |
| 141 | − | |
| 142 | −#ifdef __cplusplus | |
| 143 | −} | |
| 84 | +//============================================================================== | |
| 85 | + | |
| 86 | +typedef struct _tDattorro | |
| 87 | +{ | |
| 88 | + float predelay; | |
| 89 | + float input_filter; | |
| 90 | + float feedback_filter; | |
| 91 | + float feedback_gain; | |
| 92 | + float mix; | |
| 93 | + | |
| 94 | + | |
| 95 | + float size, size_max, t; | |
| 96 | + | |
| 97 | + float f1_delay_2_last, | |
| 98 | + f2_delay_2_last; | |
| 99 | + | |
| 100 | + float f1_last, | |
| 101 | + f2_last; | |
| 102 | + | |
| 103 | + // INPUT | |
| 104 | + tTapeDelay in_delay; | |
| 105 | + tOnePole in_filter; | |
| 106 | + tAllpass in_allpass[4]; | |
| 107 | + | |
| 108 | + // FEEDBACK 1 | |
| 109 | + tAllpass f1_allpass; | |
| 110 | + tTapeDelay f1_delay_1; | |
| 111 | + tOnePole f1_filter; | |
| 112 | + tTapeDelay f1_delay_2; | |
| 113 | + tTapeDelay f1_delay_3; | |
| 114 | + tHighpass f1_hp; | |
| 115 | + | |
| 116 | + tCycle f1_lfo; | |
| 117 | + | |
| 118 | + // FEEDBACK 2 | |
| 119 | + tAllpass f2_allpass; | |
| 120 | + tTapeDelay f2_delay_1; | |
| 121 | + tOnePole f2_filter; | |
| 122 | + tTapeDelay f2_delay_2; | |
| 123 | + tTapeDelay f2_delay_3; | |
| 124 | + tHighpass f2_hp; | |
| 125 | + | |
| 126 | + tCycle f2_lfo; | |
| 127 | + | |
| 128 | +} tDattorro; | |
| 129 | + | |
| 130 | +void tDattorro_init (tDattorro* const); | |
| 131 | +void tDattorro_free (tDattorro* const); | |
| 132 | + | |
| 133 | +float tDattorro_tick (tDattorro* const, float input); | |
| 134 | + | |
| 135 | +void tDattorro_setMix (tDattorro* const, float mix); | |
| 136 | +void tDattorro_setSize (tDattorro* const, float size); | |
| 137 | +void tDattorro_setInputDelay (tDattorro* const, float preDelay); | |
| 138 | +void tDattorro_setInputFilter (tDattorro* const, float freq); | |
| 139 | +void tDattorro_setFeedbackFilter (tDattorro* const, float freq); | |
| 140 | +void tDattorro_setFeedbackGain (tDattorro* const, float gain); | |
| 141 | + | |
| 142 | +#ifdef __cplusplus | |
| 143 | +} | |
| 144 | 144 | #endif |
| 145 | 145 | |
| 146 | −#endif // LEAF_REVERB_H_INCLUDED | |
| 147 | − | |
| 146 | +#endif // LEAF_REVERB_H_INCLUDED | |
| 147 | + | |
| 148 | 148 | //============================================================================== |
| @@ -95,7 +95,7 @@ extern "C" { · 94 unmodified lines | ||
| 95 | 95 | |
| 96 | 96 | } tSampler; |
| 97 | 97 | |
| 98 | − void tSampler_init (tSampler* const, tBuffer* s); | |
| 98 | + void tSampler_init (tSampler* const, tBuffer* const); | |
| 99 | 99 | void tSampler_free (tSampler* const); |
| 100 | 100 | |
| 101 | 101 | float tSampler_tick (tSampler* const); |
| @@ -7,13 +7,13 @@ · 6 unmodified lines | ||
| 7 | 7 | |
| 8 | 8 | ============================================================================== |
| 9 | 9 | */ |
| 10 | − | |
| 11 | −#ifndef LEAF_STRING_H_INCLUDED | |
| 12 | −#define LEAF_STRING_H_INCLUDED | |
| 13 | − | |
| 14 | −#ifdef __cplusplus | |
| 15 | −extern "C" { | |
| 16 | −#endif | |
| 10 | + | |
| 11 | +#ifndef LEAF_STRING_H_INCLUDED | |
| 12 | +#define LEAF_STRING_H_INCLUDED | |
| 13 | + | |
| 14 | +#ifdef __cplusplus | |
| 15 | +extern "C" { | |
| 16 | +#endif | |
| 17 | 17 | |
| 18 | 18 | //============================================================================== |
| 19 | 19 | |
| @@ -29,10 +29,10 @@ extern "C" { · 9 unmodified lines | ||
| 29 | 29 | /* Karplus Strong model */ |
| 30 | 30 | typedef struct _tPluck |
| 31 | 31 | { |
| 32 | − tDelayA* delayLine; // Allpass or Linear?? big difference... | |
| 33 | − tOneZero* loopFilter; | |
| 34 | − tOnePole* pickFilter; | |
| 35 | − tNoise* noise; | |
| 32 | + tDelayA delayLine; // Allpass or Linear?? big difference... | |
| 33 | + tOneZero loopFilter; | |
| 34 | + tOnePole pickFilter; | |
| 35 | + tNoise noise; | |
| 36 | 36 | |
| 37 | 37 | float lastOut; |
| 38 | 38 | float loopGain; |
| @@ -65,16 +65,16 @@ void tPluck_controlChange (tPluck* const, int number, float value); · 26 unmodified lines | ||
| 65 | 65 | // tPluck Utilities. |
| 66 | 66 | float tPluck_getLastOut (tPluck* const); |
| 67 | 67 | |
| 68 | −//============================================================================== | |
| 68 | +//============================================================================== | |
| 69 | 69 | |
| 70 | 70 | /* Stif Karplus Strong model */ |
| 71 | 71 | typedef struct _tStifKarp |
| 72 | 72 | { |
| 73 | − tDelayA* delayLine; | |
| 74 | − tDelayL* combDelay; | |
| 75 | − tOneZero* filter; | |
| 76 | − tNoise* noise; | |
| 77 | − tBiQuad* biquad[4]; | |
| 73 | + tDelayA delayLine; | |
| 74 | + tDelayL combDelay; | |
| 75 | + tOneZero filter; | |
| 76 | + tNoise noise; | |
| 77 | + tBiQuad biquad[4]; | |
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | |
| @@ -132,12 +132,12 @@ void tStifKarp_setBaseLoopGain (tStifKarp* const, float aGain ); · 51 unmodified lines | ||
| 132 | 132 | // tStifKarp utilities. |
| 133 | 133 | float tStifKarp_getLastOut (tStifKarp* const); |
| 134 | 134 | |
| 135 | −//============================================================================== | |
| 136 | − | |
| 137 | −#ifdef __cplusplus | |
| 138 | −} | |
| 139 | −#endif | |
| 140 | − | |
| 141 | −#endif // LEAF_STRING_H_INCLUDED | |
| 142 | − | |
| 135 | +//============================================================================== | |
| 136 | + | |
| 137 | +#ifdef __cplusplus | |
| 138 | +} | |
| 139 | +#endif | |
| 140 | + | |
| 141 | +#endif // LEAF_STRING_H_INCLUDED | |
| 142 | + | |
| 143 | 143 | //============================================================================== |
| @@ -389,6 +389,88 @@ void tEnv_free (tEnv* const); · 388 unmodified lines | ||
| 389 | 389 | float tEnv_tick (tEnv* const); |
| 390 | 390 | void tEnv_processBlock (tEnv* const, float* in); |
| 391 | 391 | |
| 392 | +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | |
| 393 | + | |
| 394 | +/* tSOLAD : pitch shifting algorithm that underlies tPitchShifter etc */ | |
| 395 | +#define LOOPSIZE (2048*2) // (4096*2) // loop size must be power of two | |
| 396 | +#define LOOPMASK (LOOPSIZE - 1) | |
| 397 | +#define PITCHFACTORDEFAULT 1.0f | |
| 398 | +#define INITPERIOD 64.0f | |
| 399 | +#define MAXPERIOD (float)((LOOPSIZE - w->blocksize) * 0.8f) | |
| 400 | +#define MINPERIOD 8.0f | |
| 401 | + | |
| 402 | +typedef struct _tSOLAD | |
| 403 | +{ | |
| 404 | + uint16_t timeindex; // current reference time, write index | |
| 405 | + uint16_t blocksize; // signal input / output block size | |
| 406 | + float pitchfactor; // pitch factor between 0.25 and 4 | |
| 407 | + float readlag; // read pointer's lag behind write pointer | |
| 408 | + float period; // period length in input signal | |
| 409 | + float jump; // read pointer jump length and direction | |
| 410 | + float xfadelength; // crossfade length expressed at input sample rate | |
| 411 | + float xfadevalue; // crossfade phase and value | |
| 412 | + | |
| 413 | + float* delaybuf; | |
| 414 | + | |
| 415 | +} tSOLAD; | |
| 416 | + | |
| 417 | +void tSOLAD_init (tSOLAD* const); | |
| 418 | +void tSOLAD_free (tSOLAD* const); | |
| 419 | + | |
| 420 | +// send one block of input samples, receive one block of output samples | |
| 421 | +void tSOLAD_ioSamples (tSOLAD *w, float* in, float* out, int blocksize); | |
| 422 | + | |
| 423 | +// set periodicity analysis data | |
| 424 | +void tSOLAD_setPeriod (tSOLAD *w, float period); | |
| 425 | + | |
| 426 | +// set pitch factor between 0.25 and 4 | |
| 427 | +void tSOLAD_setPitchFactor (tSOLAD *w, float pitchfactor); | |
| 428 | + | |
| 429 | +// force readpointer lag | |
| 430 | +void tSOLAD_setReadLag (tSOLAD *w, float readlag); | |
| 431 | + | |
| 432 | +// reset state variables | |
| 433 | +void tSOLAD_resetState (tSOLAD *w); | |
| 434 | + | |
| 435 | +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | |
| 436 | + | |
| 437 | +// tSNAC: period detector | |
| 438 | +#define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE | |
| 439 | +#define DEFOVERLAP 1 // default overlap | |
| 440 | +#define DEFBIAS 0.2f // default bias | |
| 441 | +#define DEFMINRMS 0.003f // default minimum RMS | |
| 442 | +#define SEEK 0.85f // seek-length as ratio of framesize | |
| 443 | + | |
| 444 | +typedef struct _tSNAC | |
| 445 | +{ | |
| 446 | + float* inputbuf; | |
| 447 | + float* processbuf; | |
| 448 | + float* spectrumbuf; | |
| 449 | + float* biasbuf; | |
| 450 | + uint16_t timeindex; | |
| 451 | + uint16_t framesize; | |
| 452 | + uint16_t overlap; | |
| 453 | + uint16_t periodindex; | |
| 454 | + | |
| 455 | + float periodlength; | |
| 456 | + float fidelity; | |
| 457 | + float biasfactor; | |
| 458 | + float minrms; | |
| 459 | + | |
| 460 | +} tSNAC; | |
| 461 | + | |
| 462 | +void tSNAC_init (tSNAC* const, int overlaparg); // constructor | |
| 463 | +void tSNAC_free (tSNAC* const); // destructor | |
| 464 | + | |
| 465 | +void tSNAC_ioSamples (tSNAC *s, float *in, float *out, int size); | |
| 466 | +void tSNAC_setOverlap (tSNAC *s, int lap); | |
| 467 | +void tSNAC_setBias (tSNAC *s, float bias); | |
| 468 | +void tSNAC_setMinRMS (tSNAC *s, float rms); | |
| 469 | + | |
| 470 | +/*To get freq, perform SAMPLE_RATE/snac_getperiod() */ | |
| 471 | +float tSNAC_getPeriod (tSNAC *s); | |
| 472 | +float tSNAC_getfidelity (tSNAC *s); | |
| 473 | + | |
| 392 | 474 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |
| 393 | 475 | |
| 394 | 476 | #ifdef __cplusplus |
| @@ -7,10 +7,10 @@ · 6 unmodified lines | ||
| 7 | 7 | ==============================================================================*/ |
| 8 | 8 | |
| 9 | 9 | #ifndef LEAF_VOCODER_H_INCLUDED |
| 10 | −#define LEAF_VOCODER_H_INCLUDED | |
| 11 | − | |
| 12 | −#ifdef __cplusplus | |
| 13 | −extern "C" { | |
| 10 | +#define LEAF_VOCODER_H_INCLUDED | |
| 11 | + | |
| 12 | +#ifdef __cplusplus | |
| 13 | +extern "C" { | |
| 14 | 14 | #endif |
| 15 | 15 | |
| 16 | 16 | //============================================================================== |
| @@ -22,16 +22,17 @@ extern "C" { · 5 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | /* tTalkbox */ |
| 24 | 24 | #define NUM_TALKBOX_PARAM 4 |
| 25 | −#define TALKBOX_BUFFER_LENGTH 1024 // Every talkbox instance introduces 5 buffers of this size - was originally 1600 | |
| 26 | 25 | |
| 27 | 26 | typedef struct _tTalkbox |
| 28 | 27 | { |
| 29 | 28 | float param[NUM_TALKBOX_PARAM]; |
| 30 | 29 | |
| 31 | − ///global internal variables | |
| 32 | − float car0[TALKBOX_BUFFER_LENGTH], car1[TALKBOX_BUFFER_LENGTH]; | |
| 33 | − float window[TALKBOX_BUFFER_LENGTH]; | |
| 34 | − float buf0[TALKBOX_BUFFER_LENGTH], buf1[TALKBOX_BUFFER_LENGTH]; | |
| 30 | + int bufsize; | |
| 31 | + float* car0; | |
| 32 | + float* car1; | |
| 33 | + float* window; | |
| 34 | + float* buf0; | |
| 35 | + float* buf1; | |
| 35 | 36 | |
| 36 | 37 | float emphasis; |
| 37 | 38 | int32_t K, N, O, pos; |
| @@ -41,7 +42,7 @@ typedef struct _tTalkbox · 3 unmodified lines | ||
| 41 | 42 | |
| 42 | 43 | } tTalkbox; |
| 43 | 44 | |
| 44 | −void tTalkbox_init (tTalkbox* const); | |
| 45 | +void tTalkbox_init (tTalkbox* const, int bufsize); | |
| 45 | 46 | void tTalkbox_free (tTalkbox* const); |
| 46 | 47 | float tTalkbox_tick (tTalkbox* const, float synth, float voice); |
| 47 | 48 | void tTalkbox_update (tTalkbox* const); |
| @@ -78,11 +79,11 @@ void tVocoder_update (tVocoder* const); · 30 unmodified lines | ||
| 78 | 79 | void tVocoder_suspend (tVocoder* const); |
| 79 | 80 | |
| 80 | 81 | //============================================================================== |
| 81 | − | |
| 82 | −#ifdef __cplusplus | |
| 83 | −} | |
| 84 | −#endif | |
| 82 | + | |
| 83 | +#ifdef __cplusplus | |
| 84 | +} | |
| 85 | +#endif | |
| 85 | 86 | |
| 86 | −#endif // LEAF_VOCODER_H_INCLUDED | |
| 87 | − | |
| 87 | +#endif // LEAF_VOCODER_H_INCLUDED | |
| 88 | + | |
| 88 | 89 | //============================================================================== |
| @@ -22,16 +22,6 @@ extern "C" { · 21 unmodified lines | ||
| 22 | 22 | //============================================================================== |
| 23 | 23 | |
| 24 | 24 | /* tLockhartWavefolder */ |
| 25 | −#define THRESH 10e-10 | |
| 26 | −#define ILL_THRESH 10e-10 | |
| 27 | −#define LOCKHART_RL 7.5e3 | |
| 28 | −#define LOCKHART_R 15e3 | |
| 29 | −#define LOCKHART_VT 26e-3 | |
| 30 | −#define LOCKHART_Is 10e-16 | |
| 31 | −#define LOCKHART_A 2.0*LOCKHART_RL/LOCKHART_R | |
| 32 | −#define LOCKHART_B (LOCKHART_R+2.0*LOCKHART_RL)/(LOCKHART_VT*LOCKHART_R) | |
| 33 | −#define LOCKHART_D (LOCKHART_RL*LOCKHART_Is)/LOCKHART_VT | |
| 34 | −#define VT_DIV_B LOCKHART_VT/LOCKHART_B | |
| 35 | 25 | |
| 36 | 26 | typedef struct _tLockhartWavefolder |
| 37 | 27 | { |
| @@ -32,6 +32,7 @@ static float get_reflected_wave_for_parallel(tWDF* const r, float input); · 31 unmodified lines | ||
| 32 | 32 | |
| 33 | 33 | static float get_reflected_wave_for_ideal(tWDF* const n, float input, float incident_wave); |
| 34 | 34 | static float get_reflected_wave_for_diode(tWDF* const n, float input, float incident_wave); |
| 35 | +static float get_reflected_wave_for_diode_pair(tWDF* const n, float input, float incident_wave); | |
| 35 | 36 | |
| 36 | 37 | //WDF |
| 37 | 38 | void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR) |
| @@ -143,10 +144,19 @@ void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL · 105 unmodified lines | ||
| 143 | 144 | } |
| 144 | 145 | else if (r->type == DiodePair) |
| 145 | 146 | { |
| 146 | − //n->calculate_reflected_wave = &calculate_reflected_wave_for_ideal; | |
| 147 | + r->port_resistance_up = tWDF_getPortResistance(child); | |
| 148 | + r->port_conductance_up = 1.0f / r->port_resistance_up; | |
| 149 | + | |
| 150 | + r->get_reflected_wave_down = &get_reflected_wave_for_diode_pair; | |
| 151 | + r->get_port_resistance = &get_port_resistance_for_root; | |
| 147 | 152 | } |
| 148 | 153 | } |
| 149 | 154 | |
| 155 | +void tWDF_free(tWDF* const r) | |
| 156 | +{ | |
| 157 | + leaf_free(r); | |
| 158 | +} | |
| 159 | + | |
| 150 | 160 | float tWDF_tick(tWDF* const r, float sample, tWDF* const outputPoint, uint8_t paramsChanged) |
| 151 | 161 | { |
| 152 | 162 | tWDF* child; |
| @@ -315,11 +325,13 @@ static void set_incident_wave_for_leaf_inverted(tWDF* const r, float incident_wa · 162 unmodified lines | ||
| 315 | 325 | |
| 316 | 326 | static void set_incident_wave_for_inverter(tWDF* const r, float incident_wave, float input) |
| 317 | 327 | { |
| 328 | + r->incident_wave_up = incident_wave; | |
| 318 | 329 | tWDF_setIncidentWave(r->child_left, -1.0f * incident_wave, input); |
| 319 | 330 | } |
| 320 | 331 | |
| 321 | 332 | static void set_incident_wave_for_series(tWDF* const r, float incident_wave, float input) |
| 322 | 333 | { |
| 334 | + r->incident_wave_up = incident_wave; | |
| 323 | 335 | float gamma_left = r->port_resistance_left * r->gamma_zero; |
| 324 | 336 | float gamma_right = r->port_resistance_right * r->gamma_zero; |
| 325 | 337 | float left_wave = tWDF_getReflectedWaveUp(r->child_left, input); |
| @@ -336,6 +348,7 @@ static void set_incident_wave_for_series(tWDF* const r, float incident_wave, flo · 10 unmodified lines | ||
| 336 | 348 | |
| 337 | 349 | static void set_incident_wave_for_parallel(tWDF* const r, float incident_wave, float input) |
| 338 | 350 | { |
| 351 | + r->incident_wave_up = incident_wave; | |
| 339 | 352 | float gamma_left = r->port_conductance_left * r->gamma_zero; |
| 340 | 353 | float gamma_right = r->port_conductance_right * r->gamma_zero; |
| 341 | 354 | float left_wave = tWDF_getReflectedWaveUp(r->child_left, input); |
| @@ -376,7 +389,8 @@ static float get_reflected_wave_for_inverter(tWDF* const r, float input) · 34 unmodified lines | ||
| 376 | 389 | static float get_reflected_wave_for_series(tWDF* const r, float input) |
| 377 | 390 | { |
| 378 | 391 | //-( downPorts[0]->a + downPorts[1]->a ); |
| 379 | − return (-1.0f * (tWDF_getReflectedWaveUp(r->child_left, input) + tWDF_getReflectedWaveUp(r->child_right, input))); | |
| 392 | + r->reflected_wave_up = (-1.0f * (tWDF_getReflectedWaveUp(r->child_left, input) + tWDF_getReflectedWaveUp(r->child_right, input))); | |
| 393 | + return r->reflected_wave_up; | |
| 380 | 394 | } |
| 381 | 395 | |
| 382 | 396 | static float get_reflected_wave_for_parallel(tWDF* const r, float input) |
| @@ -384,12 +398,8 @@ static float get_reflected_wave_for_parallel(tWDF* const r, float input) · 1 unmodified line | ||
| 384 | 398 | float gamma_left = r->port_conductance_left * r->gamma_zero; |
| 385 | 399 | float gamma_right = r->port_conductance_right * r->gamma_zero; |
| 386 | 400 | //return ( dl * downPorts[0]->a + dr * downPorts[1]->a ); |
| 387 | − return (gamma_left * tWDF_getReflectedWaveUp(r->child_left, input) + gamma_right * tWDF_getReflectedWaveUp(r->child_right, input)); | |
| 388 | −} | |
| 389 | − | |
| 390 | −float tWDFNonlinear_getReflectedWaveDown(tWDF* const n, float input, float incident_wave) | |
| 391 | −{ | |
| 392 | − return n->get_reflected_wave_down(n, input, incident_wave); | |
| 401 | + r->reflected_wave_up = (gamma_left * tWDF_getReflectedWaveUp(r->child_left, input) + gamma_right * tWDF_getReflectedWaveUp(r->child_right, input)); | |
| 402 | + return r->reflected_wave_up; | |
| 393 | 403 | } |
| 394 | 404 | |
| 395 | 405 | static float get_reflected_wave_for_ideal(tWDF* const n, float input, float incident_wave) |
| @@ -447,3 +457,13 @@ static float get_reflected_wave_for_diode(tWDF* const n, float input, float inci · 51 unmodified lines | ||
| 447 | 457 | float r = n->port_resistance_up; |
| 448 | 458 | return a + 2.0f*r*Is_DIODE - 2.0f*VT_DIODE*lambertW(a, r, Is_DIODE, 1.0f/VT_DIODE); |
| 449 | 459 | } |
| 460 | + | |
| 461 | +static float get_reflected_wave_for_diode_pair(tWDF* const n, float input, float incident_wave) | |
| 462 | +{ | |
| 463 | + float a = incident_wave; | |
| 464 | + float sgn = 0.0f; | |
| 465 | + if (a > 0.0f) sgn = 1.0f; | |
| 466 | + else if (a < 0.0f) sgn = -1.0f; | |
| 467 | + float r = n->port_resistance_up; | |
| 468 | + return a + 2 * sgn * (r*Is_DIODE - VT_DIODE*lambertW(sgn*a, r, Is_DIODE, 1.0f/VT_DIODE)); | |
| 469 | +} | |
| @@ -821,8 +821,8 @@ int tSVFE_setQ(tSVFE* const svf, float Q) · 820 unmodified lines | ||
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | void tFIR_init(tFIR* const fir, float* coeffs, int numTaps){ |
| 824 | − fir->coeff = coeffs; | |
| 825 | 824 | fir->numTaps = numTaps; |
| 825 | + fir->coeff = coeffs; | |
| 826 | 826 | fir->past = (float*)leaf_alloc(sizeof(float) * fir->numTaps); |
| 827 | 827 | for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f; |
| 828 | 828 | } |
| @@ -835,4 +835,8 @@ float tFIR_tick(tFIR* const fir, float input){ · 6 unmodified lines | ||
| 835 | 835 | return y; |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | −void tFIR_free(tFIR* const fir){} | |
| 838 | +void tFIR_free(tFIR* const fir) | |
| 839 | +{ | |
| 840 | + leaf_free(fir->past); | |
| 841 | + leaf_free(fir); | |
| 842 | +} | |
| @@ -16,9 +16,26 @@ · 15 unmodified lines | ||
| 16 | 16 | #endif |
| 17 | 17 | |
| 18 | 18 | |
| 19 | −void tFormantShifter_init(tFormantShifter* const fs) | |
| 19 | +void tFormantShifter_init(tFormantShifter* const fs, int bufsize, int order) | |
| 20 | 20 | { |
| 21 | − fs->ford = FORD; | |
| 21 | + fs->ford = order; | |
| 22 | + fs->bufsize = bufsize; | |
| 23 | + fs->fk = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 24 | + fs->fb = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 25 | + fs->fc = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 26 | + fs->frb = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 27 | + fs->frc = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 28 | + fs->fsig = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 29 | + fs->fsmooth = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 30 | + fs->ftvec = (float*) leaf_alloc(sizeof(float) * fs->ford); | |
| 31 | + | |
| 32 | + fs->fbuff = (float**) leaf_alloc(sizeof(float*) * fs->ford); | |
| 33 | + for (int i = 0; i < fs->ford; i++) | |
| 34 | + { | |
| 35 | + fs->fbuff[i] = (float*) leaf_alloc(sizeof(float) * fs->bufsize); | |
| 36 | + } | |
| 37 | + | |
| 38 | + | |
| 22 | 39 | fs->falph = powf(0.001f, 80.0f / (leaf.sampleRate)); |
| 23 | 40 | fs->flamb = -(0.8517f*sqrt(atanf(0.06583f*leaf.sampleRate))-0.1916f); |
| 24 | 41 | fs->fhp = 0.0f; |
| @@ -31,6 +48,20 @@ void tFormantShifter_init(tFormantShifter* const fs) · 6 unmodified lines | ||
| 31 | 48 | |
| 32 | 49 | void tFormantShifter_free(tFormantShifter* const fs) |
| 33 | 50 | { |
| 51 | + leaf_free(fs->fk); | |
| 52 | + leaf_free(fs->fb); | |
| 53 | + leaf_free(fs->fc); | |
| 54 | + leaf_free(fs->frb); | |
| 55 | + leaf_free(fs->frc); | |
| 56 | + leaf_free(fs->fsig); | |
| 57 | + leaf_free(fs->fsmooth); | |
| 58 | + leaf_free(fs->ftvec); | |
| 59 | + for (int i = 0; i < fs->ford; i++) | |
| 60 | + { | |
| 61 | + leaf_free(fs->fbuff[i]); | |
| 62 | + } | |
| 63 | + leaf_free(fs->fbuff); | |
| 64 | + | |
| 34 | 65 | leaf_free(fs); |
| 35 | 66 | } |
| 36 | 67 | |
| @@ -42,8 +73,7 @@ float tFormantShifter_tick(tFormantShifter* fs, float in, float fwarp) · 5 unmodified lines | ||
| 42 | 73 | |
| 43 | 74 | float tFormantShifter_remove(tFormantShifter* fs, float in) |
| 44 | 75 | { |
| 45 | − float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk, tf2, f0resp, f1resp, frlamb; | |
| 46 | − int outindex = 0; | |
| 76 | + float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk; | |
| 47 | 77 | int ti4; |
| 48 | 78 | ford = fs->ford; |
| 49 | 79 | falph = fs->falph; |
| @@ -73,7 +103,7 @@ float tFormantShifter_remove(tFormantShifter* fs, float in) · 23 unmodified lines | ||
| 73 | 103 | fa = fa - tf*fc; |
| 74 | 104 | } |
| 75 | 105 | fs->cbi++; |
| 76 | − if(fs->cbi >= FORMANT_BUFFER_SIZE) | |
| 106 | + if(fs->cbi >= fs->bufsize) | |
| 77 | 107 | { |
| 78 | 108 | fs->cbi = 0; |
| 79 | 109 | } |
| @@ -83,8 +113,7 @@ float tFormantShifter_remove(tFormantShifter* fs, float in) · 3 unmodified lines | ||
| 83 | 113 | |
| 84 | 114 | float tFormantShifter_add(tFormantShifter* fs, float in, float fwarp) |
| 85 | 115 | { |
| 86 | − float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk, tf2, f0resp, f1resp, frlamb; | |
| 87 | − int outindex = 0; | |
| 116 | + float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb; | |
| 88 | 117 | int ti4; |
| 89 | 118 | ford = fs->ford; |
| 90 | 119 | falph = fs->falph; |
| @@ -36,24 +36,21 @@ · 35 unmodified lines | ||
| 36 | 36 | |
| 37 | 37 | /* written with C99 style */ |
| 38 | 38 | |
| 39 | +#if _WIN32 || _WIN64 | |
| 39 | 40 | |
| 40 | −#include "../Inc/leaf-mempool.h" | |
| 41 | −#include "leaf.h" | |
| 42 | −#define NUM_BLOCKS 50 | |
| 41 | +#include "..\Inc\leaf-mempool.h" | |
| 42 | +#include "..\leaf.h" | |
| 43 | 43 | |
| 44 | −#ifdef STM32 | |
| 44 | +#else | |
| 45 | 45 | |
| 46 | −char memory[MPOOL_POOL_SIZE] __ATTR_RAM_D2; | |
| 46 | +#include "../Inc/leaf-mempool.h" | |
| 47 | +#include "../leaf.h" | |
| 47 | 48 | |
| 48 | −#else | |
| 49 | −char memory[MPOOL_POOL_SIZE]; | |
| 50 | 49 | #endif |
| 51 | 50 | |
| 51 | +#define NUM_BLOCKS 50 | |
| 52 | 52 | |
| 53 | 53 | mpool_pool_t blocks[NUM_BLOCKS]; |
| 54 | − | |
| 55 | − | |
| 56 | − // | |
| 57 | 54 | mpool_t leaf_pool; |
| 58 | 55 | |
| 59 | 56 | /** |
| @@ -65,10 +62,8 @@ static inline size_t mpool_align(size_t size); · 5 unmodified lines | ||
| 65 | 62 | /** |
| 66 | 63 | * create memory pool |
| 67 | 64 | */ |
| 68 | −void mpool_create (size_t size, mpool_t* pool) | |
| 65 | +void mpool_create (char* memory, size_t size, mpool_t* pool) | |
| 69 | 66 | { |
| 70 | − if (size > MPOOL_POOL_SIZE) size = MPOOL_POOL_SIZE; | |
| 71 | − | |
| 72 | 67 | pool->mpool = &blocks[0]; |
| 73 | 68 | |
| 74 | 69 | pool->mpool->pool = (void*)memory; |
| @@ -78,12 +73,12 @@ void mpool_create (size_t size, mpool_t* pool) · 3 unmodified lines | ||
| 78 | 73 | pool->usize = 0; |
| 79 | 74 | pool->msize = size; |
| 80 | 75 | |
| 81 | − for (int i = 0; i < MPOOL_POOL_SIZE; i++) memory[i]=0; | |
| 76 | + for (int i = 0; i < size; i++) memory[i]=0; | |
| 82 | 77 | } |
| 83 | 78 | |
| 84 | −void leaf_pool_init(size_t size) | |
| 79 | +void leaf_pool_init(char* memory, size_t size) | |
| 85 | 80 | { |
| 86 | − mpool_create(size, &leaf_pool); | |
| 81 | + mpool_create(memory, size, &leaf_pool); | |
| 87 | 82 | } |
| 88 | 83 | |
| 89 | 84 | /** |
| @@ -195,7 +190,7 @@ size_t leaf_pool_get_used(void) · 105 unmodified lines | ||
| 195 | 190 | |
| 196 | 191 | void* leaf_pool_get_pool(void) |
| 197 | 192 | { |
| 198 | − float* buff = (float*)memory; | |
| 193 | + float* buff = (float*)leaf_pool.mpool->pool; | |
| 199 | 194 | |
| 200 | 195 | return buff; |
| 201 | 196 | } |
| @@ -17,9 +17,10 @@ · 16 unmodified lines | ||
| 17 | 17 | #endif |
| 18 | 18 | |
| 19 | 19 | // POLY |
| 20 | −void tPoly_init(tPoly* const poly, int numVoices) | |
| 20 | +void tPoly_init(tPoly* const poly, int maxNumVoices) | |
| 21 | 21 | { |
| 22 | − poly->numVoices = numVoices; | |
| 22 | + poly->numVoices = maxNumVoices; | |
| 23 | + poly->maxNumVoices = maxNumVoices; | |
| 23 | 24 | poly->lastVoiceToChange = 0; |
| 24 | 25 | |
| 25 | 26 | // Arp mode stuff |
| @@ -35,29 +36,49 @@ void tPoly_init(tPoly* const poly, int numVoices) · 9 unmodified lines | ||
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | poly->glideTime = 5.0f; |
| 38 | − for (int i = 0; i < POLY_NUM_MAX_VOICES; ++i) | |
| 39 | + | |
| 40 | + poly->ramp = (tRamp*) leaf_alloc(sizeof(tRamp) * poly->maxNumVoices); | |
| 41 | + poly->rampVals = (float*) leaf_alloc(sizeof(float) * poly->maxNumVoices); | |
| 42 | + poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * poly->maxNumVoices); | |
| 43 | + poly->voices = (int**) leaf_alloc(sizeof(int*) * poly->maxNumVoices); | |
| 44 | + | |
| 45 | + for (int i = 0; i < poly->maxNumVoices; ++i) | |
| 39 | 46 | { |
| 47 | + poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2); | |
| 40 | 48 | poly->voices[i][0] = -1; |
| 41 | 49 | poly->firstReceived[i] = OFALSE; |
| 42 | 50 | |
| 43 | − poly->ramp[i] = (tRamp*) leaf_alloc(sizeof(tRamp)); | |
| 44 | − | |
| 45 | − tRamp_init(poly->ramp[i], poly->glideTime, 1); | |
| 51 | + tRamp_init(&poly->ramp[i], poly->glideTime, 1); | |
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | poly->pitchBend = 0.0f; |
| 49 | − poly->pitchBendRamp = (tRamp*) leaf_alloc(sizeof(tRamp)); | |
| 50 | − tRamp_init(poly->pitchBendRamp, 1.0f, 1); | |
| 51 | 55 | |
| 52 | − poly->stack = (tStack*) leaf_alloc(sizeof(tStack)); | |
| 53 | − tStack_init(poly->stack); | |
| 54 | − | |
| 55 | − poly->orderStack = (tStack*) leaf_alloc(sizeof(tStack)); | |
| 56 | − tStack_init(poly->orderStack); | |
| 56 | + tRamp_init(&poly->pitchBendRamp, 1.0f, 1); | |
| 57 | + tStack_init(&poly->stack); | |
| 58 | + tStack_init(&poly->orderStack); | |
| 57 | 59 | |
| 58 | 60 | poly->pitchGlideIsActive = OFALSE; |
| 59 | 61 | } |
| 60 | 62 | |
| 63 | +void tPoly_free(tPoly* const poly) | |
| 64 | +{ | |
| 65 | + for (int i = 0; i < poly->maxNumVoices; i++) | |
| 66 | + { | |
| 67 | + tRamp_free(&poly->ramp[i]); | |
| 68 | + leaf_free(poly->voices[i]); | |
| 69 | + } | |
| 70 | + tRamp_free(&poly->pitchBendRamp); | |
| 71 | + tStack_free(&poly->stack); | |
| 72 | + tStack_free(&poly->orderStack); | |
| 73 | + | |
| 74 | + leaf_free(poly->voices); | |
| 75 | + leaf_free(poly->ramp); | |
| 76 | + leaf_free(poly->rampVals); | |
| 77 | + leaf_free(poly->firstReceived); | |
| 78 | + | |
| 79 | + | |
| 80 | +} | |
| 81 | + | |
| 61 | 82 | void tPoly_tickPitch(tPoly* poly) |
| 62 | 83 | { |
| 63 | 84 | tPoly_tickPitchGlide(poly); |
| @@ -66,32 +87,32 @@ void tPoly_tickPitch(tPoly* poly) · 2 unmodified lines | ||
| 66 | 87 | |
| 67 | 88 | void tPoly_tickPitchGlide(tPoly* poly) |
| 68 | 89 | { |
| 69 | − for (int i = 0; i < POLY_NUM_MAX_VOICES; ++i) | |
| 90 | + for (int i = 0; i < poly->maxNumVoices; ++i) | |
| 70 | 91 | { |
| 71 | − tRamp_tick(poly->ramp[i]); | |
| 92 | + tRamp_tick(&poly->ramp[i]); | |
| 72 | 93 | } |
| 73 | 94 | } |
| 74 | 95 | |
| 75 | 96 | void tPoly_tickPitchBend(tPoly* poly) |
| 76 | 97 | { |
| 77 | − tRamp_tick(poly->pitchBendRamp); | |
| 98 | + tRamp_tick(&poly->pitchBendRamp); | |
| 78 | 99 | } |
| 79 | 100 | |
| 80 | 101 | //instead of including in dacsend, should have a separate pitch bend ramp, that is added when the ramps are ticked and sent to DAC |
| 81 | 102 | void tPoly_setPitchBend(tPoly* const poly, float pitchBend) |
| 82 | 103 | { |
| 83 | 104 | poly->pitchBend = pitchBend; |
| 84 | − tRamp_setDest(poly->pitchBendRamp, poly->pitchBend); | |
| 105 | + tRamp_setDest(&poly->pitchBendRamp, poly->pitchBend); | |
| 85 | 106 | } |
| 86 | 107 | |
| 87 | 108 | int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) |
| 88 | 109 | { |
| 89 | 110 | // if not in keymap or already on stack, dont do anything. else, add that note. |
| 90 | − if (tStack_contains(poly->stack, note) >= 0) return -1; | |
| 111 | + if (tStack_contains(&poly->stack, note) >= 0) return -1; | |
| 91 | 112 | else |
| 92 | 113 | { |
| 93 | 114 | tPoly_orderedAddToStack(poly, note); |
| 94 | − tStack_add(poly->stack, note); | |
| 115 | + tStack_add(&poly->stack, note); | |
| 95 | 116 | |
| 96 | 117 | int alteredVoice = -1; |
| 97 | 118 | oBool found = OFALSE; |
| @@ -101,7 +122,7 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 3 unmodified lines | ||
| 101 | 122 | { |
| 102 | 123 | if (!poly->firstReceived[i] || !poly->pitchGlideIsActive) |
| 103 | 124 | { |
| 104 | − tRamp_setVal(poly->ramp[i], note); | |
| 125 | + tRamp_setVal(&poly->ramp[i], note); | |
| 105 | 126 | poly->firstReceived[i] = OTRUE; |
| 106 | 127 | } |
| 107 | 128 | |
| @@ -113,7 +134,7 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 5 unmodified lines | ||
| 113 | 134 | poly->notes[note][0] = vel; |
| 114 | 135 | poly->notes[note][1] = i; |
| 115 | 136 | |
| 116 | − tRamp_setDest(poly->ramp[i], poly->voices[i][0]); | |
| 137 | + tRamp_setDest(&poly->ramp[i], poly->voices[i][0]); | |
| 117 | 138 | |
| 118 | 139 | alteredVoice = i; |
| 119 | 140 | break; |
| @@ -123,9 +144,9 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 3 unmodified lines | ||
| 123 | 144 | if (!found) //steal |
| 124 | 145 | { |
| 125 | 146 | int whichVoice, whichNote; |
| 126 | − for (int j = tStack_getSize(poly->stack) - 1; j >= 0; j--) | |
| 147 | + for (int j = tStack_getSize(&poly->stack) - 1; j >= 0; j--) | |
| 127 | 148 | { |
| 128 | − whichNote = tStack_get(poly->stack, j); | |
| 149 | + whichNote = tStack_get(&poly->stack, j); | |
| 129 | 150 | whichVoice = poly->notes[whichNote][1]; |
| 130 | 151 | if (whichVoice >= 0) |
| 131 | 152 | { |
| @@ -137,8 +158,8 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 5 unmodified lines | ||
| 137 | 158 | poly->notes[note][0] = vel; |
| 138 | 159 | poly->notes[note][1] = whichVoice; |
| 139 | 160 | |
| 140 | − tRamp_setTime(poly->ramp[whichVoice], poly->glideTime); | |
| 141 | − tRamp_setDest(poly->ramp[whichVoice], poly->voices[whichVoice][0]); | |
| 161 | + tRamp_setTime(&poly->ramp[whichVoice], poly->glideTime); | |
| 162 | + tRamp_setDest(&poly->ramp[whichVoice], poly->voices[whichVoice][0]); | |
| 142 | 163 | |
| 143 | 164 | alteredVoice = whichVoice; |
| 144 | 165 | |
| @@ -155,8 +176,8 @@ int16_t noteToTest = -1; · 10 unmodified lines | ||
| 155 | 176 | |
| 156 | 177 | int tPoly_noteOff(tPoly* const poly, uint8_t note) |
| 157 | 178 | { |
| 158 | − tStack_remove(poly->stack, note); | |
| 159 | − tStack_remove(poly->orderStack, note); | |
| 179 | + tStack_remove(&poly->stack, note); | |
| 180 | + tStack_remove(&poly->orderStack, note); | |
| 160 | 181 | poly->notes[note][0] = 0; |
| 161 | 182 | poly->notes[note][1] = -1; |
| 162 | 183 | |
| @@ -186,14 +207,14 @@ int tPoly_noteOff(tPoly* const poly, uint8_t note) · 23 unmodified lines | ||
| 186 | 207 | //grab old notes off the stack if there are notes waiting to replace the free voice |
| 187 | 208 | if (deactivatedVoice >= 0) |
| 188 | 209 | { |
| 189 | − for (int j = 0; j < tStack_getSize(poly->stack); ++j) | |
| 210 | + for (int j = 0; j < tStack_getSize(&poly->stack); ++j) | |
| 190 | 211 | { |
| 191 | − noteToTest = tStack_get(poly->stack, j); | |
| 212 | + noteToTest = tStack_get(&poly->stack, j); | |
| 192 | 213 | |
| 193 | 214 | if (poly->notes[noteToTest][1] < 0) //if there is a stolen note waiting (marked inactive but on the stack) |
| 194 | 215 | { |
| 195 | 216 | poly->voices[deactivatedVoice][0] = noteToTest; //set the newly free voice to use the old stolen note |
| 196 | − tRamp_setDest(poly->ramp[deactivatedVoice], poly->voices[deactivatedVoice][0]); | |
| 217 | + tRamp_setDest(&poly->ramp[deactivatedVoice], poly->voices[deactivatedVoice][0]); | |
| 197 | 218 | poly->voices[deactivatedVoice][1] = poly->notes[noteToTest][0]; // set the velocity of the voice to be the velocity of that note |
| 198 | 219 | poly->notes[noteToTest][1] = deactivatedVoice; //mark that it is no longer stolen and is now active |
| 199 | 220 | return -1; |
| @@ -209,15 +230,15 @@ void tPoly_orderedAddToStack(tPoly* const poly, uint8_t noteVal) · 9 unmodified lines | ||
| 209 | 230 | uint8_t j; |
| 210 | 231 | int myPitch, thisPitch, nextPitch; |
| 211 | 232 | |
| 212 | − tStack* ns = poly->orderStack; | |
| 233 | + tStack ns = poly->orderStack; | |
| 213 | 234 | |
| 214 | 235 | int whereToInsert = 0; |
| 215 | 236 | |
| 216 | − for (j = 0; j < ns->size; j++) | |
| 237 | + for (j = 0; j < ns.size; j++) | |
| 217 | 238 | { |
| 218 | 239 | myPitch = noteVal; |
| 219 | − thisPitch = ns->data[j]; | |
| 220 | − nextPitch = ns->data[j+1]; | |
| 240 | + thisPitch = ns.data[j]; | |
| 241 | + nextPitch = ns.data[j+1]; | |
| 221 | 242 | |
| 222 | 243 | if (myPitch > thisPitch) |
| 223 | 244 | { |
| @@ -230,21 +251,21 @@ void tPoly_orderedAddToStack(tPoly* const poly, uint8_t noteVal) · 6 unmodified lines | ||
| 230 | 251 | } |
| 231 | 252 | |
| 232 | 253 | //first move notes that are already in the stack one position to the right |
| 233 | − for (j = ns->size; j > whereToInsert; j--) | |
| 254 | + for (j = ns.size; j > whereToInsert; j--) | |
| 234 | 255 | { |
| 235 | − ns->data[j] = ns->data[(j - 1)]; | |
| 256 | + ns.data[j] = ns.data[(j - 1)]; | |
| 236 | 257 | } |
| 237 | 258 | |
| 238 | 259 | //then, insert the new note into the front of the stack |
| 239 | − ns->data[whereToInsert] = noteVal; | |
| 260 | + ns.data[whereToInsert] = noteVal; | |
| 240 | 261 | |
| 241 | − ns->size++; | |
| 262 | + ns.size++; | |
| 242 | 263 | |
| 243 | 264 | } |
| 244 | 265 | |
| 245 | 266 | void tPoly_setNumVoices(tPoly* const poly, uint8_t numVoices) |
| 246 | 267 | { |
| 247 | − poly->numVoices = (numVoices > POLY_NUM_MAX_VOICES) ? POLY_NUM_MAX_VOICES : numVoices; | |
| 268 | + poly->numVoices = (numVoices > poly->maxNumVoices) ? poly->maxNumVoices : numVoices; | |
| 248 | 269 | } |
| 249 | 270 | |
| 250 | 271 | void tPoly_setPitchGlideActive(tPoly* const poly, oBool isActive) |
| @@ -255,9 +276,9 @@ void tPoly_setPitchGlideActive(tPoly* const poly, oBool isActive) · 4 unmodified lines | ||
| 255 | 276 | void tPoly_setPitchGlideTime(tPoly* const poly, float t) |
| 256 | 277 | { |
| 257 | 278 | poly->glideTime = t; |
| 258 | − for (int i = 0; i < POLY_NUM_MAX_VOICES; ++i) | |
| 279 | + for (int i = 0; i < poly->maxNumVoices; ++i) | |
| 259 | 280 | { |
| 260 | − tRamp_setTime(poly->ramp[i], poly->glideTime); | |
| 281 | + tRamp_setTime(&poly->ramp[i], poly->glideTime); | |
| 261 | 282 | } |
| 262 | 283 | } |
| 263 | 284 | |
| @@ -268,7 +289,7 @@ int tPoly_getNumVoices(tPoly* const poly) · 4 unmodified lines | ||
| 268 | 289 | |
| 269 | 290 | float tPoly_getPitch(tPoly* const poly, uint8_t voice) |
| 270 | 291 | { |
| 271 | − return tRamp_sample(poly->ramp[voice]) + tRamp_sample(poly->pitchBendRamp); | |
| 292 | + return tRamp_sample(&poly->ramp[voice]) + tRamp_sample(&poly->pitchBendRamp); | |
| 272 | 293 | } |
| 273 | 294 | |
| 274 | 295 | int tPoly_getKey(tPoly* const poly, uint8_t voice) |
| @@ -31,12 +31,19 @@ void tOversampler_init(tOversampler* const os, int ratio, oBool extraQuality) · 30 unmodified lines | ||
| 31 | 31 | int idx = (int)(log2f(os->ratio))-1+offset; |
| 32 | 32 | os->numTaps = firNumTaps[idx]; |
| 33 | 33 | os->phaseLength = os->numTaps / os->ratio; |
| 34 | − os->pCoeffs = firCoeffs[idx]; | |
| 34 | + os->pCoeffs = (float*) firCoeffs[idx]; | |
| 35 | 35 | os->upState = leaf_alloc(sizeof(float) * os->phaseLength); |
| 36 | 36 | os->downState = leaf_alloc(sizeof(float) * os->phaseLength); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | +void tOversampler_free(tOversampler* const os) | |
| 41 | +{ | |
| 42 | + leaf_free(os->upState); | |
| 43 | + leaf_free(os->downState); | |
| 44 | + leaf_free(os); | |
| 45 | +} | |
| 46 | + | |
| 40 | 47 | float tOversampler_tick(tOversampler* const os, float input, float (*effectTick)(float)) |
| 41 | 48 | { |
| 42 | 49 | float buf[os->ratio]; |
| @@ -354,7 +354,7 @@ void tPeriod_init (tPeriod* const p, float* in, float* out, int bufSize, · 353 unmodified lines | ||
| 354 | 354 | |
| 355 | 355 | p->hopSize = DEFHOPSIZE; |
| 356 | 356 | p->windowSize = DEFWINDOWSIZE; |
| 357 | − p->fba = FBA; | |
| 357 | + p->fba = FBA; | |
| 358 | 358 | |
| 359 | 359 | tEnv_init(&p->env, p->windowSize, p->hopSize, p->frameSize); |
| 360 | 360 | |
| @@ -374,7 +374,6 @@ void tPeriod_free (tPeriod* const p) · 13 unmodified lines | ||
| 374 | 374 | |
| 375 | 375 | float tPeriod_findPeriod (tPeriod* p, float sample) |
| 376 | 376 | { |
| 377 | − float period; | |
| 378 | 377 | int i, iLast; |
| 379 | 378 | |
| 380 | 379 | i = (p->curBlock*p->frameSize); |
| @@ -460,7 +459,7 @@ void tPitchShift_init (tPitchShift* const ps, tPeriod* p, float* out, int bufSiz · 79 unmodified lines | ||
| 460 | 459 | ps->index = 0; |
| 461 | 460 | ps->pitchFactor = 1.0f; |
| 462 | 461 | |
| 463 | − tSOLAD_init(&ps->sola); | |
| 462 | + tSOLAD_init(&ps->sola); | |
| 464 | 463 | |
| 465 | 464 | tHighpass_init(&ps->hp, HPFREQ); |
| 466 | 465 | |
| @@ -43,14 +43,9 @@ void tPRCRev_init(tPRCRev* const r, float t60) · 42 unmodified lines | ||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | − r->allpassDelays[0] = (tDelay*) leaf_alloc(sizeof(tDelay)); | |
| 47 | − tDelay_init(r->allpassDelays[0], lengths[0], lengths[0] * 2); | |
| 48 | − | |
| 49 | − r->allpassDelays[1] = (tDelay*) leaf_alloc(sizeof(tDelay)); | |
| 50 | − tDelay_init(r->allpassDelays[1], lengths[1], lengths[1] * 2); | |
| 51 | − | |
| 52 | − r->combDelay = (tDelay*) leaf_alloc(sizeof(tDelay)); | |
| 53 | − tDelay_init(r->combDelay, lengths[2], lengths[2] * 2); | |
| 46 | + tDelay_init(&r->allpassDelays[0], lengths[0], lengths[0] * 2); | |
| 47 | + tDelay_init(&r->allpassDelays[1], lengths[1], lengths[1] * 2); | |
| 48 | + tDelay_init(&r->combDelay, lengths[2], lengths[2] * 2); | |
| 54 | 49 | |
| 55 | 50 | tPRCRev_setT60(r, t60); |
| 56 | 51 | |
| @@ -60,9 +55,9 @@ void tPRCRev_init(tPRCRev* const r, float t60) · 3 unmodified lines | ||
| 60 | 55 | |
| 61 | 56 | void tPRCRev_free(tPRCRev* const r) |
| 62 | 57 | { |
| 63 | − tDelay_free(r->allpassDelays[0]); | |
| 64 | − tDelay_free(r->allpassDelays[1]); | |
| 65 | − tDelay_free(r->combDelay); | |
| 58 | + tDelay_free(&r->allpassDelays[0]); | |
| 59 | + tDelay_free(&r->allpassDelays[1]); | |
| 60 | + tDelay_free(&r->combDelay); | |
| 66 | 61 | leaf_free(r); |
| 67 | 62 | } |
| 68 | 63 | |
| @@ -72,7 +67,7 @@ void tPRCRev_setT60(tPRCRev* const r, float t60) · 3 unmodified lines | ||
| 72 | 67 | |
| 73 | 68 | r->t60 = t60; |
| 74 | 69 | |
| 75 | − r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(r->combDelay) * leaf.invSampleRate / t60 )); | |
| 70 | + r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 )); | |
| 76 | 71 | |
| 77 | 72 | } |
| 78 | 73 | |
| @@ -88,21 +83,21 @@ float tPRCRev_tick(tPRCRev* const r, float input) · 9 unmodified lines | ||
| 88 | 83 | |
| 89 | 84 | r->lastIn = input; |
| 90 | 85 | |
| 91 | − temp = tDelay_getLastOut(r->allpassDelays[0]); | |
| 86 | + temp = tDelay_getLastOut(&r->allpassDelays[0]); | |
| 92 | 87 | temp0 = r->allpassCoeff * temp; |
| 93 | 88 | temp0 += input; |
| 94 | − tDelay_tick(r->allpassDelays[0], temp0); | |
| 89 | + tDelay_tick(&r->allpassDelays[0], temp0); | |
| 95 | 90 | temp0 = -( r->allpassCoeff * temp0) + temp; |
| 96 | 91 | |
| 97 | − temp = tDelay_getLastOut(r->allpassDelays[1]); | |
| 92 | + temp = tDelay_getLastOut(&r->allpassDelays[1]); | |
| 98 | 93 | temp1 = r->allpassCoeff * temp; |
| 99 | 94 | temp1 += temp0; |
| 100 | − tDelay_tick(r->allpassDelays[1], temp1); | |
| 95 | + tDelay_tick(&r->allpassDelays[1], temp1); | |
| 101 | 96 | temp1 = -(r->allpassCoeff * temp1) + temp; |
| 102 | 97 | |
| 103 | − temp2 = temp1 + ( r->combCoeff * tDelay_getLastOut(r->combDelay)); | |
| 98 | + temp2 = temp1 + ( r->combCoeff * tDelay_getLastOut(&r->combDelay)); | |
| 104 | 99 | |
| 105 | − out = r->mix * tDelay_tick(r->combDelay, temp2); | |
| 100 | + out = r->mix * tDelay_tick(&r->combDelay, temp2); | |
| 106 | 101 | |
| 107 | 102 | temp = (1.0f - r->mix) * input; |
| 108 | 103 | |
| @@ -115,7 +110,7 @@ float tPRCRev_tick(tPRCRev* const r, float input) · 6 unmodified lines | ||
| 115 | 110 | |
| 116 | 111 | void tPRCRevSampleRateChanged (tPRCRev* const r) |
| 117 | 112 | { |
| 118 | − r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(r->combDelay) * leaf.invSampleRate / r->t60 )); | |
| 113 | + r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 )); | |
| 119 | 114 | } |
| 120 | 115 | |
| 121 | 116 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NRev ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| @@ -142,21 +137,18 @@ void tNRev_init(tNRev* const r, float t60) · 20 unmodified lines | ||
| 142 | 137 | |
| 143 | 138 | for ( i=0; i<6; i++ ) |
| 144 | 139 | { |
| 145 | − r->combDelays[i] = (tDelay*) leaf_alloc(sizeof(tDelay)); | |
| 146 | − tDelay_init(r->combDelays[i], lengths[i], lengths[i] * 2.0f); | |
| 140 | + tDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f); | |
| 147 | 141 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); |
| 148 | 142 | } |
| 149 | 143 | |
| 150 | 144 | for ( i=0; i<8; i++ ) |
| 151 | 145 | { |
| 152 | − r->allpassDelays[i] = (tDelay*) leaf_alloc(sizeof(tDelay)); | |
| 153 | − tDelay_init(r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); | |
| 146 | + tDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); | |
| 154 | 147 | } |
| 155 | 148 | |
| 156 | 149 | for ( i=0; i<2; i++ ) |
| 157 | 150 | { |
| 158 | − tDelay_setDelay(r->allpassDelays[i], lengths[i]); | |
| 159 | − tDelay_setDelay(r->combDelays[i], lengths[i+2]); | |
| 151 | + tDelay_setDelay(&r->combDelays[i], lengths[i+2]); | |
| 160 | 152 | } |
| 161 | 153 | |
| 162 | 154 | tNRev_setT60(r, t60); |
| @@ -168,12 +160,12 @@ void tNRev_free(tNRev* const r) · 5 unmodified lines | ||
| 168 | 160 | { |
| 169 | 161 | for (int i = 0; i < 6; i++) |
| 170 | 162 | { |
| 171 | − tDelay_free(r->combDelays[i]); | |
| 163 | + tDelay_free(&r->combDelays[i]); | |
| 172 | 164 | } |
| 173 | 165 | |
| 174 | 166 | for (int i = 0; i < 8; i++) |
| 175 | 167 | { |
| 176 | − tDelay_free(r->allpassDelays[i]); | |
| 168 | + tDelay_free(&r->allpassDelays[i]); | |
| 177 | 169 | } |
| 178 | 170 | |
| 179 | 171 | leaf_free(r); |
| @@ -185,7 +177,7 @@ void tNRev_setT60(tNRev* const r, float t60) · 5 unmodified lines | ||
| 185 | 177 | |
| 186 | 178 | r->t60 = t60; |
| 187 | 179 | |
| 188 | − for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(r->combDelays[i]) * leaf.invSampleRate / t60 )); | |
| 180 | + for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 )); | |
| 189 | 181 | |
| 190 | 182 | } |
| 191 | 183 | |
| @@ -204,31 +196,31 @@ float tNRev_tick(tNRev* const r, float input) · 12 unmodified lines | ||
| 204 | 196 | temp0 = 0.0; |
| 205 | 197 | for ( i=0; i<6; i++ ) |
| 206 | 198 | { |
| 207 | − temp = input + (r->combCoeffs[i] * tDelay_getLastOut(r->combDelays[i])); | |
| 208 | − temp0 += tDelay_tick(r->combDelays[i],temp); | |
| 199 | + temp = input + (r->combCoeffs[i] * tDelay_getLastOut(&r->combDelays[i])); | |
| 200 | + temp0 += tDelay_tick(&r->combDelays[i],temp); | |
| 209 | 201 | } |
| 210 | 202 | |
| 211 | 203 | for ( i=0; i<3; i++ ) |
| 212 | 204 | { |
| 213 | − temp = tDelay_getLastOut(r->allpassDelays[i]); | |
| 205 | + temp = tDelay_getLastOut(&r->allpassDelays[i]); | |
| 214 | 206 | temp1 = r->allpassCoeff * temp; |
| 215 | 207 | temp1 += temp0; |
| 216 | − tDelay_tick(r->allpassDelays[i], temp1); | |
| 208 | + tDelay_tick(&r->allpassDelays[i], temp1); | |
| 217 | 209 | temp0 = -(r->allpassCoeff * temp1) + temp; |
| 218 | 210 | } |
| 219 | 211 | |
| 220 | 212 | // One-pole lowpass filter. |
| 221 | 213 | r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0; |
| 222 | − temp = tDelay_getLastOut(r->allpassDelays[3]); | |
| 214 | + temp = tDelay_getLastOut(&r->allpassDelays[3]); | |
| 223 | 215 | temp1 = r->allpassCoeff * temp; |
| 224 | 216 | temp1 += r->lowpassState; |
| 225 | − tDelay_tick(r->allpassDelays[3], temp1 ); | |
| 217 | + tDelay_tick(&r->allpassDelays[3], temp1 ); | |
| 226 | 218 | temp1 = -(r->allpassCoeff * temp1) + temp; |
| 227 | 219 | |
| 228 | − temp = tDelay_getLastOut(r->allpassDelays[4]); | |
| 220 | + temp = tDelay_getLastOut(&r->allpassDelays[4]); | |
| 229 | 221 | temp2 = r->allpassCoeff * temp; |
| 230 | 222 | temp2 += temp1; |
| 231 | − tDelay_tick(r->allpassDelays[4], temp2 ); | |
| 223 | + tDelay_tick(&r->allpassDelays[4], temp2 ); | |
| 232 | 224 | out = r->mix * ( -( r->allpassCoeff * temp2 ) + temp ); |
| 233 | 225 | |
| 234 | 226 | /* |
| @@ -246,275 +238,275 @@ float tNRev_tick(tNRev* const r, float input) · 11 unmodified lines | ||
| 246 | 238 | r->lastOut = out; |
| 247 | 239 | |
| 248 | 240 | return out; |
| 249 | −} | |
| 241 | +} | |
| 250 | 242 | |
| 251 | 243 | void tNRevSampleRateChanged (tNRev* const r) |
| 252 | 244 | { |
| 253 | − for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(r->combDelays[i]) * leaf.invSampleRate / r->t60 )); | |
| 254 | −} | |
| 255 | − | |
| 256 | −// ======================================DATTORRO========================================= | |
| 257 | − | |
| 258 | −#define SAMP(in) (in*r->t) | |
| 259 | − | |
| 260 | −float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f }; | |
| 261 | −float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f }; | |
| 262 | − | |
| 263 | − | |
| 264 | −void tDattorro_init (tDattorro* const r) | |
| 265 | −{ | |
| 266 | − r->size_max = 2.0f; | |
| 267 | − r->size = 1.f; | |
| 268 | − r->t = r->size * leaf.sampleRate * 0.001f; | |
| 269 | − | |
| 270 | − // INPUT | |
| 271 | − tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); | |
| 272 | − tOnePole_init(&r->in_filter, 1.f); | |
| 273 | − | |
| 274 | − for (int i = 0; i < 4; i++) | |
| 275 | − { | |
| 276 | − tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max | |
| 277 | − tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | |
| 278 | − } | |
| 279 | − | |
| 280 | − // FEEDBACK 1 | |
| 281 | − tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max | |
| 282 | − tAllpass_setGain(&r->f1_allpass, 0.7f); | |
| 283 | − | |
| 284 | − tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1); | |
| 285 | − tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1); | |
| 286 | − tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1); | |
| 287 | − | |
| 288 | − tOnePole_init(&r->f1_filter, 1.f); | |
| 289 | − | |
| 290 | − tHighpass_init(&r->f1_hp, 20.f); | |
| 291 | − | |
| 292 | − tCycle_init(&r->f1_lfo); | |
| 293 | − tCycle_setFreq(&r->f1_lfo, 0.1f); | |
| 294 | − | |
| 295 | − // FEEDBACK 2 | |
| 296 | − tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max | |
| 297 | − tAllpass_setGain(&r->f2_allpass, 0.7f); | |
| 298 | − | |
| 299 | − tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1); | |
| 300 | − tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1); | |
| 301 | − tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1); | |
| 302 | − | |
| 303 | − tOnePole_init(&r->f2_filter, 1.f); | |
| 304 | − | |
| 305 | − tHighpass_init(&r->f2_hp, 20.f); | |
| 306 | − | |
| 307 | − tCycle_init(&r->f2_lfo); | |
| 308 | − tCycle_setFreq(&r->f2_lfo, 0.07f); | |
| 309 | − | |
| 310 | − | |
| 311 | − // PARAMETERS | |
| 312 | − tDattorro_setMix(r, 0.5f); | |
| 313 | − | |
| 314 | − tDattorro_setInputDelay(r, 0.f); | |
| 315 | − | |
| 316 | − tDattorro_setInputFilter(r, 10000.f); | |
| 317 | − | |
| 318 | − tDattorro_setFeedbackFilter(r, 5000.f); | |
| 319 | − | |
| 320 | − tDattorro_setFeedbackGain(r, 0.4f); | |
| 321 | − | |
| 322 | − | |
| 323 | −} | |
| 324 | − | |
| 325 | −void tDattorro_free (tDattorro* const r) | |
| 326 | −{ | |
| 327 | − // INPUT | |
| 328 | − tTapeDelay_free(&r->in_delay); | |
| 329 | − tOnePole_free(&r->in_filter); | |
| 330 | − | |
| 331 | − for (int i = 0; i < 4; i++) | |
| 332 | − { | |
| 333 | − tAllpass_free(&r->in_allpass[i]); | |
| 334 | − } | |
| 335 | − | |
| 336 | − // FEEDBACK 1 | |
| 337 | − tAllpass_free(&r->f1_allpass); | |
| 338 | − | |
| 339 | − tTapeDelay_free(&r->f1_delay_1); | |
| 340 | − tTapeDelay_free(&r->f1_delay_2); | |
| 341 | − tTapeDelay_free(&r->f1_delay_3); | |
| 342 | − | |
| 343 | − tOnePole_free(&r->f1_filter); | |
| 344 | − | |
| 345 | − tCycle_free(&r->f1_lfo); | |
| 346 | − | |
| 347 | − // FEEDBACK 2 | |
| 348 | − tAllpass_free(&r->f2_allpass); | |
| 349 | − | |
| 350 | − tTapeDelay_free(&r->f2_delay_1); | |
| 351 | − tTapeDelay_free(&r->f2_delay_2); | |
| 352 | − tTapeDelay_free(&r->f2_delay_3); | |
| 353 | − | |
| 354 | − tOnePole_free(&r->f2_filter); | |
| 355 | − | |
| 356 | − tCycle_free(&r->f2_lfo); | |
| 357 | − | |
| 358 | − leaf_free(r); | |
| 359 | −} | |
| 360 | − | |
| 361 | −float tDattorro_tick (tDattorro* const r, float input) | |
| 362 | −{ | |
| 363 | − // INPUT | |
| 364 | − float in_sample = tTapeDelay_tick(&r->in_delay, input); | |
| 365 | − | |
| 366 | − in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 367 | − | |
| 368 | − for (int i = 0; i < 4; i++) | |
| 369 | − { | |
| 370 | − in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | |
| 371 | − } | |
| 372 | − | |
| 373 | − // FEEDBACK 1 | |
| 374 | − float f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 375 | − | |
| 376 | − tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | |
| 377 | − | |
| 378 | − f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | |
| 379 | − | |
| 380 | − f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | |
| 381 | − | |
| 382 | − f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | |
| 383 | − | |
| 384 | − f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | |
| 385 | − | |
| 386 | − float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | |
| 387 | − | |
| 388 | − r->f1_delay_2_last = f1_delay_2_sample; | |
| 389 | − | |
| 390 | − f1_sample = r->f1_delay_2_last + f1_sample; | |
| 391 | − | |
| 392 | − f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | |
| 393 | − | |
| 394 | − f1_sample *= r->feedback_gain; | |
| 395 | − | |
| 396 | − r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | |
| 397 | − | |
| 398 | − // FEEDBACK 2 | |
| 399 | − float f2_sample = in_sample + r->f1_last; | |
| 400 | − | |
| 401 | − tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | |
| 402 | − | |
| 403 | − f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | |
| 404 | − | |
| 405 | − f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | |
| 406 | − | |
| 407 | − f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | |
| 408 | − | |
| 409 | − f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | |
| 410 | − | |
| 411 | − float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | |
| 412 | − | |
| 413 | − r->f2_delay_2_last = f2_delay_2_sample; | |
| 414 | − | |
| 415 | − f2_sample = r->f2_delay_2_last + f2_sample; | |
| 416 | − | |
| 417 | − f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | |
| 418 | − | |
| 419 | − f2_sample *= r->feedback_gain; | |
| 420 | − | |
| 421 | − r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | |
| 422 | − | |
| 423 | − | |
| 424 | − // TAP OUT 1 | |
| 425 | − f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + | |
| 426 | − tTapeDelay_tapOut(&r->f1_delay_1, SAMP(99.8f)); | |
| 427 | − | |
| 428 | − f1_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(64.2f)); | |
| 429 | − | |
| 430 | − f1_sample += tTapeDelay_tapOut(&r->f1_delay_3, SAMP(67.f)); | |
| 431 | − | |
| 432 | − f1_sample -= tTapeDelay_tapOut(&r->f2_delay_1, SAMP(66.8f)); | |
| 433 | − | |
| 434 | − f1_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f)); | |
| 435 | − | |
| 436 | − f1_sample -= tTapeDelay_tapOut(&r->f2_delay_3, SAMP(35.8f)); | |
| 437 | − | |
| 438 | − f1_sample *= 0.14f; | |
| 439 | − | |
| 440 | − // TAP OUT 2 | |
| 441 | − f2_sample = tTapeDelay_tapOut(&r->f2_delay_1, SAMP(11.8f)) + | |
| 442 | − tTapeDelay_tapOut(&r->f2_delay_1, SAMP(121.7f)); | |
| 443 | − | |
| 444 | − f2_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f)); | |
| 445 | − | |
| 446 | − f2_sample += tTapeDelay_tapOut(&r->f2_delay_3, SAMP(89.7f)); | |
| 447 | − | |
| 448 | − f2_sample -= tTapeDelay_tapOut(&r->f1_delay_1, SAMP(70.8f)); | |
| 449 | − | |
| 450 | − f2_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(11.2f)); | |
| 451 | − | |
| 452 | − f2_sample -= tTapeDelay_tapOut(&r->f1_delay_3, SAMP(4.1f)); | |
| 453 | − | |
| 454 | − f2_sample *= 0.14f; | |
| 455 | − | |
| 456 | − float sample = (f1_sample + f2_sample) * 0.5f; | |
| 457 | − | |
| 458 | − return (input * (1.0f - r->mix) + sample * r->mix); | |
| 459 | −} | |
| 460 | − | |
| 461 | −void tDattorro_setMix (tDattorro* const r, float mix) | |
| 462 | −{ | |
| 463 | − r->mix = LEAF_clip(0.0f, mix, 1.0f); | |
| 464 | −} | |
| 465 | − | |
| 466 | −void tDattorro_setSize (tDattorro* const r, float size) | |
| 467 | −{ | |
| 468 | − r->size = LEAF_clip(0.01f, size*r->size_max, r->size_max); | |
| 469 | − r->t = r->size * leaf.sampleRate * 0.001f; | |
| 470 | − | |
| 471 | − /* | |
| 472 | − for (int i = 0; i < 4; i++) | |
| 473 | − { | |
| 474 | − tAllpass_setDelay(&r->in_allpass[i], SAMP(in_allpass_delays[i])); | |
| 475 | − } | |
| 476 | − */ | |
| 477 | − | |
| 478 | − // FEEDBACK 1 | |
| 479 | − //tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f)); | |
| 480 | − | |
| 481 | − tTapeDelay_setDelay(&r->f1_delay_1, SAMP(141.69f)); | |
| 482 | − tTapeDelay_setDelay(&r->f1_delay_2, SAMP(89.24f)); | |
| 483 | − tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f)); | |
| 484 | − | |
| 485 | − // maybe change rate of SINE LFO's when size changes? | |
| 486 | − | |
| 487 | − // FEEDBACK 2 | |
| 488 | − //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f)); | |
| 489 | − | |
| 490 | − tTapeDelay_setDelay(&r->f2_delay_1, SAMP(149.62f)); | |
| 491 | − tTapeDelay_setDelay(&r->f2_delay_2, SAMP(60.48f)); | |
| 492 | − tTapeDelay_setDelay(&r->f2_delay_3, SAMP(106.28f)); | |
| 493 | −} | |
| 494 | − | |
| 495 | −void tDattorro_setInputDelay (tDattorro* const r, float preDelay) | |
| 496 | −{ | |
| 497 | − r->predelay = LEAF_clip(0.0f, preDelay, 200.0f); | |
| 498 | − | |
| 499 | − tTapeDelay_setDelay(&r->in_delay, SAMP(r->predelay)); | |
| 500 | −} | |
| 501 | − | |
| 502 | −void tDattorro_setInputFilter (tDattorro* const r, float freq) | |
| 503 | −{ | |
| 504 | − r->input_filter = LEAF_clip(0.0f, freq, 20000.0f); | |
| 505 | − | |
| 506 | − tOnePole_setFreq(&r->in_filter, r->input_filter); | |
| 507 | −} | |
| 508 | − | |
| 509 | −void tDattorro_setFeedbackFilter (tDattorro* const r, float freq) | |
| 510 | −{ | |
| 511 | − r->feedback_filter = LEAF_clip(0.0f, freq, 20000.0f); | |
| 512 | − | |
| 513 | − tOnePole_setFreq(&r->f1_filter, r->feedback_filter); | |
| 514 | − tOnePole_setFreq(&r->f2_filter, r->feedback_filter); | |
| 515 | −} | |
| 516 | − | |
| 517 | −void tDattorro_setFeedbackGain (tDattorro* const r, float gain) | |
| 518 | −{ | |
| 519 | − r->feedback_gain = gain; | |
| 520 | −} | |
| 245 | + for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 )); | |
| 246 | +} | |
| 247 | + | |
| 248 | +// ======================================DATTORRO========================================= | |
| 249 | + | |
| 250 | +#define SAMP(in) (in*r->t) | |
| 251 | + | |
| 252 | +float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f }; | |
| 253 | +float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f }; | |
| 254 | + | |
| 255 | + | |
| 256 | +void tDattorro_init (tDattorro* const r) | |
| 257 | +{ | |
| 258 | + r->size_max = 2.0f; | |
| 259 | + r->size = 1.f; | |
| 260 | + r->t = r->size * leaf.sampleRate * 0.001f; | |
| 261 | + | |
| 262 | + // INPUT | |
| 263 | + tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); | |
| 264 | + tOnePole_init(&r->in_filter, 1.f); | |
| 265 | + | |
| 266 | + for (int i = 0; i < 4; i++) | |
| 267 | + { | |
| 268 | + tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max | |
| 269 | + tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | |
| 270 | + } | |
| 271 | + | |
| 272 | + // FEEDBACK 1 | |
| 273 | + tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max | |
| 274 | + tAllpass_setGain(&r->f1_allpass, 0.7f); | |
| 275 | + | |
| 276 | + tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1); | |
| 277 | + tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1); | |
| 278 | + tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1); | |
| 279 | + | |
| 280 | + tOnePole_init(&r->f1_filter, 1.f); | |
| 281 | + | |
| 282 | + tHighpass_init(&r->f1_hp, 20.f); | |
| 283 | + | |
| 284 | + tCycle_init(&r->f1_lfo); | |
| 285 | + tCycle_setFreq(&r->f1_lfo, 0.1f); | |
| 286 | + | |
| 287 | + // FEEDBACK 2 | |
| 288 | + tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max | |
| 289 | + tAllpass_setGain(&r->f2_allpass, 0.7f); | |
| 290 | + | |
| 291 | + tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1); | |
| 292 | + tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1); | |
| 293 | + tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1); | |
| 294 | + | |
| 295 | + tOnePole_init(&r->f2_filter, 1.f); | |
| 296 | + | |
| 297 | + tHighpass_init(&r->f2_hp, 20.f); | |
| 298 | + | |
| 299 | + tCycle_init(&r->f2_lfo); | |
| 300 | + tCycle_setFreq(&r->f2_lfo, 0.07f); | |
| 301 | + | |
| 302 | + | |
| 303 | + // PARAMETERS | |
| 304 | + tDattorro_setMix(r, 0.5f); | |
| 305 | + | |
| 306 | + tDattorro_setInputDelay(r, 0.f); | |
| 307 | + | |
| 308 | + tDattorro_setInputFilter(r, 10000.f); | |
| 309 | + | |
| 310 | + tDattorro_setFeedbackFilter(r, 5000.f); | |
| 311 | + | |
| 312 | + tDattorro_setFeedbackGain(r, 0.4f); | |
| 313 | + | |
| 314 | + | |
| 315 | +} | |
| 316 | + | |
| 317 | +void tDattorro_free (tDattorro* const r) | |
| 318 | +{ | |
| 319 | + // INPUT | |
| 320 | + tTapeDelay_free(&r->in_delay); | |
| 321 | + tOnePole_free(&r->in_filter); | |
| 322 | + | |
| 323 | + for (int i = 0; i < 4; i++) | |
| 324 | + { | |
| 325 | + tAllpass_free(&r->in_allpass[i]); | |
| 326 | + } | |
| 327 | + | |
| 328 | + // FEEDBACK 1 | |
| 329 | + tAllpass_free(&r->f1_allpass); | |
| 330 | + | |
| 331 | + tTapeDelay_free(&r->f1_delay_1); | |
| 332 | + tTapeDelay_free(&r->f1_delay_2); | |
| 333 | + tTapeDelay_free(&r->f1_delay_3); | |
| 334 | + | |
| 335 | + tOnePole_free(&r->f1_filter); | |
| 336 | + | |
| 337 | + tCycle_free(&r->f1_lfo); | |
| 338 | + | |
| 339 | + // FEEDBACK 2 | |
| 340 | + tAllpass_free(&r->f2_allpass); | |
| 341 | + | |
| 342 | + tTapeDelay_free(&r->f2_delay_1); | |
| 343 | + tTapeDelay_free(&r->f2_delay_2); | |
| 344 | + tTapeDelay_free(&r->f2_delay_3); | |
| 345 | + | |
| 346 | + tOnePole_free(&r->f2_filter); | |
| 347 | + | |
| 348 | + tCycle_free(&r->f2_lfo); | |
| 349 | + | |
| 350 | + leaf_free(r); | |
| 351 | +} | |
| 352 | + | |
| 353 | +float tDattorro_tick (tDattorro* const r, float input) | |
| 354 | +{ | |
| 355 | + // INPUT | |
| 356 | + float in_sample = tTapeDelay_tick(&r->in_delay, input); | |
| 357 | + | |
| 358 | + in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 359 | + | |
| 360 | + for (int i = 0; i < 4; i++) | |
| 361 | + { | |
| 362 | + in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | |
| 363 | + } | |
| 364 | + | |
| 365 | + // FEEDBACK 1 | |
| 366 | + float f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 367 | + | |
| 368 | + tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | |
| 369 | + | |
| 370 | + f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | |
| 371 | + | |
| 372 | + f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | |
| 373 | + | |
| 374 | + f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | |
| 375 | + | |
| 376 | + f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | |
| 377 | + | |
| 378 | + float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | |
| 379 | + | |
| 380 | + r->f1_delay_2_last = f1_delay_2_sample; | |
| 381 | + | |
| 382 | + f1_sample = r->f1_delay_2_last + f1_sample; | |
| 383 | + | |
| 384 | + f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | |
| 385 | + | |
| 386 | + f1_sample *= r->feedback_gain; | |
| 387 | + | |
| 388 | + r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | |
| 389 | + | |
| 390 | + // FEEDBACK 2 | |
| 391 | + float f2_sample = in_sample + r->f1_last; | |
| 392 | + | |
| 393 | + tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | |
| 394 | + | |
| 395 | + f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | |
| 396 | + | |
| 397 | + f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | |
| 398 | + | |
| 399 | + f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | |
| 400 | + | |
| 401 | + f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | |
| 402 | + | |
| 403 | + float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | |
| 404 | + | |
| 405 | + r->f2_delay_2_last = f2_delay_2_sample; | |
| 406 | + | |
| 407 | + f2_sample = r->f2_delay_2_last + f2_sample; | |
| 408 | + | |
| 409 | + f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | |
| 410 | + | |
| 411 | + f2_sample *= r->feedback_gain; | |
| 412 | + | |
| 413 | + r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | |
| 414 | + | |
| 415 | + | |
| 416 | + // TAP OUT 1 | |
| 417 | + f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + | |
| 418 | + tTapeDelay_tapOut(&r->f1_delay_1, SAMP(99.8f)); | |
| 419 | + | |
| 420 | + f1_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(64.2f)); | |
| 421 | + | |
| 422 | + f1_sample += tTapeDelay_tapOut(&r->f1_delay_3, SAMP(67.f)); | |
| 423 | + | |
| 424 | + f1_sample -= tTapeDelay_tapOut(&r->f2_delay_1, SAMP(66.8f)); | |
| 425 | + | |
| 426 | + f1_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f)); | |
| 427 | + | |
| 428 | + f1_sample -= tTapeDelay_tapOut(&r->f2_delay_3, SAMP(35.8f)); | |
| 429 | + | |
| 430 | + f1_sample *= 0.14f; | |
| 431 | + | |
| 432 | + // TAP OUT 2 | |
| 433 | + f2_sample = tTapeDelay_tapOut(&r->f2_delay_1, SAMP(11.8f)) + | |
| 434 | + tTapeDelay_tapOut(&r->f2_delay_1, SAMP(121.7f)); | |
| 435 | + | |
| 436 | + f2_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f)); | |
| 437 | + | |
| 438 | + f2_sample += tTapeDelay_tapOut(&r->f2_delay_3, SAMP(89.7f)); | |
| 439 | + | |
| 440 | + f2_sample -= tTapeDelay_tapOut(&r->f1_delay_1, SAMP(70.8f)); | |
| 441 | + | |
| 442 | + f2_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(11.2f)); | |
| 443 | + | |
| 444 | + f2_sample -= tTapeDelay_tapOut(&r->f1_delay_3, SAMP(4.1f)); | |
| 445 | + | |
| 446 | + f2_sample *= 0.14f; | |
| 447 | + | |
| 448 | + float sample = (f1_sample + f2_sample) * 0.5f; | |
| 449 | + | |
| 450 | + return (input * (1.0f - r->mix) + sample * r->mix); | |
| 451 | +} | |
| 452 | + | |
| 453 | +void tDattorro_setMix (tDattorro* const r, float mix) | |
| 454 | +{ | |
| 455 | + r->mix = LEAF_clip(0.0f, mix, 1.0f); | |
| 456 | +} | |
| 457 | + | |
| 458 | +void tDattorro_setSize (tDattorro* const r, float size) | |
| 459 | +{ | |
| 460 | + r->size = LEAF_clip(0.01f, size*r->size_max, r->size_max); | |
| 461 | + r->t = r->size * leaf.sampleRate * 0.001f; | |
| 462 | + | |
| 463 | + /* | |
| 464 | + for (int i = 0; i < 4; i++) | |
| 465 | + { | |
| 466 | + tAllpass_setDelay(&r->in_allpass[i], SAMP(in_allpass_delays[i])); | |
| 467 | + } | |
| 468 | + */ | |
| 469 | + | |
| 470 | + // FEEDBACK 1 | |
| 471 | + //tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f)); | |
| 472 | + | |
| 473 | + tTapeDelay_setDelay(&r->f1_delay_1, SAMP(141.69f)); | |
| 474 | + tTapeDelay_setDelay(&r->f1_delay_2, SAMP(89.24f)); | |
| 475 | + tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f)); | |
| 476 | + | |
| 477 | + // maybe change rate of SINE LFO's when size changes? | |
| 478 | + | |
| 479 | + // FEEDBACK 2 | |
| 480 | + //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f)); | |
| 481 | + | |
| 482 | + tTapeDelay_setDelay(&r->f2_delay_1, SAMP(149.62f)); | |
| 483 | + tTapeDelay_setDelay(&r->f2_delay_2, SAMP(60.48f)); | |
| 484 | + tTapeDelay_setDelay(&r->f2_delay_3, SAMP(106.28f)); | |
| 485 | +} | |
| 486 | + | |
| 487 | +void tDattorro_setInputDelay (tDattorro* const r, float preDelay) | |
| 488 | +{ | |
| 489 | + r->predelay = LEAF_clip(0.0f, preDelay, 200.0f); | |
| 490 | + | |
| 491 | + tTapeDelay_setDelay(&r->in_delay, SAMP(r->predelay)); | |
| 492 | +} | |
| 493 | + | |
| 494 | +void tDattorro_setInputFilter (tDattorro* const r, float freq) | |
| 495 | +{ | |
| 496 | + r->input_filter = LEAF_clip(0.0f, freq, 20000.0f); | |
| 497 | + | |
| 498 | + tOnePole_setFreq(&r->in_filter, r->input_filter); | |
| 499 | +} | |
| 500 | + | |
| 501 | +void tDattorro_setFeedbackFilter (tDattorro* const r, float freq) | |
| 502 | +{ | |
| 503 | + r->feedback_filter = LEAF_clip(0.0f, freq, 20000.0f); | |
| 504 | + | |
| 505 | + tOnePole_setFreq(&r->f1_filter, r->feedback_filter); | |
| 506 | + tOnePole_setFreq(&r->f2_filter, r->feedback_filter); | |
| 507 | +} | |
| 508 | + | |
| 509 | +void tDattorro_setFeedbackGain (tDattorro* const r, float gain) | |
| 510 | +{ | |
| 511 | + r->feedback_gain = gain; | |
| 512 | +} | |
| @@ -106,7 +106,7 @@ void tBuffer_clear (tBuffer* const s) · 105 unmodified lines | ||
| 106 | 106 | |
| 107 | 107 | //================================tSampler===================================== |
| 108 | 108 | |
| 109 | −void tSampler_init (tSampler* const p, tBuffer* s) | |
| 109 | +void tSampler_init(tSampler* const p, tBuffer* const s) | |
| 110 | 110 | { |
| 111 | 111 | p->samp = s; |
| 112 | 112 | |
| @@ -135,7 +135,7 @@ void tSampler_init (tSampler* const p, tBuffer* s) · 22 unmodified lines | ||
| 135 | 135 | |
| 136 | 136 | void tSampler_free (tSampler* const p) |
| 137 | 137 | { |
| 138 | − leaf_free(p->samp); | |
| 138 | + tRamp_free(&p->gain); | |
| 139 | 139 | leaf_free(p); |
| 140 | 140 | } |
| 141 | 141 | |
| @@ -178,52 +178,52 @@ float tSampler_tick (tSampler* const p) · 36 unmodified lines | ||
| 178 | 178 | end = p->start; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | − // Check dir (direction) to interpolate properly | |
| 182 | − if (dir > 0) | |
| 183 | − { | |
| 184 | − // FORWARD NORMAL SAMPLE | |
| 185 | − int i1 = ((idx-1) + p->len) % p->len; | |
| 186 | − int i3 = (idx+1) % p->len; | |
| 187 | − int i4 = (idx+2) % p->len; | |
| 188 | − | |
| 189 | − sample = LEAF_interpolate_hermite (buff[i1], | |
| 190 | − buff[idx], | |
| 191 | − buff[i3], | |
| 192 | − buff[i4], | |
| 193 | − alpha); | |
| 194 | − | |
| 195 | − // num samples to end of loop | |
| 196 | − numsamps = (idx - start) / p->inc; | |
| 197 | − //numsamps = (dir > 0) ? (end - idx) : (idx - start); | |
| 198 | − //numsamps *= p->iinc; | |
| 199 | − | |
| 200 | − if (p->mode == PlayLoop) | |
| 201 | − { | |
| 202 | − if (numsamps <= p->cfxlen) | |
| 203 | − { | |
| 204 | − // CROSSFADE SAMPLE | |
| 205 | − float idxx = p->idx - p->len; | |
| 206 | − int cdx = ((int)(idxx) + p->len) % p->len; | |
| 207 | − | |
| 208 | − i1 = ((cdx-1) + p->len) % p->len; | |
| 209 | − i3 = (cdx+1) % p->len; | |
| 210 | − i4 = (cdx+2) % p->len; | |
| 211 | − | |
| 212 | − cfxsample = LEAF_interpolate_hermite (buff[i1], | |
| 213 | − buff[cdx], | |
| 214 | − buff[i3], | |
| 215 | − buff[i4], | |
| 216 | − alpha); | |
| 217 | − | |
| 218 | − g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | |
| 219 | − } | |
| 220 | − } | |
| 221 | − } | |
| 222 | − else | |
| 181 | + // Check dir (direction) to interpolate properly | |
| 182 | + if (dir > 0) | |
| 183 | + { | |
| 184 | + // FORWARD NORMAL SAMPLE | |
| 185 | + int i1 = ((idx-1) + p->len) % p->len; | |
| 186 | + int i3 = (idx+1) % p->len; | |
| 187 | + int i4 = (idx+2) % p->len; | |
| 188 | + | |
| 189 | + sample = LEAF_interpolate_hermite (buff[i1], | |
| 190 | + buff[idx], | |
| 191 | + buff[i3], | |
| 192 | + buff[i4], | |
| 193 | + alpha); | |
| 194 | + | |
| 195 | + // num samples to end of loop | |
| 196 | + numsamps = (idx - start) / p->inc; | |
| 197 | + //numsamps = (dir > 0) ? (end - idx) : (idx - start); | |
| 198 | + //numsamps *= p->iinc; | |
| 199 | + | |
| 200 | + if (p->mode == PlayLoop) | |
| 201 | + { | |
| 202 | + if (numsamps <= p->cfxlen) | |
| 203 | + { | |
| 204 | + // CROSSFADE SAMPLE | |
| 205 | + float idxx = p->idx - p->len; | |
| 206 | + int cdx = ((int)(idxx) + p->len) % p->len; | |
| 207 | + | |
| 208 | + i1 = ((cdx-1) + p->len) % p->len; | |
| 209 | + i3 = (cdx+1) % p->len; | |
| 210 | + i4 = (cdx+2) % p->len; | |
| 211 | + | |
| 212 | + cfxsample = LEAF_interpolate_hermite (buff[i1], | |
| 213 | + buff[cdx], | |
| 214 | + buff[i3], | |
| 215 | + buff[i4], | |
| 216 | + alpha); | |
| 217 | + | |
| 218 | + g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | |
| 219 | + } | |
| 220 | + } | |
| 221 | + } | |
| 222 | + else | |
| 223 | 223 | { |
| 224 | − // REVERSE | |
| 225 | − int i1 = (idx+1) % p->len; | |
| 226 | − int i3 = ((idx-1) + p->len) % p->len; | |
| 224 | + // REVERSE | |
| 225 | + int i1 = (idx+1) % p->len; | |
| 226 | + int i3 = ((idx-1) + p->len) % p->len; | |
| 227 | 227 | int i4 = ((idx-2) + p->len) % p->len; |
| 228 | 228 | |
| 229 | 229 | sample = LEAF_interpolate_hermite (buff[i1], |
| @@ -21,21 +21,27 @@ void tPluck_init (tPluck* const p, float lowestFrequency) · 20 unmodified lines | ||
| 21 | 21 | { |
| 22 | 22 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; |
| 23 | 23 | |
| 24 | − p->noise = (tNoise*)leaf_alloc(sizeof(tNoise)); | |
| 25 | − tNoise_init(p->noise, WhiteNoise); | |
| 24 | + tNoise_init(&p->noise, WhiteNoise); | |
| 26 | 25 | |
| 27 | − p->pickFilter = (tOnePole*) leaf_alloc(sizeof(tOnePole)); | |
| 28 | − tOnePole_init(p->pickFilter, 0.0f); | |
| 26 | + tOnePole_init(&p->pickFilter, 0.0f); | |
| 29 | 27 | |
| 30 | − p->loopFilter = (tOneZero*) leaf_alloc(sizeof(tOneZero)); | |
| 31 | − tOneZero_init(p->loopFilter, 0.0f); | |
| 28 | + tOneZero_init(&p->loopFilter, 0.0f); | |
| 32 | 29 | |
| 33 | − p->delayLine = (tDelayA*) leaf_alloc(sizeof(tDelayA)); | |
| 34 | − tDelayA_init(p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 30 | + tDelayA_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 35 | 31 | |
| 36 | 32 | tPluck_setFrequency(p, 220.0f); |
| 37 | 33 | } |
| 38 | 34 | |
| 35 | +void tPluck_free (tPluck* const p) | |
| 36 | +{ | |
| 37 | + tNoise_free(&p->noise); | |
| 38 | + tOnePole_free(&p->pickFilter); | |
| 39 | + tOneZero_free(&p->loopFilter); | |
| 40 | + tDelayA_free(&p->delayLine); | |
| 41 | + | |
| 42 | + leaf_free(p); | |
| 43 | +} | |
| 44 | + | |
| 39 | 45 | float tPluck_getLastOut (tPluck *p) |
| 40 | 46 | { |
| 41 | 47 | return p->lastOut; |
| @@ -43,7 +49,7 @@ float tPluck_getLastOut (tPluck *p) · 1 unmodified line | ||
| 43 | 49 | |
| 44 | 50 | float tPluck_tick (tPluck *p) |
| 45 | 51 | { |
| 46 | − return (p->lastOut = 3.0f * tDelayA_tick(p->delayLine, tOneZero_tick(p->loopFilter, tDelayA_getLastOut(p->delayLine) * p->loopGain ) )); | |
| 52 | + return (p->lastOut = 3.0f * tDelayA_tick(&p->delayLine, tOneZero_tick(&p->loopFilter, tDelayA_getLastOut(&p->delayLine) * p->loopGain ) )); | |
| 47 | 53 | } |
| 48 | 54 | |
| 49 | 55 | void tPluck_pluck (tPluck* const p, float amplitude) |
| @@ -51,12 +57,12 @@ void tPluck_pluck (tPluck* const p, float amplitude) · 1 unmodified line | ||
| 51 | 57 | if ( amplitude < 0.0f) amplitude = 0.0f; |
| 52 | 58 | else if (amplitude > 1.0f) amplitude = 1.0f; |
| 53 | 59 | |
| 54 | − tOnePole_setPole(p->pickFilter, 0.999f - (amplitude * 0.15f)); | |
| 55 | − tOnePole_setGain(p->pickFilter, amplitude * 0.5f ); | |
| 60 | + tOnePole_setPole(&p->pickFilter, 0.999f - (amplitude * 0.15f)); | |
| 61 | + tOnePole_setGain(&p->pickFilter, amplitude * 0.5f ); | |
| 56 | 62 | |
| 57 | 63 | // Fill delay with noise additively with current contents. |
| 58 | − for ( uint32_t i = 0; i < (uint32_t)tDelayA_getDelay(p->delayLine); i++ ) | |
| 59 | − tDelayA_tick(p->delayLine, 0.6f * tDelayA_getLastOut(p->delayLine) + tOnePole_tick(p->pickFilter, tNoise_tick(p->noise) ) ); | |
| 64 | + for ( uint32_t i = 0; i < (uint32_t)tDelayA_getDelay(&p->delayLine); i++ ) | |
| 65 | + tDelayA_tick(&p->delayLine, 0.6f * tDelayA_getLastOut(&p->delayLine) + tOnePole_tick(&p->pickFilter, tNoise_tick(&p->noise) ) ); | |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | 68 | // Start a note with the given frequency and amplitude.; |
| @@ -82,9 +88,9 @@ void tPluck_setFrequency (tPluck* const p, float frequency ) · 19 unmodified lines | ||
| 82 | 88 | if ( frequency <= 0.0f ) frequency = 0.001f; |
| 83 | 89 | |
| 84 | 90 | // Delay = length - filter delay. |
| 85 | − float delay = ( leaf.sampleRate / frequency ) - tOneZero_getPhaseDelay(p->loopFilter, frequency ); | |
| 91 | + float delay = ( leaf.sampleRate / frequency ) - tOneZero_getPhaseDelay(&p->loopFilter, frequency ); | |
| 86 | 92 | |
| 87 | − tDelayA_setDelay(p->delayLine, delay ); | |
| 93 | + tDelayA_setDelay(&p->delayLine, delay ); | |
| 88 | 94 | |
| 89 | 95 | p->loopGain = 0.99f + (frequency * 0.000005f); |
| 90 | 96 | |
| @@ -108,22 +114,17 @@ void tStifKarp_init (tStifKarp* const p, float lowestFrequency) · 17 unmodified lines | ||
| 108 | 114 | { |
| 109 | 115 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; |
| 110 | 116 | |
| 111 | − p->delayLine = (tDelayA*) leaf_alloc(sizeof(tDelayA)); | |
| 112 | − tDelayA_init(p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 113 | − | |
| 114 | − p->combDelay = (tDelayL*) leaf_alloc(sizeof(tDelayL)); | |
| 115 | − tDelayL_init(p->combDelay, 0.0f, leaf.sampleRate * 2); | |
| 117 | + tDelayA_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 118 | + | |
| 119 | + tDelayL_init(&p->combDelay, 0.0f, leaf.sampleRate * 2); | |
| 116 | 120 | |
| 117 | − p->filter = (tOneZero*) leaf_alloc(sizeof(tOneZero)); | |
| 118 | − tOneZero_init(p->filter, 0.0f); | |
| 121 | + tOneZero_init(&p->filter, 0.0f); | |
| 119 | 122 | |
| 120 | − p->noise = (tNoise*) leaf_alloc(sizeof(tNoise)); | |
| 121 | − tNoise_init(p->noise, WhiteNoise); | |
| 123 | + tNoise_init(&p->noise, WhiteNoise); | |
| 122 | 124 | |
| 123 | 125 | for (int i = 0; i < 4; i++) |
| 124 | 126 | { |
| 125 | − p->biquad[i] = (tBiQuad*) leaf_alloc(sizeof(tBiQuad)); | |
| 126 | − tBiQuad_init(p->biquad[i]); | |
| 127 | + tBiQuad_init(&p->biquad[i]); | |
| 127 | 128 | } |
| 128 | 129 | |
| 129 | 130 | p->pluckAmplitude = 0.3f; |
| @@ -139,14 +140,14 @@ void tStifKarp_init (tStifKarp* const p, float lowestFrequency) · 9 unmodified lines | ||
| 139 | 140 | |
| 140 | 141 | void tStifKarp_free (tStifKarp* const p) |
| 141 | 142 | { |
| 142 | − tDelayA_free(p->delayLine); | |
| 143 | − tDelayL_free(p->combDelay); | |
| 144 | − tOneZero_free(p->filter); | |
| 145 | − tNoise_free(p->noise); | |
| 143 | + tDelayA_free(&p->delayLine); | |
| 144 | + tDelayL_free(&p->combDelay); | |
| 145 | + tOneZero_free(&p->filter); | |
| 146 | + tNoise_free(&p->noise); | |
| 146 | 147 | |
| 147 | 148 | for (int i = 0; i < 4; i++) |
| 148 | 149 | { |
| 149 | − tBiQuad_free(p->biquad[i]); | |
| 150 | + tBiQuad_free(&p->biquad[i]); | |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | leaf_free(p); |
| @@ -159,16 +160,16 @@ float tStifKarp_getLastOut (tStifKarp* const p) · 6 unmodified lines | ||
| 159 | 160 | |
| 160 | 161 | float tStifKarp_tick (tStifKarp* const p) |
| 161 | 162 | { |
| 162 | − float temp = tDelayA_getLastOut(p->delayLine) * p->loopGain; | |
| 163 | + float temp = tDelayA_getLastOut(&p->delayLine) * p->loopGain; | |
| 163 | 164 | |
| 164 | 165 | // Calculate allpass stretching. |
| 165 | − for (int i=0; i<4; i++) temp = tBiQuad_tick(p->biquad[i],temp); | |
| 166 | + for (int i=0; i<4; i++) temp = tBiQuad_tick(&p->biquad[i],temp); | |
| 166 | 167 | |
| 167 | 168 | // Moving average filter. |
| 168 | − temp = tOneZero_tick(p->filter, temp); | |
| 169 | + temp = tOneZero_tick(&p->filter, temp); | |
| 169 | 170 | |
| 170 | − float out = tDelayA_tick(p->delayLine, temp); | |
| 171 | − out = out - tDelayL_tick(p->combDelay, out); | |
| 171 | + float out = tDelayA_tick(&p->delayLine, temp); | |
| 172 | + out = out - tDelayL_tick(&p->combDelay, out); | |
| 172 | 173 | p->lastOut = out; |
| 173 | 174 | |
| 174 | 175 | return p->lastOut; |
| @@ -181,10 +182,10 @@ void tStifKarp_pluck (tStifKarp* const p, float amplitude) · 6 unmodified lines | ||
| 181 | 182 | |
| 182 | 183 | p->pluckAmplitude = amplitude; |
| 183 | 184 | |
| 184 | − for ( uint32_t i=0; i < (uint32_t)tDelayA_getDelay(p->delayLine); i++ ) | |
| 185 | + for ( uint32_t i=0; i < (uint32_t)tDelayA_getDelay(&p->delayLine); i++ ) | |
| 185 | 186 | { |
| 186 | 187 | // Fill delay with noise additively with current contents. |
| 187 | − tDelayA_tick(p->delayLine, (tDelayA_getLastOut(p->delayLine) * 0.6f) + 0.4f * tNoise_tick(p->noise) * p->pluckAmplitude ); | |
| 188 | + tDelayA_tick(&p->delayLine, (tDelayA_getLastOut(&p->delayLine) * 0.6f) + 0.4f * tNoise_tick(&p->noise) * p->pluckAmplitude ); | |
| 188 | 189 | //delayLine_.tick( combDelay_.tick((delayLine_.lastOut() * 0.6) + 0.4 * noise->tick() * pluckAmplitude_) ); |
| 189 | 190 | } |
| 190 | 191 | } |
| @@ -213,7 +214,7 @@ void tStifKarp_setFrequency (tStifKarp* const p, float frequency ) · 22 unmodified lines | ||
| 213 | 214 | p->lastFrequency = frequency; |
| 214 | 215 | p->lastLength = leaf.sampleRate / p->lastFrequency; |
| 215 | 216 | float delay = p->lastLength - 0.5f; |
| 216 | − tDelayA_setDelay(p->delayLine, delay ); | |
| 217 | + tDelayA_setDelay(&p->delayLine, delay); | |
| 217 | 218 | |
| 218 | 219 | // MAYBE MODIFY LOOP GAINS |
| 219 | 220 | p->loopGain = p->baseLoopGain + (frequency * 0.000005f); |
| @@ -221,7 +222,7 @@ void tStifKarp_setFrequency (tStifKarp* const p, float frequency ) · 1 unmodified line | ||
| 221 | 222 | |
| 222 | 223 | tStifKarp_setStretch(p, p->stretching); |
| 223 | 224 | |
| 224 | − tDelayL_setDelay(p->combDelay, 0.5f * p->pickupPosition * p->lastLength ); | |
| 225 | + tDelayL_setDelay(&p->combDelay, 0.5f * p->pickupPosition * p->lastLength ); | |
| 225 | 226 | |
| 226 | 227 | } |
| 227 | 228 | |
| @@ -238,13 +239,13 @@ void tStifKarp_setStretch (tStifKarp* const p, float stretch ) · 10 unmodified lines | ||
| 238 | 239 | for ( int i=0; i<4; i++ ) |
| 239 | 240 | { |
| 240 | 241 | coefficient = temp * temp; |
| 241 | − tBiQuad_setA2(p->biquad[i], coefficient); | |
| 242 | − tBiQuad_setB0(p->biquad[i], coefficient); | |
| 243 | − tBiQuad_setB2(p->biquad[i], 1.0f); | |
| 242 | + tBiQuad_setA2(&p->biquad[i], coefficient); | |
| 243 | + tBiQuad_setB0(&p->biquad[i], coefficient); | |
| 244 | + tBiQuad_setB2(&p->biquad[i], 1.0f); | |
| 244 | 245 | |
| 245 | 246 | coefficient = -2.0f * temp * cos(TWO_PI * freq / leaf.sampleRate); |
| 246 | − tBiQuad_setA1(p->biquad[i], coefficient); | |
| 247 | − tBiQuad_setB1(p->biquad[i], coefficient); | |
| 247 | + tBiQuad_setA1(&p->biquad[i], coefficient); | |
| 248 | + tBiQuad_setB1(&p->biquad[i], coefficient); | |
| 248 | 249 | |
| 249 | 250 | freq += dFreq; |
| 250 | 251 | } |
| @@ -257,7 +258,7 @@ void tStifKarp_setPickupPosition (tStifKarp* const p, float position ) · 6 unmodified lines | ||
| 257 | 258 | else if (position <= 1.0f) p->pickupPosition = position; |
| 258 | 259 | else p->pickupPosition = 1.0f; |
| 259 | 260 | |
| 260 | − tDelayL_setDelay(p->combDelay, 0.5f * p->pickupPosition * p->lastLength); | |
| 261 | + tDelayL_setDelay(&p->combDelay, 0.5f * p->pickupPosition * p->lastLength); | |
| 261 | 262 | } |
| 262 | 263 | |
| 263 | 264 | // Set the base loop gain. |
| @@ -496,7 +496,6 @@ void tADSR_init(tADSR* const adsr, float attack, float decay, float sustain, · 495 unmodified lines | ||
| 496 | 496 | adsr->decayInc = adsr->inc_buff[decayIndex]; |
| 497 | 497 | adsr->releaseInc = adsr->inc_buff[releaseIndex]; |
| 498 | 498 | adsr->rampInc = adsr->inc_buff[rampIndex]; |
| 499 | − | |
| 500 | 499 | } |
| 501 | 500 | |
| 502 | 501 | int tADSR_setAttack(tADSR* const adsr, float attack) |
| @@ -26,18 +26,32 @@ · 25 unmodified lines | ||
| 26 | 26 | * |
| 27 | 27 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 28 | 28 | |
| 29 | −void tTalkbox_init(tTalkbox* const v) | |
| 29 | +void tTalkbox_init(tTalkbox* const v, int bufsize) | |
| 30 | 30 | { |
| 31 | 31 | v->param[0] = 0.5f; //wet |
| 32 | 32 | v->param[1] = 0.0f; //dry |
| 33 | 33 | v->param[2] = 0; // Swap |
| 34 | 34 | v->param[3] = 1.0f; //quality |
| 35 | 35 | |
| 36 | + v->bufsize = bufsize; | |
| 37 | + | |
| 38 | + v->car0 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | |
| 39 | + v->car1 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | |
| 40 | + v->window = (float*) leaf_alloc(sizeof(float) * v->bufsize); | |
| 41 | + v->buf0 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | |
| 42 | + v->buf1 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | |
| 43 | + | |
| 36 | 44 | tTalkbox_update(v); |
| 37 | 45 | } |
| 38 | 46 | |
| 39 | 47 | void tTalkbox_free(tTalkbox* const v) |
| 40 | 48 | { |
| 49 | + leaf_free(v->car0); | |
| 50 | + leaf_free(v->car1); | |
| 51 | + leaf_free(v->window); | |
| 52 | + leaf_free(v->buf0); | |
| 53 | + leaf_free(v->buf1); | |
| 54 | + | |
| 41 | 55 | leaf_free(v); |
| 42 | 56 | } |
| 43 | 57 | |
| @@ -48,7 +62,7 @@ void tTalkbox_update(tTalkbox* const v) ///update internal parameters... · 4 unmodified lines | ||
| 48 | 62 | if(fs > 96000.0f) fs = 96000.0f; |
| 49 | 63 | |
| 50 | 64 | int32_t n = (int32_t)(0.01633f * fs); |
| 51 | − if(n > TALKBOX_BUFFER_LENGTH) n = TALKBOX_BUFFER_LENGTH; | |
| 65 | + if(n > v->bufsize) n = v->bufsize; | |
| 52 | 66 | |
| 53 | 67 | //O = (VstInt32)(0.0005f * fs); |
| 54 | 68 | v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs); |
| @@ -77,7 +91,7 @@ void tTalkbox_suspend(tTalkbox* const v) ///clear any buffers... · 22 unmodified lines | ||
| 77 | 91 | v->u0 = v->u1 = v->u2 = v->u3 = v->u4 = 0.0f; |
| 78 | 92 | v->d0 = v->d1 = v->d2 = v->d3 = v->d4 = 0.0f; |
| 79 | 93 | |
| 80 | − for (int32_t i = 0; i < TALKBOX_BUFFER_LENGTH; i++) | |
| 94 | + for (int32_t i = 0; i < v->bufsize; i++) | |
| 81 | 95 | { |
| 82 | 96 | v->buf0[i] = 0; |
| 83 | 97 | v->buf1[i] = 0; |
| @@ -20,9 +20,9 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | LEAF leaf; |
| 22 | 22 | |
| 23 | −void LEAF_init(float sr, int blocksize, float(*random)(void)) | |
| 23 | +void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void)) | |
| 24 | 24 | { |
| 25 | − leaf_pool_init(MPOOL_POOL_SIZE); | |
| 25 | + leaf_pool_init(memory, memorysize); | |
| 26 | 26 | |
| 27 | 27 | leaf.sampleRate = sr; |
| 28 | 28 | |
| @@ -60,18 +60,13 @@ · 59 unmodified lines | ||
| 60 | 60 | #include "./Inc/leaf-tables.h" |
| 61 | 61 | #include "./Inc/leaf-WDF.h" |
| 62 | 62 | |
| 63 | −#include "main.h" // not sure this is a good idea. not all applications will have a main.h. But doing this for now. It's so that there is a place to put the STM32 define -JS | |
| 64 | − | |
| 65 | − | |
| 66 | 63 | #endif |
| 67 | 64 | |
| 68 | − | |
| 69 | − | |
| 70 | 65 | #ifdef __cplusplus |
| 71 | 66 | extern "C" { |
| 72 | 67 | #endif |
| 73 | 68 | |
| 74 | −void LEAF_init (float sampleRate, int blocksize, float(*randomNumberFunction)(void)); | |
| 69 | +void LEAF_init (float sampleRate, int blocksize, char* memory, size_t memorysize, float(*randomNumberFunction)(void)); | |
| 75 | 70 | void LEAF_setSampleRate (float sampleRate); |
| 76 | 71 | float LEAF_getSampleRate (void); |
| 77 | 72 | |
| @@ -16,68 +16,35 @@ static void leaf_pool_report(void); · 15 unmodified lines | ||
| 16 | 16 | static void leaf_pool_dump(void); |
| 17 | 17 | static void run_pool_test(void); |
| 18 | 18 | |
| 19 | −tWDF r1; | |
| 20 | −tWDF r2; | |
| 21 | −tWDF c1; | |
| 22 | −tWDF c2; | |
| 23 | −tWDF rs1; | |
| 24 | −tWDF p1; | |
| 25 | −tWDF s1; | |
| 26 | −tWDF s2; | |
| 27 | −tWDF i; | |
| 28 | −tWDF d; | |
| 29 | 19 | tNoise noise; |
| 30 | 20 | tCycle sine; |
| 21 | +tDelay delay; | |
| 31 | 22 | |
| 32 | 23 | float gain; |
| 24 | +float freq; | |
| 25 | +float dtime; | |
| 33 | 26 | bool buttonState; |
| 34 | 27 | int ratio = 2; |
| 35 | 28 | |
| 29 | +#define MSIZE 500000 | |
| 30 | +char memory[MSIZE]; | |
| 31 | + | |
| 36 | 32 | void LEAFTest_init (float sampleRate, int blockSize) |
| 37 | 33 | { |
| 38 | − LEAF_init(sampleRate, blockSize, &getRandomFloat); | |
| 34 | + LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat); | |
| 39 | 35 | |
| 40 | 36 | tNoise_init(&noise, WhiteNoise); |
| 41 | 37 | tCycle_init(&sine); |
| 42 | 38 | tCycle_setFreq(&sine, 200); |
| 43 | − | |
| 44 | − //Bandpass circuit 1 | |
| 45 | − //use c1 for output voltage | |
| 46 | −// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL); | |
| 47 | −// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL); | |
| 48 | −// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL); | |
| 49 | −// tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL); | |
| 50 | −// tWDF_init(&p1, ParallelAdaptor, 10000.0f, &r1, &c1); | |
| 51 | −// tWDF_init(&s1, SeriesAdaptor, 0.0f, &c2, &r2); | |
| 52 | −// tWDF_init(&s2, SeriesAdaptor, 0.0f, &s1, &p1); | |
| 53 | − | |
| 54 | − //Bandpass circuit 2 | |
| 55 | −// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL); | |
| 56 | −// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL); | |
| 57 | −// tWDF_init(&s1, SeriesAdaptor, 0.0f, &c1, &r1); | |
| 58 | −// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL); | |
| 59 | −// tWDF_init(&p1, ParallelAdaptor, 10000.0f, &s1, &r2); | |
| 60 | −// tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL); | |
| 61 | −// tWDF_init(&s2, SeriesAdaptor, 0.0f, &c2, &p1); | |
| 62 | − | |
| 63 | −// tWDF_setOutputPoint(&s2, &c1); | |
| 64 | − | |
| 65 | −// tWDFNonlinear_init(&i, IdealSource, &s2); | |
| 66 | − | |
| 67 | − tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL); | |
| 68 | − tWDF_init(&rs1, ResistiveSource, 1.0f, NULL, NULL); | |
| 69 | − tWDF_init(&s1, SeriesAdaptor, 0.0f, &r1, &rs1); | |
| 70 | − tWDF_init(&d, Diode, 0.0f, &s1, NULL); | |
| 71 | − | |
| 72 | − leaf_pool_report(); | |
| 39 | + tDelay_init(&delay, 44100, 44100); | |
| 73 | 40 | } |
| 74 | 41 | |
| 75 | 42 | float LEAFTest_tick (float input) |
| 76 | 43 | { |
| 77 | − float sample = tCycle_tick(&sine) * gain; | |
| 78 | − | |
| 79 | − //tWDF_setValue(&rs1, sample*gain); | |
| 80 | − sample = tWDF_tick(&d, sample, &d, 1); | |
| 44 | + tCycle_setFreq(&sine, freq); | |
| 45 | + float sample = tCycle_tick(&sine) * 0.1; | |
| 46 | + tDelay_setDelay(&delay, dtime); | |
| 47 | + sample += tDelay_tick(&delay, sample); | |
| 81 | 48 | |
| 82 | 49 | return sample; |
| 83 | 50 | } |
| @@ -88,14 +55,10 @@ bool lastState = false, lastPlayState = false; · 4 unmodified lines | ||
| 88 | 55 | void LEAFTest_block (void) |
| 89 | 56 | { |
| 90 | 57 | float val = getSliderValue("mod freq"); |
| 91 | − val = 1.0f + 10000.0f * val; | |
| 92 | − | |
| 93 | − tWDF_setValue(&r1, val); | |
| 58 | + freq = val * 2000.f; | |
| 94 | 59 | |
| 95 | 60 | val = getSliderValue("mod depth"); |
| 96 | − val = 10.0f * val; | |
| 97 | − gain = val; | |
| 98 | − //tWDF_setValue(&r2, val); | |
| 61 | + dtime = val * 40000.; | |
| 99 | 62 | } |
| 100 | 63 | |
| 101 | 64 | void LEAFTest_controllerInput (int cnum, float cval) |