From 0e1fe750cfd8467a80530cbc70326c81f41a8fe5 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 31 Dec 2002 04:31:58 +0000 Subject: "" svn path=/trunk/; revision=314 --- externals/grill/flext/source/flstk.cpp | 122 +++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 externals/grill/flext/source/flstk.cpp (limited to 'externals/grill/flext/source/flstk.cpp') diff --git a/externals/grill/flext/source/flstk.cpp b/externals/grill/flext/source/flstk.cpp new file mode 100644 index 00000000..85d52751 --- /dev/null +++ b/externals/grill/flext/source/flstk.cpp @@ -0,0 +1,122 @@ +/* + +Copyright (c) 2002 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. + +*/ + +#include "flext.h" +#include "flstk.h" + +flext_stk::flext_stk(): + inobjs(0),outobjs(0), + inobj(NULL),outobj(NULL), + smprt(0),blsz(0) +{} + +bool flext_stk::Init() +{ + bool ret = flext_dsp::Init(); + inobjs = CntInSig(); + outobjs = CntOutSig(); + return ret; +} + +void flext_stk::Exit() +{ + ClearObjs(); + flext_dsp::Exit(); +} + +void flext_stk::ClearObjs() +{ + FreeObjs(); + + if(inobj) { + for(int i = 0; i < inobjs; ++i) delete inobj[i]; + delete[] inobj; inobj = NULL; inobjs = 0; + } + if(outobj) { + for(int i = 0; i < outobjs; ++i) delete outobj[i]; + delete[] outobj; outobj = NULL; outobjs = 0; + } +} + +void flext_stk::m_dsp(int n,t_sample *const *in,t_sample *const *out) +{ + // called on every rebuild of the dsp chain + + int i; + + if(Blocksize() != blsz || Samplerate() != smprt) { + // block size or sample rate has changed... rebuild all objects + + ClearObjs(); + + smprt = Samplerate(); + blsz = Blocksize(); + Stk::setSampleRate(smprt); + + // set up sndobjs for inlets and outlets + inobj = new Inlet *[inobjs]; + for(i = 0; i < inobjs; ++i) { + inobj[i] = new Inlet(in[i],blsz); + } + outobj = new Outlet *[outobjs]; + for(i = 0; i < outobjs; ++i) outobj[i] = new Outlet(out[i],blsz); + + NewObjs(); + } + else { + // assign changed input/output vectors + + for(i = 0; i < inobjs; ++i) inobj[i]->SetBuf(in[i]); + for(i = 0; i < outobjs; ++i) outobj[i]->SetBuf(out[i]); + } +} + +void flext_stk::m_signal(int n,t_sample *const *in,t_sample *const *out) +{ + ProcessObjs(); +} + + +// inlet class + +flext_stk::Inlet::Inlet(const t_sample *b,int v): + buf(b),vecsz(v), + index(0) +{} + +t_sample flext_stk::Inlet::tick() +{ + if(++index >= vecsz) index = 0; + return lastOut(); +} + +t_sample *flext_stk::Inlet::tick(t_sample *vector,unsigned int vectorSize) +{ + for(unsigned int i = 0; i < vectorSize; i++) vector[i] = tick(); + return vector; +} + + +// outlet class + +flext_stk::Outlet::Outlet(t_sample *b,int v): + buf(b),vecsz(v), + index(0) +{} + +void flext_stk::Outlet::tick(t_sample s) +{ + buf[index] = s; + if(++index >= vecsz) index = 0; +} + +void flext_stk::Outlet::tick(const t_sample *vector,unsigned int vectorSize) +{ + for(unsigned int i = 0; i < vectorSize; i++) tick(vector[i]); +} + -- cgit v1.2.1