[PD-cvs] externals/grill/xsample/source groove.cpp,1.24,1.25 main.h,1.27,1.28

Thomas Grill xovo at users.sourceforge.net
Wed Apr 7 04:48:20 CEST 2004


Update of /cvsroot/pure-data/externals/grill/xsample/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14342/source

Modified Files:
	groove.cpp main.h 
Log Message:
 ""

Index: groove.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/xsample/source/groove.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** groove.cpp	23 Mar 2004 03:27:37 -0000	1.24
--- groove.cpp	7 Apr 2004 02:48:18 -0000	1.25
***************
*** 44,55 ****
  	virtual V m_min(F mn);
  	virtual V m_max(F mx);
! 	
  	V ms_xzone(F xz);
! 	V mg_xzone(F &xz);
! 	V m_xsymm(F xz);
  	V m_xshape(I argc = 0,const t_atom *argv = NULL);
  	inline V ms_xshape(const AtomList &ret) { m_xshape(ret.Count(),ret.Atoms()); }
  	V mg_xshape(AtomList &ret) const;
- 	V m_xkeep(BL k);
  
  	enum xs_loop {
--- 44,56 ----
  	virtual V m_min(F mn);
  	virtual V m_max(F mx);
! 
! 	V ms_xfade(I xf);
! 
  	V ms_xzone(F xz);
! 	V mg_xzone(F &xz) { xz = _xzone*s2u; }
! 
  	V m_xshape(I argc = 0,const t_atom *argv = NULL);
  	inline V ms_xshape(const AtomList &ret) { m_xshape(ret.Count(),ret.Atoms()); }
  	V mg_xshape(AtomList &ret) const;
  
  	enum xs_loop {
***************
*** 57,61 ****
  		xsl_once = 0,xsl_loop,xsl_bidir
  	};
! 	
  	V m_loop(xs_loop lp = xsl__);
  	
--- 58,67 ----
  		xsl_once = 0,xsl_loop,xsl_bidir
  	};
! 
! 	enum xs_fade {
! 		xsf__ = -1,  // don't change
! 		xsf_keeplooppos = 0,xsf_keeplooplen,xsf_keepfade,xsf_inside
! 	};
! 
  	V m_loop(xs_loop lp = xsl__);
  	
***************
*** 66,75 ****
  	I bidir;
  
! 	F _xzone,xzone,xsymm;
      L znsmin,znsmax;
  	I xshape;
  	F xshparam;
  	D znmin,znmax;
- 	BL xkeep;
  	S **znbuf;
  	S *znpos,*znmul,*znidx;
--- 72,81 ----
  	I bidir;
  
! 	F _xzone,xzone;
      L znsmin,znsmax;
+ 	xs_fade xfade;
  	I xshape;
  	F xshparam;
  	D znmin,znmax;
  	S **znbuf;
  	S *znpos,*znmul,*znidx;
***************
*** 130,140 ****
  	FLEXT_CALLBACK(m_all)
  
  	FLEXT_CALLSET_F(ms_xzone)
  	FLEXT_CALLGET_F(mg_xzone)
- 	FLEXT_CALLSET_F(m_xsymm)
- 	FLEXT_ATTRGET_F(xsymm)
  	FLEXT_CALLVAR_V(mg_xshape,ms_xshape)
- 	FLEXT_CALLSET_B(m_xkeep)
- 	FLEXT_ATTRGET_B(xkeep)
  
  	FLEXT_CALLVAR_F(mg_pos,m_pos)
--- 136,144 ----
  	FLEXT_CALLBACK(m_all)
  
+ 	FLEXT_CALLSET_I(ms_xfade)
+ 	FLEXT_ATTRGET_I(xfade)
  	FLEXT_CALLSET_F(ms_xzone)
  	FLEXT_CALLGET_F(mg_xzone)
  	FLEXT_CALLVAR_V(mg_xshape,ms_xshape)
  
  	FLEXT_CALLVAR_F(mg_pos,m_pos)
***************
*** 164,177 ****
  	FLEXT_CADDATTR_VAR_E(c,"loop",loopmode,m_loop);
  
  	FLEXT_CADDATTR_VAR(c,"xzone",mg_xzone,ms_xzone);
- 	FLEXT_CADDATTR_VAR(c,"xsymm",xsymm,m_xsymm);
  	FLEXT_CADDATTR_VAR(c,"xshape",mg_xshape,ms_xshape);
- 	FLEXT_CADDATTR_VAR(c,"xkeep",xkeep,m_xkeep);
  }
  
  xgroove::xgroove(I argc,const t_atom *argv):
  	loopmode(xsl_loop),curpos(0),
! 	_xzone(0),xzone(0),xsymm(0.5),xkeep(false),pblksz(0),
! 	xshape(0),xshparam(1),
  	znbuf(NULL),znmul(NULL),znidx(NULL),znpos(NULL),
  	bidir(1)
--- 168,180 ----
  	FLEXT_CADDATTR_VAR_E(c,"loop",loopmode,m_loop);
  
+ 	FLEXT_CADDATTR_VAR(c,"xfade",xfade,ms_xfade);
  	FLEXT_CADDATTR_VAR(c,"xzone",mg_xzone,ms_xzone);
  	FLEXT_CADDATTR_VAR(c,"xshape",mg_xshape,ms_xshape);
  }
  
  xgroove::xgroove(I argc,const t_atom *argv):
  	loopmode(xsl_loop),curpos(0),
! 	_xzone(0),xzone(0),pblksz(0),
! 	xfade(xsf_keeplooppos),xshape(0),xshparam(1),
  	znbuf(NULL),znmul(NULL),znidx(NULL),znpos(NULL),
  	bidir(1)
***************
*** 217,225 ****
  	AddOutBang("Bang on loop end/rollover");  // loop bang
  	
  	znbuf = new S *[outchns];
! 	for(I i = 0; i < outchns; ++i) znbuf[i] = new S[0];
! 	znpos = new S[0]; // don't know vector size yet -> wait for m_dsp
! 	znidx = new S[0];
  	znmul = new S[XZONE_TABLE+1];
  	m_xshape();
  }
--- 220,230 ----
  	AddOutBang("Bang on loop end/rollover");  // loop bang
  	
+ 	// don't know vector size yet -> wait for m_dsp
  	znbuf = new S *[outchns];
! 	for(I i = 0; i < outchns; ++i) znbuf[i] = NULL;
! 	znpos = NULL; 
! 	znidx = NULL;
  	znmul = new S[XZONE_TABLE+1];
+ 
  	m_xshape();
  }
***************
*** 228,238 ****
  {
  	if(znbuf) {
! 		for(I i = 0; i < outchns; ++i) delete[] znbuf[i]; 
  		delete[] znbuf;
  	}
  
- 	if(znmul) delete[] znmul;
  	if(znpos) delete[] znpos;
  	if(znidx) delete[] znidx;
  }
  
--- 233,243 ----
  {
  	if(znbuf) {
! 		for(I i = 0; i < outchns; ++i) if(znbuf[i]) delete[] znbuf[i]; 
  		delete[] znbuf;
  	}
  
  	if(znpos) delete[] znpos;
  	if(znidx) delete[] znidx;
+ 	delete[] znmul;
  }
  
***************
*** 260,264 ****
  	xsample::m_min(mn);
  	m_pos(curpos*s2u);
! 	do_xzone();
  	outputmin();
  }
--- 265,270 ----
  	xsample::m_min(mn);
  	m_pos(curpos*s2u);
! //	do_xzone();
! 	s_dsp();
  	outputmin();
  }
***************
*** 268,272 ****
  	xsample::m_max(mx);
  	m_pos(curpos*s2u);
! 	do_xzone();
  	outputmax();
  }
--- 274,279 ----
  	xsample::m_max(mx);
  	m_pos(curpos*s2u);
! //	do_xzone();
! 	s_dsp();
  	outputmax();
  }
***************
*** 280,284 ****
  {
  	xsample::m_all();
! 	do_xzone();
  	outputmin();
  	outputmax();
--- 287,292 ----
  {
  	xsample::m_all();
! //	do_xzone();
! 	s_dsp();
  	outputmin();
  	outputmax();
***************
*** 292,295 ****
--- 300,310 ----
  }
  
+ V xgroove::ms_xfade(I xf) 
+ { 
+ 	xfade = (xs_fade)xf;
+ 	//	do_xzone();
+ 	s_dsp(); 
+ }
+ 
  V xgroove::ms_xzone(F xz) 
  { 
***************
*** 300,321 ****
  }
  
- V xgroove::mg_xzone(F &xz) 
- { 
- 	xz = _xzone*s2u; 
- }
- 
- V xgroove::m_xsymm(F xs) 
- { 
- 	if(xs < 0) 
- 		xsymm = -1;
- 	else if(xs <= 1) 
- 		xsymm = xs;
- 	else {
- 		post("%s - xsymm value out of range - set to center (0.5)",thisName());
- 		xsymm = 0.5;
- 	}
- 	do_xzone();
- }
- 
  V xgroove::m_xshape(I argc,const t_atom *argv) 
  { 
--- 315,318 ----
***************
*** 361,370 ****
  
  
- V xgroove::m_xkeep(BL k) 
- { 
- 	xkeep = k; 
- 	do_xzone();
- }
- 
  V xgroove::do_xzone()
  {
--- 358,361 ----
***************
*** 372,419 ****
  
  	xzone = _xzone; // make a copy for changing it
- 	znsmin = curmin,znsmax = curmax;
-     I plen = znsmax-znsmin; //curlen;
  
! 	if(xsymm < 0) {
! 		// crossfade zone is inside the loop (-> loop is shorter than nominal!)
! 		if(xzone >= plen) xzone = plen-1;
! 		znmin = znsmin+xzone,znmax = znsmax-xzone;
  	}
! 	else {
! 		// desired crossfade points
! 		znmin = znsmin+xzone*xsymm,znmax = znsmax+xzone*(xsymm-1);
! 		// extra space at beginning and end
! 		D o1 = znmin-xzone,o2 = buf->Frames()-(znmax+xzone); 
  
! 		if(o1 < 0 || o2 < 0) { // or (o1*o2 < 0)
! 			if(o1+o2 < 0) {
! 				// must reduce crossfade/loop length
! 				if(!xkeep) {	
! 					// prefer preservation of cross-fade length
! 					if(xzone*2 >= plen) // have to reduce cross-fade length
! 						xzone = plen/2;
! 					znmin = xzone,znmax = buf->Frames()-xzone;
! 				}
! 				else {	
! 					// prefer preservation of loop length
! 					znmin += o1,znmax -= o2;
! 					xzone = (buf->Frames()-(znmax-znmin))/2;
! 				}
! 				znsmin = 0,znsmax = buf->Frames();
! 			}
! 			else if(o1 < 0) {
! 				// min point is out of bounds (but enough space for mere shift)
! 				I i1 = (I)o1;
! 				znsmin -= i1,znsmax -= i1;
! 				znmin = znsmin+xzone*xsymm,znmax = znsmax+xzone*(xsymm-1);
! 			}
! 			else /* o2 < 0 */ { 
! 				// max point is out of bounds (but enough space for mere shift)
! 				I i2 = (I)o2;
! 				znsmin += i2,znsmax += i2;
! 				znmin = znsmin+xzone*xsymm,znmax = znsmax+xzone*(xsymm-1);
! 			}
  		}
  	}
  }
  
--- 363,432 ----
  
  	xzone = _xzone; // make a copy for changing it
  
! 	if(xfade == xsf_inside) { // fade zone goes inside the loop -> loop gets shorter
! 		const L maxfd = (curmax-curmin)/2;
! 		if(xzone > maxfd) xzone = maxfd;
! 
! 		znsmin = curmin,znsmax = curmax;
  	}
! 	else if(xfade == xsf_keepfade) { 
! 		// try to keep fade zone
! 		// shifting of loop bounds may happen
  
! 		// restrict xzone to half of buffer
! 		const L maxfd = buf->Frames()/2;
! 		if(xzone > maxfd) xzone = maxfd;
! 
! 		znsmin = curmin-xzone/2;
! 		znsmax = curmax+xzone/2;
! 
! 		// check buffer limits and shift bounds if necessary
! 		if(znsmin < 0) {
! 			znsmax -= znsmin;
! 			znsmin = 0;
! 		}
! 		if(znsmax > buf->Frames())
! 			znsmax = buf->Frames();
! 	}
! 	else if(xfade == xsf_keeplooplen) { 
! 		// try to keep loop length
! 		// shifting of loop bounds may happen
! 
! 		const L maxfd = buf->Frames()-(curmax-curmin);
! 		if(xzone > maxfd) xzone = maxfd;
! 
! 		znsmin = curmin-xzone/2;
! 		znsmax = curmax+xzone/2;
! 
! 		// check buffer limits and shift bounds if necessary
! 		// both cases can't happen because of xzone having been limited above
! 		if(znsmin < 0) {
! 			znsmax -= znsmin;
! 			znsmin = 0;
! 		}
! 		else if(znsmax > buf->Frames()) {
! 			znsmin -= znsmax-buf->Frames();
! 			znsmax = buf->Frames();
! 		}
! 	}
! 	else if(xfade == xsf_keeplooppos) { 
! 		// try to keep loop position and length
! 
! 		znsmin = curmin-xzone/2;
! 		znsmax = curmax+xzone/2;
! 
! 		L ovr = znsmax-buf->Frames();
! 		if(-znsmin > ovr) ovr = -znsmin;
! 		if(ovr > 0) {
! 			znsmin += ovr;
! 			znsmax -= ovr;
! 			xzone -= ovr*2;
  		}
  	}
+ 
+ 	znmin = znsmin+xzone;
+ 	znmax = znsmax-xzone;
+ 
+ 	FLEXT_ASSERT(znsmin <= znsmax && (znsmax-znsmin) >= xzone*2);
  }
  
***************
*** 443,447 ****
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 456,460 ----
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 451,455 ****
  			const S spd = speed[i];  // must be first because the vector is reused for output!
  			
! 			if(o >= smax) { o = smax; lpbang = true; }
  			else if(o < smin) { o = smin; lpbang = true; }
  			
--- 464,468 ----
  			const S spd = speed[i];  // must be first because the vector is reused for output!
  			
! 			if(!(o < smax)) { o = smax; lpbang = true; }
  			else if(o < smin) { o = smin; lpbang = true; }
  			
***************
*** 477,481 ****
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 490,494 ----
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 483,487 ****
  
  		for(I i = 0; i < n; ++i) {	
! 			if(o >= smax) { o = smax; lpbang = true; }
  			else if(o < smin) { o = smin; lpbang = true; }
  			
--- 496,500 ----
  
  		for(I i = 0; i < n; ++i) {	
! 			if(!(o < smax)) { o = smax; lpbang = true; }
  			else if(o < smin) { o = smin; lpbang = true; }
  			
***************
*** 523,527 ****
  #endif
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 536,540 ----
  #endif
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 568,572 ****
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 581,585 ----
  	BL lpbang = false;
  
! 	const D smin = curmin,smax = curmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 616,624 ****
  	BL lpbang = false;
  
  	const F xz = xzone,xf = (F)XZONE_TABLE/xz;
! 	const D lmin = znmin,lmax = znmax,lsh = lmax+xz-lmin;
  
      // adapt the playing bounds to the current cross-fade zone
!     const I smin = znsmin,smax = znsmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 629,639 ----
  	BL lpbang = false;
  
+ 	FLEXT_ASSERT(xzone);
+ 
  	const F xz = xzone,xf = (F)XZONE_TABLE/xz;
! 	const D lmin = znmin,lmax = znmax,lsh = lmax-lmin+xz;
  
      // adapt the playing bounds to the current cross-fade zone
!     const L smin = znsmin,smax = znsmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 630,634 ****
   		
  			// normalize offset
! 			if(o >= smax) {
  				o = fmod(o-smin,plen)+smin;
  				lpbang = true;
--- 645,649 ----
   		
  			// normalize offset
! 			if(!(o < smax)) {
  				o = fmod(o-smin,plen)+smin;
  				lpbang = true;
***************
*** 639,656 ****
  			}
  
-             // now: smin <= o < smax
- 
              if(o >= lmax) {
                  // in late cross-fade zone
  
!                 // shift it into early zone
! 				o -= lsh; 
!             }
! 
!             // now: lmin-xz <= o < lmax
! 
  			if(o < lmin) {
  				// in early cross-fade zone
! 				register F inp = xz-(F)(lmin-o);  // 0 <= inp < xz
  				znidx[i] = inp*xf;
  				znpos[i] = lmax+inp;
--- 654,666 ----
  			}
  
              if(o >= lmax) {
                  // in late cross-fade zone
+ 				o -= lsh;
+ 			}
  
!             // now: smin <= o < smax
  			if(o < lmin) {
  				// in early cross-fade zone
! 				register F inp = xz+(F)(o-lmin);  // 0 <= inp < xz
  				znidx[i] = inp*xf;
  				znpos[i] = lmax+inp;
***************
*** 708,712 ****
  	BL lpbang = false;
  
! 	const I smin = curmin,smax = curmax,plen = smax-smin; //curlen;
  
  	if(buf && plen > 0) {
--- 718,722 ----
  	BL lpbang = false;
  
! 	const I smin = curmin,smax = curmax,plen = smax-smin;
  
  	if(buf && plen > 0) {
***************
*** 718,722 ****
  
  			// normalize offset
! 			if(o >= smax) {
  				o = smax-fmod(o-smin,plen); // mirror the position at smax
  				bd = -bd;
--- 728,732 ----
  
  			// normalize offset
! 			if(!(o < smax)) {
  				o = smax-fmod(o-smin,plen); // mirror the position at smax
  				bd = -bd;
***************
*** 753,775 ****
  		case xsl_once: SETSIGFUN(posfun,SIGFUN(s_pos_once)); break;
  		case xsl_loop: 
! 			if(_xzone > 0) {
!                 // xzone might not be set yet (is done in do_xzone() )
  
  				const I blksz = Blocksize();
  
  				if(pblksz != blksz) {
  					for(I o = 0; o < outchns; ++o) {
! 						delete[] znbuf[o]; 
  						znbuf[o] = new S[blksz]; 
  					}
  				
! 					delete[] znpos; znpos = new S[blksz];
! 					delete[] znidx;	znidx = new S[blksz];
  
  					pblksz = blksz;
  				}
  
- 				do_xzone(); // recalculate (s2u may have been 0 before)
- 
  				SETSIGFUN(posfun,SIGFUN(s_pos_loopzn)); 
  
--- 763,786 ----
  		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();
  
  				if(pblksz != blksz) {
  					for(I o = 0; o < outchns; ++o) {
! 						if(znbuf[o]) delete[] znbuf[o]; 
  						znbuf[o] = new S[blksz]; 
  					}
  				
! 					if(znpos) delete[] znpos; 
! 					znpos = new S[blksz];
! 					if(znidx) delete[] znidx;
! 					znidx = new S[blksz];
  
  					pblksz = blksz;
  				}
  
  				SETSIGFUN(posfun,SIGFUN(s_pos_loopzn)); 
  

Index: main.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/xsample/source/main.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** main.h	23 Mar 2004 03:27:37 -0000	1.27
--- main.h	7 Apr 2004 02:48:18 -0000	1.28
***************
*** 13,17 ****
  
  
! #define XSAMPLE_VERSION "0.3.0pre18"
  
  
--- 13,17 ----
  
  
! #define XSAMPLE_VERSION "0.3.0pre19"
  
  
***************
*** 114,118 ****
  	enum xs_intp {
  		xsi__ = -1,  // don't change
! 		xsi_none = 0,xsi_4p,xsi_lin
  	};
  	
--- 114,118 ----
  	enum xs_intp {
  		xsi__ = -1,  // don't change
! 		xsi_none = 0,xsi_lin,xsi_4p
  	};
  	
***************
*** 147,151 ****
  	xs_sclmd sclmode; //isclmode,osclmode;
  
! 	I curmin,curmax; //,curlen;  // in samples
  	I sclmin; // in samples
  	F sclmul;
--- 147,151 ----
  	xs_sclmd sclmode; //isclmode,osclmode;
  
! 	L curmin,curmax; //,curlen;  // in samples
  	I sclmin; // in samples
  	F sclmul;





More information about the Pd-cvs mailing list