ref: 58869eabcb354df83a0833bf86c1d2a582a9b5ef
parent: 9902cb9f346c78aa0bb4ea27e9c39dcedd60ed80
author: mulshine <mulshine@princeton.edu>
date: Thu Jan 24 09:51:04 EST 2019
Sampler working great, besides crossfade.
--- a/LEAF/Inc/leaf-sample.h
+++ b/LEAF/Inc/leaf-sample.h
@@ -74,7 +74,7 @@
float idx;
float inc;
int8_t dir;
- uint8_t flip;
+ int8_t flip;
int32_t start;
int32_t end;
--- a/LEAF/Src/leaf-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -120,7 +120,7 @@
p->idx = 0.f;
p->inc = 1.f;
p->dir = 1;
- p->flip = 0;
+ p->flip = 1;
p->mode = Normal;
@@ -143,22 +143,30 @@
float* buff = p->samp->buff;
+ int dir = p->dir * p->flip;
+
int idx = (int) p->idx;
+ float alpha = p->idx - idx;
- // Check dir (direction bit) to interpolate properly
- if (p->dir > 0)
+ uint32_t start = p->start, end = p->end;
+ if (p->flip < 0)
{
+ start = p->end;
+ end = p->start;
+ }
+
+ // Check dir (direction) to interpolate properly
+ if (dir > 0)
+ {
// FORWARD
- float alpha = p->idx - idx;
-
int i1 = idx-1;
int i3 = idx+1;
int i4 = idx+2;
- if (i1 < p->start) i1 += p->len;
- if (i3 > p->end) i3 -= p->len;
- if (i4 > p->end) i4 -= p->len;
-
+ if (i1 < start) i1 += p->len;
+ if (i3 > end) i3 -= p->len;
+ if (i4 > end) i4 -= p->len;
+
sample = LEAF_interpolate_hermite (buff[i1],
buff[idx],
buff[i3],
@@ -168,16 +176,14 @@
else
{
// REVERSE
- float alpha = 1.0f - (p->idx - idx);
-
int i1 = idx+1;
int i3 = idx-1;
int i4 = idx-2;
- if (i1 > p->start) i1 -= p->len;
- if (i3 < p->end) i3 += p->len;
- if (i4 < p->end) i4 += p->len;
-
+ if (i1 > end) i1 -= p->len;
+ if (i3 < start) i3 += p->len;
+ if (i4 < start) i4 += p->len;
+
sample = LEAF_interpolate_hermite (buff[i1],
buff[idx],
buff[i3],
@@ -185,60 +191,33 @@
alpha);
}
+ p->idx += (dir * p->inc);
- p->idx += (p->dir * p->inc);
-
if (p->mode != BackAndForth)
{
// Check flip bit to change loop test
- if (p->flip > 0)
+ if (idx <= start)
{
- if (idx <= p->end)
- {
- p->idx += (float)(p->len);
- p->cnt++;
- }
- else if (idx >= p->start)
- {
- p->idx -= (float)(p->len);
- p->cnt++;
- }
+ // -inc
+ p->idx += (float)(p->len);
+ p->cnt++;
}
- else
+ else if (idx >= end)
{
- if (idx <= p->start)
- {
- p->idx += (float)(p->len);
- p->cnt++;
- }
- else if (idx >= p->end)
- {
- p->idx -= (float)(p->len);
- p->cnt++;
- }
+ // +inc
+ p->idx -= (float)(p->len);
+ p->cnt++;
}
+
}
else // BackAndForth
{
- if (p->flip > 0)
+ if ((idx < start) || (idx > end))
{
- if ((idx < p->start) || (idx > p->end))
- {
- p->dir = -p->dir;
- p->idx += (2*p->inc);
- p->cnt++;
- }
+ p->dir = -p->dir;
+ p->idx += (2*p->inc);
+ p->cnt++;
}
- else
- {
- if ((idx > p->start) || (idx < p->end))
- {
- p->dir = -p->dir;
- p->idx += (2*p->inc);
- p->cnt++;
- }
- }
-
}
@@ -270,13 +249,11 @@
{
if (p->start > p->end)
{
- p->dir = -1;
- p->flip = 1;
+ p->flip = -1;
}
else
{
- p->dir = 1;
- p->flip = 0;
+ p->flip = 1;
}
}
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -42,7 +42,7 @@
timer++;
- if (timer >= leaf.sampleRate * 4)
+ if (player.active == 0 && timer >= leaf.sampleRate * 4)
{
tSamplePlayer_play(&player);
}
@@ -55,7 +55,9 @@
{
float val = getSliderValue("rate");
- tSamplePlayer_setRate(&player, val * 16.0f - 8.0f);
+ float rate = val * 16.0f - 8.0f;
+ tSamplePlayer_setRate(&player, rate);
+ DBG("rate: " + String(rate));
val = getSliderValue("start");
float start = val * sample.length;