diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2003-01-02 04:37:31 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2003-01-02 04:37:31 +0000 |
commit | 10e0265429983876e2fd69950df4d51c8faf5635 (patch) | |
tree | 3e1c45e40bedd1b92225696ce955b902c4daf8e0 /externals/grill/flext/source | |
parent | 59e66762250fe61d570c5baf6c9ce6896a09e027 (diff) |
""
svn path=/trunk/; revision=316
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r-- | externals/grill/flext/source/flsndobj.cpp | 28 | ||||
-rw-r--r-- | externals/grill/flext/source/flsndobj.h | 2 | ||||
-rw-r--r-- | externals/grill/flext/source/flstk.cpp | 36 | ||||
-rw-r--r-- | externals/grill/flext/source/flstk.h | 46 |
4 files changed, 61 insertions, 51 deletions
diff --git a/externals/grill/flext/source/flsndobj.cpp b/externals/grill/flext/source/flsndobj.cpp index a18da9d3..e5203556 100644 --- a/externals/grill/flext/source/flsndobj.cpp +++ b/externals/grill/flext/source/flsndobj.cpp @@ -37,14 +37,16 @@ void flext_sndobj::ClearObjs() FreeObjs(); if(inobj) { - for(int i = 0; i < inobjs; ++i) { delete inobj[i]; delete tmpobj[i]; } + for(int i = 0; i < inobjs; ++i) delete inobj[i]; delete[] inobj; inobj = NULL; + } + if(tmpobj) { + for(int i = 0; i < inobjs; ++i) delete tmpobj[i]; delete[] tmpobj; tmpobj = NULL; - inobjs = 0; } if(outobj) { for(int i = 0; i < outobjs; ++i) delete outobj[i]; - delete[] outobj; outobj = NULL; outobjs = 0; + delete[] outobj; outobj = NULL; } } @@ -62,16 +64,20 @@ void flext_sndobj::m_dsp(int n,t_sample *const *in,t_sample *const *out) smprt = Samplerate(); // set up sndobjs for inlets and outlets - inobj = new Inlet *[inobjs]; - tmpobj = new SndObj *[inobjs]; - for(i = 0; i < inobjs; ++i) { - inobj[i] = new Inlet(in[i],blsz,smprt); - tmpobj[i] = new SndObj(NULL,blsz,smprt); + if(inobjs) { + inobj = new Inlet *[inobjs]; + tmpobj = new SndObj *[inobjs]; + for(i = 0; i < inobjs; ++i) { + inobj[i] = new Inlet(in[i],blsz,smprt); + tmpobj[i] = new SndObj(NULL,blsz,smprt); + } + } + if(outobjs) { + outobj = new Outlet *[outobjs]; + for(i = 0; i < outobjs; ++i) outobj[i] = new Outlet(out[i],blsz,smprt); } - outobj = new Outlet *[outobjs]; - for(i = 0; i < outobjs; ++i) outobj[i] = new Outlet(out[i],blsz,smprt); - NewObjs(); + if(!NewObjs()) ClearObjs(); } else { // assign changed input/output vectors diff --git a/externals/grill/flext/source/flsndobj.h b/externals/grill/flext/source/flsndobj.h index 66f98a94..960267be 100644 --- a/externals/grill/flext/source/flsndobj.h +++ b/externals/grill/flext/source/flsndobj.h @@ -29,7 +29,7 @@ public: flext_sndobj(); // these have to be overridden in child classes - virtual void NewObjs() {} + virtual bool NewObjs() { return true; } virtual void FreeObjs() {} virtual void ProcessObjs() {} diff --git a/externals/grill/flext/source/flstk.cpp b/externals/grill/flext/source/flstk.cpp index 6a56aacb..58fd192e 100644 --- a/externals/grill/flext/source/flstk.cpp +++ b/externals/grill/flext/source/flstk.cpp @@ -37,11 +37,11 @@ void flext_stk::ClearObjs() if(inobj) { for(int i = 0; i < inobjs; ++i) delete inobj[i]; - delete[] inobj; inobj = NULL; inobjs = 0; + delete[] inobj; inobj = NULL; } if(outobj) { for(int i = 0; i < outobjs; ++i) delete outobj[i]; - delete[] outobj; outobj = NULL; outobjs = 0; + delete[] outobj; outobj = NULL; } } @@ -61,14 +61,18 @@ void flext_stk::m_dsp(int n,t_sample *const *in,t_sample *const *out) 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); + if(inobjs) { + inobj = new Input *[inobjs]; + for(i = 0; i < inobjs; ++i) + inobj[i] = new Input(in[i],blsz); + } + if(outobjs) { + outobj = new Output *[outobjs]; + for(i = 0; i < outobjs; ++i) + outobj[i] = new Output(out[i],blsz); } - outobj = new Outlet *[outobjs]; - for(i = 0; i < outobjs; ++i) outobj[i] = new Outlet(out[i],blsz); - NewObjs(); + if(!NewObjs()) ClearObjs(); } else { // assign changed input/output vectors @@ -80,24 +84,24 @@ void flext_stk::m_dsp(int n,t_sample *const *in,t_sample *const *out) void flext_stk::m_signal(int n,t_sample *const *in,t_sample *const *out) { - ProcessObjs(); + if(inobjs || outobjs) ProcessObjs(blsz); } // inlet class -flext_stk::Inlet::Inlet(const t_sample *b,int v): +flext_stk::Input::Input(const t_sample *b,int v): buf(b),vecsz(v), index(0) {} -t_sample flext_stk::Inlet::tick() +MY_FLOAT flext_stk::Input::tick() { if(++index >= vecsz) index = 0; return lastOut(); } -t_sample *flext_stk::Inlet::tick(t_sample *vector,unsigned int vectorSize) +MY_FLOAT *flext_stk::Input::tick(MY_FLOAT *vector,unsigned int vectorSize) { for(unsigned int i = 0; i < vectorSize; i++) vector[i] = tick(); return vector; @@ -106,18 +110,18 @@ t_sample *flext_stk::Inlet::tick(t_sample *vector,unsigned int vectorSize) // outlet class -flext_stk::Outlet::Outlet(t_sample *b,int v): +flext_stk::Output::Output(t_sample *b,int v): buf(b),vecsz(v), index(0) {} -void flext_stk::Outlet::tick(t_sample s) +void flext_stk::Output::tick(MY_FLOAT s) { - buf[index] = s; + buf[index] = (t_sample)s; if(++index >= vecsz) index = 0; } -void flext_stk::Outlet::tick(const t_sample *vector,unsigned int vectorSize) +void flext_stk::Output::tick(const MY_FLOAT *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 index d340bcb1..7311e032 100644 --- a/externals/grill/flext/source/flstk.h +++ b/externals/grill/flext/source/flstk.h @@ -11,43 +11,36 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifndef __FLSTK_H #define __FLSTK_H -#include "flext.h" - -#include <stk.h> +#include <flext.h> +#include <Stk.h> 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 bool NewObjs() { return true; } virtual void FreeObjs() {} - virtual void ProcessObjs() {} + virtual void ProcessObjs(int blocksize) {} 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: + class Input: 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]; } + Input(const t_sample *b,int vecsz); - t_sample tick(); - t_sample *tick(t_sample *vector,unsigned int vectorSize); + MY_FLOAT lastOut() const { return (MY_FLOAT)buf[index]; } + MY_FLOAT tick(); + MY_FLOAT *tick(MY_FLOAT *vector,unsigned int vectorSize); void SetBuf(const t_sample *b) { buf = b; } @@ -57,14 +50,14 @@ private: }; //! STK object for writing to outlet buffer - class Outlet: + class Output: public Stk { public: - Outlet(t_sample *b,int vecsz); + Output(t_sample *b,int vecsz); - void tick(t_sample sample); - void tick(const t_sample *vector,unsigned int vectorSize); + void tick(MY_FLOAT sample); + void tick(const MY_FLOAT *vector,unsigned int vectorSize); void SetBuf(t_sample *b) { buf = b; } @@ -73,11 +66,18 @@ private: int vecsz,index; }; + Input &Inlet(int ix) { return *inobj[ix]; } + Output &Outlet(int ix) { return *outobj[ix]; } + +private: + 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); + void ClearObjs(); int inobjs,outobjs; - Inlet **inobj; - Outlet **outobj; + Input **inobj; + Output **outobj; float smprt; int blsz; |