diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2009-04-01 21:13:09 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2009-04-01 21:13:09 +0000 |
commit | 0ed7a8b68dd73e2b0473b8127aeca99f3bac9061 (patch) | |
tree | 5c67818b38a5cc2f9caa5ca7f8640ca356adf02b /externals/grill/xsample/source | |
parent | bb4c7f6a245394d09dac9adfb2efb093d3d98452 (diff) |
cleaned up grill externals - replaced with svn:externals to svn.grrrr.org/ext/trunk/
svn path=/trunk/; revision=10951
Diffstat (limited to 'externals/grill/xsample/source')
-rw-r--r-- | externals/grill/xsample/source/groove.cpp | 810 | ||||
-rw-r--r-- | externals/grill/xsample/source/inter.cpp | 82 | ||||
-rw-r--r-- | externals/grill/xsample/source/inter.h | 420 | ||||
-rw-r--r-- | externals/grill/xsample/source/main.cpp | 220 | ||||
-rw-r--r-- | externals/grill/xsample/source/main.h | 464 | ||||
-rw-r--r-- | externals/grill/xsample/source/play.cpp | 151 | ||||
-rw-r--r-- | externals/grill/xsample/source/prefix.h | 15 | ||||
-rw-r--r-- | externals/grill/xsample/source/record.cpp | 497 | ||||
-rw-r--r-- | externals/grill/xsample/source/xsample-Info.plist | 22 | ||||
-rwxr-xr-x | externals/grill/xsample/source/xsample.rsrc | 29 |
10 files changed, 0 insertions, 2710 deletions
diff --git a/externals/grill/xsample/source/groove.cpp b/externals/grill/xsample/source/groove.cpp deleted file mode 100644 index c989156e..00000000 --- a/externals/grill/xsample/source/groove.cpp +++ /dev/null @@ -1,810 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2007 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif - -#include "main.h" -#include <math.h> -#include <stdio.h> - -#ifdef _MSC_VER -#pragma warning (disable:4244) -#endif - -#ifndef M_PI -#define M_PI 3.141592653589793238462643383 -#endif - -#define XZONE_TABLE 512 - - -class xgroove: - public xinter -{ - FLEXT_HEADER_S(xgroove,xinter,setup) - -public: - xgroove(int argc,const t_atom *argv); - virtual ~xgroove(); - - void m_pos(float pos) - { - setpos(LIKELY(s2u)?pos/s2u:0); - Update(xsc_pos,true); - } - - inline void m_posmod(float pos) { setposmod(LIKELY(pos)?pos/s2u:0); } // motivated by Tim Blechmann - - inline void mg_pos(float &v) const { v = curpos*s2u; } - - - enum xs_fade { - xsf_keeplooppos = 0,xsf_keeplooplen,xsf_keepfade,xsf_inside - }; - - enum xs_shape { - xss_lin = 0,xss_qsine,xss_hsine - }; - - - void ms_xfade(int xf) - { - if(xf < 0 || xf > xsf_inside) xf = xsf_keeplooppos; - xfade = (xs_fade)xf; - Update(xsc_fade,true); - } - - void ms_xshape(int sh); - - void ms_xzone(float xz); - void mg_xzone(float &xz) { xz = _xzone*s2u; } - - void m_loop(xs_loop lp) - { - loopmode = lp,bidir = 1; - Update(xsc_loop,true); - } - -protected: - - double curpos; // in samples - float bidir; // +1 or -1 - - float _xzone,xzone; - long znsmin,znsmax; - xs_fade xfade; - int xshape; - t_sample **znbuf; - t_sample *znpos,*znmul,*znidx; - int pblksz; - - inline void setpos(double pos) - { - if(UNLIKELY(pos < znsmin)) curpos = znsmin; - else if(UNLIKELY(pos > znsmax)) curpos = znsmax; - else curpos = pos; - } - - inline void setposmod(double pos) - { - if(pos >= 0) - curpos = znsmin+fmod(pos,znsmax-znsmin); - else - curpos = znsmax+fmod(pos,znsmax-znsmin); - } - - virtual void DoReset(); - virtual void DoUpdate(unsigned int flags); - - virtual void CbSignal(); - - virtual void m_help(); - virtual void m_print(); - -private: - static void setup(t_classid c); - - //! return true if something has changed - bool do_xzone(); - - DEFSIGFUN(s_pos_off); - DEFSIGFUN(s_pos_once); - DEFSIGFUN(s_pos_loop); - DEFSIGFUN(s_pos_loopzn); - DEFSIGFUN(s_pos_bidir); - - DEFSIGCALL(posfun); - DEFSTCALL(zonefun); - - static t_sample fade_lin[],fade_qsine[],fade_hsine[]; - - FLEXT_CALLBACK_F(m_pos) - FLEXT_CALLBACK_F(m_posmod) - FLEXT_CALLBACK_F(m_min) - FLEXT_CALLBACK_F(m_max) - FLEXT_CALLBACK(m_all) - - FLEXT_CALLSET_E(m_loop,xs_loop) - - FLEXT_CALLSET_I(ms_xfade) - FLEXT_ATTRGET_I(xfade) - FLEXT_CALLSET_I(ms_xshape) - FLEXT_ATTRGET_I(xshape) - FLEXT_CALLSET_F(ms_xzone) - FLEXT_CALLGET_F(mg_xzone) - - FLEXT_CALLVAR_F(mg_pos,m_pos) - FLEXT_CALLSET_F(m_min) - FLEXT_CALLSET_F(m_max) -}; - - -FLEXT_LIB_DSP_V("xgroove~",xgroove) - - -t_sample xgroove::fade_lin[XZONE_TABLE+1]; -t_sample xgroove::fade_qsine[XZONE_TABLE+1]; -t_sample xgroove::fade_hsine[XZONE_TABLE+1]; - -void xgroove::setup(t_classid c) -{ - DefineHelp(c,"xgroove~"); - - FLEXT_CADDMETHOD_(c,0,"all",m_all); - FLEXT_CADDMETHOD(c,1,m_min); - FLEXT_CADDMETHOD(c,2,m_max); - - FLEXT_CADDATTR_VAR(c,"min",mg_min,m_min); - FLEXT_CADDATTR_VAR(c,"max",mg_max,m_max); - FLEXT_CADDATTR_VAR(c,"pos",mg_pos,m_pos); - FLEXT_CADDMETHOD_(c,0,"posmod",m_posmod); - - 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",xshape,ms_xshape); - - // initialize fade tables - for(int i = 0; i <= XZONE_TABLE; ++i) { - const float x = i*(1.f/XZONE_TABLE); - // linear - fade_lin[i] = x; - - // quarter sine wave - fade_qsine[i] = sin(x*(M_PI/2)); - - // half sine wave - fade_hsine[i] = (sin(x*M_PI-M_PI/2)+1.f)*0.5f; - } -} - -xgroove::xgroove(int argc,const t_atom *argv): - curpos(0),bidir(1), - _xzone(0),xzone(0), - xfade(xsf_keeplooppos),xshape(xss_lin), - znpos(NULL),znmul(NULL),znidx(NULL), - pblksz(0) -{ - int argi = 0; -#if FLEXT_SYS == FLEXT_SYS_MAX - if(argc > argi && CanbeInt(argv[argi])) { - outchns = GetAInt(argv[argi]); - argi++; - } -#endif - - if(argc > argi && IsSymbol(argv[argi])) { - - buf.Set(GetSymbol(argv[argi]),true); - argi++; - -#if FLEXT_SYS == FLEXT_SYS_MAX - // old-style command line? - if(UNLIKELY(argi == 1 && argc == 2 && CanbeInt(argv[argi]))) { - outchns = GetAInt(argv[argi]); - argi++; - post("%s: old style command line detected - please change to '%s [channels] [buffer]'",thisName(),thisName()); - } -#endif - } - - AddInSignal("Signal of playing speed"); // speed signal - AddInFloat("Starting point"); // min play pos - AddInFloat("Ending point"); // max play pos - for(int ci = 0; ci < outchns; ++ci) { - char tmp[30]; - STD::sprintf(tmp,"Audio signal channel %i",ci+1); - AddOutSignal(tmp); // output - } - AddOutSignal("Position currently played"); // position - AddOutFloat("Starting point (rounded to frame)"); // play min - AddOutFloat("Ending point (rounded to frame)"); // play max - AddOutBang("Bang on loop end/rollover"); // loop bang - - // don't know vector size yet -> wait for m_dsp - znbuf = new t_sample *[outchns]; - for(int i = 0; i < outchns; ++i) znbuf[i] = NULL; - - // initialize crossfade shape - ms_xshape(xshape); -} - -xgroove::~xgroove() -{ - if(znbuf) { - for(int i = 0; i < outchns; ++i) if(znbuf[i]) FreeAligned(znbuf[i]); - delete[] znbuf; - } - - if(znpos) FreeAligned(znpos); - if(znidx) FreeAligned(znidx); -} - -void xgroove::DoReset() -{ - xinter::DoReset(); - curpos = 0; - bidir = 1; -} - -void xgroove::ms_xzone(float xz) -{ - ChkBuffer(true); - - _xzone = (UNLIKELY(xz < 0) || UNLIKELY(!s2u))?0:xz/s2u; - Update(xsc_fade,true); -} - -void xgroove::ms_xshape(int sh) -{ - if(UNLIKELY(sh < 0) || UNLIKELY(sh > xss_hsine)) sh = xss_lin; - - xshape = (xs_shape)sh; - switch(xshape) { - case xss_qsine: znmul = fade_qsine; break; - case xss_hsine: znmul = fade_hsine; break; - default: - post("%s - shape parameter invalid, set to linear",thisName()); - case xss_lin: - znmul = fade_lin; break; - } - - // no need to recalc the fade zone here -} - - -void xgroove::s_pos_off(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - t_sample *pos = outvecs[outchns]; - - SetSamples(pos,n,curpos); - - playfun(n,&pos,outvecs); - - SetSamples(pos,n,scale(curpos)); -} - -void xgroove::s_pos_once(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - const t_sample *speed = invecs[0]; - t_sample *pos = outvecs[outchns]; - bool lpbang = false; - - const double smin = curmin,smax = curmax,plen = smax-smin; - - if(LIKELY(plen > 0)) { - register double o = curpos; - - for(int i = 0; i < n; ++i) { - const t_sample spd = speed[i]; // must be first because the vector is reused for output! - - if(UNLIKELY(!(o < smax))) { o = smax; lpbang = true; } - else if(UNLIKELY(o < smin)) { o = smin; lpbang = true; } - - pos[i] = o; - o += spd; - } - // normalize and store current playing position - setpos(o); - - playfun(n,&pos,outvecs); - - arrscale(n,pos,pos); - } - else - s_pos_off(n,invecs,outvecs); - - if(UNLIKELY(lpbang)) { - doplay = false; - ToOutBang(outchns+3); - } -} - -void xgroove::s_pos_loop(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - const t_sample *speed = invecs[0]; - t_sample *pos = outvecs[outchns]; - bool lpbang = false; - -#ifdef __VEC__ - // prefetch cache - vec_dst(speed,GetPrefetchConstant(1,n>>2,0),0); -#endif - - const double smin = curmin,smax = curmax,plen = smax-smin; - - if(LIKELY(plen > 0)) { - register double o = curpos; - - if(wrap && UNLIKELY(smin < 0) && UNLIKELY(smax >= buf.Frames())) { - for(int i = 0; i < n; ++i) { - const t_sample spd = speed[i]; // must be first because the vector is reused for output! - - // normalize offset - if(UNLIKELY(!(o < smax))) { // faster than o >= smax - o = fmod(o-smin,plen)+smin; - lpbang = true; - } - else if(UNLIKELY(o < smin)) { - o = fmod(o-smin,plen)+smax; - lpbang = true; - } - - // TODO normalize to 0...buf.Frames() - pos[i] = o; - o += spd; - } - } - else { - /////////////////////////////////// - // Most of the time is spent in here - /////////////////////////////////// - for(int i = 0; i < n; ++i) { - const t_sample spd = speed[i]; // must be first because the vector is reused for output! - - // normalize offset - if(UNLIKELY(!(o < smax))) { // faster than o >= smax - o = fmod(o-smin,plen)+smin; - lpbang = true; - } - else if(UNLIKELY(o < smin)) { - o = fmod(o-smin,plen)+smax; - lpbang = true; - } - - pos[i] = o; - o += spd; - } - } - - // normalize and store current playing position - setpos(o); - - playfun(n,&pos,outvecs); - - arrscale(n,pos,pos); - } - else - s_pos_off(n,invecs,outvecs); - -#ifdef __VEC__ - vec_dss(0); -#endif - - if(UNLIKELY(lpbang)) ToOutBang(outchns+3); -} - -void xgroove::s_pos_loopzn(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - const t_sample *speed = invecs[0]; - t_sample *pos = outvecs[outchns]; - bool lpbang = false; - - FLEXT_ASSERT(xzone); - - const float xz = xzone,xf = (float)XZONE_TABLE/xz; - - // adapt the playing bounds to the current cross-fade zone - const long smin = znsmin,smax = znsmax,plen = smax-smin; - - // temporary storage - const long 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(LIKELY(plen > 0)) { - bool inzn = false; - register double o = curpos; - - // calculate inner cross-fade boundaries - const double lmin = smin+xz,lmax = smax-xz,lsh = lmax-lmin+xz; - const double lmin2 = lmin-xz/2,lmax2 = lmax+xz/2; - - for(int i = 0; i < n; ++i) { - // normalize offset - if(UNLIKELY(o < smin)) { - o = fmod(o-smin,plen)+smax; - lpbang = true; - } - else if(UNLIKELY(!(o < smax))) { - o = fmod(o-smin,plen)+smin; - lpbang = true; - } - - if(UNLIKELY(o < lmin)) { - register float 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; - // now lmax <= o <= lmax2 - lpbang = true; - - inp = xz-(float)(o-lmax); // 0 <= inp < xz - znpos[i] = lmin-inp; - } - else { - // in second half of early cross-fade zone - - inp = xz+(float)(o-lmin); // 0 <= inp < xz - znpos[i] = lmax+inp; - } - znidx[i] = inp*xf; - inzn = true; - } - else if(UNLIKELY(!(o < lmax))) { - register float 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; - // now lmin2 <= o <= lmin - lpbang = true; - - inp = xz+(float)(o-lmin); // 0 <= inp < xz - znpos[i] = lmax+inp; - } - else { - // in first half of late cross-fade zone - inp = xz-(float)(o-lmax); // 0 <= inp < xz - znpos[i] = lmin-inp; - } - znidx[i] = inp*xf; - inzn = true; - } - else - znidx[i] = XZONE_TABLE,znpos[i] = 0; - - const t_sample spd = speed[i]; // must be first because the vector is reused for output! - pos[i] = o; - o += spd; - } - - // normalize and store current playing position - setpos(o); - - // calculate samples (1st voice) - playfun(n,&pos,outvecs); - - // rescale position vector - arrscale(n,pos,pos); - - if(UNLIKELY(inzn)) { - // only if we have touched the cross-fade zone - - // calculate samples in loop zone (2nd voice) - playfun(n,&znpos,znbuf); - - // calculate counterpart in loop fade - arrscale(n,znidx,znpos,XZONE_TABLE,-1); - - // calculate fade coefficients by sampling from the fade curve - zonefun(znmul,0,XZONE_TABLE+1,n,1,1,&znidx,&znidx,false); - zonefun(znmul,0,XZONE_TABLE+1,n,1,1,&znpos,&znpos,false); - - // mix voices for all channels - for(int o = 0; o < outchns; ++o) { - MulSamples(outvecs[o],outvecs[o],znidx,n); - MulSamples(znbuf[o],znbuf[o],znpos,n); - AddSamples(outvecs[o],outvecs[o],znbuf[o],n); - } - } - } - else - s_pos_off(n,invecs,outvecs); - - curmin = cmin,curmax = cmax; - - if(UNLIKELY(lpbang)) ToOutBang(outchns+3); -} - -void xgroove::s_pos_bidir(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - const t_sample *speed = invecs[0]; - t_sample *pos = outvecs[outchns]; - bool lpbang = false; - - const int smin = curmin,smax = curmax,plen = smax-smin; - - if(LIKELY(plen > 0)) { - register double o = curpos; - register float bd = bidir; - - for(int i = 0; i < n; ++i) { - const t_sample spd = speed[i]; // must be first because the vector is reused for output! - - // normalize offset - // \todo at the moment fmod doesn't take bidirectionality into account!! - if(UNLIKELY(!(o < smax))) { - o = smax-fmod(o-smax,plen); // mirror the position at smax - bd = -bd; - lpbang = true; - } - else if(UNLIKELY(o < smin)) { - o = smin+fmod(smin-o,plen); // mirror the position at smin - bd = -bd; - lpbang = true; - } - - pos[i] = o; - o += spd*bd; - } - // normalize and store current playing position - setpos(o); - - bidir = bd; - playfun(n,&pos,outvecs); - - arrscale(n,pos,pos); - } - else - s_pos_off(n,invecs,outvecs); - - if(UNLIKELY(lpbang)) ToOutBang(outchns+3); -} - -void xgroove::CbSignal() -{ - int ret = ChkBuffer(true); - - if(LIKELY(ret)) { - FLEXT_ASSERT(buf.Valid()); - - const lock_t l = Lock(); - posfun(Blocksize(),InSig(),OutSig()); - Unlock(l); - - Refresh(); - } - else - zerofun(Blocksize(),InSig(),OutSig()); -} - - -void xgroove::DoUpdate(unsigned int flags) -{ - xinter::DoUpdate(flags); - - if(flags&xsc_range) { - // output new range - ToOutFloat(outchns+1,curmin*s2u); - ToOutFloat(outchns+2,curmax*s2u); - } - - if(flags&(xsc_fade|xsc_range)) - if(do_xzone()) flags |= xsc_play; - - if(flags&(xsc_pos|xsc_range)) - // normalize position - setpos(curpos); - - // loop zone must already be set - if(flags&xsc_play) { - if(doplay) { - switch(loopmode) { - case xsl_once: - SETSIGFUN(posfun,SIGFUN(s_pos_once)); - break; - case xsl_loop: - if(xzone > 0) { - const int blksz = Blocksize(); - - if(pblksz != blksz) { - for(int o = 0; o < outchns; ++o) { - if(znbuf[o]) FreeAligned(znbuf[o]); - znbuf[o] = (t_sample *)NewAligned(blksz*sizeof(t_sample)); - } - - if(znpos) FreeAligned(znpos); - znpos = (t_sample *)NewAligned(blksz*sizeof(t_sample)); - if(znidx) FreeAligned(znidx); - znidx = (t_sample *)NewAligned(blksz*sizeof(t_sample)); - - pblksz = blksz; - } - - SETSIGFUN(posfun,SIGFUN(s_pos_loopzn)); - - // linear interpolation should be just ok for fade zone, no? - switch(outchns) { - case 1: SETSTFUN(zonefun,TMPLSTF(st_play2,1,1)); break; - case 2: SETSTFUN(zonefun,TMPLSTF(st_play2,1,2)); break; - case 4: SETSTFUN(zonefun,TMPLSTF(st_play2,1,4)); break; - default: SETSTFUN(zonefun,TMPLSTF(st_play2,1,-1)); - } - } - else - SETSIGFUN(posfun,SIGFUN(s_pos_loop)); - break; - case xsl_bidir: - SETSIGFUN(posfun,SIGFUN(s_pos_bidir)); - break; - default: ; // just to prevent warning - } - } - else - SETSIGFUN(posfun,SIGFUN(s_pos_off)); - } -} - -bool xgroove::do_xzone() -{ - // \todo do we really need this? - if(UNLIKELY(!s2u)) return false; // this can happen if DSP is off - - const long frames = buf.Frames(); - if(UNLIKELY(!frames)) return false; - - xzone = _xzone; // make a copy for changing it - - if(xfade == xsf_inside) { - // fade zone goes inside the loop -> loop becomes shorter - - // \todo what about round-off? - const long maxfd = (curmax-curmin)/2; - if(xzone > maxfd) xzone = maxfd; - - znsmin = curmin,znsmax = curmax; - } - else if(xfade == xsf_keepfade) { - // try to keep fade zone - // change of loop bounds may happen - - // restrict xzone to half of buffer - const long maxfd = frames/2; - if(xzone > maxfd) xzone = maxfd; - - // \todo what about round-off? - const long hzone = CASTINT<long>(xzone/2.f+0.5f); - znsmin = curmin-hzone; - znsmax = curmax+hzone; - - // widen loop if xzone doesn't fit into it - // \todo check formula - long lack = CASTINT<long>(ceil((xzone*2.f-(znsmax-znsmin))/2.f)); - if(lack > 0) znsmin -= lack,znsmax += lack; - - if(!wrap) { - // check buffer limits and shift bounds if necessary - if(znsmin < 0) { - znsmax -= znsmin; - znsmin = 0; - } - if(znsmax > frames) - znsmax = frames; - } - } - else if(xfade == xsf_keeplooplen) { - // try to keep loop length - // shifting of loop bounds may happen - - const long plen = curmax-curmin; - if(xzone > plen) xzone = plen; - const long maxfd = frames-plen; - if(xzone > maxfd) xzone = maxfd; - - // \todo what about round-off? - const long hzone = CASTINT<long>(xzone/2.f+0.5f); - znsmin = curmin-hzone; - znsmax = curmax+hzone; - - if(!wrap) { - // 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 > frames) { - znsmin -= znsmax-frames; - znsmax = frames; - } - } - } - else if(xfade == xsf_keeplooppos) { - // try to keep loop position and length - - // restrict fade zone to maximum length - const long plen = curmax-curmin; - if(xzone > plen) xzone = plen; - - // \todo what about round-off? - const long hzone = CASTINT<long>(xzone/2.f+0.5f); - znsmin = curmin-hzone; - znsmax = curmax+hzone; - - long ovr = znsmax-frames; - if(-znsmin > ovr) ovr = -znsmin; - if(ovr > 0) { - znsmin += ovr; - znsmax -= ovr; - xzone -= ovr*2; - } - } - - FLEXT_ASSERT(znsmin <= znsmax && (znsmax-znsmin) >= xzone*2.f); - - return true; -} - - -void xgroove::m_help() -{ - post("%s - part of xsample objects, version " XSAMPLE_VERSION,thisName()); - post("(C) Thomas Grill, 2001-2007"); -#if FLEXT_SYS == FLEXT_SYS_MAX - post("Arguments: %s [channels=1] [buffer]",thisName()); -#else - post("Arguments: %s [buffer]",thisName()); -#endif - post("Inlets: 1:Messages/Speed signal, 2:Min position, 3:Max position"); - post("Outlets: 1:Audio signal, 2:Position signal, 3:Min position (rounded), 4:Max position (rounded)"); - post("Methods:"); - post("\thelp: shows this help"); - post("\tset [name] / @buffer [name]: set buffer or reinit"); - post("\tenable 0/1: turn dsp calculation off/on"); - post("\treset: reset min/max playing points and playing offset"); - post("\tprint: print current settings"); - post("\t@loop 0/1/2: sets looping to off/forward/bidirectional"); - post("\t@interp 0/1/2: set interpolation to off/4-point/linear"); - post("\t@min {unit}: set minimum playing point"); - post("\t@max {unit}: set maximum playing point"); - post("\tall: select entire buffer length"); - post("\tpos {unit}: set playing position (obeying the current scale mode)"); - post("\tposmod {unit}: set playing position (modulo into min/max range)"); - post("\tbang/start: start playing"); - post("\tstop: stop playing"); - post("\trefresh: checks buffer and refreshes outlets"); - post("\t@units 0/1/2/3: set units to frames/buffer size/ms/s"); - post("\t@sclmode 0/1/2/3: set range of position to units/units in loop/buffer/loop"); - post("\t@xzone {unit}: length of loop crossfade zone"); - post("\t@xfade 0/1/2/3: fade mode (keep loop/keep loop length/keep fade/inside loop)"); - post("\t@xshape 0/1/2: shape of crossfade (linear/quarter sine/half sine)"); - post(""); -} - -void xgroove::m_print() -{ - static const char *sclmode_txt[] = {"units","units in loop","buffer","loop"}; - static const char *interp_txt[] = {"off","4-point","linear"}; - static const char *loop_txt[] = {"once","looping","bidir"}; - - // print all current settings - post("%s - current settings:",thisName()); - post("bufname = '%s', length = %.3f, channels = %i",buf.Name(),(float)(buf.Frames()*s2u),buf.Channels()); - post("out channels = %i, frames/unit = %.3f, scale mode = %s",outchns,(float)(1./s2u),sclmode_txt[sclmode]); - post("loop = %s, interpolation = %s",loop_txt[(int)loopmode],interp_txt[interp >= xsi_none && interp <= xsi_lin?interp:xsi_none]); - post("loop crossfade zone = %.3f",(float)(xzone*s2u)); - post(""); -} diff --git a/externals/grill/xsample/source/inter.cpp b/externals/grill/xsample/source/inter.cpp deleted file mode 100644 index 1f70b79f..00000000 --- a/externals/grill/xsample/source/inter.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2006 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#include "main.h" -#include <math.h> - -#ifdef _MSC_VER -#pragma warning (disable:4244) -#endif - -#ifndef TMPLOPT -#include "inter.h" -#endif - -void xinter::setup(t_classid c) -{ - FLEXT_CADDBANG(c,0,m_start); - FLEXT_CADDMETHOD_(c,0,"start",m_start); - FLEXT_CADDMETHOD_(c,0,"stop",m_stop); - - FLEXT_CADDATTR_VAR_E(c,"interp",interp,m_interp); -} - -void xinter::DoUpdate(unsigned int flags) -{ - xsample::DoUpdate(flags); - - if(flags&xsc_play) { - switch(outchns) { - case 1: SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,1)); break; - case 2: SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,2)); break; - case 4: SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,4)); break; - default: SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,-1)); - } - - if(doplay && buf.Ok()) { - if(interp == xsi_4p) - switch(buf.Channels()*1000+outchns) { - case 1001: SETSIGFUN(playfun,TMPLFUN(s_play4,1,1)); break; - case 1002: SETSIGFUN(playfun,TMPLFUN(s_play4,1,2)); break; - case 2001: SETSIGFUN(playfun,TMPLFUN(s_play4,2,1)); break; - case 2002: SETSIGFUN(playfun,TMPLFUN(s_play4,2,2)); break; - case 4001: - case 4002: - case 4003: SETSIGFUN(playfun,TMPLFUN(s_play4,4,-1)); break; - case 4004: SETSIGFUN(playfun,TMPLFUN(s_play4,4,4)); break; - default: SETSIGFUN(playfun,TMPLFUN(s_play4,-1,-1)); - } - else if(interp == xsi_lin) - switch(buf.Channels()*1000+outchns) { - case 1001: SETSIGFUN(playfun,TMPLFUN(s_play2,1,1)); break; - case 1002: SETSIGFUN(playfun,TMPLFUN(s_play2,1,2)); break; - case 2001: SETSIGFUN(playfun,TMPLFUN(s_play2,2,1)); break; - case 2002: SETSIGFUN(playfun,TMPLFUN(s_play2,2,2)); break; - case 4001: - case 4002: - case 4003: SETSIGFUN(playfun,TMPLFUN(s_play2,4,-1)); break; - case 4004: SETSIGFUN(playfun,TMPLFUN(s_play2,4,4)); break; - default: SETSIGFUN(playfun,TMPLFUN(s_play2,-1,-1)); - } - else - switch(buf.Channels()*1000+outchns) { - case 1001: SETSIGFUN(playfun,TMPLFUN(s_play1,1,1)); break; - case 1002: SETSIGFUN(playfun,TMPLFUN(s_play1,1,2)); break; - case 2001: SETSIGFUN(playfun,TMPLFUN(s_play1,2,1)); break; - case 2002: SETSIGFUN(playfun,TMPLFUN(s_play1,2,2)); break; - case 4001: - case 4002: - case 4003: SETSIGFUN(playfun,TMPLFUN(s_play1,4,-1)); break; - case 4004: SETSIGFUN(playfun,TMPLFUN(s_play1,4,4)); break; - default: SETSIGFUN(playfun,TMPLFUN(s_play1,-1,-1)); - } - } - else - SETSIGFUN(playfun,TMPLFUN(s_play0,-1,-1)); - } -} diff --git a/externals/grill/xsample/source/inter.h b/externals/grill/xsample/source/inter.h deleted file mode 100644 index f8a0881b..00000000 --- a/externals/grill/xsample/source/inter.h +++ /dev/null @@ -1,420 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2006 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#ifndef __INTER_H -#define __INTER_H - -TMPLDEF void xinter::st_play0(const t_sample *,const int ,const int ,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) -{ - // stopped/invalid buffer -> output zero - for(int ci = 0; ci < outchns; ++ci) ZeroSamples(outvecs[ci],n); -} - -TMPLDEF void xinter::st_play1(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) -{ - SIGCHNS(BCHNS,inchns,OCHNS,outchns); - - // position info are frame units - const t_sample *pos = invecs[0]; - t_sample *const *sig = outvecs; - - // no interpolation - // ---------------- - - if(UNLIKELY(smin == smax)) { - // zero loop length -> assume that smin is a valid sample position... - - int ci; - for(ci = 0; ci < OCHNS; ++ci) SetSamples(sig[ci],n,bdt[smin*BCHNS]); - // clear rest of output channels (if buffer has less channels) - for(; ci < outchns; ++ci) ZeroSamples(sig[ci],n); - } - else if(OCHNS == 1) { - t_sample *sig0 = sig[0]; - for(int i = 0; i < n; ++i) { - register long oint = CASTINT<long>(*(pos++)); - - // for xplay oint can be out of bounds -> check - if(LIKELY(oint >= smin)) - if(LIKELY(oint < smax)) { - // normal - *(sig0++) = bdt[oint*BCHNS]; - } - else { - // position > last sample ... take only last sample - *(sig0++) = bdt[(smax-1)*BCHNS]; - } - else { - // position < 0 ... take only 0th sample - *(sig0++) = bdt[smin*BCHNS]; - } - } - } - else { - for(int i = 0,si = 0; i < n; ++i,++si) { - register long oint = CASTINT<long>(*(pos++)); - register const t_sample *fp; - - // for xplay oint can be out of bounds -> check - if(LIKELY(oint >= smin)) - if(LIKELY(oint < smax)) { - // normal - fp = bdt+oint*BCHNS; - } - else { - // position > last sample ... take only last sample - fp = bdt+(smax-1)*BCHNS; - } - else { - // position < 0 ... take only 0th sample - fp = bdt+smin*BCHNS; - } - - for(int ci = 0; ci < OCHNS; ++ci) - sig[ci][si] = fp[ci]; - } - - // clear rest of output channels (if buffer has less channels) - for(int ci = OCHNS; ci < outchns; ++ci) ZeroSamples(sig[ci],n); - } -} - -TMPLDEF void xinter::st_play2(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) -{ - const int plen = smax-smin; - if(UNLIKELY(plen < 2)) { - st_play1 TMPLCALL (bdt,smin,smax,n,inchns,outchns,invecs,outvecs,looped); - return; - } - - SIGCHNS(BCHNS,inchns,OCHNS,outchns); - - // position info are frame units - const t_sample *pos = invecs[0]; - t_sample *const *sig = outvecs; - - // linear interpolation - // -------------------- - - const int maxo = smax-1; // last sample in buffer - - if(OCHNS == 1) { - t_sample *sig0 = sig[0]; - for(int i = 0; i < n; ++i) { - const float o = *(pos++); - register long oint = CASTINT<long>(o); - const float frac = o-oint; - t_sample fp0,fp1; - - if(LIKELY(oint >= smin)) - if(LIKELY(oint < maxo)) { - // normal interpolation - fp0 = bdt[oint*BCHNS]; - fp1 = bdt[(oint+1)*BCHNS]; - } - else { - // position is past last sample - if(looped) { - oint = smin+(oint-smin)%plen; - fp0 = bdt[oint*BCHNS]; - fp1 = oint >= maxo?bdt[smin]:fp0; - } - else - fp0 = fp1 = bdt[maxo*BCHNS]; - } - else { - // position is before first sample - if(looped) { - oint = smax-(smin-oint)%plen; - fp0 = bdt[oint*BCHNS]; - fp1 = oint >= maxo?bdt[smin]:fp0; - } - else - fp0 = fp1 = bdt[smin*BCHNS]; - } - - *(sig0++) = fp0+frac*(fp1-fp0); - } - } - else { - for(int i = 0,si = 0; i < n; ++i,++si) { - const float o = *(pos++); - register long oint = CASTINT<long>(o); - const t_sample *fp0,*fp1; - const float frac = o-oint; - - if(LIKELY(oint >= smin)) - if(LIKELY(oint < maxo)) { - // normal interpolation - fp0 = bdt+oint*BCHNS; - fp1 = fp0+BCHNS; - } - else { - // position is past last sample - if(looped) { - oint = smin+(oint-smin)%plen; - fp0 = bdt+oint*BCHNS; - fp1 = oint >= maxo?bdt+smin:fp0; - } - else - fp0 = fp1 = bdt+maxo*BCHNS; - } - else { - // position is before first sample - if(looped) { - oint = smax-(smin-oint)%plen; - fp0 = bdt+oint*BCHNS; - fp1 = oint >= maxo?bdt+smin:fp0; - } - else - fp0 = fp1 = bdt+smin*BCHNS; - } - - for(int ci = 0; ci < OCHNS; ++ci) - sig[ci][si] = fp0[ci]+frac*(fp1[ci]-fp0[ci]); - } - - // clear rest of output channels (if buffer has less channels) - for(int ci = OCHNS; ci < outchns; ++ci) ZeroSamples(sig[ci],n); - } -} - -TMPLDEF void xinter::st_play4(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) -{ - const int plen = smax-smin; //curlen; - if(UNLIKELY(plen < 4)) { - if(plen < 2) st_play1 TMPLCALL (bdt,smin,smax,n,inchns,outchns,invecs,outvecs,looped); - else st_play2 TMPLCALL (bdt,smin,smax,n,inchns,outchns,invecs,outvecs,looped); - return; - } - - SIGCHNS(BCHNS,inchns,OCHNS,outchns); - - // position info are frame units - const t_sample *pos = invecs[0]; - t_sample *const *sig = outvecs; - - // 4-point interpolation - // --------------------- - const int maxo = smax-1; // last sample in play region - - if(OCHNS == 1) { - t_sample *sig0 = sig[0]; - for(int i = 0; i < n; ++i) { - float o = pos[i]; - register long oint = CASTINT<long>(o); - register t_sample fa,fb,fc,fd; - const float frac = o-oint; - register const t_sample *ptr = bdt+oint*BCHNS; - - if(LIKELY(oint > smin)) { - if(LIKELY(oint < maxo-2)) { - // normal case - fa = ptr[-BCHNS]; - fb = ptr[0]; - fc = ptr[BCHNS]; - fd = ptr[BCHNS*2]; - } - else { - // not enough space at the end - - if(looped) { - // normalize position - oint = smin+(oint-smin)%plen; - goto looped1; - } - else { - // last sample is outside in any case - fd = bdt[maxo*BCHNS]; - - if(oint-1 >= maxo) - // if first is outside, all are outside - fa = fb = fc = fd; - else { - fa = ptr[-BCHNS]; - if(oint >= maxo) - fb = fc = fd; - else { - fb = ptr[0]; - fc = oint+1 < maxo?ptr[BCHNS]:fd; - } - } - } - } - } - else { - // not enough space at the beginning - - if(looped) { - // normalize position - oint = smax-(smin-oint)%plen; -looped1: - ptr = bdt+oint*BCHNS; - - // inside in any case - fb = ptr[0]; - - if(oint < maxo-1) { - fa = oint > smin?ptr[-BCHNS]:bdt[maxo*BCHNS]; - fc = ptr[BCHNS]; - fd = ptr[BCHNS*2]; - } - else { - fa = ptr[-BCHNS]; - fc = oint < maxo?ptr[BCHNS]:ptr[(1-plen)*BCHNS]; - fd = ptr[(2-plen)*BCHNS]; - } - } - else { - // first sample is outside in any case - fa = bdt[smin*BCHNS]; - - if(oint+2 < smin) - // if last is outside, all are outside - fb = fc = fd = fa; - else { - fd = ptr[BCHNS*2]; - if(oint+1 < smin) - fb = fc = fa; - else { - fc = ptr[BCHNS]; - fb = oint < smin?fa:ptr[0]; - } - } - } - } - - const float f1 = frac*0.5f-0.5f; - const float f3 = frac*3.0f-1.0f; - - const float amdf = (fa-fd)*frac; - const float cmb = fc-fb; - const float bma = fb-fa; - sig0[i] = fb + frac*( cmb - f1 * ( amdf+bma+cmb*f3 ) ); - } - } - else { - for(int i = 0,si = 0; i < n; ++i,++si) { - float o = *(pos++); - register long oint = CASTINT<long>(o); - const float frac = o-oint; - register const t_sample *ptr = bdt+oint*BCHNS; - register const t_sample *fa,*fb,*fc,*fd; - - if(LIKELY(oint > smin)) - if(LIKELY(oint < maxo-2)) { - // normal case - fb = ptr; - fa = fb-BCHNS; - fc = fb+BCHNS; - fd = fc+BCHNS; - } - else { - // not enough space at the end - - if(looped) { - // normalize position - oint = smin+(oint-smin)%plen; - goto looped2; - } - else { - // last sample is outside in any case - fd = bdt+maxo*BCHNS; - - if(oint-1 >= maxo) - // if first is outside, all are outside - fa = fb = fc = fd; - else { - fa = ptr-BCHNS; - if(oint >= maxo) - fb = fc = fd; - else { - fb = ptr; - fc = oint+1 < maxo?ptr+BCHNS:fd; - } - } - } - } - else { - // not enough space at the beginning - - if(looped) { - // normalize position - oint = smax-(smin-oint)%plen; -looped2: - // inside in any case - fb = bdt+oint*BCHNS; - - if(oint < maxo-1) { - fa = oint > smin?fb-BCHNS:bdt+maxo*BCHNS; - fc = fb+BCHNS; - fd = fc+BCHNS; - } - else { - fa = fb-BCHNS; - fc = oint < maxo?fb+BCHNS:bdt+(oint-plen+1)*BCHNS; - fd = bdt+(oint-plen+2)*BCHNS; - } - } - else { - // first sample is outside in any case - fa = bdt+smin*BCHNS; - - if(oint+2 < smin) - // if last is outside, all are outside - fb = fc = fd = fa; - else { - fd = ptr+BCHNS*2; - if(oint+1 < smin) - fb = fc = fa; - else { - fc = ptr+BCHNS; - fb = oint < smin?fa:ptr; - } - } - } - } - - const float f1 = 0.5f*(frac-1.0f); - const float f3 = frac*3.0f-1.0f; - - for(int ci = 0; ci < OCHNS; ++ci) { - const float amdf = (fa[ci]-fd[ci])*frac; - const float cmb = fc[ci]-fb[ci]; - const float bma = fb[ci]-fa[ci]; - sig[ci][si] = fb[ci] + frac*( cmb - f1 * ( amdf+bma+cmb*f3 ) ); - } - } - - // clear rest of output channels (if buffer has less channels) - for(int ci = OCHNS; ci < outchns; ++ci) ZeroSamples(sig[ci],n); - } -} - - -TMPLDEF inline void xinter::s_play0(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - st_play0 TMPLCALL (buf.Data(),curmin,curmax,n,buf.Channels(),outchns,invecs,outvecs,loopmode == xsl_loop); -} - -TMPLDEF inline void xinter::s_play1(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - st_play1 TMPLCALL (buf.Data(),curmin,curmax,n,buf.Channels(),outchns,invecs,outvecs,loopmode == xsl_loop); -} - -TMPLDEF inline void xinter::s_play2(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - st_play2 TMPLCALL (buf.Data(),curmin,curmax,n,buf.Channels(),outchns,invecs,outvecs,loopmode == xsl_loop); -} - -TMPLDEF inline void xinter::s_play4(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - st_play4 TMPLCALL (buf.Data(),curmin,curmax,n,buf.Channels(),outchns,invecs,outvecs,loopmode == xsl_loop); -} - -#endif diff --git a/externals/grill/xsample/source/main.cpp b/externals/grill/xsample/source/main.cpp deleted file mode 100644 index 025352a3..00000000 --- a/externals/grill/xsample/source/main.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2007 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#include "main.h" - - -// Initialization function for xsample library -static void xsample_main() -{ - flext::post("-------------------------------"); - flext::post("xsample objects, version " XSAMPLE_VERSION); - flext::post(""); - flext::post(" xrecord~, xplay~, xgroove~ "); - flext::post(" (C)2001-2007 Thomas Grill "); -#ifdef FLEXT_DEBUG - flext::post(""); - flext::post("DEBUG BUILD - " __DATE__ " " __TIME__); -#endif - flext::post("-------------------------------"); - - // call the objects' setup routines - FLEXT_DSP_SETUP(xrecord); - FLEXT_DSP_SETUP(xplay); - FLEXT_DSP_SETUP(xgroove); -} - -// setup the library -FLEXT_LIB_SETUP(xsample,xsample_main) - -// ------------------------------ - -void xsample::setup(t_classid c) -{ - FLEXT_CADDMETHOD_(c,0,"help",m_help); - FLEXT_CADDMETHOD_(c,0,"set",m_set); - FLEXT_CADDMETHOD_(c,0,"print",m_print); - FLEXT_CADDMETHOD_(c,0,"refresh",m_refresh); - FLEXT_CADDMETHOD_(c,0,"reset",m_reset); - - FLEXT_CADDATTR_VAR(c,"buffer",mg_buffer,ms_buffer); - FLEXT_CADDATTR_VAR_E(c,"units",unitmode,m_units); - FLEXT_CADDATTR_VAR_E(c,"sclmode",sclmode,m_sclmode); - FLEXT_CADDATTR_GET(c,"scale",s2u); -} - -xsample::xsample(): - update(xsc_all),wrap(false), -#if FLEXT_SYS == FLEXT_SYS_MAX - unitmode(xsu_ms), // Max/MSP defaults to milliseconds -#else - unitmode(xsu_sample), // PD defaults to samples -#endif - sclmode(xss_unitsinbuf), - curmin(0),curmax(1L<<(sizeof(curmax)*8-2)) -{} - -xsample::~xsample() {} - -bool xsample::Finalize() -{ - if(!flext_dsp::Finalize()) return false; - - // flags have been set in constructor - Refresh(); - return true; -} - -int xsample::ChkBuffer(bool refresh) -{ - if(!buf.Ok()) return 0; - - if(UNLIKELY(buf.Update())) { -#ifdef FLEXT_DEBUG - post("%s - buffer update!",thisName()); -#endif - Update(xsc_buffer); - if(refresh) { - Refresh(); - return buf.Ok() && buf.Valid()?1:0; - } - else - return buf.Valid()?1:0; - } - else - return buf.Valid()?-1:0; -} - -/* called after all buffer objects have been created in the patch */ -void xsample::CbLoadbang() -{ - ChkBuffer(true); -} - -void xsample::m_set(int argc,const t_atom *argv) -{ - const t_symbol *sym = argc >= 1?GetASymbol(argv[0]):NULL; - int r = buf.Set(sym); - if(LIKELY(sym) && UNLIKELY(r < 0)) - post("%s - can't find buffer %s",thisName(),GetString(sym)); - Update(xsc_buffer,true); -} - -void xsample::m_min(float mn) -{ - int ret = ChkBuffer(true); - - if(LIKELY(ret) && LIKELY(s2u)) { - long cmn = CASTINT<long>(mn/s2u+0.5f); // conversion to samples - - if(UNLIKELY(cmn < 0)) - curmin = 0; - else if(UNLIKELY(cmn > curmax)) - curmin = curmax; - else - curmin = cmn; - - Update(xsc_range,true); - } -} - -void xsample::m_max(float mx) -{ - int ret = ChkBuffer(true); - - if(LIKELY(ret) && LIKELY(s2u)) { - long cmx = CASTINT<long>(mx/s2u+0.5f); // conversion to samples - - if(UNLIKELY(cmx > buf.Frames())) - curmax = buf.Frames(); - else if(UNLIKELY(cmx < curmin)) - curmax = curmin; - else - curmax = cmx; - - Update(xsc_range,true); - } -} - -bool xsample::CbDsp() -{ - // this is hopefully called at change of sample rate ?! - -#ifdef FLEXT_DEBUG - post("%s - DSP reset!",thisName()); -#endif - - // for PD at least this is also called if a table has been deleted... - // then we must reset the buffer - - Update(xsc_srate|xsc_buffer,true); - return true; -} - -void xsample::DoReset() -{ - ResetRange(); -} - -void xsample::DoUpdate(unsigned int flags) -{ - if(flags&xsc_buffer) - buf.Set(); - - if(flags&xsc_range && buf.Ok()) { - const int f = buf.Frames(); - - if(!wrap) { - // normalize bounds - if(curmin < 0) curmin = 0; - else if(curmin > f) curmin = f; - - if(curmax > f) curmax = f; - else if(curmax < curmin) curmax = curmin; - } - else - // don't normalize - if(curmax < curmin) curmax = curmin; - } - - if(flags&xsc_units) { - switch(unitmode) { - case xsu_sample: // samples - s2u = 1; - break; - case xsu_buffer: // buffer size - s2u = buf.Ok() && buf.Frames()?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()); - } - - switch(sclmode) { - case xss_unitsinbuf: // samples/units - sclmin = 0; sclmul = s2u; - break; - case xss_unitsinloop: // samples/units from recmin to recmax - sclmin = curmin; sclmul = s2u; - break; - case xss_buffer: // unity between 0 and buffer size - sclmin = 0; sclmul = buf.Ok() && buf.Frames()?1.f/buf.Frames():0; - break; - case xss_loop: // unity between recmin and recmax - sclmin = curmin; sclmul = curmin < curmax?1.f/(curmax-curmin):0; - break; - default: - post("%s - Unknown scale mode",thisName()); - } - } -} diff --git a/externals/grill/xsample/source/main.h b/externals/grill/xsample/source/main.h deleted file mode 100644 index 8cf39d7d..00000000 --- a/externals/grill/xsample/source/main.h +++ /dev/null @@ -1,464 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2006 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#ifndef __XSAMPLE_H -#define __XSAMPLE_H - -#include "prefix.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) -#error You need at least flext version 0.5.0 -#endif - -#define XSAMPLE_VERSION "0.3.2pre" - -extern "C++" { - -// most compilers are somehow broken - in other words - can't handle all C++ features - -#if defined(_MSC_VER) -// MS VC 6.0 can't handle <int,int> templates?! -> no optimization -// MS VC .NET 2002 just dies with template optimization switched on - #if _MSC_VER >= 1310 - #define TMPLOPT - #endif -#elif defined(__BORLANDC__) -// handles all optimizations - #define TMPLOPT -#elif defined(__GNUC__) -// GNUC 2.95.2 dies at compile with <int,int> templates -#if __GNUC__ >= 3 - #define TMPLOPT // only workable with gcc >= 3.0 -#endif -#elif defined(__MWERKS__) -// CodeWarrior <= 8 can't take address of a template member function - #ifndef FLEXT_DEBUG - #define TMPLOPT - #endif -// #define SIGSTATIC // define that for CW6 -#elif defined(__MRC__) -// Apple MPW - MrCpp -// #define TMPLOPT // template optimation for more speed -#else -// another compiler -// #define TMPLOPT // template optimation for more speed (about 10%) - //#define SIGSTATIC // another redirection to avoid addresses of class member functions -#endif - - -#if defined(__MWERKS__) && !defined(__MACH__) - #define STD std -#else - #define STD -#endif - - -#ifdef __ALTIVEC__ -#if FLEXT_CPU == FLEXT_CPU_PPC && defined(__MWERKS__) - #pragma altivec_model on - #include <vBasicOps.h> - #include <vectorOps.h> -#elif FLEXT_CPU == FLEXT_CPU_PPC && defined(__GNUG__) - #include <vecLib/vBasicOps.h> - #include <vecLib/vectorOps.h> -#endif - // this is for the UInt32 prototype (thanks to Jamie) - // \TODO we'd rather not use Carbon but some other framework - #ifdef __MACH__ - #include <Carbon/Carbon.h> - #endif - - // Initialize a prefetch constant for use with vec_dst(), vec_dstt(), vec_dstst or vec_dststt - // Taken from the "AltiVec tutorial" by Ian Ollmann, Ph.D. - inline UInt32 GetPrefetchConstant( int blockSizeInVectors,int blockCount,int blockStride ) - { -// FLEXT_ASSERT( blockSizeInVectors > 0 && blockSizeInVectors <= 32 ); -// FLEXT_ASSERT( blockCount > 0 && blockCount <= 256 ); -// FLEXT_ASSERT( blockStride > MIN_SHRT && blockStride <= MAX_SHRT ); - return ((blockSizeInVectors << 24) & 0x1F000000) | - ((blockCount << 16) && 0x00FF0000) | - (blockStride & 0xFFFF); - } -#endif - -#if 0 // FLEXT_CPU == FLEXT_CPU_PPC && defined(__GNUC__) -#include <ppc_intrinsics.h> -template<typename I,typename F> -inline I CASTINT( F f ) -{ - int i; - __stfiwx(__fctiwz(f),0,&i); - return i; -} -#elif FLEXT_CPU == FLEXT_CPU_INTEL && defined(_MSC_VER) -template<typename I,typename F> -inline I CASTINT(F x) { -// by Laurent de Soras (http://ldesoras.free.fr) -// assert (x > static_cast <double> (INT_MIN / 2) + 1.0); -// assert (x < static_cast <double> (INT_MAX / 2) + 1.0); - const float round_towards_m_i = -0.5f; - I i; - __asm - { - fld x - fadd st,st - fabs - fadd round_towards_m_i - fistp i - sar i, 1 - } - if(x < 0) i = -i; - return i; -} -#else -template<typename I,typename F> inline I CASTINT(F o) { return static_cast<I>(o); } -#endif - - -class xsample: - public flext_dsp -{ - FLEXT_HEADER_S(xsample,flext_dsp,setup) - -public: - xsample(); - ~xsample(); - - enum xs_change { - xsc__ = 0, - xsc_units = 0x0001, - xsc_play = 0x0002, - xsc_pos = 0x0008, - xsc_range = 0x0010, - xsc_transport = 0x0020, - xsc_fade = 0x0040, - - xsc_intp = xsc_play, - xsc_srate = xsc_play|xsc_units, - xsc_chns = xsc_play, - xsc_loop = xsc_play, - xsc_startstop = xsc_play|xsc_transport, - xsc_buffer = xsc_units|xsc_pos|xsc_range|xsc_play, - xsc_reset = xsc_buffer, - xsc_all = 0xffff - }; - - enum xs_unit { - xsu_sample = 0,xsu_buffer,xsu_ms,xsu_s - }; - - enum xs_intp { - xsi_none = 0,xsi_4p,xsi_lin - }; - - enum xs_sclmd { - xss_unitsinbuf = 0,xss_unitsinloop,xss_buffer,xss_loop - }; - -protected: - virtual bool Finalize(); - - buffer buf; - - void m_reset() - { - ChkBuffer(true); - DoReset(); - Refresh(); - } - - void m_set(int argc,const t_atom *argv); - - void m_refresh() - { - Update(xsc_buffer,true); - } - - void m_units(xs_unit mode) - { - unitmode = mode; - Update(xsc_units,true); - } - - void m_sclmode(xs_sclmd mode) - { - sclmode = mode; - Update(xsc_units,true); - } - - void m_all() - { - ChkBuffer(true); - ResetRange(); - Refresh(); - } - - void m_wrap(bool w) - { - wrap = w; - Update(xsc_pos|xsc_range,true); - } - - void m_min(float mn); - void m_max(float mx); - - xs_unit unitmode; - xs_sclmd sclmode; - - long curmin,curmax; //,curlen; // in samples - long sclmin; // in samples - float sclmul; - float s2u; // sample to unit conversion factor - bool wrap; - - inline float scale(float smp) const { return (smp-sclmin)*sclmul; } - - static void arrscale(int n,const t_sample *in,t_sample *out,t_sample add,t_sample mul) { flext::ScaleSamples(out,in,mul,add,n); } - inline void arrscale(int n,const t_sample *in,t_sample *out) const { arrscale(n,in,out,-sclmin*sclmul,sclmul); } - - static void arrmul(int n,const t_sample *in,t_sample *out,t_sample mul) { flext::MulSamples(out,in,mul,n); } - inline void arrmul(int n,const t_sample *in,t_sample *out) const { arrmul(n,in,out,(t_sample)(1.f/s2u)); } - - void mg_buffer(AtomList &l) { if(buf.Symbol()) { l(1); SetSymbol(l[0],buf.Symbol()); } } - inline void ms_buffer(const AtomList &l) { m_set(l.Count(),l.Atoms()); } - - inline void mg_min(float &v) const { v = curmin*s2u; } - inline void mg_max(float &v) const { v = curmax*s2u; } - - void Refresh() { if(update && !Initing()) { DoUpdate(update); update = xsc__; } } - void Update(unsigned int f,bool refr = false) { update |= f; if(refr) Refresh(); } - - //! return 0...invalid, 1...changed, -1...unchanged - int ChkBuffer(bool refr = false); - - typedef flext::buffer::lock_t lock_t; - - //! Lock buffer (buffer must be checked ok) - lock_t Lock() { return buf.Lock(); } - //! Unlock buffer (buffer must be checked ok) - void Unlock(lock_t l) { buf.Unlock(l); } - - void ResetRange() - { - curmin = 0; - curmax = buf.Frames(); - Update(xsc_range); - } - - virtual void DoReset(); - virtual void DoUpdate(unsigned int flags); - - virtual void CbLoadbang(); - virtual bool CbDsp(); - - virtual void m_help() = 0; - virtual void m_print() = 0; - -private: - - unsigned int update; - - static void setup(t_classid c); - - FLEXT_CALLBACK(m_help) - FLEXT_CALLBACK_V(m_set) - FLEXT_CALLBACK(m_print) - FLEXT_CALLBACK(m_refresh) - FLEXT_CALLBACK(m_reset) - - FLEXT_CALLVAR_V(mg_buffer,ms_buffer) - - FLEXT_CALLSET_E(m_units,xs_unit) - FLEXT_ATTRGET_E(unitmode,xs_unit) - FLEXT_CALLSET_E(m_sclmode,xs_sclmd) - FLEXT_ATTRGET_E(sclmode,xs_sclmd) - - FLEXT_ATTRGET_F(s2u) - - FLEXT_CALLSET_B(m_wrap) - FLEXT_ATTRGET_B(wrap) - -protected: - FLEXT_CALLGET_F(mg_min) - FLEXT_CALLGET_F(mg_max) -}; - - -// defines which are used in the derived classes -#ifdef SIGSTATIC - #ifdef TMPLOPT - #define TMPLFUN(FUN,BCHNS,IOCHNS) &thisType::st_##FUN<BCHNS,IOCHNS> - #define TMPLSTF(FUN,BCHNS,IOCHNS) &thisType::FUN<BCHNS,IOCHNS> - #define SIGFUN(FUN) &thisType::st_##FUN - #define TMPLDEF template <int _BCHNS_,int _IOCHNS_> - #define TMPLCALL <_BCHNS_,_IOCHNS_> - #else - #define TMPLFUN(FUN,BCHNS,IOCHNS) &thisType::st_##FUN - #define TMPLSTF(FUN,BCHNS,IOCHNS) &thisType::FUN - #define SIGFUN(FUN) &thisType::st_##FUN - #define TMPLDEF - #define TMPLCALL - #endif - - #define DEFSIGFUN(NAME) \ - static void st_##NAME(thisType *obj,int n,t_sample *const *in,t_sample *const *out) { obj->NAME (n,in,out); } \ - void NAME(int n,t_sample *const *in,t_sample *const *out) - - #define TMPLSIGFUN(NAME) \ - TMPLDEF static void st_##NAME(thisType *obj,int n,t_sample *const *in,t_sample *const *out) { obj->NAME TMPLCALL (n,in,out); } \ - TMPLDEF void NAME(int n,t_sample *const *in,t_sample *const *out) - - #define TMPLSTFUN(NAME) TMPLDEF static void NAME(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs) - - #define SETSIGFUN(VAR,FUN) v_##VAR = FUN - - #define SETSTFUN(VAR,FUN) VAR = FUN - - #define DEFSIGCALL(NAME) \ - inline void NAME(int n,t_sample *const *in,t_sample *const *out) { (*v_##NAME)(this,n,in,out); } \ - void (*v_##NAME)(thisType *obj,int n,t_sample *const *in,t_sample *const *out) - - #define DEFSTCALL(NAME) \ - void (*NAME)(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs) - -#else - #ifdef TMPLOPT - #define TMPLFUN(FUN,BCHNS,IOCHNS) &thisType::FUN<BCHNS,IOCHNS> - #define SIGFUN(FUN) &thisType::FUN - #define TMPLDEF template <int _BCHNS_,int _IOCHNS_> - #define TMPLCALL <_BCHNS_,_IOCHNS_> - #else - #define TMPLFUN(FUN,BCHNS,IOCHNS) &thisType::FUN - #define SIGFUN(FUN) &thisType::FUN - #define TMPLDEF - #define TMPLCALL - #endif - - #define TMPLSTF(FUN,BCHNS,IOCHNS) TMPLFUN(FUN,BCHNS,IOCHNS) - - #define DEFSIGFUN(NAME) void NAME(int n,t_sample *const *in,t_sample *const *out) - #define TMPLSIGFUN(NAME) TMPLDEF void NAME(int n,t_sample *const *in,t_sample *const *out) - #define TMPLSTFUN(NAME) TMPLDEF static void NAME(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) - - #define SETSIGFUN(VAR,FUN) v_##VAR = FUN - - #define DEFSIGCALL(NAME) \ - inline void NAME(int n,t_sample *const *in,t_sample *const *out) { (this->*v_##NAME)(n,in,out); } \ - void (thisType::*v_##NAME)(int n,t_sample *const *invecs,t_sample *const *outvecs) - - #define SETSTFUN(VAR,FUN) VAR = FUN - - #define DEFSTCALL(NAME) \ - void (*NAME)(const t_sample *bdt,const int smin,const int smax,const int n,const int inchns,const int outchns,t_sample *const *invecs,t_sample *const *outvecs,bool looped) -#endif - - - - - -#ifndef MIN -#define MIN(x,y) ((x) < (y)?(x):(y)) -#endif - -// in the signal functions -#ifdef TMPLOPT - // optimization by using constants for channel numbers - #define SIGCHNS(BCHNS,bchns,IOCHNS,iochns) \ - const int BCHNS = _BCHNS_ < 0?(bchns):_BCHNS_; \ - const int IOCHNS = _IOCHNS_ < 0?MIN(iochns,BCHNS):MIN(_IOCHNS_,BCHNS) -#else - // no template optimization - #if FLEXT_SYS == FLEXT_SYS_PD // only mono buffers - #define SIGCHNS(BCHNS,bchns,IOCHNS,iochns) \ - const int BCHNS = 1; \ - const int IOCHNS = MIN(iochns,BCHNS) - #else // MAXMSP - #define SIGCHNS(BCHNS,bchns,IOCHNS,iochns) \ - const int BCHNS = bchns; \ - const int IOCHNS = MIN(iochns,BCHNS) - #endif -#endif - - -class xinter: - public xsample -{ - FLEXT_HEADER_S(xinter,xsample,setup) - -public: - - enum xs_loop { - xsl_once = 0,xsl_loop,xsl_bidir - }; - - xinter() - : outchns(1),doplay(false) - , interp(xsi_4p),loopmode(xsl_loop) - {} - - void m_start() - { - ChkBuffer(); - doplay = true; - Update(xsc_startstop,true); - } - - void m_stop() - { - ChkBuffer(); - doplay = false; - Update(xsc_startstop,true); - } - - void m_interp(xs_intp mode) - { - interp = mode; - Update(xsc_intp,true); - } - -protected: - - int outchns; - bool doplay; - xs_intp interp; - xs_loop loopmode; - - TMPLSIGFUN(s_play0); - TMPLSIGFUN(s_play1); - TMPLSIGFUN(s_play2); - TMPLSIGFUN(s_play4); - - TMPLSTFUN(st_play0); - TMPLSTFUN(st_play1); - TMPLSTFUN(st_play2); - TMPLSTFUN(st_play4); - - DEFSIGCALL(playfun); - DEFSIGCALL(zerofun); - - virtual void DoUpdate(unsigned int flags); - - FLEXT_CALLBACK(m_start) - FLEXT_CALLBACK(m_stop) - - FLEXT_CALLSET_E(m_interp,xs_intp) - FLEXT_ATTRGET_E(interp,xs_intp) - - FLEXT_ATTRGET_E(loopmode,xs_loop) - -private: - static void setup(t_classid c); -}; - -#ifdef TMPLOPT -#include "inter.h" -#endif - -} - -#endif diff --git a/externals/grill/xsample/source/play.cpp b/externals/grill/xsample/source/play.cpp deleted file mode 100644 index 0f6fec5e..00000000 --- a/externals/grill/xsample/source/play.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2007 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#include "main.h" -#include <stdio.h> - -#ifdef _MSC_VER -#pragma warning (disable:4244) -#endif - - -class xplay: - public xinter -{ - FLEXT_HEADER_S(xplay,xinter,setup) - -public: - xplay(int argc,const t_atom *argv); - - void m_loop(xs_loop lp) - { - loopmode = lp; - Update(xsc_loop,true); - } - -protected: - - virtual void CbSignal(); - - virtual void m_help(); - virtual void m_print(); - -private: - static void setup(t_classid c); - - FLEXT_CALLSET_E(m_loop,xs_loop) -}; - -FLEXT_LIB_DSP_V("xplay~",xplay) - -void xplay::setup(t_classid c) -{ - DefineHelp(c,"xplay~"); - - FLEXT_CADDATTR_VAR_E(c,"loop",loopmode,m_loop); -} - -xplay::xplay(int argc,const t_atom *argv) -{ - // set the loopmode to non-wrapping (for sample interpolation) - loopmode = xsl_once; - - int argi = 0; -#if FLEXT_SYS == FLEXT_SYS_MAX - if(argc > argi && CanbeInt(argv[argi])) { - outchns = GetAInt(argv[argi]); - argi++; - } -#endif - - if(argc > argi && IsSymbol(argv[argi])) { - buf.Set(GetSymbol(argv[argi]),true); - argi++; - -#if FLEXT_SYS == FLEXT_SYS_MAX - // oldstyle command line? - if(argi == 1 && argc == 2 && CanbeInt(argv[argi])) { - outchns = GetAInt(argv[argi]); - argi++; - post("%s: old style command line detected - please change to '%s [channels] [buffer]'",thisName(),thisName()); - } -#endif - } - - AddInSignal("Messages and Signal of playing position"); // pos signal - for(int ci = 0; ci < outchns; ++ci) { - char tmp[30]; - STD::sprintf(tmp,"Audio signal channel %i",ci+1); - AddOutSignal(tmp); - } -} - -void xplay::CbSignal() -{ - int ret = ChkBuffer(true); - int n = Blocksize(); - const t_sample *const *in = InSig(); - t_sample *const *out = OutSig(); - - // check whether buffer is invalid or changed - if(ret) { - const lock_t l = Lock(); - - // convert position units to frames - arrmul(n,in[0],out[0]); - // call resample routine - playfun(n,out,out); - - Unlock(l); - - Refresh(); - } - else - zerofun(n,out,out); -} - - - -void xplay::m_help() -{ - post("%s - part of xsample objects, version " XSAMPLE_VERSION,thisName()); -#ifdef FLEXT_DEBUG - post("compiled on " __DATE__ " " __TIME__); -#endif - post("(C) Thomas Grill, 2001-2007"); -#if FLEXT_SYS == FLEXT_SYS_MAX - post("Arguments: %s [channels=1] [buffer]",thisName()); -#else - post("Arguments: %s [buffer]",thisName()); -#endif - post("Inlets: 1:Messages/Position signal"); - post("Outlets: 1:Audio signal"); - post("Methods:"); - post("\thelp: shows this help"); - post("\tset name: set buffer"); - post("\tenable 0/1: turn dsp calculation off/on"); - post("\tprint: print current settings"); - post("\tbang/start: begin playing"); - post("\tstop: stop playing"); - post("\treset: checks buffer"); - post("\trefresh: checks buffer and refreshes outlets"); - post("\t@units 0/1/2/3: set units to samples/buffer size/ms/s"); - post("\t@interp 0/1/2: set interpolation to off/4-point/linear"); - post("\t@loop 0/1/2: sets looping (interpolation) to off/forward/bidirectional"); - post(""); -} - -void xplay::m_print() -{ - const char *interp_txt[] = {"off","4-point","linear"}; - // print all current settings - post("%s - current settings:",thisName()); - post("bufname = '%s', length = %.3f, channels = %i",buf.Name(),(float)(buf.Frames()*s2u),buf.Channels()); - post("out channels = %i, samples/unit = %.3f, interpolation = %s",outchns,(float)(1./s2u),interp_txt[interp >= xsi_none && interp <= xsi_lin?interp:xsi_none]); - post(""); -} diff --git a/externals/grill/xsample/source/prefix.h b/externals/grill/xsample/source/prefix.h deleted file mode 100644 index 415f07c3..00000000 --- a/externals/grill/xsample/source/prefix.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. - -*/ - -#define FLEXT_ATTRIBUTES 1 - -#include <flext.h> - -#include <math.h> diff --git a/externals/grill/xsample/source/record.cpp b/externals/grill/xsample/source/record.cpp deleted file mode 100644 index 07c94b45..00000000 --- a/externals/grill/xsample/source/record.cpp +++ /dev/null @@ -1,497 +0,0 @@ -/* -xsample - extended sample objects for Max/MSP and pd (pure data) - -Copyright (c) 2001-2007 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. -*/ - -#include "main.h" -#include <stdio.h> - -#ifdef _MSC_VER -#pragma warning (disable:4244) -#endif - -extern "C++" { - -class xrecord: - public xsample -{ - FLEXT_HEADER_S(xrecord,xsample,setup) - -public: - xrecord(int argc,const t_atom *argv); - - void m_pos(float pos) - { - curpos = LIKELY(pos)?CASTINT<long>(pos/s2u+.5):0; - Update(xsc_pos); - Refresh(); - } - - inline void mg_pos(float &v) const { v = curpos*s2u; } - - void m_start(); - void m_stop(); - - inline void m_append(bool app) - { - appmode = app; - Update(xsc_play); - if(!appmode) m_pos(0); - } - - void m_draw(int argc,const t_atom *argv); - -protected: - int inchns; - bool sigmode,appmode; - float drintv; - - bool dorec,doloop; - int mixmode; - long curpos; // in samples - - virtual void DoReset(); - virtual void DoUpdate(unsigned int flags); - - virtual void CbSignal(); - - virtual void m_help(); - virtual void m_print(); - -private: - static void setup(t_classid c); - - TMPLSIGFUN(s_rec); - - DEFSIGCALL(recfun); - - FLEXT_CALLBACK(m_start) - FLEXT_CALLBACK(m_stop) - - FLEXT_CALLVAR_F(mg_pos,m_pos) - FLEXT_CALLBACK(m_all) - FLEXT_CALLSET_F(m_min) - FLEXT_CALLSET_F(m_max) - FLEXT_CALLBACK_F(m_min) - FLEXT_CALLBACK_F(m_max) - - FLEXT_ATTRVAR_B(doloop) - FLEXT_ATTRVAR_I(mixmode) - FLEXT_ATTRVAR_B(sigmode) - FLEXT_CALLSET_B(m_append) - FLEXT_ATTRGET_B(appmode) - - FLEXT_CALLBACK_V(m_draw) -}; - -} - - -FLEXT_LIB_DSP_V("xrecord~",xrecord) - - -void xrecord::setup(t_classid c) -{ - DefineHelp(c,"xrecord~"); - - FLEXT_CADDBANG(c,0,m_start); - FLEXT_CADDMETHOD_(c,0,"start",m_start); - FLEXT_CADDMETHOD_(c,0,"stop",m_stop); - - FLEXT_CADDATTR_VAR(c,"pos",mg_pos,m_pos); - FLEXT_CADDATTR_VAR(c,"min",mg_min,m_min); - FLEXT_CADDATTR_VAR(c,"max",mg_max,m_max); - FLEXT_CADDMETHOD_(c,0,"all",m_all); - - FLEXT_CADDMETHOD_(c,0,"draw",m_draw); - - FLEXT_CADDATTR_VAR1(c,"loop",doloop); - FLEXT_CADDATTR_VAR1(c,"mixmode",mixmode); - FLEXT_CADDATTR_VAR1(c,"sigmode",sigmode); - FLEXT_CADDATTR_VAR(c,"append",appmode,m_append); -} - -xrecord::xrecord(int argc,const t_atom *argv): - inchns(1), - sigmode(false),appmode(true), - drintv(0), - dorec(false),doloop(false), - mixmode(0) -{ - int argi = 0; -#if FLEXT_SYS == FLEXT_SYS_MAX - if(argc > argi && CanbeInt(argv[argi])) { - inchns = GetAInt(argv[argi]); - argi++; - } -#endif - - if(argc > argi && IsSymbol(argv[argi])) { - buf.Set(GetSymbol(argv[argi]),true); - argi++; - -#if FLEXT_SYS == FLEXT_SYS_MAX - // oldstyle command line? - if(argi == 1 && argc == 2 && CanbeInt(argv[argi])) { - inchns = GetAInt(argv[argi]); - argi++; - post("%s: old style command line detected - please change to '%s [channels] [buffer]'",thisName(),thisName()); - } -#endif - } - - for(int ci = 0; ci < inchns; ++ci) { - char tmp[40]; - STD::sprintf(tmp,ci == 0?"Messages/audio channel %i":"Audio channel %i",ci+1); - AddInSignal(tmp); // audio signals - } - AddInSignal("On/Off/Fade/Mix signal (0..1)"); // on/off signal - AddInFloat("Starting point of recording"); // min - AddInFloat("Ending point of recording"); // max - AddOutSignal("Current position of recording"); // pos signal - AddOutFloat("Starting point (rounded to frame)"); // min - AddOutFloat("Ending point (rounded to frame)"); // max - AddOutBang("Bang on loop end/rollover"); // loop bang - - FLEXT_ADDMETHOD(inchns+1,m_min); - FLEXT_ADDMETHOD(inchns+2,m_max); -} - -void xrecord::m_start() -{ - ChkBuffer(); - - if(!sigmode && !appmode) { curpos = 0; Update(xsc_pos); } - - dorec = true; - Update(xsc_startstop); - Refresh(); -} - -void xrecord::m_stop() -{ - ChkBuffer(); - dorec = false; - Update(xsc_startstop); - Refresh(); -} - -void xrecord::DoReset() -{ - xsample::DoReset(); - curpos = 0; -} - -void xrecord::m_draw(int argc,const t_atom *argv) -{ - if(argc >= 1) { - drintv = GetAInt(argv[0]); - if(dorec) buf.SetRefrIntv(drintv); - } - else - buf.Dirty(true); -} - -TMPLDEF void xrecord::s_rec(int n,t_sample *const *invecs,t_sample *const *outvecs) -{ - SIGCHNS(BCHNS,buf.Channels(),ICHNS,inchns); - - const t_sample *const *sig = invecs; - register int si = 0; - const t_sample *on = invecs[inchns]; - t_sample *pos = outvecs[0]; - - bool lpbang = false; - register const float pf = sclmul; - register long o = curpos; - - if(o < curmin) o = curmin; - - if(dorec && LIKELY(curmax > curmin)) { - while(n) { - long ncur = curmax-o; // at max to buffer or recording end - - if(UNLIKELY(ncur <= 0)) { // end of buffer - if(doloop) { - ncur = curmax-(o = curmin); - } - else { - // loop expired; - dorec = false; - Update(xsc_startstop); - } - - lpbang = true; - } - - if(UNLIKELY(!dorec)) break; - - if(UNLIKELY(ncur > n)) ncur = n; - - register int i; - register t_sample *bf = buf.Data()+o*BCHNS; - register float p = scale(o); - - if(sigmode) { - if(appmode) { - // append to current position - - switch(mixmode) { - case 0: - for(i = 0; i < ncur; ++i,++si) { - if(!(*(on++) < 0)) { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] = sig[ci][si]; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else - *(pos++) = p; - } - break; - case 1: - for(i = 0; i < ncur; ++i,++si) { - register const t_sample g = *(on++); - if(!(g < 0)) { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] = bf[ci]*(1.-g)+sig[ci][si]*g; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else - *(pos++) = p; - } - break; - case 2: - for(i = 0; i < ncur; ++i,++si) { - if(!(*(on++) < 0)) { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] += sig[ci][si]; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else - *(pos++) = p; - } - break; - } - } - else { - // don't append - switch(mixmode) { - case 0: { - for(i = 0; i < ncur; ++i,++si) { - if(!(*(on++) < 0)) - { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] = sig[ci][si]; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else { - *(pos++) = p = scale(o = 0); - bf = buf.Data(); - } - } - break; - } - case 1: { - for(i = 0; i < ncur; ++i,++si) { - register const t_sample g = *(on++); - if(!(g < 0)) { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] = bf[ci]*(1.-g)+sig[ci][si]*g; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else { - *(pos++) = p = scale(o = 0); - bf = buf.Data(); - } - } - break; - } - case 2: { - for(i = 0; i < ncur; ++i,++si) { - if(!(*(on++) < 0)) - { - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] += sig[ci][si]; - bf += BCHNS; - *(pos++) = p,p += pf,++o; - } - else { - *(pos++) = p = scale(o = 0); - bf = buf.Data(); - } - } - break; - } - } - } - } - else { - // message mode - - // Altivec optimization for that! - switch(mixmode) { - case 0: { - for(int ci = 0; ci < ICHNS; ++ci) { - register t_sample *b = bf+ci; - register const float *s = sig[ci]+si; - for(i = 0; i < ncur; ++i,b += BCHNS,++s) - *b = *s; - } - si += ncur; - break; - } - case 1: { - for(i = 0; i < ncur; ++i,++si) { - register const t_sample w = *(on++); - for(int ci = 0; ci < ICHNS; ++ci) - bf[ci] = bf[ci]*(1.-w)+sig[ci][si]*w; - bf += BCHNS; - } - break; - } - case 2: { - for(int ci = 0; ci < ICHNS; ++ci) { - register t_sample *b = bf+ci; - register const float *s = sig[ci]+si; - for(i = 0; i < ncur; ++i,b += BCHNS,++s) - *b += *s; - } - si += ncur; - break; - } - } - - for(i = 0; i < ncur; ++i) { - *(pos++) = p,p += pf,++o; - } - } - - n -= ncur; - } - curpos = o; - - buf.Dirty(); - } - - if(n) { - register float p = scale(o); - while(n--) *(pos++) = p; - } - - if(lpbang) ToOutBang(3); -} - -void xrecord::CbSignal() -{ - int ret = ChkBuffer(true); - - if(ret) { - // call the appropriate dsp function - - const lock_t l = Lock(); - recfun(Blocksize(),InSig(),OutSig()); - Unlock(l); - - Refresh(); - } - else - // set position signal to zero - ZeroSamples(OutSig()[0],Blocksize()); -} - -void xrecord::DoUpdate(unsigned int flags) -{ - xsample::DoUpdate(flags); - - if(flags&(xsc_pos|xsc_range)) { - if(curpos < curmin) curpos = curmin; - else if(curpos > curmax) curpos = curmax; - } - - if(flags&xsc_range) { - ToOutFloat(1,curmin*s2u); - ToOutFloat(2,curmax*s2u); - } - - if(flags&xsc_transport && buf.Ok()) { - if(dorec) - buf.SetRefrIntv(drintv); - else { - buf.Dirty(true); - buf.SetRefrIntv(0); - } - } - - if(flags&xsc_play) { - switch(buf.Channels()*1000+inchns) { - case 1001: SETSIGFUN(recfun,TMPLFUN(s_rec,1,1)); break; - case 1002: SETSIGFUN(recfun,TMPLFUN(s_rec,1,2)); break; - case 2001: SETSIGFUN(recfun,TMPLFUN(s_rec,2,1)); break; - case 2002: SETSIGFUN(recfun,TMPLFUN(s_rec,2,2)); break; - case 4001: - case 4002: - case 4003: SETSIGFUN(recfun,TMPLFUN(s_rec,4,-1)); break; - case 4004: SETSIGFUN(recfun,TMPLFUN(s_rec,4,4)); break; - default: SETSIGFUN(recfun,TMPLFUN(s_rec,-1,-1)); break; - } - } -} - - -void xrecord::m_help() -{ - post("%s - part of xsample objects, version " XSAMPLE_VERSION,thisName()); -#ifdef FLEXT_DEBUG - post("compiled on " __DATE__ " " __TIME__); -#endif - post("(C) Thomas Grill, 2001-2007"); -#if FLEXT_SYS == FLEXT_SYS_MAX - post("Arguments: %s [channels=1] [buffer]",thisName()); -#else - post("Arguments: %s [buffer]",thisName()); -#endif - post("Inlets: 1:Messages/Audio signal, 2:Trigger signal, 3:Min point, 4: Max point"); - post("Outlets: 1:Position signal, 2:Min point, 3:Max point"); - post("Methods:"); - post("\thelp: shows this help"); - post("\tset [name]: set buffer or reinit"); - post("\tenable 0/1: turn dsp calculation off/on"); - post("\treset: reset min/max recording points and recording offset"); - post("\tprint: print current settings"); - post("\t@sigmode 0/1: specify message or signal triggered recording"); - post("\t@append 0/1: reset recording position or append to current position"); - post("\t@loop 0/1: switches looping off/on"); - post("\t@mixmode 0/1/2: specify how audio signal should be mixed in (none,mixed,added)"); - post("\tmin {unit}: set minimum recording point"); - post("\tmax {unit}: set maximum recording point"); - post("\tall: select entire buffer length"); - post("\tpos {unit}: set recording position (obeying the current scale mode)"); - post("\tbang/start: start recording"); - post("\tstop: stop recording"); - post("\trefresh: checks buffer and refreshes outlets"); - post("\t@units 0/1/2/3: set units to frames/buffer size/ms/s"); - post("\t@sclmode 0/1/2/3: set range of position to units/units in loop/buffer/loop"); - post("\tdraw [{float}]: redraw buffer immediately (arg omitted) or periodic (in ms)"); - post(""); -} - -void xrecord::m_print() -{ - static const char sclmode_txt[][20] = {"units","units in loop","buffer","loop"}; - - // print all current settings - post("%s - current settings:",thisName()); - post("bufname = '%s', length = %.3f, channels = %i",buf.Name(),(float)(buf.Frames()*s2u),buf.Channels()); - post("in channels = %i, frames/unit = %.3f, scale mode = %s",inchns,(float)(1./s2u),sclmode_txt[sclmode]); - post("sigmode = %s, append = %s, loop = %s, mixmode = %i",sigmode?"yes":"no",appmode?"yes":"no",doloop?"yes":"no",mixmode); - post(""); -} - diff --git a/externals/grill/xsample/source/xsample-Info.plist b/externals/grill/xsample/source/xsample-Info.plist deleted file mode 100644 index 3d1bc4c8..00000000 --- a/externals/grill/xsample/source/xsample-Info.plist +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDevelopmentRegion</key> - <string>English</string> - <key>CFBundleExecutable</key> - <string>xsample</string> - <key>CFBundleIdentifier</key> - <string>org.grrrr.xsample</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundlePackageType</key> - <string>iLaX</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>1.0</string> - <key>CSResourcesFileMapped</key> - <string>yes</string> -</dict> -</plist> diff --git a/externals/grill/xsample/source/xsample.rsrc b/externals/grill/xsample/source/xsample.rsrc deleted file mode 100755 index eb62e523..00000000 --- a/externals/grill/xsample/source/xsample.rsrc +++ /dev/null @@ -1,29 +0,0 @@ -(This file must be converted with BinHex 4.0) -:!!"bFh*M8P0&4!#3#!8hIF-!N!3"!!!!"-!!!!2!!!!!Gb"MEfjdB@PZC@3JE@9 -cFf&RC5"TEL"LD@jKFRNJ+Lm0$@KcE'PNCA+j,R*cFQ-#!!)!FR0bBe*6483"!2q -3"!)!FR0bBe*6483"!2q3"!#3%U((pmm!N!B%Z#TLAhC`D@il#3N[+L"`BA4MD'P -ZE'9d)'PZ)(4SDA-JF'&dBfKPFLGc)(CTFfpLDL!U,`d*#94&5'&ZC'aP)'*IG'9 -S1`Q3"#mU)(4PH(3JC@4TG'pb)'KKEQ4XC5!U,`d*I5"LAh9Z1`ep1`d0,bSJBQp -i)'CXB@Gc)#S[$3dMC!!!!1aJ#J!!E8&i6!a#!!"1qJ!`6R8LAb!I,S"R%L"!F!! -3%'!%%1J!!9()rrT#%%l4@8m[,`!)6VVrh#"I)!K1G8j@r[T)j`!`*Qi!#&P2,ca -Y3AK-2c`!!DJ1)&mN5#!+Cbi[#NKZr[T)E[lm5'lr!+QS5'lr!%kkrlK)E[m!3IS -!,NK3)'X!N!"1N!"2l`!-B!j"qJ!f5&!JD`#3!%k3!&K260m-!%jH6R@%E@&TEJ! -!3#9c1L"ZEh3JBACKD@aKBQaP)'C[FL!f1%X!G'KTFb"[BQTPBh3JDA-JEQpd)'& -fB@PXB@*XC5"QEh)J0MK,!*!&l'!+!!"Y3AK-$%)!!%lk!$"1G5*I)"mZJ'F5)%" -`!"!3B!33k!!"8FMrqN)36Y&C6bm[!!K1Z[rF)&mJ#%je6PEqqNMR!$!QEJ!)@8m -[2'e"H%`r2!!"U!iJAb4))!TR,Lm+5'lqqNKZr[a)E[m!UDK)E[m!6VVrZ%KZr`" -"qJ!Z5&!JD`#3!%k3!%r[!!aJ$N(k!$C)8#"V!*!!6T!!@%p-h``!6Pj1GB4YB@P -Z!!"!*A-k)'j[G#"KGQ&TE'&LE'8JCQpb)$Bi5`"dD'Pc)'pLDQ9MG#"TFb"ZEh3 -JBACKD@aKBQaP)'C[FL!f1%X!N!AXB!S!!'e"H%`-3J!!6[S!-%je)PmJ(bk!Ca) -J3(!!%""J""$S!!&4b2rk3K"1d9P2,bm!#%kkrp`JAb!)6R919[lk51F!-#CZ!!K -C6bmmE8&i6$mm!!'S$L"I*%JJ#QFZ,`T)E[lk5'lqr%KZr`#TU%KZr`"1Z[qi5'l -r!%(k!#j)8#"V!*!!6T!!6qm!$'!13IS!0NK3)'X!N!"1N!"B6dcI$!"1ANjeK'e -KD@i!!%!PFcSJEQpd)'&fB@PXB@*XC5"QEh)J0MK,!(4SDA-JEf*UC@0d)'Pc)'j -[G#"KGQ&TE'&LE'8JCQpb)$Bi5`#3"HaJ#J!!E8&i6!a#!!"1qJ!`6R8LAb!I,S" -R%L"!F!!3%'!%%1J!!9()rrT#%%l4@8m[,`!)6VVrh#"I)!K1G8j@r[T)j`!`*Qi -!#&P2,caY3AK-2c`!!DJ1)&mN5#!+Cbi[#NKZr[T)E[lm5'lr!+QS5'lr!%kkrlK -)E[m!3IS!,NK3)'X!N!"1N!"2l`!-B!j"qJ!f5&!JD`#3!%k3!&K260m-!%jH6R@ -%E@&TEJ!!3#9c1L"ZEh3JBACKD@aKBQaP)'C[FL!f1%X!G'KTFb"[BQTPBh3JDA- -JEQpd)'&fB@PXB@*XC5"QEh)J0MK,!*!%!3!!!!6!!!!$`!!!!(F9906%"6i!!!! -F!&B!!'e"H%`!!`!+(d!!N!B9901`(d%!#!!!!2!9901X(d)!%3!!!H!9901S(d- -!'!!!!Y!9901N"hKcB@e`E'8)H'GbEfpfCAi'H("XBAPq#(KbC@0[FQ4qq+N: |