aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/xsample/source
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/xsample/source')
-rw-r--r--externals/grill/xsample/source/groove.cpp67
-rw-r--r--externals/grill/xsample/source/main.cpp98
-rw-r--r--externals/grill/xsample/source/main.h2
3 files changed, 107 insertions, 60 deletions
diff --git a/externals/grill/xsample/source/groove.cpp b/externals/grill/xsample/source/groove.cpp
index f96b33bb..a3f2ed02 100644
--- a/externals/grill/xsample/source/groove.cpp
+++ b/externals/grill/xsample/source/groove.cpp
@@ -17,7 +17,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#endif
-#define XZONE_TABLE 64
+#define XZONE_TABLE 512
class xgroove:
@@ -300,7 +300,7 @@ V xgroove::m_max(F mx)
V xgroove::m_pos(F pos)
{
- setpos(pos?pos/s2u:0);
+ setpos(pos && s2u?pos/s2u:0);
}
V xgroove::m_all()
@@ -329,7 +329,7 @@ V xgroove::ms_xfade(I xf)
V xgroove::ms_xzone(F xz)
{
bufchk();
- _xzone = xz < 0?0:xz/s2u;
+ _xzone = xz < 0 || !s2u?0:xz/s2u;
// do_xzone();
s_dsp();
}
@@ -642,6 +642,11 @@ V xgroove::s_pos_loopzn(I n,S *const *invecs,S *const *outvecs)
// adapt the playing bounds to the current cross-fade zone
const L smin = znsmin,smax = znsmax,plen = smax-smin;
+ // temporary storage
+ const L cmin = curmin,cmax = curmax;
+ // hack -> set curmin/curmax to loop extremes so that sampling functions (playfun) don't get confused
+ curmin = smin,curmax = smax;
+
if(buf && plen > 0) {
BL inzn = false;
register D o = curpos;
@@ -661,17 +666,24 @@ V xgroove::s_pos_loopzn(I n,S *const *invecs,S *const *outvecs)
lpbang = true;
}
+#if 1
if(o < lmin) {
register F inp;
if(o < lmin2) {
+ // in first half of early cross-fade zone
+ // this happens only once, then the offset is normalized to the end
+ // of the loop (before mid of late crossfade)
+
o += lsh;
- lpbang = true;
// now lmax <= o <= lmax2
+ lpbang = true;
inp = xz-(F)(o-lmax); // 0 <= inp < xz
znpos[i] = lmin-inp;
}
- else { // in early cross-fade zone
+ else {
+ // in second half of early cross-fade zone
+
inp = xz+(F)(o-lmin); // 0 <= inp < xz
znpos[i] = lmax+inp;
}
@@ -681,14 +693,18 @@ V xgroove::s_pos_loopzn(I n,S *const *invecs,S *const *outvecs)
else if(!(o < lmax)) {
register F inp;
if(!(o < lmax2)) {
+ // in second half of late cross-fade zone
+ // this happens only once, then the offset is normalized to the beginning
+ // of the loop (after mid of early crossfade)
o -= lsh;
- lpbang = true;
// now lmin2 <= o <= lmin
+ lpbang = true;
inp = xz+(F)(o-lmin); // 0 <= inp < xz
znpos[i] = lmax+inp;
}
- else { // in late cross-fade zone
+ else {
+ // in first half of late cross-fade zone
inp = xz-(F)(o-lmax); // 0 <= inp < xz
znpos[i] = lmin-inp;
}
@@ -701,6 +717,27 @@ V xgroove::s_pos_loopzn(I n,S *const *invecs,S *const *outvecs)
const S spd = speed[i]; // must be first because the vector is reused for output!
pos[i] = o;
o += spd;
+#else
+ if(o >= lmax) {
+ o -= lsh;
+ lpbang = true;
+ }
+
+ if(o < lmin) {
+ register F inp = (F)(o-smin); // 0 <= inp < xz
+ znpos[i] = lmax+inp;
+ znidx[i] = inp*xf;
+ inzn = true;
+ }
+ else {
+ znpos[i] = 0;
+ znidx[i] = XZONE_TABLE;
+ }
+
+ const S spd = speed[i]; // must be first because the vector is reused for output!
+ pos[i] = o;
+ o += spd;
+#endif
}
// normalize and store current playing position
@@ -736,6 +773,8 @@ V xgroove::s_pos_loopzn(I n,S *const *invecs,S *const *outvecs)
else
s_pos_off(n,invecs,outvecs);
+ curmin = cmin,curmax = cmax;
+
if(lpbang) ToOutBang(outchns+3);
}
@@ -787,12 +826,14 @@ V xgroove::s_pos_bidir(I n,S *const *invecs,S *const *outvecs)
V xgroove::s_dsp()
{
if(doplay) {
+ // xzone might not be set yet (is done in do_xzone() )
+ do_xzone(); // recalculate (s2u may have been 0 before)
+
switch(loopmode) {
- case xsl_once: SETSIGFUN(posfun,SIGFUN(s_pos_once)); break;
+ case xsl_once:
+ SETSIGFUN(posfun,SIGFUN(s_pos_once));
+ break;
case xsl_loop:
- // xzone might not be set yet (is done in do_xzone() )
- do_xzone(); // recalculate (s2u may have been 0 before)
-
if(xzone > 0) {
const I blksz = Blocksize();
@@ -823,7 +864,9 @@ V xgroove::s_dsp()
else
SETSIGFUN(posfun,SIGFUN(s_pos_loop));
break;
- case xsl_bidir: SETSIGFUN(posfun,SIGFUN(s_pos_bidir)); break;
+ case xsl_bidir:
+ SETSIGFUN(posfun,SIGFUN(s_pos_bidir));
+ break;
}
}
else
diff --git a/externals/grill/xsample/source/main.cpp b/externals/grill/xsample/source/main.cpp
index 258fb37a..3cec1b66 100644
--- a/externals/grill/xsample/source/main.cpp
+++ b/externals/grill/xsample/source/main.cpp
@@ -60,7 +60,7 @@ xsample::xsample():
unitmode(xsu_sample), // PD defaults to samples
#endif
sclmode(xss_unitsinbuf),
- curmin(0),curmax(1<<30)
+ curmin(0),curmax(1<<31)
{}
xsample::~xsample()
@@ -98,6 +98,8 @@ BL xsample::m_refresh()
if(buf->Set()) { s_dsp(); ret = true; } // channel count may have changed
else ret = false;
+ m_units();
+ m_sclmode();
// realize positions... 2 times bufchk()!!
m_min((F)curmin*s2u); // also checks pos
m_max((F)curmax*s2u); // also checks pos
@@ -129,70 +131,72 @@ V xsample::m_units(xs_unit mode)
{
if(mode != xsu__) unitmode = mode;
- if(bufchk())
- switch(unitmode) {
- case xsu_sample: // samples
- s2u = 1;
- break;
- case xsu_buffer: // buffer size
- s2u = 1.f/buf->Frames();
- break;
- case xsu_ms: // ms
- s2u = 1000.f/Samplerate();
- break;
- case xsu_s: // s
- s2u = 1.f/Samplerate();
- break;
- default:
- post("%s: Unknown unit mode",thisName());
- }
+ switch(unitmode) {
+ case xsu_sample: // samples
+ s2u = 1;
+ break;
+ case xsu_buffer: // buffer size
+ s2u = bufchk()?1.f/buf->Frames():0;
+ break;
+ case xsu_ms: // ms
+ s2u = 1000.f/Samplerate();
+ break;
+ case xsu_s: // s
+ s2u = 1.f/Samplerate();
+ break;
+ default:
+ post("%s: Unknown unit mode",thisName());
+ }
}
V xsample::m_sclmode(xs_sclmd mode)
{
if(mode != xss__) sclmode = mode;
- if(bufchk())
- switch(sclmode) {
- case 0: // samples/units
- sclmin = 0; sclmul = s2u;
- break;
- case 1: // samples/units from recmin to recmax
- sclmin = curmin; sclmul = s2u;
- break;
- case 2: // unity between 0 and buffer size
- sclmin = 0; sclmul = buf->Frames()?1.f/buf->Frames():0;
- break;
- case 3: // unity between recmin and recmax
- sclmin = curmin; sclmul = curmin != curmax?1.f/(curmax-curmin):0;
- break;
- default:
- post("%s: Unknown scale mode",thisName());
- }
+ switch(sclmode) {
+ case 0: // samples/units
+ sclmin = 0; sclmul = s2u;
+ break;
+ case 1: // samples/units from recmin to recmax
+ sclmin = curmin; sclmul = s2u;
+ break;
+ case 2: // unity between 0 and buffer size
+ sclmin = 0; sclmul = (bufchk() && buf->Frames())?1.f/buf->Frames():0;
+ break;
+ case 3: // unity between recmin and recmax
+ sclmin = curmin; sclmul = curmin != curmax?1.f/(curmax-curmin):0;
+ break;
+ default:
+ post("%s: Unknown scale mode",thisName());
+ }
}
V xsample::m_min(F mn)
{
- if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
+// if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
- mn /= s2u; // conversion to samples
- if(mn < 0) mn = 0;
- else if(mn > curmax) mn = (F)curmax;
- curmin = (I)(mn+.5);
+ if(s2u) {
+ mn /= s2u; // conversion to samples
+ if(mn < 0) mn = 0;
+ else if(mn > curmax) mn = (F)curmax;
+ curmin = (I)(mn+.5);
- m_sclmode();
+ m_sclmode();
+ }
}
V xsample::m_max(F mx)
{
- if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
+// if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
- mx /= s2u; // conversion to samples
- if(mx > buf->Frames()) mx = (F)buf->Frames();
- else if(mx < curmin) mx = (F)curmin;
- curmax = (I)(mx+.5);
+ if(s2u) {
+ mx /= s2u; // conversion to samples
+ if(mx > buf->Frames()) mx = (F)buf->Frames();
+ else if(mx < curmin) mx = (F)curmin;
+ curmax = (I)(mx+.5);
- m_sclmode();
+ m_sclmode();
+ }
}
V xsample::m_all()
diff --git a/externals/grill/xsample/source/main.h b/externals/grill/xsample/source/main.h
index daa99b5d..c6511139 100644
--- a/externals/grill/xsample/source/main.h
+++ b/externals/grill/xsample/source/main.h
@@ -12,7 +12,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define __XSAMPLE_H
-#define XSAMPLE_VERSION "0.3.0"
+#define XSAMPLE_VERSION "0.3.1pre3"
#define FLEXT_ATTRIBUTES 1