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