History

Merge branch 'master' of https://github.com/spiricom/leaf

Jeff Snyder committed 7 years ago

Commit 84de0e32 parents ae6880a ad69b2310 files · +265 −210Browse files

Unified · Split

10 files
  1. LEAF/Inc/leaf-crusher.h +1 −1
  2. LEAF/Inc/leaf-globals.h +3 −3
  3. LEAF/Inc/leaf-sample.h +1 −0
  4. LEAF/Src/leaf-crusher.c +1 −1
  5. LEAF/Src/leaf-sample.c +61 −53
  6. LEAF_JUCEPlugin/.DS_Store +0 −0
  7. LEAF_JUCEPlugin/JuceLibraryCode/AppConfig.h +6 −0
  8. LEAF_JUCEPlugin/LEAF.jucer +1 −1
  9. LEAF_JUCEPlugin/Source/LEAFLink.cpp +3 −4
  10. LEAF_JUCEPlugin/Source/MyTest.cpp +189 −148
LEAF/Inc/leaf-crusher.h+1−1
@@ -61,4 +61,4 @@ void tCrusher_setSamplingRatio (tCrusher* const, float ratio); · 60 unmodified lines
6161
6262 #endif // LEAF_WAVEFOLDER_H_INCLUDED
6363
64−//==============================================================================
64+//==============================================================================
LEAF/Inc/leaf-globals.h+3−3
@@ -25,12 +25,12 @@ typedef struct _LEAF · 24 unmodified lines
2525 float invSampleRate;
2626 int blockSize;
2727
28− /*
28+
2929 float* sinewave;
3030 float* sawtooth[11];
3131 float* square[11];
3232 float* triangle[11];
33− */
33+
3434
3535 float (*random)(void);
3636 } LEAF;
@@ -57,7 +57,7 @@ extern const float shaper1[SHAPER1_TABLE_SIZE]; · 20 unmodified lines
5757 // Feel free to change to suit memory constraints or desired delay max length / functionality.
5858
5959
60−
60+#define TALKBOX_BUFFER_LENGTH 1600 // Every talkbox instance introduces 5 buffers of this size
6161
6262 union unholy_t { /* a union between a float and an integer */
6363 float f;
LEAF/Inc/leaf-sample.h+1−0
@@ -77,6 +77,7 @@ extern "C" { · 76 unmodified lines
7777
7878 float idx;
7979 float inc;
80+ float last;
8081 float iinc;
8182 int8_t dir;
8283 int8_t flip;
LEAF/Src/leaf-crusher.c+1−1
@@ -81,4 +81,4 @@ void tCrusher_setRound (tCrusher* const c, float rnd) · 80 unmodified lines
8181 void tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
8282 {
8383 c->srr = ratio;
84−}
84+}
LEAF/Src/leaf-sample.c+61−53
@@ -141,8 +141,13 @@ void tSampler_free (tSampler* const p) · 140 unmodified lines
141141
142142 float tSampler_tick (tSampler* const p)
143143 {
144− if (p->active == 0 || (p->len < 4)) return 0.f;
145−
144+ if (p->active == 0) return 0.f;
145+
146+ if ((p->inc == 0.0f) || (p->len < 4))
147+ {
148+ return p->last;
149+ }
150+
146151 float sample = 0.f;
147152 float cfxsample = 0.f;
148153 int numsamps;
@@ -162,7 +167,7 @@ float tSampler_tick (tSampler* const p) · 13 unmodified lines
162167 }
163168 else
164169 {
165− idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards
170+ idx = (int) (p->idx+1.f); // we think this is because flooring on int works different when reading backwards
166171 alpha = (p->idx+1.f) - idx;
167172 }
168173
@@ -173,52 +178,53 @@ float tSampler_tick (tSampler* const p) · 4 unmodified lines
173178 end = p->start;
174179 }
175180
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 == PlayLoop)
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
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
217223 {
218− // REVERSE
219− int i1 = idx+1;
220− int i3 = idx-1;
221− int i4 = idx-2;
224+ // REVERSE
225+ int i1 = (idx+1) % p->len;
226+ int i3 = ((idx-1) + p->len) % p->len;
227+ int i4 = ((idx-2) + p->len) % p->len;
222228
223229 sample = LEAF_interpolate_hermite (buff[i1],
224230 buff[idx],
@@ -234,12 +240,12 @@ float tSampler_tick (tSampler* const p) · 9 unmodified lines
234240 {
235241 // CROSSFADE SAMPLE
236242 float idxx = p->idx + p->len + 1.f;
237− int cdx = (int)(idxx);
243+ int cdx = ((int)(idxx)) % p->len;
238244 alpha = idxx - cdx;
239245
240− i1 = cdx+1;
241− i3 = cdx-1;
242− i4 = cdx-2;
246+ i1 = (cdx+1) % p->len;
247+ i3 = ((cdx-1) + p->len) % p->len;
248+ i4 = ((cdx-2) + p->len) % p->len;
243249
244250 cfxsample = LEAF_interpolate_hermite (buff[i1],
245251 buff[cdx],
@@ -322,7 +328,9 @@ float tSampler_tick (tSampler* const p) · 76 unmodified lines
322328 }
323329 }
324330
325− return sample;
331+ p->last = sample;
332+
333+ return p->last;
326334 }
327335
328336 void tSampler_setSample (tSampler* const p, tBuffer* s)
LEAF_JUCEPlugin/.DS_Store+0−0

Binary file not shown.

LEAF_JUCEPlugin/JuceLibraryCode/AppConfig.h+6−0
@@ -451,6 +451,12 @@ · 450 unmodified lines
451451 #ifndef JucePlugin_IAAName
452452 #define JucePlugin_IAAName "pumusic: LEAF"
453453 #endif
454+#ifndef JucePlugin_VSTNumMidiInputs
455+ #define JucePlugin_VSTNumMidiInputs 16
456+#endif
457+#ifndef JucePlugin_VSTNumMidiOutputs
458+ #define JucePlugin_VSTNumMidiOutputs 16
459+#endif
454460 #ifndef JucePlugin_MaxNumInputChannels
455461 #define JucePlugin_MaxNumInputChannels 2
456462 #endif
LEAF_JUCEPlugin/LEAF.jucer+1−1
@@ -8,7 +8,7 @@ · 7 unmodified lines
88 pluginIsSynth="0" pluginWantsMidiIn="1" pluginProducesMidiOut="0"
99 pluginIsMidiEffectPlugin="0" pluginEditorRequiresKeys="0" pluginAUExportPrefix="LEAFAU"
1010 pluginRTASCategory="" aaxIdentifier="com.pumusic.LEAF" pluginAAXCategory="2"
11− jucerVersion="5.4.1" companyName="Princeton University" companyEmail="mrmulshine@gmail.com"
11+ jucerVersion="5.4.3" companyName="Princeton University" companyEmail="mrmulshine@gmail.com"
1212 displaySplashScreen="1" reportAppUsage="1" splashScreenColour="Dark"
1313 buildStandalone="1" enableIAA="0" cppLanguageStandard="11" companyCopyright="Princeton University"
1414 pluginFormats="buildVST,buildAU,buildStandalone" pluginCharacteristicsValue="pluginWantsMidiIn">
LEAF_JUCEPlugin/Source/LEAFLink.cpp+3−4
@@ -15,14 +15,13 @@ · 14 unmodified lines
1515
1616 std::vector<juce::String> cButtonNames = std::vector<juce::String>
1717 {
18−
18+ "record"
1919 };
2020
2121 std::vector<juce::String> cSliderNames = std::vector<juce::String>
2222 {
23− "gain",
24− "frequency",
25− "distortion"
23+ "mod freq",
24+ "mod depth"
2625 };
2726
2827 std::vector<juce::String> cComboBoxNames = std::vector<juce::String>
LEAF_JUCEPlugin/Source/MyTest.cpp+189−148
@@ -1,153 +1,194 @@
1−/*
2− ==============================================================================
3−
4− FM.c
5− Created: 23 Jan 2017 9:39:38am
6− Author: Michael R Mulshine
7−
8− ==============================================================================
9−*/
10−
11−#include "LEAFTest.h"
12−#include "MyTest.h"
13−
14−
15−static void leaf_pool_report(void);
16−static void leaf_pool_dump(void);
17−static void run_pool_test(void);
18−
19−float gain, freqVal;
20−float clipThreshold = 1.f;
21−
22−tCycle test;
23−tOversampler2x os2;
24−tOversampler4x os4;
25−
26−void LEAFTest_init (float sampleRate, int blockSize)
27−{
28− LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
29−
30− tCycle_init(&test);
31− tOversampler2x_init(&os2);
32− tOversampler4x_init(&os4);
33−
34− leaf_pool_report();
35−}
36−
37−
38−float softClip(float sample)
39−{
40− return LEAF_softClip(sample, clipThreshold);
41−}
42−
43−float lastOut;
44−
45−float LEAFTest_tick (float input)
46−{
47− tCycle_setFreq(&test, freqVal);
48− float sample = tCycle_tick(&test);
49−
50− sample = tOversampler4x_tick(&os4, sample, &softClip);
51−
52− return sample * gain;
53−}
54−
55−bool lastState = false, lastPlayState = false;
56−void LEAFTest_block (void)
57−{
58− clipThreshold = (1.f - getSliderValue("distortion")) * 0.3f;
59− gain = getSliderValue("gain") * 0.5f;
60− freqVal = getSliderValue("frequency") * 18000.f;
61−}
62−
63−void LEAFTest_controllerInput (int cnum, float cval)
64−{
65−
66−}
67−
68−void LEAFTest_pitchBendInput (int pitchBend)
69−{
70−
71−}
72−
73−int lastNote;
74−void LEAFTest_noteOn (int note, float velocity)
75−{
76−}
77−
78−
79−void LEAFTest_noteOff (int note)
80−{
1+/*
2+ ==============================================================================
3+
4+ FM.c
5+ Created: 23 Jan 2017 9:39:38am
6+ Author: Michael R Mulshine
7+
8+ ==============================================================================
9+*/
10+
11+#include "LEAFTest.h"
12+#include "MyTest.h"
13+
14+
15+static void leaf_pool_report(void);
16+static void leaf_pool_dump(void);
17+static void run_pool_test(void);
18+
19+float mix = 0.f;
20+float fx = 1.f;
21+
22+#define NUM_GRAINS 20
23+
24+
25+
26+tTapeDelay delay;
27+
28+float feedback = 0.f;
29+
30+tBuffer buff;
31+tSampler samp;
32+
33+tCycle osc;
34+
35+void LEAFTest_init (float sampleRate, int blockSize)
36+{
37+ LEAF_init(sampleRate, blockSize, &getRandomFloat);
38+
39+ // Init and set record
40+ tBuffer_init (&buff, leaf.sampleRate * 1.f); // init, 1 second buffer
41+ tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
42+ tBuffer_record(&buff); // starts recording
43+
44+ // Init and set play
45+ tSampler_init (&samp, &buff); // init, give address of record buffer
46+ tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
47+ tSampler_setRate(&samp, 1.f); // Rate of 1.0
48+ tSampler_play(&samp); // start spitting samples out
49+
50+ tCycle_init(&osc);
51+
52+ leaf_pool_report();
8153 }
8254
83−
84−
85−void LEAFTest_end (void)
86−{
87−
88−}
89−
90−// LEAF POOL UTILITIES
91−
92−void leaf_pool_report(void)
93−{
94− DBG(String(leaf_pool_get_used()) + " of " + String(leaf_pool_get_size()));
95−}
96−
97−void leaf_pool_dump(void)
98−{
99− float* buff = (float*)leaf_pool_get_pool();
100− int siz = leaf_pool_get_size();
101− siz /= sizeof(float);
102− for (int i = 0; i < siz; i++)
103− {
104− DBG(String(buff[i]));
105− }
106−}
107−
108−static void run_pool_test(void)
109−{
110− leaf_pool_report();
111−
112− DBG("ALLOC BUFFER 1");
113− int size = 50;
114− float* buffer;
115− buffer = (float*) leaf_alloc(sizeof(float) * size);
116−
117− for (int i = 0; i < size; i++)
118− {
119− buffer[i] = (float)i;
120−
121− }
122−
123− leaf_pool_report();
124−
125− DBG("ALLOC BUFFER 2");
126− size = 25;
127−
128− buffer = (float*) leaf_alloc(sizeof(float) * size);
129−
130− leaf_pool_report();
131−
132− for (int i = 0; i < size; i++)
55+float depth = 1.0f;
56+
57+float LEAFTest_tick (float input)
58+{
59+ float sample = 0.f;
60+
61+ tBuffer_tick(&buff, input); // ticking the buffer records in to buffer
62+
63+ tSampler_setRate(&samp, tCycle_tick(&osc) * depth);
64+
65+ // dont tick sampler if buffer not active (not recording)
66+ if (buff.active == 0)
67+ {
68+ sample = tSampler_tick(&samp); // ticking sampler loops sample
69+ }
70+
71+
72+ return sample;
73+}
74+
75+bool lastState = false, lastPlayState = false;
76+void LEAFTest_block (void)
77+{
78+ bool state = getButtonState("record");
79+
80+ if (state)
13381 {
134− buffer[i] = (float)(i*2);
82+ setButtonState("record", false);
83+ tBuffer_record(&buff);
13584 }
136− leaf_free(buffer);
137−
138− leaf_pool_report();
139−
140− DBG("ALLOC BUFFER 3");
141− size = 15;
14285
143− buffer = (float*) leaf_alloc(sizeof(float) * size);
144−
145− for (int i = 0; i < size; i++)
146− {
147− buffer[i] = (float)(i*3);
148− }
149−
150− leaf_pool_report();
151−
152− leaf_pool_dump();
153−}
86+ float val = getSliderValue("mod freq");
87+
88+ float freq = 0.1 + 999.9 * val;
89+
90+ tCycle_setFreq(&osc, freq);
91+
92+ DBG("mod freq: " + String(freq));
93+
94+ val = getSliderValue("mod depth");
95+
96+ depth = 0.1 + val * 15.9f;
97+
98+ DBG("mod depth: " + String(depth));
99+
100+
101+}
102+
103+void LEAFTest_controllerInput (int cnum, float cval)
104+{
105+
106+}
107+
108+void LEAFTest_pitchBendInput (int pitchBend)
109+{
110+
111+}
112+
113+int lastNote;
114+void LEAFTest_noteOn (int note, float velocity)
115+{
116+}
117+
118+
119+void LEAFTest_noteOff (int note)
120+{
121+}
122+
123+
124+
125+void LEAFTest_end (void)
126+{
127+
128+}
129+
130+// LEAF POOL UTILITIES
131+
132+void leaf_pool_report(void)
133+{
134+ DBG(String(leaf_pool_get_used()) + " of " + String(leaf_pool_get_size()));
135+}
136+
137+void leaf_pool_dump(void)
138+{
139+ float* buff = (float*)leaf_pool_get_pool();
140+ int siz = leaf_pool_get_size();
141+ siz /= sizeof(float);
142+ for (int i = 0; i < siz; i++)
143+ {
144+ DBG(String(buff[i]));
145+ }
146+}
147+
148+static void run_pool_test(void)
149+{
150+ leaf_pool_report();
151+
152+ DBG("ALLOC BUFFER 1");
153+ int size = 50;
154+ float* buffer;
155+ buffer = (float*) leaf_alloc(sizeof(float) * size);
156+
157+ for (int i = 0; i < size; i++)
158+ {
159+ buffer[i] = (float)i;
160+
161+ }
162+
163+ leaf_pool_report();
164+
165+ DBG("ALLOC BUFFER 2");
166+ size = 25;
167+
168+ buffer = (float*) leaf_alloc(sizeof(float) * size);
169+
170+ leaf_pool_report();
171+
172+ for (int i = 0; i < size; i++)
173+ {
174+ buffer[i] = (float)(i*2);
175+ }
176+ leaf_free(buffer);
177+
178+ leaf_pool_report();
179+
180+ DBG("ALLOC BUFFER 3");
181+ size = 15;
182+
183+ buffer = (float*) leaf_alloc(sizeof(float) * size);
184+
185+ for (int i = 0; i < size; i++)
186+ {
187+ buffer[i] = (float)(i*3);
188+ }
189+
190+ leaf_pool_report();
191+
192+ leaf_pool_dump();
193+}
194+

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