ref: 1a65dc6f465711ffa88151dfa8846b989ee70d54
parent: 6c87e507028c0c63facde25ee24e6f482fe3e995
author: mulshine <mulshine@princeton.edu>
date: Wed Jan 30 11:15:15 EST 2019
Sampler working well with manual linear crossfade.
--- a/LEAF/Src/leaf-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -106,7 +106,7 @@
//==============================================================================
-#define CFX 50
+#define CFX 10
void tSamplePlayer_init (tSamplePlayer* const p, tSample* s)
{
@@ -144,6 +144,7 @@
float sample = 0.f;
float cfxsample = 0.f;
+ int cfx = CFX;
float* buff = p->samp->buff;
@@ -179,10 +180,15 @@
buff[i3],
buff[i4],
alpha);
- if ((end - idx) <= CFX)
+
+ cfx = (end - idx) / p->inc;
+
+ if (cfx <= CFX)
{
// CROSSFADE SAMPLE
- int cdx = idx - p->len;
+ float idxx = p->idx - p->len;
+ int cdx = (int)(idxx);
+ float alpha = idxx - cdx;
i1 = cdx-1;
i3 = cdx+1;
@@ -193,10 +199,8 @@
buff[i3],
buff[i4],
alpha);
-
- p->g2 = (float) (CFX - (end - idx - 1)) / (float) CFX;
- p->g1 = 1.f - p->g2;
}
+ else cfx = CFX;
}
else
{
@@ -215,7 +219,9 @@
buff[i4],
1.0f-alpha);
- if ((idx - start) <= CFX)
+ cfx = (idx - start) / p->inc;
+
+ if (cfx <= CFX)
{
// CROSSFADE SAMPLE
int cdx = idx + p->len;
@@ -229,10 +235,8 @@
buff[i3],
buff[i4],
alpha);
-
- p->g2 = (float) (CFX - (idx - start - 1)) / (float) CFX;
- p->g1 = 1.f - p->g2;
}
+ else cfx = CFX;
}
p->idx += (dir * p->inc);
@@ -259,7 +263,12 @@
}
}
- return sample * p->g1 + cfxsample * p->g2;
+ sample = sample * p->g1 + cfxsample * p->g2;
+
+ p->g2 = (float) (CFX - cfx) / (float) CFX;
+ p->g1 = 1.f - p->g2;
+
+ return sample;
}
void tSamplePlayer_setSample (tSamplePlayer* const p, tSample* s)