History

fixed sampler and made other changes

spiricom committed 6 years ago

Commit 866c7c11 parent 19a991d13 files · +330 −223Browse files

Unified · Split

13 files
  1. .DS_Store +0 −0
  2. LEAF/.DS_Store +0 −0
  3. LEAF/Inc/.DS_Store +0 −0
  4. LEAF/Inc/leaf-effects.h +5 −4
  5. LEAF/Inc/leaf-math.h +10 −1
  6. LEAF/Inc/leaf-sampling.h +4 −3
  7. LEAF/Src/.DS_Store +0 −0
  8. LEAF/Src/leaf-distortion.c +10 −3
  9. LEAF/Src/leaf-effects.c +23 −6
  10. LEAF/Src/leaf-math.c +32 −3
  11. LEAF/Src/leaf-mempool.c +1 −1
  12. LEAF/Src/leaf-sampling.c +248 −205
  13. LEAF/leaf.h +1 −1
.DS_Store+0−0

Binary file not shown.

LEAF/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/leaf-effects.h+5−4
@@ -14,7 +14,7 @@ extern "C" { · 13 unmodified lines
1414 #endif
1515
1616 //==============================================================================
17−
17+#include "leaf-dynamics.h"
1818 #include "leaf-global.h"
1919 #include "leaf-math.h"
2020 #include "leaf-analysis.h"
@@ -241,9 +241,6 @@ extern "C" { · 220 unmodified lines
241241 //==============================================================================
242242
243243
244−#define FORD 7
245−#define FORMANT_BUFFER_SIZE 2048
246−
247244 typedef struct _tFormantShifter
248245 {
249246 int ford;
@@ -267,6 +264,10 @@ extern "C" { · 17 unmodified lines
267264 unsigned int cbi;
268265 float shiftFactor;
269266 float intensity, invIntensity;
267+ tHighpass hp;
268+ tHighpass hp2;
269+ tFeedbackLeveler fbl1;
270+ tFeedbackLeveler fbl2;
270271
271272 } _tFormantShifter;
272273
LEAF/Inc/leaf-math.h+10−1
@@ -70,6 +70,8 @@ extern "C" { · 69 unmodified lines
7070 #define INV_TWO_TO_7 0.0078125f
7171 #define TWO_TO_8 256.f
7272 #define INV_TWO_TO_8 0.00390625f
73+#define TWO_TO_9 512.f
74+#define INV_TWO_TO_9 0.001953125f
7375 #define TWO_TO_10 1024.f
7476 #define INV_TWO_TO_10 0.0009765625f
7577 #define TWO_TO_11 2048.f
@@ -88,6 +90,9 @@ extern "C" { · 12 unmodified lines
8890 #define TWO_TO_32 4294967296.0f
8991 #define INV_TWO_TO_32 0.000000000232831f
9092
93+
94+#define LOGTEN 2.302585092994
95+
9196 // Jones shaper
9297 float LEAF_shaper (float input, float m_drive);
9398 float LEAF_reedTable (float input, float offset, float slope);
@@ -119,6 +124,7 @@ extern "C" { · 25 unmodified lines
119124
120125 // Hermite interpolation
121126 float LEAF_interpolate_hermite (float A, float B, float C, float D, float t);
127+ float LEAF_interpolate_hermite_x(float yy0, float yy1, float yy2, float yy3, float xx);
122128 float LEAF_interpolation_linear (float A, float B, float t);
123129
124130 float interpolate3max(float *buf, const int peakindex);
@@ -134,8 +140,11 @@ extern "C" { · 9 unmodified lines
134140
135141 float fastexp2f(float f);
136142
137−#define LOGTEN 2.302585092994
138143
144+ void LEAF_crossfade(float fade, float* volumes);
145+
146+
147+
139148 float fast_mtof(float f);
140149
141150 float fastexpf(float x);
LEAF/Inc/leaf-sampling.h+4−3
@@ -91,7 +91,7 @@ extern "C" { · 90 unmodified lines
9191 int32_t end, targetend;
9292 uint32_t len;
9393 uint32_t cfxlen;
94−
94+ float numticks;
9595 PlayMode mode;
9696 int retrigger;
9797
@@ -116,7 +116,9 @@ extern "C" { · 18 unmodified lines
116116 void tSampler_setStart (tSampler* const, int32_t start);
117117 void tSampler_setEnd (tSampler* const, int32_t end);
118118
119− void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length);
119+ static void handleStartEndChange(tSampler* const sp);
120+
121+ void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
120122
121123 void tSampler_setRate (tSampler* const, float rate);
122124
@@ -129,4 +131,3 @@ extern "C" { · 6 unmodified lines
129131 #endif // LEAF_SAMPLING_H_INCLUDED
130132
131133 //==============================================================================
132−
LEAF/Src/.DS_Store+0−0

Binary file not shown.

LEAF/Src/leaf-distortion.c+10−3
@@ -1,8 +1,8 @@
11 //
2−// leaf-oversampler.c
2+// leaf-distortion.c
33 // LEAF
44 //
5−// Created by Matthew Wang and Joshua Becker on 2/28/19.
5+// Created by Jeff Snyder, Matthew Wang, Michael Mulshine, and Joshua Becker
66 // Copyright © 2019 Princeton University. All rights reserved.
77 //
88
@@ -16,6 +16,8 @@ · 7 unmodified lines
1616 #include "../Inc/leaf-distortion.h"
1717 #include "../Inc/leaf-tables.h"
1818
19+//testing
20+#include "gpio.h"
1921
2022 #endif
2123
@@ -62,7 +64,7 @@ double tLockhartWavefolderLambert(double x, double ln) · 40 unmodified lines
6264 {
6365 double thresh, w, expw, p, r, s, err;
6466 // Error threshold
65− thresh = 10e-10;
67+ thresh = 10e-12;
6668 // Initial guess (use previous value)
6769 w = ln;
6870
@@ -77,10 +79,15 @@ double tLockhartWavefolderLambert(double x, double ln) · 8 unmodified lines
7779 err = (p/(r-(p*s)));
7880
7981 if (fabs(err)<thresh) {
82+
8083 break;
8184 }
8285
8386 w = w - err;
87+ if (i == 999)
88+ {
89+ //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, GPIO_PIN_SET);
90+ }
8491
8592 }
8693 return w;
LEAF/Src/leaf-effects.c+23−6
@@ -645,7 +645,7 @@ float* tAutotune_tick(tAutotune* const rt, float sample) · 644 unmodified lines
645645 _tAutotune* r = *rt;
646646
647647 float tempPeriod = tPeriodDetection_findPeriod(&r->pd, sample);
648− if (tempPeriod < 1000.0f) //to avoid trying to follow consonants
648+ if (tempPeriod < 1000.0f) //to avoid trying to follow consonants JS
649649 {
650650 r->inputPeriod = tempPeriod;
651651 }
@@ -1253,6 +1253,7 @@ static void solad_init(_tSOLAD* const w) · 601 unmodified lines
12531253 //============================================================================================================
12541254 // FORMANTSHIFTER
12551255 //============================================================================================================
1256+// algorithm from Tom Baran's autotalent code.
12561257
12571258 void tFormantShifter_init(tFormantShifter* const fsr, int bufsize, int order)
12581259 {
@@ -1286,6 +1287,10 @@ void tFormantShifter_init(tFormantShifter* const fsr, int bufsize, int order) · 27 unmodified lines
12861287 fs->cbi = 0;
12871288 fs->intensity = 1.0f;
12881289 fs->invIntensity = 1.0f;
1290+ tHighpass_init(&fs->hp, 20.0f);
1291+ tHighpass_init(&fs->hp2, 20.0f);
1292+ tFeedbackLeveler_init(&fs->fbl1, 0.8f, .005f, 0.125, 1);
1293+ tFeedbackLeveler_init(&fs->fbl2, 0.8f, .005f, 0.125, 1);
12891294 }
12901295
12911296 void tFormantShifter_free(tFormantShifter* const fsr)
@@ -1305,6 +1310,10 @@ void tFormantShifter_free(tFormantShifter* const fsr) · 13 unmodified lines
13051310 leaf_free(fs->fbuff[i]);
13061311 }
13071312 leaf_free(fs->fbuff);
1313+ tHighpass_free(&fs->hp);
1314+ tHighpass_free(&fs->hp2);
1315+ tFeedbackLeveler_free(&fs->fbl1);
1316+ tFeedbackLeveler_free(&fs->fbl2);
13081317 leaf_free(fs);
13091318 }
13101319
@@ -1317,9 +1326,10 @@ float tFormantShifter_tick(tFormantShifter* const fsr, float in) · 6 unmodified lines
13171326 float tFormantShifter_remove(tFormantShifter* const fsr, float in)
13181327 {
13191328 _tFormantShifter* fs = *fsr;
1329+ in = tFeedbackLeveler_tick(&fs->fbl1, in);
1330+ in = tHighpass_tick(&fs->hp, tanhf(in * fs->intensity));
13201331
1321− in *= fs->intensity;
1322−
1332+
13231333 float fa, fb, fc, foma, falph, ford, flamb, tf, fk;
13241334 int ti4;
13251335 ford = fs->ford;
@@ -1361,10 +1371,9 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 35 unmodified lines
13611371 {
13621372 _tFormantShifter* fs = *fsr;
13631373
1364− float fa, fb, fc, falph, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb;
1374+ float fa, fb, fc, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb;
13651375 int ti4;
13661376 ford = fs->ford;
1367− falph = fs->falph;
13681377
13691378 flpa = fs->flpa;
13701379 flamb = fs->flamb;
@@ -1451,7 +1460,9 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 80 unmodified lines
14511460 fs->fmute = (1.0f-tf2) + tf2*fs->fmute;
14521461 // now tf is signal output
14531462 // ...and we're done messing with formants
1454−
1463+ tf = tFeedbackLeveler_tick(&fs->fbl2, tf);
1464+ //tf = tHighpass_tick(&fs->hp2, tanhf(tf));
1465+
14551466 return tf;
14561467 }
14571468
@@ -1465,7 +1476,13 @@ void tFormantShifter_setShiftFactor(tFormantShifter* const fsr, float shiftFacto · 7 unmodified lines
14651476 void tFormantShifter_setIntensity(tFormantShifter* const fsr, float intensity)
14661477 {
14671478 _tFormantShifter* fs = *fsr;
1479+
1480+
1481+
14681482 fs->intensity = intensity;
1483+
1484+ tFeedbackLeveler_setTargetLevel(&fs->fbl1, intensity);
1485+ tFeedbackLeveler_setTargetLevel(&fs->fbl2, intensity);
14691486 //make sure you don't divide by zero, doofies
14701487 if (fs->intensity != 0.0f)
14711488 {
LEAF/Src/leaf-math.c+32−3
@@ -120,6 +120,19 @@ float fastexp2f(float x) · 119 unmodified lines
120120 }
121121 }
122122
123+
124+/*
125+you pass in a float array to get back two indexes representing the volumes of the left (index 0) and right (index 1) channels
126+when t is -1, volumes[0] = 0, volumes[1] = 1
127+when t = 0, volumes[0] = 0.707, volumes[1] = 0.707 (equal-power cross fade)
128+when t = 1, volumes[0] = 1, volumes[1] = 0
129+*/
130+
131+void LEAF_crossfade(float fade, float* volumes) {
132+ volumes[0] = sqrtf(0.5f * (1.0f + fade));
133+ volumes[1] = sqrtf(0.5f * (1.0f - fade));
134+}
135+
123136 // dope af
124137 float LEAF_chebyshevT(float in, int n){
125138 if (n == 0) return 1;
@@ -363,14 +376,30 @@ float LEAF_interpolate_hermite (float A, float B, float C, float D, float alpha) · 237 unmodified lines
363376 {
364377 alpha = LEAF_clip(0.0f, alpha, 1.0f);
365378
366− float a = -A/2.0f + (3.0f*B)/2.0f - (3.0f*C)/2.0f + D/2.0f;
367− float b = A - (5.0f*B)/2.0f + 2.0f*C - D / 2.0f;
368− float c = -A/2.0f + C/2.0f;
379+ float a = -A*0.5f + (3.0f*B)*0.5f - (3.0f*C)*0.5f + D*0.5f;
380+ float b = A - (5.0f*B)*0.5f + 2.0f*C - D * 0.5f;
381+ float c = -A*0.5f + C*0.5f;
369382 float d = B;
370383
371384 return a*alpha*alpha*alpha + b*alpha*alpha + c*alpha + d;
372385 }
373386
387+
388+// from http://www.musicdsp.org/archive.php?classid=5#93
389+//xx is alpha (fractional part of sample value)
390+//grabbed this from Tom Erbe's Delay pd code
391+float LEAF_interpolate_hermite_x(float yy0, float yy1, float yy2, float yy3, float xx)
392+{
393+ // 4-point, 3rd-order Hermite (x-form)
394+ float c0 = yy1;
395+ float c1 = 0.5f * (yy2 - yy0);
396+ float y0my1 = yy0 - yy1;
397+ float c3 = (yy1 - yy2) + 0.5f * (yy3 - y0my1 - yy2);
398+ float c2 = y0my1 + c1 - c3;
399+
400+ return ((c3 * xx + c2) * xx + c1) * xx + c0;
401+}
402+
374403 // alpha, [0.0, 1.0]
375404 float LEAF_interpolation_linear (float A, float B, float alpha)
376405 {
LEAF/Src/leaf-mempool.c+1−1
@@ -281,6 +281,6 @@ static inline void delink_node(mpool_node_t* node) · 280 unmodified lines
281281
282282 void leaf_mempool_overrun(void)
283283 {
284−
284+ //TODO: we should set up some kind of leaf_error method that reaches user space to notify library users of things that failed.
285285 }
286286
LEAF/Src/leaf-sampling.c+248−205
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include "../Inc/leaf-sampling.h"
2020 #include "../leaf.h"
2121
22+
2223 #endif
2324
2425 //==============================================================================
@@ -188,27 +189,60 @@ float tSampler_tick (tSampler* const sp) · 163 unmodified lines
188189 _tSampler* p = *sp;
189190
190191 if (p->active == 0) return 0.f;
191−
192− if ((p->inc == 0.0f) || (p->len < 4))
192+
193+ if ((p->inc == 0.0f) || (p->len == 0))
193194 {
194− updateStartEnd(sp);
195195 return p->last;
196196 }
197−
198− // attemptStartEndChange(sp);
199−
197+
198+ attemptStartEndChange(sp);
199+
200200 float sample = 0.f;
201201 float cfxsample = 0.f;
202202 float numticks;
203203 float g1 = 1.f, g2 = 0.f;
204−
204+
205205 float* buff = p->samp->buff;
206−
206+
207207 int dir = p->bnf * p->dir * p->flip;
208208
209209 int idx, revidx;
210210 float alpha, revalpha;
211−
211+
212+ int32_t start = p->start, end = p->end;
213+ if (p->flip < 0)
214+ {
215+ start = p->end;
216+ end = p->start;
217+ }
218+ if (p->mode == PlayLoop)
219+ {
220+
221+ while((int)p->idx < start)
222+ {
223+ p->idx += (float)(p->len);
224+ }
225+ while((int)p->idx > end)
226+ {
227+
228+ p->idx -= (float)(p->len);
229+ }
230+ }
231+ else // == PlayBackAndForth
232+ {
233+ if (p->idx < start)
234+ {
235+ p->bnf = -p->bnf;
236+ p->idx = start;
237+ }
238+ else if (p->idx > end)
239+ {
240+ p->bnf = -p->bnf;
241+ p->idx = end;
242+ }
243+ }
244+
245+
212246
213247 idx = (int) p->idx;
214248 alpha = p->idx - idx;
@@ -217,157 +251,151 @@ float tSampler_tick (tSampler* const sp) · 2 unmodified lines
217251 revalpha = 1.f - alpha;
218252
219253
220− int32_t start = p->start, end = p->end;
221− if (p->flip < 0)
222− {
223− start = p->end;
224− end = p->start;
225− }
254+
255+
226256
227257 uint32_t cfxlen = p->cfxlen;
228− if (p->len < cfxlen) cfxlen = 0;//p->len;
258+ if (p->len < cfxlen) cfxlen = p->len * 0.25f;//p->len;
229259
230260 int length = p->samp->length;
231261
232− // Check dir (direction) to interpolate properly
233262 if (dir > 0)
263+ { // num samples (hopping the increment size) to end of loop
264+ numticks = (end-idx) * p->iinc;
265+ }
266+ else
234267 {
235− // FORWARD NORMAL SAMPLE
236− int i1 = ((idx-1) < 0) ? 0 : idx-1;
237− int i3 = ((idx+1) >= length) ? (idx) : (idx+1);
238− int i4 = ((idx+2) >= length) ? (length-1) : (idx+2);
239−
240− sample = LEAF_interpolate_hermite (buff[i1],
241− buff[idx],
242− buff[i3],
243− buff[i4],
244− alpha);
245−
246− // num samples to end of loop
247− numticks = (end-idx) * p->iinc;
248− // if (numticks > cfxlen)
249− // {
250− // updateStartEnd(sp);
251− // start = p->start;
252− // end = p->end;
253− // if (p->flip < 0)
254− // {
255− // start = p->end;
256− // end = p->start;
257− // }
258− // numticks = (end-idx) * p->iinc;
259− // }
260− //numsamps = (dir > 0) ? (end - idx) : (idx - start);
261− //numsamps *= p->iinc;
262−
263− if (p->mode == PlayLoop)
264− {
265− if (numticks <= (float) cfxlen)
266− {
267− // CROSSFADE SAMPLE
268− int cdx = start - numticks * p->inc;
269− if (cdx < 1)
270− {
271− cdx = -cdx;
272−
273− i1 = ((cdx+1) >= length) ? (length-1) : cdx+1;
274− i3 = ((cdx-1) < 0) ? cdx : (cdx-1);
275− i4 = ((cdx-2) < 0) ? 0 : (cdx-2);
276−
277− cfxsample = LEAF_interpolate_hermite (buff[i1],
278− buff[cdx],
279− buff[i3],
280− buff[i4],
281− revalpha);
282− }
283− else
284− {
285− i1 = ((cdx-1) < 0) ? 0 : cdx-1;
286− i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1);
287− i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2);
288−
289− cfxsample = LEAF_interpolate_hermite (buff[i1],
290− buff[cdx],
291− buff[i3],
292− buff[i4],
293− alpha);
294− }
295− g2 = (float) (cfxlen - numticks) / (float) cfxlen;
296− }
297− }
268+ numticks = (revidx-start) * p->iinc;
298269 }
270+
271+
272+
273+ if (cfxlen > 0) // necessary to avoid divide by zero, also a waste of computation otherwise
274+ {
275+
276+ // Check dir (direction) to interpolate properly
277+ if (dir > 0)
278+ {
279+ // FORWARD NORMAL SAMPLE
280+ int i1 = ((idx-1) < 0) ? 0 : idx-1;
281+ int i3 = ((idx+1) >= length) ? (idx) : (idx+1);
282+ int i4 = ((idx+2) >= length) ? (length-1) : (idx+2);
283+
284+ sample = LEAF_interpolate_hermite (buff[i1],
285+ buff[idx],
286+ buff[i3],
287+ buff[i4],
288+ alpha);
289+
290+ if (p->mode == PlayLoop)
291+ {
292+
293+
294+
295+ if (numticks <= (float) cfxlen)
296+ {
297+ // CROSSFADE SAMPLE
298+ int cdx = start - (numticks * p->inc);
299+ if (cdx < 1)
300+ {
301+ cdx = -cdx;
302+
303+ i1 = ((cdx+1) >= length) ? (length-1) : cdx+1;
304+ i3 = ((cdx-1) < 0) ? cdx : (cdx-1);
305+ i4 = ((cdx-2) < 0) ? 0 : (cdx-2);
306+
307+ cfxsample = LEAF_interpolate_hermite_x (buff[i1],
308+ buff[cdx],
309+ buff[i3],
310+ buff[i4],
311+ revalpha);
312+ }
313+ else
314+ {
315+ i1 = ((cdx-1) < 0) ? 0 : cdx-1;
316+ i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1);
317+ i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2);
318+
319+ cfxsample = LEAF_interpolate_hermite_x (buff[i1],
320+ buff[cdx],
321+ buff[i3],
322+ buff[i4],
323+ alpha);
324+ }
325+
326+ g2 = (float) (cfxlen - numticks) / (float) cfxlen;
327+
328+ }
329+
330+ }
331+
332+ }
333+ else
334+ {
335+ // REVERSE
336+ int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1;
337+ int i3 = ((revidx-1) < 0) ? revidx : (revidx-1);
338+ int i4 = ((revidx-2) < 0) ? 0 : (revidx-2);
339+
340+ sample = LEAF_interpolate_hermite_x (buff[i1],
341+ buff[revidx],
342+ buff[i3],
343+ buff[i4],
344+ revalpha);
345+
346+
347+
348+
349+ if (p->mode == PlayLoop)
350+ {
351+ if (numticks <= (float) cfxlen)
352+ {
353+ // CROSSFADE SAMPLE
354+ int cdx = end + (numticks * p->inc);
355+ if (cdx > p->samp->length - 2)
356+ {
357+ cdx = end - (numticks * p->inc);
358+
359+ i1 = ((cdx-1) < 0) ? 0 : cdx-1;
360+ i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1);
361+ i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2);
362+
363+ cfxsample = LEAF_interpolate_hermite_x (buff[i1],
364+ buff[cdx],
365+ buff[i3],
366+ buff[i4],
367+ revalpha);
368+ }
369+ else
370+ {
371+ i1 = ((cdx+1) >= length) ? (length-1) : cdx+1;
372+ i3 = ((cdx-1) < 0) ? cdx : (cdx-1);
373+ i4 = ((cdx-2) < 0) ? 0 : (cdx-2);
374+
375+ cfxsample = LEAF_interpolate_hermite_x (buff[i1],
376+ buff[cdx],
377+ buff[i3],
378+ buff[i4],
379+ alpha);
380+ }
381+ g2 = (float) (cfxlen - numticks) / (float) cfxlen;
382+ }
383+ }
384+ }
385+ }
299386 else
300387 {
301− // REVERSE
302− int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1;
303− int i3 = ((revidx-1) < 0) ? revidx : (revidx-1);
304− int i4 = ((revidx-2) < 0) ? 0 : (revidx-2);
305−
306− sample = LEAF_interpolate_hermite (buff[i1],
307− buff[revidx],
308− buff[i3],
309− buff[i4],
310− revalpha);
311−
312− numticks = (revidx-start) * p->iinc;
313−
314− // still get clicks i think because updating start/end can put us in the middle of a crossfade
315− // if (numticks > cfxlen)
316− // {
317− // updateStartEnd(sp);
318− // start = p->start;
319− // end = p->end;
320− // if (p->flip < 0)
321− // {
322− // start = p->end;
323− // end = p->start;
324− // }
325− // numticks = (revidx-start) * p->iinc;
326− // }
327−
328− if (p->mode == PlayLoop)
329− {
330− if (numticks <= (float) cfxlen)
331− {
332− // CROSSFADE SAMPLE
333− int cdx = end + numticks * p->inc;
334− if (cdx > p->samp->length - 2)
335− {
336− cdx = end - numticks * p->inc;
337−
338− i1 = ((cdx-1) < 0) ? 0 : cdx-1;
339− i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1);
340− i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2);
341−
342− cfxsample = LEAF_interpolate_hermite (buff[i1],
343− buff[cdx],
344− buff[i3],
345− buff[i4],
346− alpha);
347− }
348− else
349− {
350− i1 = ((cdx+1) >= length) ? (length-1) : cdx+1;
351− i3 = ((cdx-1) < 0) ? cdx : (cdx-1);
352− i4 = ((cdx-2) < 0) ? 0 : (cdx-2);
353−
354− cfxsample = LEAF_interpolate_hermite (buff[i1],
355− buff[cdx],
356− buff[i3],
357− buff[i4],
358− revalpha);
359− }
360− g2 = (float) (cfxlen - numticks) / (float) cfxlen;
361− }
362− }
388+ g2 = 0.0f;
363389 }
364390
365391
366392 float inc = fmod(p->inc, p->len);
367393 p->idx += (dir * inc);
368−
394+
395+
396+
369397 // attemptStartEndChange(sp);
370−
398+
371399 if (p->mode == PlayNormal)
372400 {
373401 if (numticks < (0.007f * leaf.sampleRate))
@@ -376,36 +404,7 @@ float tSampler_tick (tSampler* const sp) · 2 unmodified lines
376404 p->active = -1;
377405 }
378406 }
379− else if (p->mode == PlayLoop)
380− {
381− // mike's suggestion: make sure idx is within bounds of start and end (instead of targetstart/targetend stuff)
382− if (idx < start)
383− {
384− updateStartEnd(sp);
385− p->idx += (float)(p->len);
386− }
387− else if (idx > end)
388− {
389− updateStartEnd(sp);
390− p->idx -= (float)(p->len);
391− }
392− }
393− else // == PlayBackAndForth
394− {
395− if (p->idx < start)
396− {
397− updateStartEnd(sp);
398− p->bnf = -p->bnf;
399− p->idx = start;
400− }
401− else if (p->idx > end)
402− {
403− updateStartEnd(sp);
404− p->bnf = -p->bnf;
405− p->idx = end;
406− }
407− }
408−
407+
409408 g1 = 1.f - g2;
410409
411410 sample = sample * g1 + cfxsample * g2;
@@ -440,9 +439,12 @@ float tSampler_tick (tSampler* const sp) · 28 unmodified lines
440439
441440 }
442441 }
443−
442+
443+
444444 p->last = sample;
445445
446+
447+
446448 return p->last;
447449 }
448450
@@ -458,7 +460,7 @@ void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length) · 9 unmodified lines
458460
459461 uint32_t cfxlen = LEAF_clip(0, length, 1000);
460462
461− //if (cfxlen > p->len) cfxlen = p->len * 0.25f;
463+ if (cfxlen > (p->len * 0.25f)) cfxlen = p->len * 0.25f;
462464
463465 p->cfxlen = cfxlen;
464466 }
@@ -491,6 +493,7 @@ void tSampler_play (tSampler* const sp) · 26 unmodified lines
491493 if (p->flip > 0) p->idx = p->end;
492494 else p->idx = p->start;
493495 }
496+ handleStartEndChange(&p);
494497 }
495498 }
496499
@@ -508,8 +511,8 @@ static void handleStartEndChange(tSampler* const sp) · 11 unmodified lines
508511 _tSampler* p = *sp;
509512
510513 p->len = abs(p->end - p->start);
511−
512− //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f;
514+
515+ if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f;
513516
514517 if (p->start > p->end)
515518 {
@@ -539,77 +542,117 @@ static void attemptStartEndChange(tSampler* const sp) · 23 unmodified lines
539542 static void updateStartEnd(tSampler* const sp)
540543 {
541544 _tSampler* p = *sp;
545+
546+
547+
542548 if (p->targetstart >= 0)
543549 {
544− p->start = p->targetstart;
545− handleStartEndChange(sp);
546− p->targetstart = -1;
550+ if (p->targetstart != p->end)
551+ {
552+ p->start = p->targetstart;
553+ handleStartEndChange(sp);
554+ p->targetstart = -1;
555+ }
547556 }
548557 if (p->targetend >= 0)
549558 {
550− p->end = p->targetend;
551− handleStartEndChange(sp);
552− p->targetend = -1;
559+ if (p->targetend != p->start)
560+ {
561+ p->end = p->targetend;
562+ handleStartEndChange(sp);
563+ p->targetend = -1;
564+ }
553565 }
554566 }
555567
556568 void tSampler_setStart (tSampler* const sp, int32_t start)
557569 {
558570 _tSampler* p = *sp;
559−
560− if (p->active)
571+
572+ int tempflip;
573+ if (start == p->end)
561574 {
562− int dir = p->bnf * p->dir * p->flip;
575+ return;
576+ }
577+ // if (p->active)
578+ {
579+
580+ if (start > p->end)
581+ {
582+ tempflip = -1;
583+ }
584+ else
585+ {
586+ tempflip = 1;
587+ }
588+
589+ int dir = p->bnf * p->dir * tempflip;
563590 uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen;
564− if (p->flip > 0 && dir > 0) // start is start and we're playing forward
591+ if (tempflip > 0 && dir > 0) // start is start and we're playing forward
565592 {
566− if ((start > p->idx) || (p->end-p->idx <= cfxlen)) // start given is after current index or we're in a crossfade
593+ if (((start > p->idx) || (p->end-p->idx <= cfxlen)) && (start > p->end))// start given is after current index or we're in a crossfade
567594 {
568595 p->targetstart = start;
569596 return;
570597 }
571598 }
572− else if (p->flip < 0 && dir < 0) // start is end and we're playing in reverse
599+ else if (tempflip < 0 && dir < 0) // start is end and we're playing in reverse
573600 {
574− if ((start < p->idx) || (p->idx-p->end <= cfxlen)) // start given is before current index or we're in a crossfade
601+ if (((start < p->idx) || (p->idx-p->end <= cfxlen)) && (start < p->end))// start given is before current index or we're in a crossfade
575602 {
576603 p->targetstart = start;
577604 return;
578605 }
579606 }
580607 }
581−
582− p->start = LEAF_clipInt(0, start, p->samp->length - 1);
583− handleStartEndChange(sp);
584− p->targetstart = -1;
608+
609+ p->start = LEAF_clipInt(0, start, p->samp->length - 1);
610+ handleStartEndChange(sp);
611+ p->targetstart = -1;
612+
585613 }
586614
587615 void tSampler_setEnd (tSampler* const sp, int32_t end)
588616 {
589617 _tSampler* p = *sp;
590−
591− if (p->active)
618+
619+ int tempflip;
620+
621+ if (end == p->start)
592622 {
593− int dir = p->bnf * p->dir * p->flip;
623+ return;
624+ }
625+ //if (p->active)
626+ {
627+
628+
629+ if (p->start > end)
630+ {
631+ tempflip = -1;
632+ }
633+ else
634+ {
635+ tempflip = 1;
636+ }
637+ int dir = p->bnf * p->dir * tempflip;
594638 uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen;
595− if (p->flip > 0 && dir < 0) // end is end and we're playing in reverse
639+ if (tempflip > 0 && dir < 0) // end is end and we're playing in reverse
596640 {
597− if ((end < p->idx) || (p->idx-p->start <= cfxlen)) // end given is before current index or we're in a crossfade
641+ if (((end < p->idx) || (p->idx-p->start <= cfxlen)) && (end < p->start)) // end given is before current index or we're in a crossfade
598642 {
599643 p->targetend = end;
600644 return;
601645 }
602646 }
603− else if (p->flip < 0 && dir > 0) // end is start and we're playing forward
647+ else if (tempflip < 0 && dir > 0) // end is start and we're playing forward
604648 {
605− if ((end > p->idx) || (p->start-p->idx <= cfxlen)) // end given is after current index or we're in a crossfade
649+ if (((end > p->idx) || (p->start-p->idx <= cfxlen)) && (end > p->start)) // end given is after current index or we're in a crossfade
606650 {
607651 p->targetend = end;
608652 return;
609653 }
610654 }
611655 }
612−
613656 p->end = LEAF_clipInt(0, end, (p->samp->length - 1));
614657 handleStartEndChange(sp);
615658 p->targetend = -1;
@@ -628,8 +671,8 @@ void tSampler_setRate (tSampler* const sp, float rate) · 12 unmodified lines
628671 {
629672 p->dir = 1;
630673 }
631−
632− p->inc = rate; //LEAF_clip(0.f, rate, 8.0f); any reason to clip this?
674+
675+ p->inc = rate;
633676 p->iinc = 1.f / p->inc;
634677 }
635678
LEAF/leaf.h+1−1
@@ -45,13 +45,13 @@ · 44 unmodified lines
4545 #include "./Inc/leaf-mempool.h"
4646 #include "./Inc/leaf-tables.h"
4747 #include "./Inc/leaf-distortion.h"
48+#include "./Inc/leaf-dynamics.h"
4849 #include "./Inc/leaf-oscillators.h"
4950 #include "./Inc/leaf-filters.h"
5051 #include "./Inc/leaf-delay.h"
5152 #include "./Inc/leaf-reverb.h"
5253 #include "./Inc/leaf-effects.h"
5354 #include "./Inc/leaf-envelopes.h"
54−#include "./Inc/leaf-dynamics.h"
5555 #include "./Inc/leaf-analysis.h"
5656 #include "./Inc/leaf-instruments.h"
5757 #include "./Inc/leaf-midi.h"

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