History

pass in char* for mempool, updated most objects to use mempool for large/variable size members

Matthew Wang committed 7 years ago

Commit d6d64a91 parent 77f442e29 files · +869 −844Browse files

Unified · Split

29 files
  1. LEAF/Inc/leaf-808.h +27 −27
  2. LEAF/Inc/leaf-WDF.h +1 −0
  3. LEAF/Inc/leaf-formant.h +29 −28
  4. LEAF/Inc/leaf-globals.h +0 −8
  5. LEAF/Inc/leaf-mempool.h +2 −2
  6. LEAF/Inc/leaf-midi.h +10 −8
  7. LEAF/Inc/leaf-oversampler.h +1 −0
  8. LEAF/Inc/leaf-pitch.h +20 −104
  9. LEAF/Inc/leaf-reverb.h +74 −74
  10. LEAF/Inc/leaf-sample.h +1 −1
  11. LEAF/Inc/leaf-string.h +25 −25
  12. LEAF/Inc/leaf-utilities.h +82 −0
  13. LEAF/Inc/leaf-vocoder.h +17 −16
  14. LEAF/Inc/leaf-wavefolder.h +0 −10
  15. LEAF/Src/leaf-WDF.c +28 −8
  16. LEAF/Src/leaf-filter.c +6 −2
  17. LEAF/Src/leaf-formant.c +36 −7
  18. LEAF/Src/leaf-mempool.c +12 −17
  19. LEAF/Src/leaf-midi.c +63 −42
  20. LEAF/Src/leaf-oversampler.c +8 −1
  21. LEAF/Src/leaf-pitch.c +2 −3
  22. LEAF/Src/leaf-reverb.c +297 −305
  23. LEAF/Src/leaf-sample.c +47 −47
  24. LEAF/Src/leaf-string.c +47 −46
  25. LEAF/Src/leaf-utilities.c +0 −1
  26. LEAF/Src/leaf-vocoder.c +17 −3
  27. LEAF/Src/leaf.c +2 −2
  28. LEAF/leaf.h +1 −6
  29. LEAF_JUCEPlugin/Source/MyTest.cpp +14 −51
LEAF/Inc/leaf-808.h+27−27
@@ -4,25 +4,25 @@ · 3 unmodified lines
44 Created: 30 Nov 2018 10:24:44am
55 Author: airship
66
7−==============================================================================*/
8−
9−#ifndef LEAF_808_H_INCLUDED
10−#define LEAF_808_H_INCLUDED
11−
12−#ifdef __cplusplus
13−extern "C" {
14−#endif
15−
16−//==============================================================================
7+==============================================================================*/
8+
9+#ifndef LEAF_808_H_INCLUDED
10+#define LEAF_808_H_INCLUDED
11+
12+#ifdef __cplusplus
13+extern "C" {
14+#endif
15+
16+//==============================================================================
1717
1818 #include "leaf-globals.h"
1919 #include "leaf-math.h"
2020
2121 #include "leaf-oscillator.h"
2222 #include "leaf-utilities.h"
23−#include "leaf-filter.h"
24−
25−//==============================================================================
23+#include "leaf-filter.h"
24+
25+//==============================================================================
2626
2727 // 808 Cowbell
2828 typedef struct _t808Cowbell {
@@ -50,7 +50,7 @@ void t808Cowbell_setBandpassFreq (t808Cowbell* const, float freq); · 21 unmodified lines
5050 void t808Cowbell_setFreq (t808Cowbell* const, float freq);
5151 void t808Cowbell_setOscMix (t808Cowbell* const, float oscMix);
5252
53−//==============================================================================
53+//==============================================================================
5454
5555 // 808 Hihat
5656 typedef struct _t808Hihat {
@@ -88,8 +88,8 @@ void t808Hihat_setStickBandPassQ (t808Hihat* const hihat, float Q); · 31 unmodified lines
8888 void t808Hihat_setOscFreq (t808Hihat* const, float freq);
8989 void t808Hihat_setStretch (t808Hihat* const hihat, float stretch);
9090 void t808Hihat_setFM (t808Hihat* const hihat, float FM_amount);
91−
92−//==============================================================================
91+
92+//==============================================================================
9393
9494 // 808 Snare
9595 typedef struct _t808Snare {
@@ -131,7 +131,7 @@ void t808Snare_setToneNoiseMix (t808Snare* const, float toneNoiseMi · 35 unmodified lines
131131 void t808Snare_setNoiseFilterFreq (t808Snare* const, float noiseFilterFreq);
132132 void t808Snare_setNoiseFilterQ (t808Snare* const, float noiseFilterQ);
133133
134−//==============================================================================
134+//==============================================================================
135135
136136 // 808 Kick
137137 typedef struct _t808Kick {
@@ -169,16 +169,16 @@ void t808Kick_setSighAmount (t808Kick* const, float sigh); · 31 unmodified lines
169169 void t808Kick_setChirpAmount (t808Kick* const, float chirp);
170170 void t808Kick_setToneNoiseMix (t808Kick* const, float toneNoiseMix);
171171 void t808Kick_setNoiseFilterFreq (t808Kick* const, float noiseFilterFreq);
172−void t808Kick_setNoiseFilterQ (t808Kick* const, float noiseFilterQ);
173−
174−//==============================================================================
175−
176−#ifdef __cplusplus
177−}
178−#endif
179−
180−#endif // LEAF_808_H_INCLUDED
181−
172+void t808Kick_setNoiseFilterQ (t808Kick* const, float noiseFilterQ);
173+
174+//==============================================================================
175+
176+#ifdef __cplusplus
177+}
178+#endif
179+
180+#endif // LEAF_808_H_INCLUDED
181+
182182 //==============================================================================
183183
184184
LEAF/Inc/leaf-WDF.h+1−0
@@ -64,6 +64,7 @@ struct _tWDF · 63 unmodified lines
6464
6565 //WDF Linear Components
6666 void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR);
67+void tWDF_free(tWDF* const r);
6768 float tWDF_tick(tWDF* const r, float sample, tWDF* const outputPoint, uint8_t paramsChanged);
6869
6970 void tWDF_setValue(tWDF* const r, float value);
LEAF/Inc/leaf-formant.h+29−28
@@ -4,21 +4,21 @@ · 3 unmodified lines
44 Created: 30 Nov 2018 11:03:37am
55 Author: airship
66
7−==============================================================================*/
8−
9−#ifndef LEAF_FORMANT_H_INCLUDED
10−#define LEAF_FORMANT_H_INCLUDED
11−
12−#ifdef __cplusplus
13−extern "C" {
7+==============================================================================*/
8+
9+#ifndef LEAF_FORMANT_H_INCLUDED
10+#define LEAF_FORMANT_H_INCLUDED
11+
12+#ifdef __cplusplus
13+extern "C" {
1414 #endif
1515
16−//==============================================================================
16+//==============================================================================
1717
1818 #include "leaf-globals.h"
1919 #include "leaf-math.h"
2020
21−//==============================================================================
21+//==============================================================================
2222
2323 #define FORD 7
2424 #define FORMANT_BUFFER_SIZE 2048
@@ -26,41 +26,42 @@ extern "C" { · 1 unmodified line
2626 typedef struct _tFormantShifter
2727 {
2828 int ford;
29+ int bufsize;
2930 float falph;
3031 float flamb;
31− float fk[FORD];
32− float fb[FORD];
33− float fc[FORD];
34− float frb[FORD];
35− float frc[FORD];
36− float fsig[FORD];
37− float fsmooth[FORD];
32+ float* fk;
33+ float* fb;
34+ float* fc;
35+ float* frb;
36+ float* frc;
37+ float* fsig;
38+ float* fsmooth;
3839 float fhp;
3940 float flp;
4041 float flpa;
41− float fbuff[FORD][FORMANT_BUFFER_SIZE];
42− float ftvec[FORD];
42+ float** fbuff;
43+ float* ftvec;
4344 float fmute;
4445 float fmutealph;
4546 unsigned int cbi;
4647
4748 } tFormantShifter;
4849
49−void tFormantShifter_init (tFormantShifter* const);
50+void tFormantShifter_init (tFormantShifter* const, int bufsize, int order);
5051 void tFormantShifter_free (tFormantShifter* const);
5152
5253 float tFormantShifter_tick (tFormantShifter* const, float input, float fwarp);
5354 float tFormantShifter_remove (tFormantShifter* const, float input);
5455 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);
5657
57−//==============================================================================
58−
59−#ifdef __cplusplus
60−}
61−#endif
62−
63−#endif // LEAF_FORMANT_H_INCLUDED
64−
58+//==============================================================================
59+
60+#ifdef __cplusplus
61+}
62+#endif
63+
64+#endif // LEAF_FORMANT_H_INCLUDED
65+
6566 //==============================================================================
6667
LEAF/Inc/leaf-globals.h+0−8
@@ -41,17 +41,9 @@ extern LEAF leaf; // The global instance of LEAF. · 40 unmodified lines
4141
4242 //==============================================================================
4343
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)
4944 #define PS_FRAME_SIZE 1024 // SNAC_FRAME_SIZE in leaf-pitch.h should match (or be smaller than?) this
5045 #define ENV_WINDOW_SIZE 1024
5146 #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.
5547
5648 union unholy_t { /* a union between a float and an integer */
5749 float f;
LEAF/Inc/leaf-mempool.h+2−2
@@ -75,7 +75,7 @@ typedef struct mpool_t { · 74 unmodified lines
7575 int next;
7676 } mpool_t;
7777
78−void mpool_create (size_t size, mpool_t* pool);
78+void mpool_create (char* memory, size_t size, mpool_t* pool);
7979
8080 void *mpool_alloc(size_t size, mpool_t* pool);
8181 void mpool_free(void* ptr, mpool_t* pool);
@@ -84,7 +84,7 @@ size_t mpool_get_size(mpool_t* pool); · 2 unmodified lines
8484 size_t mpool_get_used(mpool_t* pool);
8585
8686
87−void leaf_pool_init(size_t size);
87+void leaf_pool_init(char* memory, size_t size);
8888
8989 void* leaf_alloc(size_t size);
9090 void leaf_free(void* ptr);
LEAF/Inc/leaf-midi.h+10−8
@@ -25,18 +25,20 @@ extern "C" { · 24 unmodified lines
2525 /* tPoly */
2626 typedef struct _tPoly
2727 {
28− tStack* stack;
29− tStack* orderStack;
28+ tStack stack;
29+ tStack orderStack;
3030
31− tRamp* ramp[POLY_NUM_MAX_VOICES];
32− float rampVals[POLY_NUM_MAX_VOICES];
33− oBool firstReceived[POLY_NUM_MAX_VOICES];
31+ tRamp* ramp;
32+ float* rampVals;
33+ oBool* firstReceived;
3434 float glideTime;
3535 oBool pitchGlideIsActive;
3636
3737 int numVoices;
38+ int maxNumVoices;
3839
39− int voices[POLY_NUM_MAX_VOICES][2];
40+ //int voices[POLY_NUM_MAX_VOICES][2];
41+ int** voices;
4042
4143 int notes[128][2];
4244
@@ -47,7 +49,7 @@ typedef struct _tPoly · 4 unmodified lines
4749 int lastVoiceToChange;
4850
4951 float pitchBend;
50− tRamp* pitchBendRamp;
52+ tRamp pitchBendRamp;
5153
5254 int currentNote;
5355 int currentVoice;
@@ -57,7 +59,7 @@ typedef struct _tPoly · 3 unmodified lines
5759 } tPoly;
5860
5961 /* MPoly*/
60−void tPoly_init(tPoly* const, int numVoices);
62+void tPoly_init(tPoly* const, int maxNumVoices);
6163 void tPoly_free(tPoly* const);
6264
6365 //ADDING A NOTE
LEAF/Inc/leaf-oversampler.h+1−0
@@ -33,6 +33,7 @@ typedef struct _tOversampler · 32 unmodified lines
3333 } tOversampler;
3434
3535 void tOversampler_init(tOversampler* const, int order, oBool extraQuality);
36+void tOversampler_free(tOversampler* const);
3637 void tOversampler_upsample(tOversampler* const, float input, float* output);
3738 float tOversampler_downsample(tOversampler *const os, float* input);
3839 float tOversampler_tick(tOversampler* const, float input, float (*effectTick)(float));
LEAF/Inc/leaf-pitch.h+20−104
@@ -6,13 +6,13 @@ · 5 unmodified lines
66 Author: airship
77
88 ==============================================================================
9−*/
10−
11−#ifndef LEAF_PITCH_H_INCLUDED
12−#define LEAF_PITCH_H_INCLUDED
13−
14−#ifdef __cplusplus
15−extern "C" {
9+*/
10+
11+#ifndef LEAF_PITCH_H_INCLUDED
12+#define LEAF_PITCH_H_INCLUDED
13+
14+#ifdef __cplusplus
15+extern "C" {
1616 #endif
1717
1818 //==============================================================================
@@ -22,8 +22,8 @@ extern "C" { · 3 unmodified lines
2222
2323 #include "leaf-filter.h"
2424 #include "leaf-utilities.h"
25−#include "leaf.h"
26−//==============================================================================
25+#include "../leaf.h"
26+//==============================================================================
2727
2828 #define DEFPITCHRATIO 2.0f
2929 #define DEFTIMECONSTANT 100.0f
@@ -32,92 +32,8 @@ extern "C" { · 2 unmodified lines
3232 #define FBA 20
3333 #define HPFREQ 40.0f
3434
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);
6535
66−// set periodicity analysis data
67−void tSOLAD_setPeriod (tSOLAD *w, float period);
68−
69−// set pitch factor between 0.25 and 4
70−void tSOLAD_setPitchFactor (tSOLAD *w, float pitchfactor);
71−
72−// force readpointer lag
73−void tSOLAD_setReadLag (tSOLAD *w, float readlag);
74−
75−// reset state variables
76−void tSOLAD_resetState (tSOLAD *w);
77−
78−//==============================================================================
79−
80−// tSNAC: period detector
81−#define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE
82−#define DEFOVERLAP 1 // default overlap
83−#define DEFBIAS 0.2f // default bias
84−#define DEFMINRMS 0.003f // default minimum RMS
85−#define SEEK 0.85f // seek-length as ratio of framesize
86−
87−typedef struct _tSNAC
88−{
89− float* inputbuf;
90− float* processbuf;
91− float* spectrumbuf;
92− float* biasbuf;
93− uint16_t timeindex;
94− uint16_t framesize;
95− uint16_t overlap;
96− uint16_t periodindex;
97−
98− float periodlength;
99− float fidelity;
100− float biasfactor;
101− float minrms;
102−
103−} tSNAC;
104−
105−
106−
107−
108−void tSNAC_init (tSNAC* const, int overlaparg); // constructor
109−void tSNAC_free (tSNAC* const); // destructor
110−
111−void tSNAC_ioSamples (tSNAC *s, float *in, float *out, int size);
112−void tSNAC_setOverlap (tSNAC *s, int lap);
113−void tSNAC_setBias (tSNAC *s, float bias);
114−void tSNAC_setMinRMS (tSNAC *s, float rms);
115−
116−/*To get freq, perform SAMPLE_RATE/snac_getperiod() */
117−float tSNAC_getPeriod (tSNAC *s);
118−float tSNAC_getfidelity (tSNAC *s);
119−
120−//==============================================================================
36+//==============================================================================
12137
12238 // Pitch shifter
12339 typedef struct _tPitchShifter
@@ -164,7 +80,7 @@ void tPitchShifter_setHopSize (tPitchShifter* const, int hs); · 40 unmodified lines
16480 void tPitchShifter_setWindowSize (tPitchShifter* const, int ws);
16581 float tPitchShifter_getPeriod (tPitchShifter* const);
16682
167−//==============================================================================
83+//==============================================================================
16884
16985 // Period detection
17086 typedef struct _tPeriod
@@ -203,7 +119,7 @@ float tPeriod_findPeriod (tPeriod* const, float sample); · 32 unmodified lines
203119 void tPeriod_setHopSize (tPeriod* p, int hs);
204120 void tPeriod_setWindowSize (tPeriod* p, int ws);
205121
206−//==============================================================================
122+//==============================================================================
207123
208124 // Pitch shift
209125 typedef struct _tPitchShift
@@ -234,12 +150,12 @@ float tPitchShift_shiftToFunc (tPitchShift* const, float (*fun)(fl · 24 unmodified lines
234150 float tPitchShift_shiftToFreq (tPitchShift* const, float freq);
235151 void tPitchShift_setPitchFactor (tPitchShift* const, float pf);
236152
237−//==============================================================================
238−
239−#ifdef __cplusplus
240−}
241−#endif
242−
243−#endif // LEAF_PITCH_H_INCLUDED
244−
153+//==============================================================================
154+
155+#ifdef __cplusplus
156+}
157+#endif
158+
159+#endif // LEAF_PITCH_H_INCLUDED
160+
245161 //==============================================================================
LEAF/Inc/leaf-reverb.h+74−74
@@ -7,22 +7,22 @@ · 6 unmodified lines
77 ==============================================================================*/
88
99 #ifndef LEAF_REVERB_H_INCLUDED
10−#define LEAF_REVERB_H_INCLUDED
11−
12−#ifdef __cplusplus
13−extern "C" {
10+#define LEAF_REVERB_H_INCLUDED
11+
12+#ifdef __cplusplus
13+extern "C" {
1414 #endif
1515
16−//==============================================================================
16+//==============================================================================
1717
1818 #include "leaf-globals.h"
1919 #include "leaf-math.h"
2020
21−#include "leaf-delay.h"
22−#include "leaf-filter.h"
21+#include "leaf-delay.h"
22+#include "leaf-filter.h"
2323 #include "leaf-oscillator.h"
2424
25−//==============================================================================
25+//==============================================================================
2626
2727 /* PRCRev: Reverb, reimplemented from STK (Cook and Scavone). */
2828 typedef struct _tPRCRev
@@ -31,8 +31,8 @@ typedef struct _tPRCRev · 2 unmodified lines
3131
3232 float inv_441;
3333
34− tDelay* allpassDelays[2];
35− tDelay* combDelay;
34+ tDelay allpassDelays[2];
35+ tDelay combDelay;
3636 float allpassCoeff;
3737 float combCoeff;
3838
@@ -60,8 +60,8 @@ typedef struct _tNRev · 21 unmodified lines
6060
6161 float inv_sr, inv_441;
6262
63− tDelay* allpassDelays[8];
64− tDelay* combDelays[6];
63+ tDelay allpassDelays[8];
64+ tDelay combDelays[6];
6565 float allpassCoeff;
6666 float combCoeffs[6];
6767 float lowpassState;
@@ -81,68 +81,68 @@ void tNRev_setT60 (tNRev* const, float t60); · 13 unmodified lines
8181 // Set mix between dry input and wet output signal.
8282 void tNRev_setMix (tNRev* const, float mix);
8383
84−//==============================================================================
85−
86−typedef struct _tDattorro
87−{
88− float predelay;
89− float input_filter;
90− float feedback_filter;
91− float feedback_gain;
92− float mix;
93−
94−
95− float size, size_max, t;
96−
97− float f1_delay_2_last,
98− f2_delay_2_last;
99−
100− float f1_last,
101− f2_last;
102−
103− // INPUT
104− tTapeDelay in_delay;
105− tOnePole in_filter;
106− tAllpass in_allpass[4];
107−
108− // FEEDBACK 1
109− tAllpass f1_allpass;
110− tTapeDelay f1_delay_1;
111− tOnePole f1_filter;
112− tTapeDelay f1_delay_2;
113− tTapeDelay f1_delay_3;
114− tHighpass f1_hp;
115−
116− tCycle f1_lfo;
117−
118− // FEEDBACK 2
119− tAllpass f2_allpass;
120− tTapeDelay f2_delay_1;
121− tOnePole f2_filter;
122− tTapeDelay f2_delay_2;
123− tTapeDelay f2_delay_3;
124− tHighpass f2_hp;
125−
126− tCycle f2_lfo;
127−
128−} tDattorro;
129−
130−void tDattorro_init (tDattorro* const);
131−void tDattorro_free (tDattorro* const);
132−
133−float tDattorro_tick (tDattorro* const, float input);
134−
135−void tDattorro_setMix (tDattorro* const, float mix);
136−void tDattorro_setSize (tDattorro* const, float size);
137−void tDattorro_setInputDelay (tDattorro* const, float preDelay);
138−void tDattorro_setInputFilter (tDattorro* const, float freq);
139−void tDattorro_setFeedbackFilter (tDattorro* const, float freq);
140−void tDattorro_setFeedbackGain (tDattorro* const, float gain);
141−
142−#ifdef __cplusplus
143−}
84+//==============================================================================
85+
86+typedef struct _tDattorro
87+{
88+ float predelay;
89+ float input_filter;
90+ float feedback_filter;
91+ float feedback_gain;
92+ float mix;
93+
94+
95+ float size, size_max, t;
96+
97+ float f1_delay_2_last,
98+ f2_delay_2_last;
99+
100+ float f1_last,
101+ f2_last;
102+
103+ // INPUT
104+ tTapeDelay in_delay;
105+ tOnePole in_filter;
106+ tAllpass in_allpass[4];
107+
108+ // FEEDBACK 1
109+ tAllpass f1_allpass;
110+ tTapeDelay f1_delay_1;
111+ tOnePole f1_filter;
112+ tTapeDelay f1_delay_2;
113+ tTapeDelay f1_delay_3;
114+ tHighpass f1_hp;
115+
116+ tCycle f1_lfo;
117+
118+ // FEEDBACK 2
119+ tAllpass f2_allpass;
120+ tTapeDelay f2_delay_1;
121+ tOnePole f2_filter;
122+ tTapeDelay f2_delay_2;
123+ tTapeDelay f2_delay_3;
124+ tHighpass f2_hp;
125+
126+ tCycle f2_lfo;
127+
128+} tDattorro;
129+
130+void tDattorro_init (tDattorro* const);
131+void tDattorro_free (tDattorro* const);
132+
133+float tDattorro_tick (tDattorro* const, float input);
134+
135+void tDattorro_setMix (tDattorro* const, float mix);
136+void tDattorro_setSize (tDattorro* const, float size);
137+void tDattorro_setInputDelay (tDattorro* const, float preDelay);
138+void tDattorro_setInputFilter (tDattorro* const, float freq);
139+void tDattorro_setFeedbackFilter (tDattorro* const, float freq);
140+void tDattorro_setFeedbackGain (tDattorro* const, float gain);
141+
142+#ifdef __cplusplus
143+}
144144 #endif
145145
146−#endif // LEAF_REVERB_H_INCLUDED
147−
146+#endif // LEAF_REVERB_H_INCLUDED
147+
148148 //==============================================================================
LEAF/Inc/leaf-sample.h+1−1
@@ -95,7 +95,7 @@ extern "C" { · 94 unmodified lines
9595
9696 } tSampler;
9797
98− void tSampler_init (tSampler* const, tBuffer* s);
98+ void tSampler_init (tSampler* const, tBuffer* const);
9999 void tSampler_free (tSampler* const);
100100
101101 float tSampler_tick (tSampler* const);
LEAF/Inc/leaf-string.h+25−25
@@ -7,13 +7,13 @@ · 6 unmodified lines
77
88 ==============================================================================
99 */
10−
11−#ifndef LEAF_STRING_H_INCLUDED
12−#define LEAF_STRING_H_INCLUDED
13−
14−#ifdef __cplusplus
15−extern "C" {
16−#endif
10+
11+#ifndef LEAF_STRING_H_INCLUDED
12+#define LEAF_STRING_H_INCLUDED
13+
14+#ifdef __cplusplus
15+extern "C" {
16+#endif
1717
1818 //==============================================================================
1919
@@ -29,10 +29,10 @@ extern "C" { · 9 unmodified lines
2929 /* Karplus Strong model */
3030 typedef struct _tPluck
3131 {
32− tDelayA* delayLine; // Allpass or Linear?? big difference...
33− tOneZero* loopFilter;
34− tOnePole* pickFilter;
35− tNoise* noise;
32+ tDelayA delayLine; // Allpass or Linear?? big difference...
33+ tOneZero loopFilter;
34+ tOnePole pickFilter;
35+ tNoise noise;
3636
3737 float lastOut;
3838 float loopGain;
@@ -65,16 +65,16 @@ void tPluck_controlChange (tPluck* const, int number, float value); · 26 unmodified lines
6565 // tPluck Utilities.
6666 float tPluck_getLastOut (tPluck* const);
6767
68−//==============================================================================
68+//==============================================================================
6969
7070 /* Stif Karplus Strong model */
7171 typedef struct _tStifKarp
7272 {
73− tDelayA* delayLine;
74− tDelayL* combDelay;
75− tOneZero* filter;
76− tNoise* noise;
77− tBiQuad* biquad[4];
73+ tDelayA delayLine;
74+ tDelayL combDelay;
75+ tOneZero filter;
76+ tNoise noise;
77+ tBiQuad biquad[4];
7878
7979
8080
@@ -132,12 +132,12 @@ void tStifKarp_setBaseLoopGain (tStifKarp* const, float aGain ); · 51 unmodified lines
132132 // tStifKarp utilities.
133133 float tStifKarp_getLastOut (tStifKarp* const);
134134
135−//==============================================================================
136−
137−#ifdef __cplusplus
138−}
139−#endif
140−
141−#endif // LEAF_STRING_H_INCLUDED
142−
135+//==============================================================================
136+
137+#ifdef __cplusplus
138+}
139+#endif
140+
141+#endif // LEAF_STRING_H_INCLUDED
142+
143143 //==============================================================================
LEAF/Inc/leaf-utilities.h+82−0
@@ -389,6 +389,88 @@ void tEnv_free (tEnv* const); · 388 unmodified lines
389389 float tEnv_tick (tEnv* const);
390390 void tEnv_processBlock (tEnv* const, float* in);
391391
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+
392474 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
393475
394476 #ifdef __cplusplus
LEAF/Inc/leaf-vocoder.h+17−16
@@ -7,10 +7,10 @@ · 6 unmodified lines
77 ==============================================================================*/
88
99 #ifndef LEAF_VOCODER_H_INCLUDED
10−#define LEAF_VOCODER_H_INCLUDED
11−
12−#ifdef __cplusplus
13−extern "C" {
10+#define LEAF_VOCODER_H_INCLUDED
11+
12+#ifdef __cplusplus
13+extern "C" {
1414 #endif
1515
1616 //==============================================================================
@@ -22,16 +22,17 @@ extern "C" { · 5 unmodified lines
2222
2323 /* tTalkbox */
2424 #define NUM_TALKBOX_PARAM 4
25−#define TALKBOX_BUFFER_LENGTH 1024 // Every talkbox instance introduces 5 buffers of this size - was originally 1600
2625
2726 typedef struct _tTalkbox
2827 {
2928 float param[NUM_TALKBOX_PARAM];
3029
31− ///global internal variables
32− float car0[TALKBOX_BUFFER_LENGTH], car1[TALKBOX_BUFFER_LENGTH];
33− float window[TALKBOX_BUFFER_LENGTH];
34− float buf0[TALKBOX_BUFFER_LENGTH], buf1[TALKBOX_BUFFER_LENGTH];
30+ int bufsize;
31+ float* car0;
32+ float* car1;
33+ float* window;
34+ float* buf0;
35+ float* buf1;
3536
3637 float emphasis;
3738 int32_t K, N, O, pos;
@@ -41,7 +42,7 @@ typedef struct _tTalkbox · 3 unmodified lines
4142
4243 } tTalkbox;
4344
44−void tTalkbox_init (tTalkbox* const);
45+void tTalkbox_init (tTalkbox* const, int bufsize);
4546 void tTalkbox_free (tTalkbox* const);
4647 float tTalkbox_tick (tTalkbox* const, float synth, float voice);
4748 void tTalkbox_update (tTalkbox* const);
@@ -78,11 +79,11 @@ void tVocoder_update (tVocoder* const); · 30 unmodified lines
7879 void tVocoder_suspend (tVocoder* const);
7980
8081 //==============================================================================
81−
82−#ifdef __cplusplus
83−}
84−#endif
82+
83+#ifdef __cplusplus
84+}
85+#endif
8586
86−#endif // LEAF_VOCODER_H_INCLUDED
87−
87+#endif // LEAF_VOCODER_H_INCLUDED
88+
8889 //==============================================================================
LEAF/Inc/leaf-wavefolder.h+0−10
@@ -22,16 +22,6 @@ extern "C" { · 21 unmodified lines
2222 //==============================================================================
2323
2424 /* 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
3525
3626 typedef struct _tLockhartWavefolder
3727 {
LEAF/Src/leaf-WDF.c+28−8
@@ -32,6 +32,7 @@ static float get_reflected_wave_for_parallel(tWDF* const r, float input); · 31 unmodified lines
3232
3333 static float get_reflected_wave_for_ideal(tWDF* const n, float input, float incident_wave);
3434 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);
3536
3637 //WDF
3738 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
143144 }
144145 else if (r->type == DiodePair)
145146 {
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;
147152 }
148153 }
149154
155+void tWDF_free(tWDF* const r)
156+{
157+ leaf_free(r);
158+}
159+
150160 float tWDF_tick(tWDF* const r, float sample, tWDF* const outputPoint, uint8_t paramsChanged)
151161 {
152162 tWDF* child;
@@ -315,11 +325,13 @@ static void set_incident_wave_for_leaf_inverted(tWDF* const r, float incident_wa · 162 unmodified lines
315325
316326 static void set_incident_wave_for_inverter(tWDF* const r, float incident_wave, float input)
317327 {
328+ r->incident_wave_up = incident_wave;
318329 tWDF_setIncidentWave(r->child_left, -1.0f * incident_wave, input);
319330 }
320331
321332 static void set_incident_wave_for_series(tWDF* const r, float incident_wave, float input)
322333 {
334+ r->incident_wave_up = incident_wave;
323335 float gamma_left = r->port_resistance_left * r->gamma_zero;
324336 float gamma_right = r->port_resistance_right * r->gamma_zero;
325337 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
336348
337349 static void set_incident_wave_for_parallel(tWDF* const r, float incident_wave, float input)
338350 {
351+ r->incident_wave_up = incident_wave;
339352 float gamma_left = r->port_conductance_left * r->gamma_zero;
340353 float gamma_right = r->port_conductance_right * r->gamma_zero;
341354 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
376389 static float get_reflected_wave_for_series(tWDF* const r, float input)
377390 {
378391 //-( 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;
380394 }
381395
382396 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
384398 float gamma_left = r->port_conductance_left * r->gamma_zero;
385399 float gamma_right = r->port_conductance_right * r->gamma_zero;
386400 //return ( dl * downPorts[0]->a + dr * downPorts[1]->a );
387− return (gamma_left * tWDF_getReflectedWaveUp(r->child_left, input) + gamma_right * tWDF_getReflectedWaveUp(r->child_right, input));
388−}
389−
390−float tWDFNonlinear_getReflectedWaveDown(tWDF* const n, float input, float incident_wave)
391−{
392− return n->get_reflected_wave_down(n, input, incident_wave);
401+ r->reflected_wave_up = (gamma_left * tWDF_getReflectedWaveUp(r->child_left, input) + gamma_right * tWDF_getReflectedWaveUp(r->child_right, input));
402+ return r->reflected_wave_up;
393403 }
394404
395405 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
447457 float r = n->port_resistance_up;
448458 return a + 2.0f*r*Is_DIODE - 2.0f*VT_DIODE*lambertW(a, r, Is_DIODE, 1.0f/VT_DIODE);
449459 }
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+}
LEAF/Src/leaf-filter.c+6−2
@@ -821,8 +821,8 @@ int tSVFE_setQ(tSVFE* const svf, float Q) · 820 unmodified lines
821821 }
822822
823823 void tFIR_init(tFIR* const fir, float* coeffs, int numTaps){
824− fir->coeff = coeffs;
825824 fir->numTaps = numTaps;
825+ fir->coeff = coeffs;
826826 fir->past = (float*)leaf_alloc(sizeof(float) * fir->numTaps);
827827 for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f;
828828 }
@@ -835,4 +835,8 @@ float tFIR_tick(tFIR* const fir, float input){ · 6 unmodified lines
835835 return y;
836836 }
837837
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+}
LEAF/Src/leaf-formant.c+36−7
@@ -16,9 +16,26 @@ · 15 unmodified lines
1616 #endif
1717
1818
19−void tFormantShifter_init(tFormantShifter* const fs)
19+void tFormantShifter_init(tFormantShifter* const fs, int bufsize, int order)
2020 {
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+
2239 fs->falph = powf(0.001f, 80.0f / (leaf.sampleRate));
2340 fs->flamb = -(0.8517f*sqrt(atanf(0.06583f*leaf.sampleRate))-0.1916f);
2441 fs->fhp = 0.0f;
@@ -31,6 +48,20 @@ void tFormantShifter_init(tFormantShifter* const fs) · 6 unmodified lines
3148
3249 void tFormantShifter_free(tFormantShifter* const fs)
3350 {
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+
3465 leaf_free(fs);
3566 }
3667
@@ -42,8 +73,7 @@ float tFormantShifter_tick(tFormantShifter* fs, float in, float fwarp) · 5 unmodified lines
4273
4374 float tFormantShifter_remove(tFormantShifter* fs, float in)
4475 {
45− float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk, tf2, f0resp, f1resp, frlamb;
46− int outindex = 0;
76+ float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk;
4777 int ti4;
4878 ford = fs->ford;
4979 falph = fs->falph;
@@ -73,7 +103,7 @@ float tFormantShifter_remove(tFormantShifter* fs, float in) · 23 unmodified lines
73103 fa = fa - tf*fc;
74104 }
75105 fs->cbi++;
76− if(fs->cbi >= FORMANT_BUFFER_SIZE)
106+ if(fs->cbi >= fs->bufsize)
77107 {
78108 fs->cbi = 0;
79109 }
@@ -83,8 +113,7 @@ float tFormantShifter_remove(tFormantShifter* fs, float in) · 3 unmodified lines
83113
84114 float tFormantShifter_add(tFormantShifter* fs, float in, float fwarp)
85115 {
86− float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk, tf2, f0resp, f1resp, frlamb;
87− int outindex = 0;
116+ float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb;
88117 int ti4;
89118 ford = fs->ford;
90119 falph = fs->falph;
LEAF/Src/leaf-mempool.c+12−17
@@ -36,24 +36,21 @@ · 35 unmodified lines
3636
3737 /* written with C99 style */
3838
39+#if _WIN32 || _WIN64
3940
40−#include "../Inc/leaf-mempool.h"
41−#include "leaf.h"
42−#define NUM_BLOCKS 50
41+#include "..\Inc\leaf-mempool.h"
42+#include "..\leaf.h"
4343
44−#ifdef STM32
44+#else
4545
46−char memory[MPOOL_POOL_SIZE] __ATTR_RAM_D2;
46+#include "../Inc/leaf-mempool.h"
47+#include "../leaf.h"
4748
48−#else
49−char memory[MPOOL_POOL_SIZE];
5049 #endif
5150
51+#define NUM_BLOCKS 50
5252
5353 mpool_pool_t blocks[NUM_BLOCKS];
54−
55−
56− //
5754 mpool_t leaf_pool;
5855
5956 /**
@@ -65,10 +62,8 @@ static inline size_t mpool_align(size_t size); · 5 unmodified lines
6562 /**
6663 * create memory pool
6764 */
68−void mpool_create (size_t size, mpool_t* pool)
65+void mpool_create (char* memory, size_t size, mpool_t* pool)
6966 {
70− if (size > MPOOL_POOL_SIZE) size = MPOOL_POOL_SIZE;
71−
7267 pool->mpool = &blocks[0];
7368
7469 pool->mpool->pool = (void*)memory;
@@ -78,12 +73,12 @@ void mpool_create (size_t size, mpool_t* pool) · 3 unmodified lines
7873 pool->usize = 0;
7974 pool->msize = size;
8075
81− for (int i = 0; i < MPOOL_POOL_SIZE; i++) memory[i]=0;
76+ for (int i = 0; i < size; i++) memory[i]=0;
8277 }
8378
84−void leaf_pool_init(size_t size)
79+void leaf_pool_init(char* memory, size_t size)
8580 {
86− mpool_create(size, &leaf_pool);
81+ mpool_create(memory, size, &leaf_pool);
8782 }
8883
8984 /**
@@ -195,7 +190,7 @@ size_t leaf_pool_get_used(void) · 105 unmodified lines
195190
196191 void* leaf_pool_get_pool(void)
197192 {
198− float* buff = (float*)memory;
193+ float* buff = (float*)leaf_pool.mpool->pool;
199194
200195 return buff;
201196 }
LEAF/Src/leaf-midi.c+63−42
@@ -17,9 +17,10 @@ · 16 unmodified lines
1717 #endif
1818
1919 // POLY
20−void tPoly_init(tPoly* const poly, int numVoices)
20+void tPoly_init(tPoly* const poly, int maxNumVoices)
2121 {
22− poly->numVoices = numVoices;
22+ poly->numVoices = maxNumVoices;
23+ poly->maxNumVoices = maxNumVoices;
2324 poly->lastVoiceToChange = 0;
2425
2526 // Arp mode stuff
@@ -35,29 +36,49 @@ void tPoly_init(tPoly* const poly, int numVoices) · 9 unmodified lines
3536 }
3637
3738 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)
3946 {
47+ poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2);
4048 poly->voices[i][0] = -1;
4149 poly->firstReceived[i] = OFALSE;
4250
43− poly->ramp[i] = (tRamp*) leaf_alloc(sizeof(tRamp));
44−
45− tRamp_init(poly->ramp[i], poly->glideTime, 1);
51+ tRamp_init(&poly->ramp[i], poly->glideTime, 1);
4652 }
4753
4854 poly->pitchBend = 0.0f;
49− poly->pitchBendRamp = (tRamp*) leaf_alloc(sizeof(tRamp));
50− tRamp_init(poly->pitchBendRamp, 1.0f, 1);
5155
52− poly->stack = (tStack*) leaf_alloc(sizeof(tStack));
53− tStack_init(poly->stack);
54−
55− poly->orderStack = (tStack*) leaf_alloc(sizeof(tStack));
56− tStack_init(poly->orderStack);
56+ tRamp_init(&poly->pitchBendRamp, 1.0f, 1);
57+ tStack_init(&poly->stack);
58+ tStack_init(&poly->orderStack);
5759
5860 poly->pitchGlideIsActive = OFALSE;
5961 }
6062
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+
6182 void tPoly_tickPitch(tPoly* poly)
6283 {
6384 tPoly_tickPitchGlide(poly);
@@ -66,32 +87,32 @@ void tPoly_tickPitch(tPoly* poly) · 2 unmodified lines
6687
6788 void tPoly_tickPitchGlide(tPoly* poly)
6889 {
69− for (int i = 0; i < POLY_NUM_MAX_VOICES; ++i)
90+ for (int i = 0; i < poly->maxNumVoices; ++i)
7091 {
71− tRamp_tick(poly->ramp[i]);
92+ tRamp_tick(&poly->ramp[i]);
7293 }
7394 }
7495
7596 void tPoly_tickPitchBend(tPoly* poly)
7697 {
77− tRamp_tick(poly->pitchBendRamp);
98+ tRamp_tick(&poly->pitchBendRamp);
7899 }
79100
80101 //instead of including in dacsend, should have a separate pitch bend ramp, that is added when the ramps are ticked and sent to DAC
81102 void tPoly_setPitchBend(tPoly* const poly, float pitchBend)
82103 {
83104 poly->pitchBend = pitchBend;
84− tRamp_setDest(poly->pitchBendRamp, poly->pitchBend);
105+ tRamp_setDest(&poly->pitchBendRamp, poly->pitchBend);
85106 }
86107
87108 int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel)
88109 {
89110 // 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;
91112 else
92113 {
93114 tPoly_orderedAddToStack(poly, note);
94− tStack_add(poly->stack, note);
115+ tStack_add(&poly->stack, note);
95116
96117 int alteredVoice = -1;
97118 oBool found = OFALSE;
@@ -101,7 +122,7 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 3 unmodified lines
101122 {
102123 if (!poly->firstReceived[i] || !poly->pitchGlideIsActive)
103124 {
104− tRamp_setVal(poly->ramp[i], note);
125+ tRamp_setVal(&poly->ramp[i], note);
105126 poly->firstReceived[i] = OTRUE;
106127 }
107128
@@ -113,7 +134,7 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 5 unmodified lines
113134 poly->notes[note][0] = vel;
114135 poly->notes[note][1] = i;
115136
116− tRamp_setDest(poly->ramp[i], poly->voices[i][0]);
137+ tRamp_setDest(&poly->ramp[i], poly->voices[i][0]);
117138
118139 alteredVoice = i;
119140 break;
@@ -123,9 +144,9 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 3 unmodified lines
123144 if (!found) //steal
124145 {
125146 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--)
127148 {
128− whichNote = tStack_get(poly->stack, j);
149+ whichNote = tStack_get(&poly->stack, j);
129150 whichVoice = poly->notes[whichNote][1];
130151 if (whichVoice >= 0)
131152 {
@@ -137,8 +158,8 @@ int tPoly_noteOn(tPoly* const poly, int note, uint8_t vel) · 5 unmodified lines
137158 poly->notes[note][0] = vel;
138159 poly->notes[note][1] = whichVoice;
139160
140− tRamp_setTime(poly->ramp[whichVoice], poly->glideTime);
141− tRamp_setDest(poly->ramp[whichVoice], poly->voices[whichVoice][0]);
161+ tRamp_setTime(&poly->ramp[whichVoice], poly->glideTime);
162+ tRamp_setDest(&poly->ramp[whichVoice], poly->voices[whichVoice][0]);
142163
143164 alteredVoice = whichVoice;
144165
@@ -155,8 +176,8 @@ int16_t noteToTest = -1; · 10 unmodified lines
155176
156177 int tPoly_noteOff(tPoly* const poly, uint8_t note)
157178 {
158− tStack_remove(poly->stack, note);
159− tStack_remove(poly->orderStack, note);
179+ tStack_remove(&poly->stack, note);
180+ tStack_remove(&poly->orderStack, note);
160181 poly->notes[note][0] = 0;
161182 poly->notes[note][1] = -1;
162183
@@ -186,14 +207,14 @@ int tPoly_noteOff(tPoly* const poly, uint8_t note) · 23 unmodified lines
186207 //grab old notes off the stack if there are notes waiting to replace the free voice
187208 if (deactivatedVoice >= 0)
188209 {
189− for (int j = 0; j < tStack_getSize(poly->stack); ++j)
210+ for (int j = 0; j < tStack_getSize(&poly->stack); ++j)
190211 {
191− noteToTest = tStack_get(poly->stack, j);
212+ noteToTest = tStack_get(&poly->stack, j);
192213
193214 if (poly->notes[noteToTest][1] < 0) //if there is a stolen note waiting (marked inactive but on the stack)
194215 {
195216 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]);
197218 poly->voices[deactivatedVoice][1] = poly->notes[noteToTest][0]; // set the velocity of the voice to be the velocity of that note
198219 poly->notes[noteToTest][1] = deactivatedVoice; //mark that it is no longer stolen and is now active
199220 return -1;
@@ -209,15 +230,15 @@ void tPoly_orderedAddToStack(tPoly* const poly, uint8_t noteVal) · 9 unmodified lines
209230 uint8_t j;
210231 int myPitch, thisPitch, nextPitch;
211232
212− tStack* ns = poly->orderStack;
233+ tStack ns = poly->orderStack;
213234
214235 int whereToInsert = 0;
215236
216− for (j = 0; j < ns->size; j++)
237+ for (j = 0; j < ns.size; j++)
217238 {
218239 myPitch = noteVal;
219− thisPitch = ns->data[j];
220− nextPitch = ns->data[j+1];
240+ thisPitch = ns.data[j];
241+ nextPitch = ns.data[j+1];
221242
222243 if (myPitch > thisPitch)
223244 {
@@ -230,21 +251,21 @@ void tPoly_orderedAddToStack(tPoly* const poly, uint8_t noteVal) · 6 unmodified lines
230251 }
231252
232253 //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--)
234255 {
235− ns->data[j] = ns->data[(j - 1)];
256+ ns.data[j] = ns.data[(j - 1)];
236257 }
237258
238259 //then, insert the new note into the front of the stack
239− ns->data[whereToInsert] = noteVal;
260+ ns.data[whereToInsert] = noteVal;
240261
241− ns->size++;
262+ ns.size++;
242263
243264 }
244265
245266 void tPoly_setNumVoices(tPoly* const poly, uint8_t numVoices)
246267 {
247− poly->numVoices = (numVoices > POLY_NUM_MAX_VOICES) ? POLY_NUM_MAX_VOICES : numVoices;
268+ poly->numVoices = (numVoices > poly->maxNumVoices) ? poly->maxNumVoices : numVoices;
248269 }
249270
250271 void tPoly_setPitchGlideActive(tPoly* const poly, oBool isActive)
@@ -255,9 +276,9 @@ void tPoly_setPitchGlideActive(tPoly* const poly, oBool isActive) · 4 unmodified lines
255276 void tPoly_setPitchGlideTime(tPoly* const poly, float t)
256277 {
257278 poly->glideTime = t;
258− for (int i = 0; i < POLY_NUM_MAX_VOICES; ++i)
279+ for (int i = 0; i < poly->maxNumVoices; ++i)
259280 {
260− tRamp_setTime(poly->ramp[i], poly->glideTime);
281+ tRamp_setTime(&poly->ramp[i], poly->glideTime);
261282 }
262283 }
263284
@@ -268,7 +289,7 @@ int tPoly_getNumVoices(tPoly* const poly) · 4 unmodified lines
268289
269290 float tPoly_getPitch(tPoly* const poly, uint8_t voice)
270291 {
271− return tRamp_sample(poly->ramp[voice]) + tRamp_sample(poly->pitchBendRamp);
292+ return tRamp_sample(&poly->ramp[voice]) + tRamp_sample(&poly->pitchBendRamp);
272293 }
273294
274295 int tPoly_getKey(tPoly* const poly, uint8_t voice)
LEAF/Src/leaf-oversampler.c+8−1
@@ -31,12 +31,19 @@ void tOversampler_init(tOversampler* const os, int ratio, oBool extraQuality) · 30 unmodified lines
3131 int idx = (int)(log2f(os->ratio))-1+offset;
3232 os->numTaps = firNumTaps[idx];
3333 os->phaseLength = os->numTaps / os->ratio;
34− os->pCoeffs = firCoeffs[idx];
34+ os->pCoeffs = (float*) firCoeffs[idx];
3535 os->upState = leaf_alloc(sizeof(float) * os->phaseLength);
3636 os->downState = leaf_alloc(sizeof(float) * os->phaseLength);
3737 }
3838 }
3939
40+void tOversampler_free(tOversampler* const os)
41+{
42+ leaf_free(os->upState);
43+ leaf_free(os->downState);
44+ leaf_free(os);
45+}
46+
4047 float tOversampler_tick(tOversampler* const os, float input, float (*effectTick)(float))
4148 {
4249 float buf[os->ratio];
LEAF/Src/leaf-pitch.c+2−3
@@ -354,7 +354,7 @@ void tPeriod_init (tPeriod* const p, float* in, float* out, int bufSize, · 353 unmodified lines
354354
355355 p->hopSize = DEFHOPSIZE;
356356 p->windowSize = DEFWINDOWSIZE;
357− p->fba = FBA;
357+ p->fba = FBA;
358358
359359 tEnv_init(&p->env, p->windowSize, p->hopSize, p->frameSize);
360360
@@ -374,7 +374,6 @@ void tPeriod_free (tPeriod* const p) · 13 unmodified lines
374374
375375 float tPeriod_findPeriod (tPeriod* p, float sample)
376376 {
377− float period;
378377 int i, iLast;
379378
380379 i = (p->curBlock*p->frameSize);
@@ -460,7 +459,7 @@ void tPitchShift_init (tPitchShift* const ps, tPeriod* p, float* out, int bufSiz · 79 unmodified lines
460459 ps->index = 0;
461460 ps->pitchFactor = 1.0f;
462461
463− tSOLAD_init(&ps->sola);
462+ tSOLAD_init(&ps->sola);
464463
465464 tHighpass_init(&ps->hp, HPFREQ);
466465
LEAF/Src/leaf-reverb.c+297−305
@@ -43,14 +43,9 @@ void tPRCRev_init(tPRCRev* const r, float t60) · 42 unmodified lines
4343 }
4444 }
4545
46− r->allpassDelays[0] = (tDelay*) leaf_alloc(sizeof(tDelay));
47− tDelay_init(r->allpassDelays[0], lengths[0], lengths[0] * 2);
48−
49− r->allpassDelays[1] = (tDelay*) leaf_alloc(sizeof(tDelay));
50− tDelay_init(r->allpassDelays[1], lengths[1], lengths[1] * 2);
51−
52− r->combDelay = (tDelay*) leaf_alloc(sizeof(tDelay));
53− tDelay_init(r->combDelay, lengths[2], lengths[2] * 2);
46+ tDelay_init(&r->allpassDelays[0], lengths[0], lengths[0] * 2);
47+ tDelay_init(&r->allpassDelays[1], lengths[1], lengths[1] * 2);
48+ tDelay_init(&r->combDelay, lengths[2], lengths[2] * 2);
5449
5550 tPRCRev_setT60(r, t60);
5651
@@ -60,9 +55,9 @@ void tPRCRev_init(tPRCRev* const r, float t60) · 3 unmodified lines
6055
6156 void tPRCRev_free(tPRCRev* const r)
6257 {
63− tDelay_free(r->allpassDelays[0]);
64− tDelay_free(r->allpassDelays[1]);
65− tDelay_free(r->combDelay);
58+ tDelay_free(&r->allpassDelays[0]);
59+ tDelay_free(&r->allpassDelays[1]);
60+ tDelay_free(&r->combDelay);
6661 leaf_free(r);
6762 }
6863
@@ -72,7 +67,7 @@ void tPRCRev_setT60(tPRCRev* const r, float t60) · 3 unmodified lines
7267
7368 r->t60 = t60;
7469
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 ));
7671
7772 }
7873
@@ -88,21 +83,21 @@ float tPRCRev_tick(tPRCRev* const r, float input) · 9 unmodified lines
8883
8984 r->lastIn = input;
9085
91− temp = tDelay_getLastOut(r->allpassDelays[0]);
86+ temp = tDelay_getLastOut(&r->allpassDelays[0]);
9287 temp0 = r->allpassCoeff * temp;
9388 temp0 += input;
94− tDelay_tick(r->allpassDelays[0], temp0);
89+ tDelay_tick(&r->allpassDelays[0], temp0);
9590 temp0 = -( r->allpassCoeff * temp0) + temp;
9691
97− temp = tDelay_getLastOut(r->allpassDelays[1]);
92+ temp = tDelay_getLastOut(&r->allpassDelays[1]);
9893 temp1 = r->allpassCoeff * temp;
9994 temp1 += temp0;
100− tDelay_tick(r->allpassDelays[1], temp1);
95+ tDelay_tick(&r->allpassDelays[1], temp1);
10196 temp1 = -(r->allpassCoeff * temp1) + temp;
10297
103− temp2 = temp1 + ( r->combCoeff * tDelay_getLastOut(r->combDelay));
98+ temp2 = temp1 + ( r->combCoeff * tDelay_getLastOut(&r->combDelay));
10499
105− out = r->mix * tDelay_tick(r->combDelay, temp2);
100+ out = r->mix * tDelay_tick(&r->combDelay, temp2);
106101
107102 temp = (1.0f - r->mix) * input;
108103
@@ -115,7 +110,7 @@ float tPRCRev_tick(tPRCRev* const r, float input) · 6 unmodified lines
115110
116111 void tPRCRevSampleRateChanged (tPRCRev* const r)
117112 {
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 ));
119114 }
120115
121116 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NRev ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
@@ -142,21 +137,18 @@ void tNRev_init(tNRev* const r, float t60) · 20 unmodified lines
142137
143138 for ( i=0; i<6; i++ )
144139 {
145− r->combDelays[i] = (tDelay*) leaf_alloc(sizeof(tDelay));
146− tDelay_init(r->combDelays[i], lengths[i], lengths[i] * 2.0f);
140+ tDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f);
147141 r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60));
148142 }
149143
150144 for ( i=0; i<8; i++ )
151145 {
152− r->allpassDelays[i] = (tDelay*) leaf_alloc(sizeof(tDelay));
153− tDelay_init(r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f);
146+ tDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f);
154147 }
155148
156149 for ( i=0; i<2; i++ )
157150 {
158− tDelay_setDelay(r->allpassDelays[i], lengths[i]);
159− tDelay_setDelay(r->combDelays[i], lengths[i+2]);
151+ tDelay_setDelay(&r->combDelays[i], lengths[i+2]);
160152 }
161153
162154 tNRev_setT60(r, t60);
@@ -168,12 +160,12 @@ void tNRev_free(tNRev* const r) · 5 unmodified lines
168160 {
169161 for (int i = 0; i < 6; i++)
170162 {
171− tDelay_free(r->combDelays[i]);
163+ tDelay_free(&r->combDelays[i]);
172164 }
173165
174166 for (int i = 0; i < 8; i++)
175167 {
176− tDelay_free(r->allpassDelays[i]);
168+ tDelay_free(&r->allpassDelays[i]);
177169 }
178170
179171 leaf_free(r);
@@ -185,7 +177,7 @@ void tNRev_setT60(tNRev* const r, float t60) · 5 unmodified lines
185177
186178 r->t60 = t60;
187179
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 ));
189181
190182 }
191183
@@ -204,31 +196,31 @@ float tNRev_tick(tNRev* const r, float input) · 12 unmodified lines
204196 temp0 = 0.0;
205197 for ( i=0; i<6; i++ )
206198 {
207− temp = input + (r->combCoeffs[i] * tDelay_getLastOut(r->combDelays[i]));
208− temp0 += tDelay_tick(r->combDelays[i],temp);
199+ temp = input + (r->combCoeffs[i] * tDelay_getLastOut(&r->combDelays[i]));
200+ temp0 += tDelay_tick(&r->combDelays[i],temp);
209201 }
210202
211203 for ( i=0; i<3; i++ )
212204 {
213− temp = tDelay_getLastOut(r->allpassDelays[i]);
205+ temp = tDelay_getLastOut(&r->allpassDelays[i]);
214206 temp1 = r->allpassCoeff * temp;
215207 temp1 += temp0;
216− tDelay_tick(r->allpassDelays[i], temp1);
208+ tDelay_tick(&r->allpassDelays[i], temp1);
217209 temp0 = -(r->allpassCoeff * temp1) + temp;
218210 }
219211
220212 // One-pole lowpass filter.
221213 r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0;
222− temp = tDelay_getLastOut(r->allpassDelays[3]);
214+ temp = tDelay_getLastOut(&r->allpassDelays[3]);
223215 temp1 = r->allpassCoeff * temp;
224216 temp1 += r->lowpassState;
225− tDelay_tick(r->allpassDelays[3], temp1 );
217+ tDelay_tick(&r->allpassDelays[3], temp1 );
226218 temp1 = -(r->allpassCoeff * temp1) + temp;
227219
228− temp = tDelay_getLastOut(r->allpassDelays[4]);
220+ temp = tDelay_getLastOut(&r->allpassDelays[4]);
229221 temp2 = r->allpassCoeff * temp;
230222 temp2 += temp1;
231− tDelay_tick(r->allpassDelays[4], temp2 );
223+ tDelay_tick(&r->allpassDelays[4], temp2 );
232224 out = r->mix * ( -( r->allpassCoeff * temp2 ) + temp );
233225
234226 /*
@@ -246,275 +238,275 @@ float tNRev_tick(tNRev* const r, float input) · 11 unmodified lines
246238 r->lastOut = out;
247239
248240 return out;
249−}
241+}
250242
251243 void tNRevSampleRateChanged (tNRev* const r)
252244 {
253− for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
254−}
255−
256−// ======================================DATTORRO=========================================
257−
258−#define SAMP(in) (in*r->t)
259−
260−float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f };
261−float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f };
262−
263−
264−void tDattorro_init (tDattorro* const r)
265−{
266− r->size_max = 2.0f;
267− r->size = 1.f;
268− r->t = r->size * leaf.sampleRate * 0.001f;
269−
270− // INPUT
271− tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f));
272− tOnePole_init(&r->in_filter, 1.f);
273−
274− for (int i = 0; i < 4; i++)
275− {
276− tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max
277− tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
278− }
279−
280− // FEEDBACK 1
281− tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max
282− tAllpass_setGain(&r->f1_allpass, 0.7f);
283−
284− tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1);
285− tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1);
286− tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1);
287−
288− tOnePole_init(&r->f1_filter, 1.f);
289−
290− tHighpass_init(&r->f1_hp, 20.f);
291−
292− tCycle_init(&r->f1_lfo);
293− tCycle_setFreq(&r->f1_lfo, 0.1f);
294−
295− // FEEDBACK 2
296− tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max
297− tAllpass_setGain(&r->f2_allpass, 0.7f);
298−
299− tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1);
300− tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1);
301− tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1);
302−
303− tOnePole_init(&r->f2_filter, 1.f);
304−
305− tHighpass_init(&r->f2_hp, 20.f);
306−
307− tCycle_init(&r->f2_lfo);
308− tCycle_setFreq(&r->f2_lfo, 0.07f);
309−
310−
311− // PARAMETERS
312− tDattorro_setMix(r, 0.5f);
313−
314− tDattorro_setInputDelay(r, 0.f);
315−
316− tDattorro_setInputFilter(r, 10000.f);
317−
318− tDattorro_setFeedbackFilter(r, 5000.f);
319−
320− tDattorro_setFeedbackGain(r, 0.4f);
321−
322−
323−}
324−
325−void tDattorro_free (tDattorro* const r)
326−{
327− // INPUT
328− tTapeDelay_free(&r->in_delay);
329− tOnePole_free(&r->in_filter);
330−
331− for (int i = 0; i < 4; i++)
332− {
333− tAllpass_free(&r->in_allpass[i]);
334− }
335−
336− // FEEDBACK 1
337− tAllpass_free(&r->f1_allpass);
338−
339− tTapeDelay_free(&r->f1_delay_1);
340− tTapeDelay_free(&r->f1_delay_2);
341− tTapeDelay_free(&r->f1_delay_3);
342−
343− tOnePole_free(&r->f1_filter);
344−
345− tCycle_free(&r->f1_lfo);
346−
347− // FEEDBACK 2
348− tAllpass_free(&r->f2_allpass);
349−
350− tTapeDelay_free(&r->f2_delay_1);
351− tTapeDelay_free(&r->f2_delay_2);
352− tTapeDelay_free(&r->f2_delay_3);
353−
354− tOnePole_free(&r->f2_filter);
355−
356− tCycle_free(&r->f2_lfo);
357−
358− leaf_free(r);
359−}
360−
361−float tDattorro_tick (tDattorro* const r, float input)
362−{
363− // INPUT
364− float in_sample = tTapeDelay_tick(&r->in_delay, input);
365−
366− in_sample = tOnePole_tick(&r->in_filter, in_sample);
367−
368− for (int i = 0; i < 4; i++)
369− {
370− in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
371− }
372−
373− // FEEDBACK 1
374− float f1_sample = in_sample + r->f2_last; // + f2_last_out;
375−
376− tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
377−
378− f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
379−
380− f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
381−
382− f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
383−
384− f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
385−
386− float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
387−
388− r->f1_delay_2_last = f1_delay_2_sample;
389−
390− f1_sample = r->f1_delay_2_last + f1_sample;
391−
392− f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
393−
394− f1_sample *= r->feedback_gain;
395−
396− r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
397−
398− // FEEDBACK 2
399− float f2_sample = in_sample + r->f1_last;
400−
401− tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
402−
403− f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
404−
405− f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
406−
407− f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
408−
409− f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
410−
411− float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
412−
413− r->f2_delay_2_last = f2_delay_2_sample;
414−
415− f2_sample = r->f2_delay_2_last + f2_sample;
416−
417− f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
418−
419− f2_sample *= r->feedback_gain;
420−
421− r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
422−
423−
424− // TAP OUT 1
425− f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) +
426− tTapeDelay_tapOut(&r->f1_delay_1, SAMP(99.8f));
427−
428− f1_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(64.2f));
429−
430− f1_sample += tTapeDelay_tapOut(&r->f1_delay_3, SAMP(67.f));
431−
432− f1_sample -= tTapeDelay_tapOut(&r->f2_delay_1, SAMP(66.8f));
433−
434− f1_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
435−
436− f1_sample -= tTapeDelay_tapOut(&r->f2_delay_3, SAMP(35.8f));
437−
438− f1_sample *= 0.14f;
439−
440− // TAP OUT 2
441− f2_sample = tTapeDelay_tapOut(&r->f2_delay_1, SAMP(11.8f)) +
442− tTapeDelay_tapOut(&r->f2_delay_1, SAMP(121.7f));
443−
444− f2_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
445−
446− f2_sample += tTapeDelay_tapOut(&r->f2_delay_3, SAMP(89.7f));
447−
448− f2_sample -= tTapeDelay_tapOut(&r->f1_delay_1, SAMP(70.8f));
449−
450− f2_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(11.2f));
451−
452− f2_sample -= tTapeDelay_tapOut(&r->f1_delay_3, SAMP(4.1f));
453−
454− f2_sample *= 0.14f;
455−
456− float sample = (f1_sample + f2_sample) * 0.5f;
457−
458− return (input * (1.0f - r->mix) + sample * r->mix);
459−}
460−
461−void tDattorro_setMix (tDattorro* const r, float mix)
462−{
463− r->mix = LEAF_clip(0.0f, mix, 1.0f);
464−}
465−
466−void tDattorro_setSize (tDattorro* const r, float size)
467−{
468− r->size = LEAF_clip(0.01f, size*r->size_max, r->size_max);
469− r->t = r->size * leaf.sampleRate * 0.001f;
470−
471− /*
472− for (int i = 0; i < 4; i++)
473− {
474− tAllpass_setDelay(&r->in_allpass[i], SAMP(in_allpass_delays[i]));
475− }
476− */
477−
478− // FEEDBACK 1
479− //tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f));
480−
481− tTapeDelay_setDelay(&r->f1_delay_1, SAMP(141.69f));
482− tTapeDelay_setDelay(&r->f1_delay_2, SAMP(89.24f));
483− tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f));
484−
485− // maybe change rate of SINE LFO's when size changes?
486−
487− // FEEDBACK 2
488− //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f));
489−
490− tTapeDelay_setDelay(&r->f2_delay_1, SAMP(149.62f));
491− tTapeDelay_setDelay(&r->f2_delay_2, SAMP(60.48f));
492− tTapeDelay_setDelay(&r->f2_delay_3, SAMP(106.28f));
493−}
494−
495−void tDattorro_setInputDelay (tDattorro* const r, float preDelay)
496−{
497− r->predelay = LEAF_clip(0.0f, preDelay, 200.0f);
498−
499− tTapeDelay_setDelay(&r->in_delay, SAMP(r->predelay));
500−}
501−
502−void tDattorro_setInputFilter (tDattorro* const r, float freq)
503−{
504− r->input_filter = LEAF_clip(0.0f, freq, 20000.0f);
505−
506− tOnePole_setFreq(&r->in_filter, r->input_filter);
507−}
508−
509−void tDattorro_setFeedbackFilter (tDattorro* const r, float freq)
510−{
511− r->feedback_filter = LEAF_clip(0.0f, freq, 20000.0f);
512−
513− tOnePole_setFreq(&r->f1_filter, r->feedback_filter);
514− tOnePole_setFreq(&r->f2_filter, r->feedback_filter);
515−}
516−
517−void tDattorro_setFeedbackGain (tDattorro* const r, float gain)
518−{
519− r->feedback_gain = gain;
520−}
245+ for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
246+}
247+
248+// ======================================DATTORRO=========================================
249+
250+#define SAMP(in) (in*r->t)
251+
252+float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f };
253+float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f };
254+
255+
256+void tDattorro_init (tDattorro* const r)
257+{
258+ r->size_max = 2.0f;
259+ r->size = 1.f;
260+ r->t = r->size * leaf.sampleRate * 0.001f;
261+
262+ // INPUT
263+ tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f));
264+ tOnePole_init(&r->in_filter, 1.f);
265+
266+ for (int i = 0; i < 4; i++)
267+ {
268+ tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max
269+ tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
270+ }
271+
272+ // FEEDBACK 1
273+ tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max
274+ tAllpass_setGain(&r->f1_allpass, 0.7f);
275+
276+ tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1);
277+ tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1);
278+ tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1);
279+
280+ tOnePole_init(&r->f1_filter, 1.f);
281+
282+ tHighpass_init(&r->f1_hp, 20.f);
283+
284+ tCycle_init(&r->f1_lfo);
285+ tCycle_setFreq(&r->f1_lfo, 0.1f);
286+
287+ // FEEDBACK 2
288+ tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max
289+ tAllpass_setGain(&r->f2_allpass, 0.7f);
290+
291+ tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1);
292+ tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1);
293+ tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1);
294+
295+ tOnePole_init(&r->f2_filter, 1.f);
296+
297+ tHighpass_init(&r->f2_hp, 20.f);
298+
299+ tCycle_init(&r->f2_lfo);
300+ tCycle_setFreq(&r->f2_lfo, 0.07f);
301+
302+
303+ // PARAMETERS
304+ tDattorro_setMix(r, 0.5f);
305+
306+ tDattorro_setInputDelay(r, 0.f);
307+
308+ tDattorro_setInputFilter(r, 10000.f);
309+
310+ tDattorro_setFeedbackFilter(r, 5000.f);
311+
312+ tDattorro_setFeedbackGain(r, 0.4f);
313+
314+
315+}
316+
317+void tDattorro_free (tDattorro* const r)
318+{
319+ // INPUT
320+ tTapeDelay_free(&r->in_delay);
321+ tOnePole_free(&r->in_filter);
322+
323+ for (int i = 0; i < 4; i++)
324+ {
325+ tAllpass_free(&r->in_allpass[i]);
326+ }
327+
328+ // FEEDBACK 1
329+ tAllpass_free(&r->f1_allpass);
330+
331+ tTapeDelay_free(&r->f1_delay_1);
332+ tTapeDelay_free(&r->f1_delay_2);
333+ tTapeDelay_free(&r->f1_delay_3);
334+
335+ tOnePole_free(&r->f1_filter);
336+
337+ tCycle_free(&r->f1_lfo);
338+
339+ // FEEDBACK 2
340+ tAllpass_free(&r->f2_allpass);
341+
342+ tTapeDelay_free(&r->f2_delay_1);
343+ tTapeDelay_free(&r->f2_delay_2);
344+ tTapeDelay_free(&r->f2_delay_3);
345+
346+ tOnePole_free(&r->f2_filter);
347+
348+ tCycle_free(&r->f2_lfo);
349+
350+ leaf_free(r);
351+}
352+
353+float tDattorro_tick (tDattorro* const r, float input)
354+{
355+ // INPUT
356+ float in_sample = tTapeDelay_tick(&r->in_delay, input);
357+
358+ in_sample = tOnePole_tick(&r->in_filter, in_sample);
359+
360+ for (int i = 0; i < 4; i++)
361+ {
362+ in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
363+ }
364+
365+ // FEEDBACK 1
366+ float f1_sample = in_sample + r->f2_last; // + f2_last_out;
367+
368+ tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
369+
370+ f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
371+
372+ f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
373+
374+ f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
375+
376+ f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
377+
378+ float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
379+
380+ r->f1_delay_2_last = f1_delay_2_sample;
381+
382+ f1_sample = r->f1_delay_2_last + f1_sample;
383+
384+ f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
385+
386+ f1_sample *= r->feedback_gain;
387+
388+ r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
389+
390+ // FEEDBACK 2
391+ float f2_sample = in_sample + r->f1_last;
392+
393+ tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
394+
395+ f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
396+
397+ f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
398+
399+ f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
400+
401+ f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
402+
403+ float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
404+
405+ r->f2_delay_2_last = f2_delay_2_sample;
406+
407+ f2_sample = r->f2_delay_2_last + f2_sample;
408+
409+ f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
410+
411+ f2_sample *= r->feedback_gain;
412+
413+ r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
414+
415+
416+ // TAP OUT 1
417+ f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) +
418+ tTapeDelay_tapOut(&r->f1_delay_1, SAMP(99.8f));
419+
420+ f1_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(64.2f));
421+
422+ f1_sample += tTapeDelay_tapOut(&r->f1_delay_3, SAMP(67.f));
423+
424+ f1_sample -= tTapeDelay_tapOut(&r->f2_delay_1, SAMP(66.8f));
425+
426+ f1_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
427+
428+ f1_sample -= tTapeDelay_tapOut(&r->f2_delay_3, SAMP(35.8f));
429+
430+ f1_sample *= 0.14f;
431+
432+ // TAP OUT 2
433+ f2_sample = tTapeDelay_tapOut(&r->f2_delay_1, SAMP(11.8f)) +
434+ tTapeDelay_tapOut(&r->f2_delay_1, SAMP(121.7f));
435+
436+ f2_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
437+
438+ f2_sample += tTapeDelay_tapOut(&r->f2_delay_3, SAMP(89.7f));
439+
440+ f2_sample -= tTapeDelay_tapOut(&r->f1_delay_1, SAMP(70.8f));
441+
442+ f2_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(11.2f));
443+
444+ f2_sample -= tTapeDelay_tapOut(&r->f1_delay_3, SAMP(4.1f));
445+
446+ f2_sample *= 0.14f;
447+
448+ float sample = (f1_sample + f2_sample) * 0.5f;
449+
450+ return (input * (1.0f - r->mix) + sample * r->mix);
451+}
452+
453+void tDattorro_setMix (tDattorro* const r, float mix)
454+{
455+ r->mix = LEAF_clip(0.0f, mix, 1.0f);
456+}
457+
458+void tDattorro_setSize (tDattorro* const r, float size)
459+{
460+ r->size = LEAF_clip(0.01f, size*r->size_max, r->size_max);
461+ r->t = r->size * leaf.sampleRate * 0.001f;
462+
463+ /*
464+ for (int i = 0; i < 4; i++)
465+ {
466+ tAllpass_setDelay(&r->in_allpass[i], SAMP(in_allpass_delays[i]));
467+ }
468+ */
469+
470+ // FEEDBACK 1
471+ //tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f));
472+
473+ tTapeDelay_setDelay(&r->f1_delay_1, SAMP(141.69f));
474+ tTapeDelay_setDelay(&r->f1_delay_2, SAMP(89.24f));
475+ tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f));
476+
477+ // maybe change rate of SINE LFO's when size changes?
478+
479+ // FEEDBACK 2
480+ //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f));
481+
482+ tTapeDelay_setDelay(&r->f2_delay_1, SAMP(149.62f));
483+ tTapeDelay_setDelay(&r->f2_delay_2, SAMP(60.48f));
484+ tTapeDelay_setDelay(&r->f2_delay_3, SAMP(106.28f));
485+}
486+
487+void tDattorro_setInputDelay (tDattorro* const r, float preDelay)
488+{
489+ r->predelay = LEAF_clip(0.0f, preDelay, 200.0f);
490+
491+ tTapeDelay_setDelay(&r->in_delay, SAMP(r->predelay));
492+}
493+
494+void tDattorro_setInputFilter (tDattorro* const r, float freq)
495+{
496+ r->input_filter = LEAF_clip(0.0f, freq, 20000.0f);
497+
498+ tOnePole_setFreq(&r->in_filter, r->input_filter);
499+}
500+
501+void tDattorro_setFeedbackFilter (tDattorro* const r, float freq)
502+{
503+ r->feedback_filter = LEAF_clip(0.0f, freq, 20000.0f);
504+
505+ tOnePole_setFreq(&r->f1_filter, r->feedback_filter);
506+ tOnePole_setFreq(&r->f2_filter, r->feedback_filter);
507+}
508+
509+void tDattorro_setFeedbackGain (tDattorro* const r, float gain)
510+{
511+ r->feedback_gain = gain;
512+}
LEAF/Src/leaf-sample.c+47−47
@@ -106,7 +106,7 @@ void tBuffer_clear (tBuffer* const s) · 105 unmodified lines
106106
107107 //================================tSampler=====================================
108108
109−void tSampler_init (tSampler* const p, tBuffer* s)
109+void tSampler_init(tSampler* const p, tBuffer* const s)
110110 {
111111 p->samp = s;
112112
@@ -135,7 +135,7 @@ void tSampler_init (tSampler* const p, tBuffer* s) · 22 unmodified lines
135135
136136 void tSampler_free (tSampler* const p)
137137 {
138− leaf_free(p->samp);
138+ tRamp_free(&p->gain);
139139 leaf_free(p);
140140 }
141141
@@ -178,52 +178,52 @@ float tSampler_tick (tSampler* const p) · 36 unmodified lines
178178 end = p->start;
179179 }
180180
181− // Check dir (direction) to interpolate properly
182− if (dir > 0)
183− {
184− // FORWARD NORMAL SAMPLE
185− int i1 = ((idx-1) + p->len) % p->len;
186− int i3 = (idx+1) % p->len;
187− int i4 = (idx+2) % p->len;
188−
189− sample = LEAF_interpolate_hermite (buff[i1],
190− buff[idx],
191− buff[i3],
192− buff[i4],
193− alpha);
194−
195− // num samples to end of loop
196− numsamps = (idx - start) / p->inc;
197− //numsamps = (dir > 0) ? (end - idx) : (idx - start);
198− //numsamps *= p->iinc;
199−
200− if (p->mode == PlayLoop)
201− {
202− if (numsamps <= p->cfxlen)
203− {
204− // CROSSFADE SAMPLE
205− float idxx = p->idx - p->len;
206− int cdx = ((int)(idxx) + p->len) % p->len;
207−
208− i1 = ((cdx-1) + p->len) % p->len;
209− i3 = (cdx+1) % p->len;
210− i4 = (cdx+2) % p->len;
211−
212− cfxsample = LEAF_interpolate_hermite (buff[i1],
213− buff[cdx],
214− buff[i3],
215− buff[i4],
216− alpha);
217−
218− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
219− }
220− }
221− }
222− else
181+ // Check dir (direction) to interpolate properly
182+ if (dir > 0)
183+ {
184+ // FORWARD NORMAL SAMPLE
185+ int i1 = ((idx-1) + p->len) % p->len;
186+ int i3 = (idx+1) % p->len;
187+ int i4 = (idx+2) % p->len;
188+
189+ sample = LEAF_interpolate_hermite (buff[i1],
190+ buff[idx],
191+ buff[i3],
192+ buff[i4],
193+ alpha);
194+
195+ // num samples to end of loop
196+ numsamps = (idx - start) / p->inc;
197+ //numsamps = (dir > 0) ? (end - idx) : (idx - start);
198+ //numsamps *= p->iinc;
199+
200+ if (p->mode == PlayLoop)
201+ {
202+ if (numsamps <= p->cfxlen)
203+ {
204+ // CROSSFADE SAMPLE
205+ float idxx = p->idx - p->len;
206+ int cdx = ((int)(idxx) + p->len) % p->len;
207+
208+ i1 = ((cdx-1) + p->len) % p->len;
209+ i3 = (cdx+1) % p->len;
210+ i4 = (cdx+2) % p->len;
211+
212+ cfxsample = LEAF_interpolate_hermite (buff[i1],
213+ buff[cdx],
214+ buff[i3],
215+ buff[i4],
216+ alpha);
217+
218+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
219+ }
220+ }
221+ }
222+ else
223223 {
224− // REVERSE
225− int i1 = (idx+1) % p->len;
226− int i3 = ((idx-1) + p->len) % p->len;
224+ // REVERSE
225+ int i1 = (idx+1) % p->len;
226+ int i3 = ((idx-1) + p->len) % p->len;
227227 int i4 = ((idx-2) + p->len) % p->len;
228228
229229 sample = LEAF_interpolate_hermite (buff[i1],
LEAF/Src/leaf-string.c+47−46
@@ -21,21 +21,27 @@ void tPluck_init (tPluck* const p, float lowestFrequency) · 20 unmodified lines
2121 {
2222 if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
2323
24− p->noise = (tNoise*)leaf_alloc(sizeof(tNoise));
25− tNoise_init(p->noise, WhiteNoise);
24+ tNoise_init(&p->noise, WhiteNoise);
2625
27− p->pickFilter = (tOnePole*) leaf_alloc(sizeof(tOnePole));
28− tOnePole_init(p->pickFilter, 0.0f);
26+ tOnePole_init(&p->pickFilter, 0.0f);
2927
30− p->loopFilter = (tOneZero*) leaf_alloc(sizeof(tOneZero));
31− tOneZero_init(p->loopFilter, 0.0f);
28+ tOneZero_init(&p->loopFilter, 0.0f);
3229
33− p->delayLine = (tDelayA*) leaf_alloc(sizeof(tDelayA));
34− tDelayA_init(p->delayLine, 0.0f, leaf.sampleRate * 2);
30+ tDelayA_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
3531
3632 tPluck_setFrequency(p, 220.0f);
3733 }
3834
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+
3945 float tPluck_getLastOut (tPluck *p)
4046 {
4147 return p->lastOut;
@@ -43,7 +49,7 @@ float tPluck_getLastOut (tPluck *p) · 1 unmodified line
4349
4450 float tPluck_tick (tPluck *p)
4551 {
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 ) ));
4753 }
4854
4955 void tPluck_pluck (tPluck* const p, float amplitude)
@@ -51,12 +57,12 @@ void tPluck_pluck (tPluck* const p, float amplitude) · 1 unmodified line
5157 if ( amplitude < 0.0f) amplitude = 0.0f;
5258 else if (amplitude > 1.0f) amplitude = 1.0f;
5359
54− tOnePole_setPole(p->pickFilter, 0.999f - (amplitude * 0.15f));
55− tOnePole_setGain(p->pickFilter, amplitude * 0.5f );
60+ tOnePole_setPole(&p->pickFilter, 0.999f - (amplitude * 0.15f));
61+ tOnePole_setGain(&p->pickFilter, amplitude * 0.5f );
5662
5763 // Fill delay with noise additively with current contents.
58− for ( uint32_t i = 0; i < (uint32_t)tDelayA_getDelay(p->delayLine); i++ )
59− tDelayA_tick(p->delayLine, 0.6f * tDelayA_getLastOut(p->delayLine) + tOnePole_tick(p->pickFilter, tNoise_tick(p->noise) ) );
64+ for ( uint32_t i = 0; i < (uint32_t)tDelayA_getDelay(&p->delayLine); i++ )
65+ tDelayA_tick(&p->delayLine, 0.6f * tDelayA_getLastOut(&p->delayLine) + tOnePole_tick(&p->pickFilter, tNoise_tick(&p->noise) ) );
6066 }
6167
6268 // Start a note with the given frequency and amplitude.;
@@ -82,9 +88,9 @@ void tPluck_setFrequency (tPluck* const p, float frequency ) · 19 unmodified lines
8288 if ( frequency <= 0.0f ) frequency = 0.001f;
8389
8490 // 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 );
8692
87− tDelayA_setDelay(p->delayLine, delay );
93+ tDelayA_setDelay(&p->delayLine, delay );
8894
8995 p->loopGain = 0.99f + (frequency * 0.000005f);
9096
@@ -108,22 +114,17 @@ void tStifKarp_init (tStifKarp* const p, float lowestFrequency) · 17 unmodified lines
108114 {
109115 if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
110116
111− p->delayLine = (tDelayA*) leaf_alloc(sizeof(tDelayA));
112− tDelayA_init(p->delayLine, 0.0f, leaf.sampleRate * 2);
113−
114− p->combDelay = (tDelayL*) leaf_alloc(sizeof(tDelayL));
115− tDelayL_init(p->combDelay, 0.0f, leaf.sampleRate * 2);
117+ tDelayA_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
118+
119+ tDelayL_init(&p->combDelay, 0.0f, leaf.sampleRate * 2);
116120
117− p->filter = (tOneZero*) leaf_alloc(sizeof(tOneZero));
118− tOneZero_init(p->filter, 0.0f);
121+ tOneZero_init(&p->filter, 0.0f);
119122
120− p->noise = (tNoise*) leaf_alloc(sizeof(tNoise));
121− tNoise_init(p->noise, WhiteNoise);
123+ tNoise_init(&p->noise, WhiteNoise);
122124
123125 for (int i = 0; i < 4; i++)
124126 {
125− p->biquad[i] = (tBiQuad*) leaf_alloc(sizeof(tBiQuad));
126− tBiQuad_init(p->biquad[i]);
127+ tBiQuad_init(&p->biquad[i]);
127128 }
128129
129130 p->pluckAmplitude = 0.3f;
@@ -139,14 +140,14 @@ void tStifKarp_init (tStifKarp* const p, float lowestFrequency) · 9 unmodified lines
139140
140141 void tStifKarp_free (tStifKarp* const p)
141142 {
142− tDelayA_free(p->delayLine);
143− tDelayL_free(p->combDelay);
144− tOneZero_free(p->filter);
145− tNoise_free(p->noise);
143+ tDelayA_free(&p->delayLine);
144+ tDelayL_free(&p->combDelay);
145+ tOneZero_free(&p->filter);
146+ tNoise_free(&p->noise);
146147
147148 for (int i = 0; i < 4; i++)
148149 {
149− tBiQuad_free(p->biquad[i]);
150+ tBiQuad_free(&p->biquad[i]);
150151 }
151152
152153 leaf_free(p);
@@ -159,16 +160,16 @@ float tStifKarp_getLastOut (tStifKarp* const p) · 6 unmodified lines
159160
160161 float tStifKarp_tick (tStifKarp* const p)
161162 {
162− float temp = tDelayA_getLastOut(p->delayLine) * p->loopGain;
163+ float temp = tDelayA_getLastOut(&p->delayLine) * p->loopGain;
163164
164165 // 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);
166167
167168 // Moving average filter.
168− temp = tOneZero_tick(p->filter, temp);
169+ temp = tOneZero_tick(&p->filter, temp);
169170
170− float out = tDelayA_tick(p->delayLine, temp);
171− out = out - tDelayL_tick(p->combDelay, out);
171+ float out = tDelayA_tick(&p->delayLine, temp);
172+ out = out - tDelayL_tick(&p->combDelay, out);
172173 p->lastOut = out;
173174
174175 return p->lastOut;
@@ -181,10 +182,10 @@ void tStifKarp_pluck (tStifKarp* const p, float amplitude) · 6 unmodified lines
181182
182183 p->pluckAmplitude = amplitude;
183184
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++ )
185186 {
186187 // 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 );
188189 //delayLine_.tick( combDelay_.tick((delayLine_.lastOut() * 0.6) + 0.4 * noise->tick() * pluckAmplitude_) );
189190 }
190191 }
@@ -213,7 +214,7 @@ void tStifKarp_setFrequency (tStifKarp* const p, float frequency ) · 22 unmodified lines
213214 p->lastFrequency = frequency;
214215 p->lastLength = leaf.sampleRate / p->lastFrequency;
215216 float delay = p->lastLength - 0.5f;
216− tDelayA_setDelay(p->delayLine, delay );
217+ tDelayA_setDelay(&p->delayLine, delay);
217218
218219 // MAYBE MODIFY LOOP GAINS
219220 p->loopGain = p->baseLoopGain + (frequency * 0.000005f);
@@ -221,7 +222,7 @@ void tStifKarp_setFrequency (tStifKarp* const p, float frequency ) · 1 unmodified line
221222
222223 tStifKarp_setStretch(p, p->stretching);
223224
224− tDelayL_setDelay(p->combDelay, 0.5f * p->pickupPosition * p->lastLength );
225+ tDelayL_setDelay(&p->combDelay, 0.5f * p->pickupPosition * p->lastLength );
225226
226227 }
227228
@@ -238,13 +239,13 @@ void tStifKarp_setStretch (tStifKarp* const p, float stretch ) · 10 unmodified lines
238239 for ( int i=0; i<4; i++ )
239240 {
240241 coefficient = temp * temp;
241− tBiQuad_setA2(p->biquad[i], coefficient);
242− tBiQuad_setB0(p->biquad[i], coefficient);
243− tBiQuad_setB2(p->biquad[i], 1.0f);
242+ tBiQuad_setA2(&p->biquad[i], coefficient);
243+ tBiQuad_setB0(&p->biquad[i], coefficient);
244+ tBiQuad_setB2(&p->biquad[i], 1.0f);
244245
245246 coefficient = -2.0f * temp * cos(TWO_PI * freq / leaf.sampleRate);
246− tBiQuad_setA1(p->biquad[i], coefficient);
247− tBiQuad_setB1(p->biquad[i], coefficient);
247+ tBiQuad_setA1(&p->biquad[i], coefficient);
248+ tBiQuad_setB1(&p->biquad[i], coefficient);
248249
249250 freq += dFreq;
250251 }
@@ -257,7 +258,7 @@ void tStifKarp_setPickupPosition (tStifKarp* const p, float position ) · 6 unmodified lines
257258 else if (position <= 1.0f) p->pickupPosition = position;
258259 else p->pickupPosition = 1.0f;
259260
260− tDelayL_setDelay(p->combDelay, 0.5f * p->pickupPosition * p->lastLength);
261+ tDelayL_setDelay(&p->combDelay, 0.5f * p->pickupPosition * p->lastLength);
261262 }
262263
263264 // Set the base loop gain.
LEAF/Src/leaf-utilities.c+0−1
@@ -496,7 +496,6 @@ void tADSR_init(tADSR* const adsr, float attack, float decay, float sustain, · 495 unmodified lines
496496 adsr->decayInc = adsr->inc_buff[decayIndex];
497497 adsr->releaseInc = adsr->inc_buff[releaseIndex];
498498 adsr->rampInc = adsr->inc_buff[rampIndex];
499−
500499 }
501500
502501 int tADSR_setAttack(tADSR* const adsr, float attack)
LEAF/Src/leaf-vocoder.c+17−3
@@ -26,18 +26,32 @@ · 25 unmodified lines
2626 *
2727 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2828
29−void tTalkbox_init(tTalkbox* const v)
29+void tTalkbox_init(tTalkbox* const v, int bufsize)
3030 {
3131 v->param[0] = 0.5f; //wet
3232 v->param[1] = 0.0f; //dry
3333 v->param[2] = 0; // Swap
3434 v->param[3] = 1.0f; //quality
3535
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+
3644 tTalkbox_update(v);
3745 }
3846
3947 void tTalkbox_free(tTalkbox* const v)
4048 {
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+
4155 leaf_free(v);
4256 }
4357
@@ -48,7 +62,7 @@ void tTalkbox_update(tTalkbox* const v) ///update internal parameters... · 4 unmodified lines
4862 if(fs > 96000.0f) fs = 96000.0f;
4963
5064 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;
5266
5367 //O = (VstInt32)(0.0005f * fs);
5468 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
7791 v->u0 = v->u1 = v->u2 = v->u3 = v->u4 = 0.0f;
7892 v->d0 = v->d1 = v->d2 = v->d3 = v->d4 = 0.0f;
7993
80− for (int32_t i = 0; i < TALKBOX_BUFFER_LENGTH; i++)
94+ for (int32_t i = 0; i < v->bufsize; i++)
8195 {
8296 v->buf0[i] = 0;
8397 v->buf1[i] = 0;
LEAF/Src/leaf.c+2−2
@@ -20,9 +20,9 @@ · 19 unmodified lines
2020
2121 LEAF leaf;
2222
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))
2424 {
25− leaf_pool_init(MPOOL_POOL_SIZE);
25+ leaf_pool_init(memory, memorysize);
2626
2727 leaf.sampleRate = sr;
2828
LEAF/leaf.h+1−6
@@ -60,18 +60,13 @@ · 59 unmodified lines
6060 #include "./Inc/leaf-tables.h"
6161 #include "./Inc/leaf-WDF.h"
6262
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−
6663 #endif
6764
68−
69−
7065 #ifdef __cplusplus
7166 extern "C" {
7267 #endif
7368
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));
7570 void LEAF_setSampleRate (float sampleRate);
7671 float LEAF_getSampleRate (void);
7772
LEAF_JUCEPlugin/Source/MyTest.cpp+14−51
@@ -16,68 +16,35 @@ static void leaf_pool_report(void); · 15 unmodified lines
1616 static void leaf_pool_dump(void);
1717 static void run_pool_test(void);
1818
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;
2919 tNoise noise;
3020 tCycle sine;
21+tDelay delay;
3122
3223 float gain;
24+float freq;
25+float dtime;
3326 bool buttonState;
3427 int ratio = 2;
3528
29+#define MSIZE 500000
30+char memory[MSIZE];
31+
3632 void LEAFTest_init (float sampleRate, int blockSize)
3733 {
38− LEAF_init(sampleRate, blockSize, &getRandomFloat);
34+ LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
3935
4036 tNoise_init(&noise, WhiteNoise);
4137 tCycle_init(&sine);
4238 tCycle_setFreq(&sine, 200);
43−
44− //Bandpass circuit 1
45− //use c1 for output voltage
46−// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
47−// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);
48−// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);
49−// tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL);
50−// tWDF_init(&p1, ParallelAdaptor, 10000.0f, &r1, &c1);
51−// tWDF_init(&s1, SeriesAdaptor, 0.0f, &c2, &r2);
52−// tWDF_init(&s2, SeriesAdaptor, 0.0f, &s1, &p1);
53−
54− //Bandpass circuit 2
55−// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
56−// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);
57−// tWDF_init(&s1, SeriesAdaptor, 0.0f, &c1, &r1);
58−// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);
59−// tWDF_init(&p1, ParallelAdaptor, 10000.0f, &s1, &r2);
60−// tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL);
61−// tWDF_init(&s2, SeriesAdaptor, 0.0f, &c2, &p1);
62−
63−// tWDF_setOutputPoint(&s2, &c1);
64−
65−// tWDFNonlinear_init(&i, IdealSource, &s2);
66−
67− tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
68− tWDF_init(&rs1, ResistiveSource, 1.0f, NULL, NULL);
69− tWDF_init(&s1, SeriesAdaptor, 0.0f, &r1, &rs1);
70− tWDF_init(&d, Diode, 0.0f, &s1, NULL);
71−
72− leaf_pool_report();
39+ tDelay_init(&delay, 44100, 44100);
7340 }
7441
7542 float LEAFTest_tick (float input)
7643 {
77− float sample = tCycle_tick(&sine) * gain;
78−
79− //tWDF_setValue(&rs1, sample*gain);
80− sample = tWDF_tick(&d, sample, &d, 1);
44+ tCycle_setFreq(&sine, freq);
45+ float sample = tCycle_tick(&sine) * 0.1;
46+ tDelay_setDelay(&delay, dtime);
47+ sample += tDelay_tick(&delay, sample);
8148
8249 return sample;
8350 }
@@ -88,14 +55,10 @@ bool lastState = false, lastPlayState = false; · 4 unmodified lines
8855 void LEAFTest_block (void)
8956 {
9057 float val = getSliderValue("mod freq");
91− val = 1.0f + 10000.0f * val;
92−
93− tWDF_setValue(&r1, val);
58+ freq = val * 2000.f;
9459
9560 val = getSliderValue("mod depth");
96− val = 10.0f * val;
97− gain = val;
98− //tWDF_setValue(&r2, val);
61+ dtime = val * 40000.;
9962 }
10063
10164 void LEAFTest_controllerInput (int cnum, float cval)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t