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/flsndobj.cpp | 8 ++ externals/grill/flext/source/flstk.cpp | 122 ++++++++++++++++++++++++++++++ externals/grill/flext/source/flstk.h | 84 ++++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 externals/grill/flext/source/flstk.cpp create mode 100644 externals/grill/flext/source/flstk.h (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flsndobj.cpp b/externals/grill/flext/source/flsndobj.cpp index c3b54014..090b5034 100644 --- a/externals/grill/flext/source/flsndobj.cpp +++ b/externals/grill/flext/source/flsndobj.cpp @@ -1,3 +1,11 @@ +/* + +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 "flsndobj.h" 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]); +} + diff --git a/externals/grill/flext/source/flstk.h b/externals/grill/flext/source/flstk.h new file mode 100644 index 00000000..e9f12650 --- /dev/null +++ b/externals/grill/flext/source/flstk.h @@ -0,0 +1,84 @@ +/* + +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. + +*/ + +#ifndef __FLSTK_H +#define __FLSTK_H + +#include "flext.h" + +#include + +class FLEXT_SHARE flext_stk: + public flext_dsp +{ + FLEXT_HEADER(flext_stk,flext_dsp) + +public: + flext_stk(); + + // these have to be overridden in child classes + virtual void NewObjs() {} + virtual void FreeObjs() {} + virtual void ProcessObjs() {} + +protected: + virtual bool Init(); + virtual void Exit(); + + virtual void m_dsp(int n,t_sample *const *in,t_sample *const *out); + virtual void m_signal(int n,t_sample *const *in,t_sample *const *out); + +private: + //! STK object for reading from inlet buffer + class Inlet: + public Stk + { + public: + Inlet(const t_sample *b,int vecsz); + + const t_sample *lastFrame() const { return buf+index; } + t_sample lastOut() const { return buf[index]; } + + t_sample tick(); + t_sample *tick(t_sample *vector,unsigned int vectorSize); + + void SetBuf(const t_sample *b) { buf = b; } + + private: + const t_sample *buf; + int vecsz,index; + }; + + //! STK object for writing to outlet buffer + class Outlet: + public Stk + { + public: + Outlet(t_sample *b,int vecsz); + + void tick(t_sample sample); + void tick(const t_sample *vector,unsigned int vectorSize); + + void SetBuf(t_sample *b) { buf = b; } + + private: + t_sample *buf; + int vecsz,index; + }; + + void ClearObjs(); + + int inobjs,outobjs; + Inlet **inobj; + Outlet **outobj; + + float smprt; + int blsz; +}; + +#endif -- cgit v1.2.1