History

Cleaned up some file headers. Implemented tCrusher, bit/sample reduction bitcrusher / shaper.

mulshine committed 7 years ago

Commit 3ada2d41 parent b0cf3f132 files · +840 −662Browse files

Unified · Split

32 files
  1. LEAF/Inc/leaf-808.h +1 −1
  2. LEAF/Inc/leaf-crusher.h +64 −0
  3. LEAF/Inc/leaf-delay.h +1 −1
  4. LEAF/Inc/leaf-filter.h +1 −1
  5. LEAF/Inc/leaf-globals.h +5 −0
  6. LEAF/Inc/leaf-math.h +45 −41
  7. LEAF/Inc/leaf-oscillator.h +1 −1
  8. LEAF/Inc/leaf-reverb.h +1 −1
  9. LEAF/Inc/leaf-sample.h +67 −67
  10. LEAF/Inc/leaf-utilities.h +1 −1
  11. LEAF/Inc/leaf-vocoder.h +1 −1
  12. LEAF/Inc/leaf-wavefolder.h +18 −18
  13. LEAF/Inc/leaf-wavetables.h +1 −1
  14. LEAF/Src/leaf-808.c +3 −5
  15. LEAF/Src/leaf-crusher.c +84 −0
  16. LEAF/Src/leaf-delay.c +3 −5
  17. LEAF/Src/leaf-filter.c +3 −5
  18. LEAF/Src/leaf-formant.c +3 −5
  19. LEAF/Src/leaf-math.c +48 −6
  20. LEAF/Src/leaf-midi.c +3 −5
  21. LEAF/Src/leaf-oscillator.c +3 −5
  22. LEAF/Src/leaf-pitch.c +3 −5
  23. LEAF/Src/leaf-reverb.c +3 −5
  24. LEAF/Src/leaf-sample.c +406 −406
  25. LEAF/Src/leaf-string.c +3 −5
  26. LEAF/Src/leaf-utilities.c +3 −5
  27. LEAF/Src/leaf-vocoder.c +3 −5
  28. LEAF/Src/leaf-wavefolder.c +3 −5
  29. LEAF/leaf.h +4 −2
  30. LEAF_JUCEPlugin/LEAF.jucer +2 −0
  31. LEAF_JUCEPlugin/Source/LEAFLink.cpp +6 −6
  32. LEAF_JUCEPlugin/Source/MyTest.cpp +47 −48
LEAF/Inc/leaf-808.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− leaf_808.h
3+ leaf-808.h
44 Created: 30 Nov 2018 10:24:44am
55 Author: airship
66
LEAF/Inc/leaf-crusher.h+64−0
@@ -0,0 +1,64 @@
1+/*
2+ ==============================================================================
3+
4+ leaf-crusher.h
5+ Created: 7 Feb 2019 10:58:22am
6+ Author: airship
7+
8+ ==============================================================================
9+*/
10+
11+#ifndef LEAF_CRUSHER_H_INCLUDED
12+#define LEAF_CRUSHER_H_INCLUDED
13+
14+
15+#ifdef __cplusplus
16+extern "C" {
17+#endif
18+
19+//==============================================================================
20+
21+#include "leaf-globals.h"
22+#include "leaf-math.h"
23+
24+//==============================================================================
25+
26+typedef struct _tCrusher
27+{
28+ float srr;
29+ float mult, div;
30+ float rnd;
31+
32+ uint32_t op; //which bitwise operation (0-7)
33+
34+ float gain;
35+
36+} tCrusher;
37+
38+
39+void tCrusher_init (tCrusher* const);
40+void tCrusher_free (tCrusher* const);
41+
42+float tCrusher_tick (tCrusher* const, float input);
43+
44+// 0-7
45+void tCrusher_setOperation (tCrusher* const, uint32_t op);
46+
47+// 0.0 - 1.0
48+void tCrusher_setQuality (tCrusher* const, float val);
49+
50+// what division to round to
51+void tCrusher_setRound (tCrusher* const, float rnd);
52+
53+// sampling ratio
54+void tCrusher_setSamplingRatio (tCrusher* const, float ratio);
55+
56+//==============================================================================
57+
58+#ifdef __cplusplus
59+}
60+#endif
61+
62+#endif // LEAF_WAVEFOLDER_H_INCLUDED
63+
64+//==============================================================================
LEAF/Inc/leaf-delay.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFDelay.h
3+ leaf-delay.h
44 Created: 20 Jan 2017 12:01:24pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-filter.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFFilter.h
3+ leaf-filter.h
44 Created: 20 Jan 2017 12:01:10pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-globals.h+5−0
@@ -60,6 +60,11 @@ extern const float shaper1[SHAPER1_TABLE_SIZE]; · 59 unmodified lines
6060 #define TALKBOX_BUFFER_LENGTH 1600 // Every talkbox instance introduces 5 buffers of this size
6161
6262
63+union unholy_t { /* a union between a float and an integer */
64+ float f;
65+ int i;
66+};
67+
6368 //==============================================================================
6469
6570 #ifdef __cplusplus
LEAF/Inc/leaf-math.h+45−41
@@ -1,22 +1,22 @@
11 /*==============================================================================
22
3− LEAFMath.h
3+ leaf-math.h
44 Created: 22 Jan 2017 7:02:56pm
55 Author: Michael R Mulshine
66
77 ==============================================================================*/
88
99 #ifndef LEAF_MATH_H_INCLUDED
10−#define LEAF_MATH_H_INCLUDED
11−
12−#ifdef __cplusplus
13−extern "C" {
10+#define LEAF_MATH_H_INCLUDED
11+
12+#ifdef __cplusplus
13+extern "C" {
1414 #endif
1515
1616 #include "math.h"
1717 #include "stdint.h"
18−#include "stdlib.h"
19−
18+#include "stdlib.h"
19+
2020 //==============================================================================
2121
2222 typedef enum oBool
@@ -76,47 +76,51 @@ typedef enum oBool · 53 unmodified lines
7676
7777 // Jones shaper
7878 float LEAF_shaper (float input, float m_drive);
79−float LEAF_reedTable (float input, float offset, float slope);
79+float LEAF_reedTable (float input, float offset, float slope);
80+
81+float LEAF_reduct (float input, float srr);
82+float LEAF_round (float input, float rnd);
83+float LEAF_bitwise_or(float input, uint32_t op);
8084
81−float LEAF_clip (float min, float val, float max);
85+float LEAF_clip (float min, float val, float max);
8286 int LEAF_clipInt (int min, int val, int max);
8387 float LEAF_softClip (float val, float thresh);
84−oBool LEAF_isPrime (uint64_t number );
85−
86−float LEAF_midiToFrequency (float f);
87−float LEAF_frequencyToMidi(float f);
88−
89−void LEAF_generate_sine (float* buffer, int size);
90−void LEAF_generate_sawtooth (float* buffer, float basefreq, int size);
91−void LEAF_generate_triangle (float* buffer, float basefreq, int size);
88+oBool LEAF_isPrime (uint64_t number );
89+
90+float LEAF_midiToFrequency (float f);
91+float LEAF_frequencyToMidi(float f);
92+
93+void LEAF_generate_sine (float* buffer, int size);
94+void LEAF_generate_sawtooth (float* buffer, float basefreq, int size);
95+void LEAF_generate_triangle (float* buffer, float basefreq, int size);
9296 void LEAF_generate_square (float* buffer, float basefreq, int size);
9397
9498 // dope af
9599 float LEAF_chebyshevT(float in, int n);
96100 float LEAF_CompoundChebyshevT(float in, int n, float* amps);
97−
98−
99−// Hermite interpolation
100−float LEAF_interpolate_hermite (float A, float B, float C, float D, float t);
101−float LEAF_interpolation_linear (float A, float B, float t);
102−
103−float interpolate3max(float *buf, const int peakindex);
104−float interpolate3phase(float *buf, const int peakindex);
105−
106−// alternative implementation for abs()
107−// REQUIRES: 32 bit integers
108−int fastabs_int(int in);
109−
110−// alternative implementation for abs()
111−// REQUIRES: 32 bit floats
112−float fastabs(float f);
113−
114−//==============================================================================
115−
116−#ifdef __cplusplus
117−}
118−#endif
119101
120−#endif // LEAF_MATH_H_INCLUDED
121−
102+
103+// Hermite interpolation
104+float LEAF_interpolate_hermite (float A, float B, float C, float D, float t);
105+float LEAF_interpolation_linear (float A, float B, float t);
106+
107+float interpolate3max(float *buf, const int peakindex);
108+float interpolate3phase(float *buf, const int peakindex);
109+
110+// alternative implementation for abs()
111+// REQUIRES: 32 bit integers
112+int fastabs_int(int in);
113+
114+// alternative implementation for abs()
115+// REQUIRES: 32 bit floats
116+float fastabs(float f);
117+
118+//==============================================================================
119+
120+#ifdef __cplusplus
121+}
122+#endif
123+
124+#endif // LEAF_MATH_H_INCLUDED
125+
122126 //==============================================================================
LEAF/Inc/leaf-oscillator.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFOscillator.h
3+ leaf-oscillator.h
44 Created: 20 Jan 2017 12:00:58pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-reverb.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFReverb.h
3+ leaf-reverb.h
44 Created: 20 Jan 2017 12:02:04pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-sample.h+67−67
@@ -17,8 +17,8 @@ extern "C" { · 16 unmodified lines
1717 //==============================================================================
1818
1919 #include "leaf-globals.h"
20−#include "leaf-math.h"
21−
20+#include "leaf-math.h"
21+
2222 #include "leaf-utilities.h"
2323
2424 //==============================================================================
@@ -34,11 +34,11 @@ extern "C" { · 9 unmodified lines
3434 {
3535 float* buff;
3636
37− uint32_t idx;
37+ uint32_t idx;
3838 uint32_t length;
3939
40− RecordMode mode;
41−
40+ RecordMode mode;
41+
4242 int active;
4343
4444 } tBuffer;
@@ -46,72 +46,72 @@ extern "C" { · 1 unmodified line
4646 void tBuffer_init (tBuffer* const, uint32_t length);
4747 void tBuffer_free (tBuffer* const);
4848
49− void tBuffer_tick (tBuffer* const, float sample);
50−
51− void tBuffer_read(tBuffer* const, float* buff, uint32_t len);
52−
53− float tBuffer_get (tBuffer* const, int idx);
49+ void tBuffer_tick (tBuffer* const, float sample);
50+
51+ void tBuffer_read(tBuffer* const, float* buff, uint32_t len);
52+
53+ float tBuffer_get (tBuffer* const, int idx);
5454
5555 void tBuffer_record (tBuffer* const);
5656 void tBuffer_stop (tBuffer* const);
5757
58− void tBuffer_setRecordMode (tBuffer* const, RecordMode mode);
59−
60− void tBuffer_clear (tBuffer* const);
61−
62−//==============================================================================
63−
64− typedef enum Mode
65− {
66− Normal,
67− Loop,
68− BackAndForth,
69− SampleModeNil
70− } Mode;
71−
72− typedef struct _tSampler
73− {
74− tBuffer* samp;
75−
76− tRamp gain;
77−
78− float idx;
79− float inc;
80− float iinc;
81− int8_t dir;
82− int8_t flip;
83− int8_t bnf;
84−
85− int32_t start;
86− int32_t end;
87− uint32_t len;
88− uint32_t cfxlen;
89−
90− Mode mode;
91− int retrigger;
92−
93− int active;
94−
95− } tSampler;
96−
97− void tSampler_init (tSampler* const, tBuffer* s);
98− void tSampler_free (tSampler* const);
99−
100− float tSampler_tick (tSampler* const);
101−
102− void tSampler_setSample (tSampler* const, tBuffer* s);
103−
104− void tSampler_setMode (tSampler* const, Mode mode);
105−
106− void tSampler_play (tSampler* const);
107− void tSampler_stop (tSampler* const);
108−
109− void tSampler_setStart (tSampler* const, int32_t start);
110− void tSampler_setEnd (tSampler* const, int32_t end);
111−
112− void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length);
113−
114− void tSampler_setRate (tSampler* const, float rate);
58+ void tBuffer_setRecordMode (tBuffer* const, RecordMode mode);
59+
60+ void tBuffer_clear (tBuffer* const);
61+
62+//==============================================================================
63+
64+ typedef enum Mode
65+ {
66+ Normal,
67+ Loop,
68+ BackAndForth,
69+ SampleModeNil
70+ } Mode;
71+
72+ typedef struct _tSampler
73+ {
74+ tBuffer* samp;
75+
76+ tRamp gain;
77+
78+ float idx;
79+ float inc;
80+ float iinc;
81+ int8_t dir;
82+ int8_t flip;
83+ int8_t bnf;
84+
85+ int32_t start;
86+ int32_t end;
87+ uint32_t len;
88+ uint32_t cfxlen;
89+
90+ Mode mode;
91+ int retrigger;
92+
93+ int active;
94+
95+ } tSampler;
96+
97+ void tSampler_init (tSampler* const, tBuffer* s);
98+ void tSampler_free (tSampler* const);
99+
100+ float tSampler_tick (tSampler* const);
101+
102+ void tSampler_setSample (tSampler* const, tBuffer* s);
103+
104+ void tSampler_setMode (tSampler* const, Mode mode);
105+
106+ void tSampler_play (tSampler* const);
107+ void tSampler_stop (tSampler* const);
108+
109+ void tSampler_setStart (tSampler* const, int32_t start);
110+ void tSampler_setEnd (tSampler* const, int32_t end);
111+
112+ void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length);
113+
114+ void tSampler_setRate (tSampler* const, float rate);
115115
116116 //==============================================================================
117117
LEAF/Inc/leaf-utilities.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFUtilities.h
3+ leaf-utilities.h
44 Created: 20 Jan 2017 12:02:17pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-vocoder.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFInstrument.h
3+ leaf-vocoder.h
44 Created: 20 Jan 2017 12:01:54pm
55 Author: Michael R Mulshine
66
LEAF/Inc/leaf-wavefolder.h+18−18
@@ -4,14 +4,14 @@ · 3 unmodified lines
44 Created: 30 Nov 2018 11:57:05am
55 Author: airship
66
7−==============================================================================*/
8−
9−#ifndef LEAF_WAVEFOLDER_H_INCLUDED
10−#define LEAF_WAVEFOLDER_H_INCLUDED
11−
12−
13−#ifdef __cplusplus
14−extern "C" {
7+==============================================================================*/
8+
9+#ifndef LEAF_WAVEFOLDER_H_INCLUDED
10+#define LEAF_WAVEFOLDER_H_INCLUDED
11+
12+
13+#ifdef __cplusplus
14+extern "C" {
1515 #endif
1616
1717 //==============================================================================
@@ -45,14 +45,14 @@ void tLockhartWavefolder_init (tLockhartWavefolder* const); · 27 unmodified lines
4545 void tLockhartWavefolder_free (tLockhartWavefolder* const);
4646
4747 float tLockhartWavefolder_tick (tLockhartWavefolder* const, float samp);
48−
49−
50−//==============================================================================
51−
52−#ifdef __cplusplus
53−}
54−#endif
55−
56−#endif // LEAF_WAVEFOLDER_H_INCLUDED
57−
48+
49+
50+//==============================================================================
51+
52+#ifdef __cplusplus
53+}
54+#endif
55+
56+#endif // LEAF_WAVEFOLDER_H_INCLUDED
57+
5858 //==============================================================================
LEAF/Inc/leaf-wavetables.h+1−1
@@ -1,6 +1,6 @@
11 /*==============================================================================
22
3− LEAFWavetables.h
3+ leaf-wavetables.h
44 Created: 4 Dec 2016 9:42:41pm
55 Author: Michael R Mulshine
66
LEAF/Src/leaf-808.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf_808.cpp
3+ leaf-808.c
54 Created: 30 Nov 2018 10:24:21am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-crusher.c+84−0
@@ -0,0 +1,84 @@
1+/*==============================================================================
2+
3+ leaf-crusher.c
4+ Created: 30 Nov 2018 11:56:49am
5+ Author: airship
6+
7+==============================================================================*/
8+
9+#if _WIN32 || _WIN64
10+
11+#include "..\Inc\leaf-crusher.h"
12+
13+#else
14+
15+#include "../Inc/leaf-crusher.h"
16+
17+#endif
18+
19+//==============================================================================
20+
21+#define SCALAR 5000.f
22+
23+void tCrusher_init (tCrusher* const c)
24+{
25+ c->op = 4;
26+ c->div = SCALAR;
27+ c->rnd = 0.25f;
28+ c->srr = 0.25f;
29+
30+ c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
31+}
32+
33+void tCrusher_free (tCrusher* const c)
34+{
35+ leaf_free(c);
36+}
37+
38+float tCrusher_tick (tCrusher* const c, float input)
39+{
40+ float sample = input;
41+
42+ sample *= SCALAR; // SCALAR is 5000 by default
43+
44+ sample = floorf(sample);
45+
46+ sample /= c->div;
47+
48+ sample = LEAF_bitwise_or(sample, c->op << 23);
49+
50+ sample = LEAF_clip(-1.f, sample, 1.f);
51+
52+ sample = LEAF_round(sample, c->rnd);
53+
54+ sample = LEAF_reduct(sample, c->srr);
55+
56+ return sample * c->gain;
57+
58+}
59+
60+void tCrusher_setOperation (tCrusher* const c, uint32_t op)
61+{
62+ c->op = op % 8;
63+}
64+
65+// 0.0 - 1.0
66+void tCrusher_setQuality (tCrusher* const c, float val)
67+{
68+ val = LEAF_clip(0.0f, val, 1.0f);
69+
70+ c->div = 0.01f + val * SCALAR;
71+
72+ c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
73+}
74+
75+// what decimal to round to
76+void tCrusher_setRound (tCrusher* const c, float rnd)
77+{
78+ c->rnd = fabsf(rnd);
79+}
80+
81+void tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
82+{
83+ c->srr = ratio;
84+}
LEAF/Src/leaf-delay.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFDelay.c
3+ leaf-delay.c
54 Created: 20 Jan 2017 12:01:24pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-filter.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFFilter.c
3+ leaf-filter.c
54 Created: 20 Jan 2017 12:01:10pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-formant.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf-formant.cpp
3+ leaf-formant.c
54 Created: 30 Nov 2018 11:03:30am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-math.c+48−6
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFMath.c
3+ leaf-math.c
54 Created: 22 Jan 2017 7:02:56pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
@@ -24,7 +22,7 @@ · 11 unmodified lines
2422 #define TWO_TO_16 65536.f
2523
2624 #define EXPONENTIAL_TABLE_SIZE 65536
27−
25+
2826
2927 float interpolate3max(float *buf, const int peakindex)
3028 {
@@ -119,6 +117,50 @@ float LEAF_shaper(float input, float m_drive) · 88 unmodified lines
119117 float shaperOut = w*(c+ 0.05f*xc2)*(m_drive + 0.75f);
120118 shaperOut *= 0.5f; // post_scale
121119 return shaperOut;
120+}
121+
122+// reduce sample resolution
123+float LEAF_reduct (float input, float sr)
124+{
125+ float samp = input;
126+
127+ samp *= sr;
128+
129+ // method 1
130+ samp = ceilf(samp);
131+
132+ samp /= sr;
133+
134+ /*
135+ // method 2
136+ samp = floorf(samp + 0.5f) - 0.5f;
137+
138+ samp /= srr;
139+ */
140+
141+ return samp;
142+}
143+
144+// round input to nearest rnd
145+float LEAF_round (float input, float rnd)
146+{
147+ rnd = fabsf(rnd);
148+
149+ if (rnd <= 0.0000001f) return input;
150+
151+ float scale = 1.f / rnd;
152+
153+ return roundf(input * scale) / scale;
154+}
155+
156+union unholy_t unholy;
157+
158+float LEAF_bitwise_or(float input, uint32_t op)
159+{
160+ unholy.f = input;
161+ unholy.i = (unholy.i | op);
162+
163+ return unholy.f;
122164 }
123165
124166 float LEAF_reedTable(float input, float offset, float slope)
LEAF/Src/leaf-midi.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf-midi.cpp
3+ leaf-midi.c
54 Created: 30 Nov 2018 11:29:16am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-oscillator.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFOscillator.c
3+ leaf-oscillator.c
54 Created: 20 Jan 2017 12:00:58pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-pitch.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf-pitch.cpp
3+ leaf-pitch.c
54 Created: 30 Nov 2018 11:02:59am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-reverb.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFReverb.c
3+ leaf-reverb.c
54 Created: 20 Jan 2017 12:02:04pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-sample.c+406−406
@@ -1,7 +1,7 @@
11 /*
22 ==============================================================================
33
4− LEAFUtilities.c
4+ leaf-sample.c
55 Created: 20 Jan 2017 12:02:17pm
66 Author: Michael R Mulshine
77
@@ -10,7 +10,7 @@ · 2 unmodified lines
1010
1111
1212 #if _WIN32 || _WIN64
13−
13+
1414 #include "..\Inc\leaf-sample.h"
1515 #include "..\leaf.h"
1616
@@ -19,412 +19,412 @@ · 2 unmodified lines
1919 #include "../Inc/leaf-sample.h"
2020 #include "../leaf.h"
2121
22−#endif
23−
24−//==============================================================================
25−
26−void tBuffer_init (tBuffer* const s, uint32_t length)
27−{
28− s->buff = (float*) leaf_alloc( sizeof(float) * length);
29−
30−
31− s->length = length;
32− s->active = 0;
33− s->idx = 0;
34− s->mode = RecordOneShot;
35−
36− tBuffer_clear(s);
37−}
38−
39−void tBuffer_free (tBuffer* const s)
40−{
41− leaf_free(s->buff);
42− leaf_free(s);
43−}
44−
45−void tBuffer_tick (tBuffer* const s, float sample)
46−{
47− if (s->active == 1)
48− {
49− s->buff[s->idx] = sample;
50−
51− s->idx += 1;
52−
53− if (s->idx >= s->length)
54− {
55− if (s->mode == RecordOneShot)
56− {
57− tBuffer_stop(s);
58− }
59− else if (s->mode == RecordLoop)
60− {
61− s->idx = 0;
62− }
63− }
64− }
65−}
66−
67−void tBuffer_read(tBuffer* const s, float* buff, uint32_t len)
68−{
69− for (int i = 0; i < s->length; i++)
70− {
71− if (i < len) s->buff[i] = buff[i];
72− else s->buff[i] = 0.f;
73− }
74−}
75−
76−float tBuffer_get (tBuffer* const s, int idx)
77−{
78− if ((idx < 0) || (idx >= s->length)) return 0.f;
79−
80− return s->buff[idx];
81−}
82−
83−void tBuffer_record(tBuffer* const s)
84−{
85− s->active = 1;
86− s->idx = 0;
87−}
88−
89−void tBuffer_stop(tBuffer* const s)
90−{
91− s->active = 0;
92−}
93−
94−void tBuffer_setRecordMode (tBuffer* const s, RecordMode mode)
95−{
96− s->mode = mode;
97−}
98−
99−void tBuffer_clear (tBuffer* const s)
100−{
101− for (int i = 0; i < s->length; i++)
102− {
103− s->buff[i] = 0.f;
104− }
105−}
106−
107−//================================tSampler=====================================
108−
109−void tSampler_init (tSampler* const p, tBuffer* s)
110−{
111− p->samp = s;
112−
113− p->active = 0;
114−
115− p->start = 0;
116− p->end = p->samp->length - 1;
117−
118− p->len = p->end - p->start;
119−
120− p->idx = 0.f;
121− p->inc = 1.f;
122− p->iinc = 1.f;
123−
124− p->dir = 1;
125− p->flip = 1;
126− p->bnf = 1;
127−
128− p->mode = Normal;
129−
130− p->cfxlen = 300; // default 300 sample crossfade
131−
132− tRamp_init(&p->gain, 7.0f, 1);
133− tRamp_setVal(&p->gain, 0.f);
134−}
135−
136−void tSampler_free (tSampler* const p)
137−{
138− leaf_free(p->samp);
139− leaf_free(p);
140−}
141−
142−float tSampler_tick (tSampler* const p)
143−{
144− if (p->active == 0 || (p->len < 4)) return 0.f;
145−
146− float sample = 0.f;
147− float cfxsample = 0.f;
148− int numsamps;
149− float g1 = 1.f, g2 = 0.f;
150−
151− float* buff = p->samp->buff;
152−
153− int dir = p->bnf * p->dir * p->flip;
154−
22+#endif
23+
24+//==============================================================================
25+
26+void tBuffer_init (tBuffer* const s, uint32_t length)
27+{
28+ s->buff = (float*) leaf_alloc( sizeof(float) * length);
29+
30+
31+ s->length = length;
32+ s->active = 0;
33+ s->idx = 0;
34+ s->mode = RecordOneShot;
35+
36+ tBuffer_clear(s);
37+}
38+
39+void tBuffer_free (tBuffer* const s)
40+{
41+ leaf_free(s->buff);
42+ leaf_free(s);
43+}
44+
45+void tBuffer_tick (tBuffer* const s, float sample)
46+{
47+ if (s->active == 1)
48+ {
49+ s->buff[s->idx] = sample;
50+
51+ s->idx += 1;
52+
53+ if (s->idx >= s->length)
54+ {
55+ if (s->mode == RecordOneShot)
56+ {
57+ tBuffer_stop(s);
58+ }
59+ else if (s->mode == RecordLoop)
60+ {
61+ s->idx = 0;
62+ }
63+ }
64+ }
65+}
66+
67+void tBuffer_read(tBuffer* const s, float* buff, uint32_t len)
68+{
69+ for (int i = 0; i < s->length; i++)
70+ {
71+ if (i < len) s->buff[i] = buff[i];
72+ else s->buff[i] = 0.f;
73+ }
74+}
75+
76+float tBuffer_get (tBuffer* const s, int idx)
77+{
78+ if ((idx < 0) || (idx >= s->length)) return 0.f;
79+
80+ return s->buff[idx];
81+}
82+
83+void tBuffer_record(tBuffer* const s)
84+{
85+ s->active = 1;
86+ s->idx = 0;
87+}
88+
89+void tBuffer_stop(tBuffer* const s)
90+{
91+ s->active = 0;
92+}
93+
94+void tBuffer_setRecordMode (tBuffer* const s, RecordMode mode)
95+{
96+ s->mode = mode;
97+}
98+
99+void tBuffer_clear (tBuffer* const s)
100+{
101+ for (int i = 0; i < s->length; i++)
102+ {
103+ s->buff[i] = 0.f;
104+ }
105+}
106+
107+//================================tSampler=====================================
108+
109+void tSampler_init (tSampler* const p, tBuffer* s)
110+{
111+ p->samp = s;
112+
113+ p->active = 0;
114+
115+ p->start = 0;
116+ p->end = p->samp->length - 1;
117+
118+ p->len = p->end - p->start;
119+
120+ p->idx = 0.f;
121+ p->inc = 1.f;
122+ p->iinc = 1.f;
123+
124+ p->dir = 1;
125+ p->flip = 1;
126+ p->bnf = 1;
127+
128+ p->mode = Normal;
129+
130+ p->cfxlen = 300; // default 300 sample crossfade
131+
132+ tRamp_init(&p->gain, 7.0f, 1);
133+ tRamp_setVal(&p->gain, 0.f);
134+}
135+
136+void tSampler_free (tSampler* const p)
137+{
138+ leaf_free(p->samp);
139+ leaf_free(p);
140+}
141+
142+float tSampler_tick (tSampler* const p)
143+{
144+ if (p->active == 0 || (p->len < 4)) return 0.f;
145+
146+ float sample = 0.f;
147+ float cfxsample = 0.f;
148+ int numsamps;
149+ float g1 = 1.f, g2 = 0.f;
150+
151+ float* buff = p->samp->buff;
152+
153+ int dir = p->bnf * p->dir * p->flip;
154+
155155 int idx;
156156 float alpha;
157−
158− if (dir > 0)
159− {
157+
158+ if (dir > 0)
159+ {
160160 idx = (int) p->idx;
161161 alpha = p->idx - idx;
162− }
163− else
164− {
165− idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards
166− alpha = (p->idx+1.f) - idx;
167− }
168−
169− int32_t start = p->start, end = p->end;
170− if (p->flip < 0)
171− {
172− start = p->end;
173− end = p->start;
174− }
175−
176− // Check dir (direction) to interpolate properly
177− if (dir > 0)
178− {
179− // FORWARD NORMAL SAMPLE
180− int i1 = idx-1;
181− int i3 = idx+1;
182− int i4 = idx+2;
183−
184− sample = LEAF_interpolate_hermite (buff[i1],
185− buff[idx],
186− buff[i3],
187− buff[i4],
188− alpha);
189−
190− // num samples to end of loop
191− numsamps = (dir > 0) ? (end - idx) : (idx - start);
192− numsamps *= p->iinc;
193−
194− if (p->mode == Loop)
195− {
196− if (numsamps <= p->cfxlen)
197− {
198− // CROSSFADE SAMPLE
199− float idxx = p->idx - p->len;
200− int cdx = (int)(idxx);
201−
202− i1 = cdx-1;
203− i3 = cdx+1;
204− i4 = cdx+2;
205−
206− cfxsample = LEAF_interpolate_hermite (buff[i1],
207− buff[cdx],
208− buff[i3],
209− buff[i4],
210− alpha);
211−
212− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
213− }
214− }
215− }
216− else
217− {
218− // REVERSE
219− int i1 = idx+1;
220− int i3 = idx-1;
221− int i4 = idx-2;
222−
223− sample = LEAF_interpolate_hermite (buff[i1],
224− buff[idx],
225− buff[i3],
226− buff[i4],
227− 1.0f-alpha);
228−
229− numsamps = (idx - start) / p->inc;
230−
231− if (p->mode == Loop)
232− {
233− if (numsamps <= p->cfxlen)
234− {
235− // CROSSFADE SAMPLE
236− float idxx = p->idx + p->len + 1.f;
237− int cdx = (int)(idxx);
238− alpha = idxx - cdx;
239−
240− i1 = cdx+1;
241− i3 = cdx-1;
242− i4 = cdx-2;
243−
244− cfxsample = LEAF_interpolate_hermite (buff[i1],
245− buff[cdx],
246− buff[i3],
247− buff[i4],
248− 1.f-alpha);
249−
250− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
251− }
252− }
253− }
254−
255− p->idx += (dir * p->inc);
256−
257− if (p->mode == Normal)
258− {
259− if (numsamps < (0.007f * leaf.sampleRate))
260− {
261− tRamp_setDest(&p->gain, 0.f);
262− p->active = -1;
263− }
264− }
265− else if (p->mode == Loop ) // == Normal or Loop
266− {
267− if (idx <= start)
268− {
269− p->idx += (float)(p->len);
270− }
271− else if (idx >= end)
272− {
273− p->idx -= (float)(p->len);
274− }
275− }
276− else // == BackAndForth
277− {
278− if (p->idx < start)
279− {
280− p->bnf = -p->bnf;
281− p->idx = start;
282− }
283− else if (p->idx > end)
284− {
285− p->bnf = -p->bnf;
286− p->idx = end;
287− }
288− }
289−
290− g1 = 1.f - g2;
291−
292− sample = sample * g1 + cfxsample * g2;
293−
294− sample = sample * tRamp_tick(&p->gain);
295−
296− if (p->active < 0)
297− {
298− if (tRamp_sample(&p->gain) <= 0.00001f)
299− {
300− if (p->retrigger == 1)
301− {
302− p->active = 1;
303− p->retrigger = 0;
304− tRamp_setDest(&p->gain, 1.f);
305−
306− if (p->dir > 0)
307− {
308− if (p->flip > 0) p->idx = p->start;
309− else p->idx = p->end;
310− }
311− else
312− {
313− if (p->flip > 0) p->idx = p->end;
314− else p->idx = p->start;
315− }
316− }
317− else
318− {
319− p->active = 0;
320− }
321−
322− }
323− }
324−
325− return sample;
326−}
327−
328−void tSampler_setSample (tSampler* const p, tBuffer* s)
329−{
330− p->samp = s;
331−}
332−
333−void tSampler_setMode (tSampler* const p, Mode mode)
334−{
335− p->mode = mode;
336−}
337−
338−void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length)
339−{
340− uint32_t cfxlen = LEAF_clip(0, length, 1000);
341−
342− //if (cfxlen > p->len) cfxlen = p->len * 0.25f;
343−
344− p->cfxlen = cfxlen;
345−}
346−
347−void tSampler_play (tSampler* const p)
348−{
349− if (p->active != 0)
350− {
351− p->active = -1;
352− p->retrigger = 1;
353−
354− tRamp_setDest(&p->gain, 0.f);
355− }
356− else
357− {
358− p->active = 1;
359− p->retrigger = 0;
360−
361− tRamp_setDest(&p->gain, 1.f);
362−
363− if (p->dir > 0)
364− {
365− if (p->flip > 0) p->idx = p->start;
366− else p->idx = p->end;
367− }
368− else
369− {
370− if (p->flip > 0) p->idx = p->end;
371− else p->idx = p->start;
372− }
373− }
374−}
375−
376−void tSampler_stop (tSampler* const p)
377−{
378− p->active = -1;
379−
380− tRamp_setDest(&p->gain, 0.f);
381−}
382−
383−static void handleStartEndChange(tSampler* const p)
384−{
385− p->len = abs(p->end - p->start);
386−
387− //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f;
388−
389− if (p->start > p->end)
390− {
391− p->flip = -1;
392− }
393− else
394− {
395− p->flip = 1;
396− }
397−}
398−
399−void tSampler_setStart (tSampler* const p, int32_t start)
400−{
401− p->start = LEAF_clipInt(0, start, (p->samp->length - 1));
402−
403− handleStartEndChange(p);
404−}
405−
406−void tSampler_setEnd (tSampler* const p, int32_t end)
407−{
408− p->end = LEAF_clipInt(0, end, (p->samp->length - 1));
409−
410− handleStartEndChange(p);
411−}
412−
413−void tSampler_setRate (tSampler* const p, float rate)
414−{
415− if (rate < 0.f)
416− {
417− rate = -rate;
418− p->dir = -1;
419− }
420− else
421− {
422− p->dir = 1;
423− }
424−
425− p->inc = LEAF_clip(0.f, rate, 8.0f);
426− p->iinc = 1.f / p->inc;
427−}
428−
429−
162+ }
163+ else
164+ {
165+ idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards
166+ alpha = (p->idx+1.f) - idx;
167+ }
168+
169+ int32_t start = p->start, end = p->end;
170+ if (p->flip < 0)
171+ {
172+ start = p->end;
173+ end = p->start;
174+ }
175+
176+ // Check dir (direction) to interpolate properly
177+ if (dir > 0)
178+ {
179+ // FORWARD NORMAL SAMPLE
180+ int i1 = idx-1;
181+ int i3 = idx+1;
182+ int i4 = idx+2;
183+
184+ sample = LEAF_interpolate_hermite (buff[i1],
185+ buff[idx],
186+ buff[i3],
187+ buff[i4],
188+ alpha);
189+
190+ // num samples to end of loop
191+ numsamps = (dir > 0) ? (end - idx) : (idx - start);
192+ numsamps *= p->iinc;
193+
194+ if (p->mode == Loop)
195+ {
196+ if (numsamps <= p->cfxlen)
197+ {
198+ // CROSSFADE SAMPLE
199+ float idxx = p->idx - p->len;
200+ int cdx = (int)(idxx);
201+
202+ i1 = cdx-1;
203+ i3 = cdx+1;
204+ i4 = cdx+2;
205+
206+ cfxsample = LEAF_interpolate_hermite (buff[i1],
207+ buff[cdx],
208+ buff[i3],
209+ buff[i4],
210+ alpha);
211+
212+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
213+ }
214+ }
215+ }
216+ else
217+ {
218+ // REVERSE
219+ int i1 = idx+1;
220+ int i3 = idx-1;
221+ int i4 = idx-2;
222+
223+ sample = LEAF_interpolate_hermite (buff[i1],
224+ buff[idx],
225+ buff[i3],
226+ buff[i4],
227+ 1.0f-alpha);
228+
229+ numsamps = (idx - start) / p->inc;
230+
231+ if (p->mode == Loop)
232+ {
233+ if (numsamps <= p->cfxlen)
234+ {
235+ // CROSSFADE SAMPLE
236+ float idxx = p->idx + p->len + 1.f;
237+ int cdx = (int)(idxx);
238+ alpha = idxx - cdx;
239+
240+ i1 = cdx+1;
241+ i3 = cdx-1;
242+ i4 = cdx-2;
243+
244+ cfxsample = LEAF_interpolate_hermite (buff[i1],
245+ buff[cdx],
246+ buff[i3],
247+ buff[i4],
248+ 1.f-alpha);
249+
250+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
251+ }
252+ }
253+ }
254+
255+ p->idx += (dir * p->inc);
256+
257+ if (p->mode == Normal)
258+ {
259+ if (numsamps < (0.007f * leaf.sampleRate))
260+ {
261+ tRamp_setDest(&p->gain, 0.f);
262+ p->active = -1;
263+ }
264+ }
265+ else if (p->mode == Loop ) // == Normal or Loop
266+ {
267+ if (idx <= start)
268+ {
269+ p->idx += (float)(p->len);
270+ }
271+ else if (idx >= end)
272+ {
273+ p->idx -= (float)(p->len);
274+ }
275+ }
276+ else // == BackAndForth
277+ {
278+ if (p->idx < start)
279+ {
280+ p->bnf = -p->bnf;
281+ p->idx = start;
282+ }
283+ else if (p->idx > end)
284+ {
285+ p->bnf = -p->bnf;
286+ p->idx = end;
287+ }
288+ }
289+
290+ g1 = 1.f - g2;
291+
292+ sample = sample * g1 + cfxsample * g2;
293+
294+ sample = sample * tRamp_tick(&p->gain);
295+
296+ if (p->active < 0)
297+ {
298+ if (tRamp_sample(&p->gain) <= 0.00001f)
299+ {
300+ if (p->retrigger == 1)
301+ {
302+ p->active = 1;
303+ p->retrigger = 0;
304+ tRamp_setDest(&p->gain, 1.f);
305+
306+ if (p->dir > 0)
307+ {
308+ if (p->flip > 0) p->idx = p->start;
309+ else p->idx = p->end;
310+ }
311+ else
312+ {
313+ if (p->flip > 0) p->idx = p->end;
314+ else p->idx = p->start;
315+ }
316+ }
317+ else
318+ {
319+ p->active = 0;
320+ }
321+
322+ }
323+ }
324+
325+ return sample;
326+}
327+
328+void tSampler_setSample (tSampler* const p, tBuffer* s)
329+{
330+ p->samp = s;
331+}
332+
333+void tSampler_setMode (tSampler* const p, Mode mode)
334+{
335+ p->mode = mode;
336+}
337+
338+void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length)
339+{
340+ uint32_t cfxlen = LEAF_clip(0, length, 1000);
341+
342+ //if (cfxlen > p->len) cfxlen = p->len * 0.25f;
343+
344+ p->cfxlen = cfxlen;
345+}
346+
347+void tSampler_play (tSampler* const p)
348+{
349+ if (p->active != 0)
350+ {
351+ p->active = -1;
352+ p->retrigger = 1;
353+
354+ tRamp_setDest(&p->gain, 0.f);
355+ }
356+ else
357+ {
358+ p->active = 1;
359+ p->retrigger = 0;
360+
361+ tRamp_setDest(&p->gain, 1.f);
362+
363+ if (p->dir > 0)
364+ {
365+ if (p->flip > 0) p->idx = p->start;
366+ else p->idx = p->end;
367+ }
368+ else
369+ {
370+ if (p->flip > 0) p->idx = p->end;
371+ else p->idx = p->start;
372+ }
373+ }
374+}
375+
376+void tSampler_stop (tSampler* const p)
377+{
378+ p->active = -1;
379+
380+ tRamp_setDest(&p->gain, 0.f);
381+}
382+
383+static void handleStartEndChange(tSampler* const p)
384+{
385+ p->len = abs(p->end - p->start);
386+
387+ //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f;
388+
389+ if (p->start > p->end)
390+ {
391+ p->flip = -1;
392+ }
393+ else
394+ {
395+ p->flip = 1;
396+ }
397+}
398+
399+void tSampler_setStart (tSampler* const p, int32_t start)
400+{
401+ p->start = LEAF_clipInt(0, start, (p->samp->length - 1));
402+
403+ handleStartEndChange(p);
404+}
405+
406+void tSampler_setEnd (tSampler* const p, int32_t end)
407+{
408+ p->end = LEAF_clipInt(0, end, (p->samp->length - 1));
409+
410+ handleStartEndChange(p);
411+}
412+
413+void tSampler_setRate (tSampler* const p, float rate)
414+{
415+ if (rate < 0.f)
416+ {
417+ rate = -rate;
418+ p->dir = -1;
419+ }
420+ else
421+ {
422+ p->dir = 1;
423+ }
424+
425+ p->inc = LEAF_clip(0.f, rate, 8.0f);
426+ p->iinc = 1.f / p->inc;
427+}
428+
429+
430430 //==============================================================================
LEAF/Src/leaf-string.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf-string.cpp
3+ leaf-string.c
54 Created: 30 Nov 2018 10:41:42am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-utilities.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFUtilities.c
3+ leaf-utilities.c
54 Created: 20 Jan 2017 12:02:17pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119
1210 #if _WIN32 || _WIN64
LEAF/Src/leaf-vocoder.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− LEAFInstrument.c
3+ leaf-vocoder.c
54 Created: 20 Jan 2017 12:01:54pm
65 Author: Michael R Mulshine
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/Src/leaf-wavefolder.c+3−5
@@ -1,12 +1,10 @@
1−/*
2− ==============================================================================
1+/*==============================================================================
32
4− leaf-wavefolder.cpp
3+ leaf-wavefolder.c
54 Created: 30 Nov 2018 11:56:49am
65 Author: airship
76
8− ==============================================================================
9−*/
7+==============================================================================*/
108
119 #if _WIN32 || _WIN64
1210
LEAF/leaf.h+4−2
@@ -32,7 +32,8 @@ · 31 unmodified lines
3232 #include ".\Inc\leaf-pitch.h"
3333 #include ".\Inc\leaf-formant.h"
3434 #include ".\Inc\leaf-midi.h"
35−#include ".\Inc\leaf-sample.h"
35+#include ".\Inc\leaf-sample.h"
36+#include ".\Inc\leaf-crusher.h"
3637 #include ".\Inc\leaf-wavefolder.h"
3738 #include ".\Inc\leaf-wavetables.h"
3839
@@ -51,7 +52,8 @@ · 12 unmodified lines
5152 #include "./Inc/leaf-pitch.h"
5253 #include "./Inc/leaf-formant.h"
5354 #include "./Inc/leaf-midi.h"
54−#include "./Inc/leaf-sample.h"
55+#include "./Inc/leaf-sample.h"
56+#include "./Inc/leaf-crusher.h"
5557 #include "./Inc/leaf-wavefolder.h"
5658 #include "./Inc/leaf-wavetables.h"
5759
LEAF_JUCEPlugin/LEAF.jucer+2−0
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040 file="../LEAF/Inc/leaf-utilities.h"/>
4141 <FILE id="Szb5LP" name="leaf-vocoder.h" compile="0" resource="0" file="../LEAF/Inc/leaf-vocoder.h"/>
4242 <FILE id="T6KXi7" name="leaf-sample.h" compile="0" resource="0" file="../LEAF/Inc/leaf-sample.h"/>
43+ <FILE id="bpUZCA" name="leaf-crusher.h" compile="0" resource="0" file="../LEAF/Inc/leaf-crusher.h"/>
4344 <FILE id="PRkOp2" name="leaf-wavefolder.h" compile="0" resource="0"
4445 file="../LEAF/Inc/leaf-wavefolder.h"/>
4546 <FILE id="KpGzKv" name="leaf-wavetables.h" compile="0" resource="0"
@@ -62,6 +63,7 @@ · 16 unmodified lines
6263 file="../LEAF/Src/leaf-utilities.c"/>
6364 <FILE id="u1aLLR" name="leaf-vocoder.c" compile="1" resource="0" file="../LEAF/Src/leaf-vocoder.c"/>
6465 <FILE id="nmtoFJ" name="leaf-sample.c" compile="1" resource="0" file="../LEAF/Src/leaf-sample.c"/>
66+ <FILE id="Oymcac" name="leaf-crusher.c" compile="1" resource="0" file="../LEAF/Src/leaf-crusher.c"/>
6567 <FILE id="LVoaGm" name="leaf-wavefolder.c" compile="1" resource="0"
6668 file="../LEAF/Src/leaf-wavefolder.c"/>
6769 <FILE id="HRk07h" name="leaf-wavetables.c" compile="1" resource="0"
LEAF_JUCEPlugin/Source/LEAFLink.cpp+6−6
@@ -15,16 +15,16 @@ · 14 unmodified lines
1515
1616 std::vector<juce::String> cButtonNames = std::vector<juce::String>
1717 {
18− "sample",
19− "play"
18+
2019 };
2120
2221 std::vector<juce::String> cSliderNames = std::vector<juce::String>
2322 {
24− "rate",
25− "start",
26− "end",
27− "cfxlen"
23+ "sr",
24+ "rnd",
25+ "qual",
26+ "op",
27+ "mix"
2828 };
2929
3030 std::vector<juce::String> cComboBoxNames = std::vector<juce::String>
LEAF_JUCEPlugin/Source/MyTest.cpp+47−48
@@ -14,77 +14,76 @@ · 13 unmodified lines
1414
1515 static void leaf_pool_report(void);
1616 static void leaf_pool_dump(void);
17−static void run_pool_test(void);
18−
19−tBuffer sample;
17+static void run_pool_test(void);
18+
19+float mix = 0.f;
20+float fx = 1.f;
2021
21−tSampler player;
22+tCrusher crusher;
2223
2324 void LEAFTest_init (float sampleRate, int blockSize)
2425 {
25− LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
26−
27− tBuffer_init(&sample, leaf.sampleRate * 2);
28−
29− tSampler_init(&player, &sample);
30− tSampler_setMode(&player, Normal);
31−
32− leaf_pool_report();
33−
34− tBuffer_record(&sample);
26+ LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
27+
28+ tCrusher_init(&crusher);
29+
30+ leaf_pool_report();
3531 }
3632
3733 int timer = 0;
3834
3935 float LEAFTest_tick (float input)
4036 {
41− tBuffer_tick(&sample, input);
37+ float sample = 0.f;
4238
43− return tSampler_tick(&player);
39+ sample = (mix * tCrusher_tick(&crusher, input)) + ((1.f - mix) * input);
40+
41+ return sample;
4442 }
45−
43+
4644 bool lastState = false, lastPlayState = false;
4745 void LEAFTest_block (void)
48−{
49− float val = getSliderValue("rate");
46+{
47+ float val = getSliderValue("mix");
48+
49+ mix = val;
50+
51+ val = getSliderValue("sr");
52+
53+ tCrusher_setSamplingRatio(&crusher, val * 3.99f + 0.01f);
5054
51− float rate = val * 16.0f - 8.0f;
52− tSampler_setRate(&player, rate);
53− //DBG("rate: " + String(rate));
55+ val = getSliderValue("rnd");
5456
55− val = getSliderValue("start");
56− float start = val * sample.length;
57− tSampler_setStart(&player, start);
58− //DBG("start: " + String(start));
57+ tCrusher_setRound(&crusher, val);
5958
60− val = getSliderValue("end");
61− float end = val * sample.length;
62− tSampler_setEnd(&player, end);
63− //DBG("end: " + String(end));
59+ val = getSliderValue("qual");
6460
65− val = getSliderValue("cfxlen");
66− uint32_t cfxlen = val * 500;
67− tSampler_setCrossfadeLength(&player, cfxlen);
68− DBG("cfxlen: " + String(cfxlen));
61+ tCrusher_setQuality(&crusher, val);
6962
70− bool state = getButtonState("sample");
63+ val = getSliderValue("op");
7164
72− if (state && !lastState)
73− {
74− timer = 0;
75− tBuffer_record(&sample);
76− }
65+ tCrusher_setOperation(&crusher, (int)(val * 8.0f));
7766
78− lastState = state;
67+ /*
68+ float samp = -1.f + 2.f * val;
7969
80− state = getButtonState("play");
70+ union unholy_t bw;
71+ bw.f = samp;
72+ bw.i = (bw.i | (op << 23));
8173
82− if (state && !lastPlayState)
83− {
84− tSampler_play(&player);
85− }
74+ DBG(String(samp) + " " + String(bw.f));
75+ */
8676
87− lastPlayState = state;
77+ // rounding test
78+ /*
79+ val = getSliderValue("rnd");
80+
81+ float to_rnd = -1.f + 2.f * val;
82+
83+ float rnd = LEAF_round(to_rnd, 0.3f);
84+
85+ DBG("to_rnd: " + String(to_rnd) + " rnd: " + String(rnd));
86+ */
8887 }
8988
9089 void LEAFTest_controllerInput (int cnum, float cval)
@@ -148,7 +147,7 @@ static void run_pool_test(void) · 57 unmodified lines
148147 }
149148
150149 leaf_pool_report();
151−
150+
152151 DBG("ALLOC BUFFER 2");
153152 size = 25;
154153

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