History

Saving state in looper.

mulshine committed 7 years ago

Commit 3e8b4821 parent 3f1b8b22 files · +70 −38Browse files

Unified · Split

2 files
  1. LEAF/Inc/leaf-sample.h +5 −1
  2. LEAF/Src/leaf-sample.c +65 −37
LEAF/Inc/leaf-sample.h+5−1
@@ -17,7 +17,9 @@ extern "C" { · 16 unmodified lines
1717 //==============================================================================
1818
1919 #include "leaf-globals.h"
20−#include "leaf-math.h"
20+#include "leaf-math.h"
21+
22+#include "leaf-utilities.h"
2123
2224 //==============================================================================
2325
@@ -71,6 +73,8 @@ extern "C" { · 47 unmodified lines
7173 {
7274 tBuffer* samp;
7375
76+ tRamp gain;
77+
7478 float idx;
7579 float inc;
7680 float iinc;
LEAF/Src/leaf-sample.c+65−37
@@ -126,6 +126,9 @@ void tSampler_init (tSampler* const p, tBuffer* s) · 125 unmodified lines
126126 p->mode = Normal;
127127
128128 p->cfxlen = 300; // default 300 sample crossfade
129+
130+ tRamp_init(&p->gain, 7.0f, 1);
131+ tRamp_setVal(&p->gain, 0.f);
129132 }
130133
131134 void tSampler_free (tSampler* const p)
@@ -186,25 +189,27 @@ float tSampler_tick (tSampler* const p) · 54 unmodified lines
186189 numsamps = (dir > 0) ? (end - idx) : (idx - start);
187190 numsamps *= p->iinc;
188191
189− if (numsamps <= p->cfxlen)
192+ if (p->mode == Loop)
190193 {
191− // CROSSFADE SAMPLE
192− float idxx = p->idx - p->len;
193− int cdx = (int)(idxx);
194−
195− i1 = cdx-1;
196− i3 = cdx+1;
197− i4 = cdx+2;
198−
199− cfxsample = LEAF_interpolate_hermite (buff[i1],
200− buff[cdx],
201− buff[i3],
202− buff[i4],
203− alpha);
204−
205− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
194+ if (numsamps <= p->cfxlen)
195+ {
196+ // CROSSFADE SAMPLE
197+ float idxx = p->idx - p->len;
198+ int cdx = (int)(idxx);
199+
200+ i1 = cdx-1;
201+ i3 = cdx+1;
202+ i4 = cdx+2;
203+
204+ cfxsample = LEAF_interpolate_hermite (buff[i1],
205+ buff[cdx],
206+ buff[i3],
207+ buff[i4],
208+ alpha);
209+
210+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
211+ }
206212 }
207− else g2 = 0.f;
208213 }
209214 else
210215 {
@@ -221,31 +226,37 @@ float tSampler_tick (tSampler* const p) · 10 unmodified lines
221226
222227 numsamps = (idx - start) / p->inc;
223228
224− if (numsamps <= p->cfxlen)
229+ if (p->mode == Loop)
225230 {
226− // CROSSFADE SAMPLE
227− float idxx = p->idx + p->len + 1.f;
228− int cdx = (int)(idxx);
229− alpha = idxx - cdx;
230−
231− i1 = cdx+1;
232− i3 = cdx-1;
233− i4 = cdx-2;
234−
235− cfxsample = LEAF_interpolate_hermite (buff[i1],
236− buff[cdx],
237− buff[i3],
238− buff[i4],
239− 1.f-alpha);
240−
241− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
231+ if (numsamps <= p->cfxlen)
232+ {
233+ // CROSSFADE SAMPLE
234+ float idxx = p->idx + p->len + 1.f;
235+ int cdx = (int)(idxx);
236+ alpha = idxx - cdx;
237+
238+ i1 = cdx+1;
239+ i3 = cdx-1;
240+ i4 = cdx-2;
241+
242+ cfxsample = LEAF_interpolate_hermite (buff[i1],
243+ buff[cdx],
244+ buff[i3],
245+ buff[i4],
246+ 1.f-alpha);
247+
248+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
249+ }
242250 }
243− else g2 = 0.f;
244251 }
245252
246253 p->idx += (dir * p->inc);
247254
248− if (p->mode != BackAndForth ) // == Normal or Loop
255+ if (p->mode == Normal)
256+ {
257+ if (numsamps == 0) p->active = 0;
258+ }
259+ else if (p->mode == Loop ) // == Normal or Loop
249260 {
250261 if (idx <= start)
251262 {
@@ -261,12 +272,24 @@ float tSampler_tick (tSampler* const p) · 9 unmodified lines
261272 if ((idx <= start) || (idx >= end))
262273 {
263274 p->dir = -p->dir;
275+ p->idx += (p->dir * p->flip * p->inc);
264276 }
265277 }
266278
267279 g1 = 1.f - g2;
280+
268281 sample = sample * g1 + cfxsample * g2;
269282
283+ sample = sample * tRamp_tick(&p->gain);
284+
285+ if (p->active < 0)
286+ {
287+ if (tRamp_sample(&p->gain) <= 0.00001f)
288+ {
289+ p->active = 0;
290+ }
291+ }
292+
270293 return sample;
271294 }
272295
@@ -303,11 +326,16 @@ void tSampler_play (tSampler* const p) · 30 unmodified lines
303326 if (p->flip > 0) p->idx = p->end;
304327 else p->idx = p->start;
305328 }
329+
330+ tRamp_setVal(&p->gain, 0.f);
331+ tRamp_setDest(&p->gain, 1.f);
306332 }
307333
308334 void tSampler_stop (tSampler* const p)
309335 {
310− p->active = 0;
336+ p->active = -1;
337+
338+ tRamp_setDest(&p->gain, 0.f);
311339 }
312340
313341 static void handleStartEndChange(tSampler* const p)

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