From 2f012f2baaae9cf9a53afd2398d326a6cdf56fec Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 30 Mar 2003 02:48:59 +0000 Subject: "" svn path=/trunk/; revision=511 --- externals/grill/vasp/source/buflib.cpp | 60 ++++++++++++++++++++++----------- externals/grill/vasp/source/main.cpp | 6 ++-- externals/grill/vasp/source/obj_imm.cpp | 25 ++++++++++---- externals/grill/vasp/source/vbuffer.h | 2 +- 4 files changed, 63 insertions(+), 30 deletions(-) (limited to 'externals/grill/vasp/source') diff --git a/externals/grill/vasp/source/buflib.cpp b/externals/grill/vasp/source/buflib.cpp index d4a6338e..b3595158 100644 --- a/externals/grill/vasp/source/buflib.cpp +++ b/externals/grill/vasp/source/buflib.cpp @@ -12,13 +12,18 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "buflib.h" #include -#define LIBTICK 100 // tick time in ms -#define LIBTOL 2 // how many ticks till release +#define LIBTICK 0.1 // tick time in s +#define LIBTOL 3 // how many ticks till release #define REUSE_MAXLOSEREL 0.1 // max. fraction of lost buffer size #define REUSE_MAXLOSEABS 10000 // max. lost buffer size -#define LIBMAGIC 12349876L // magic number for s_thing data check + +#ifdef __MWERKS__ +#define STD std +#else +#define STD +#endif class FreeEntry @@ -39,7 +44,6 @@ public: V IncRef(); V DecRef(); -// UL magic; const t_symbol *sym; I refcnt,tick; BufEntry *nxt; @@ -63,13 +67,11 @@ static V FreeLibSym(const t_symbol *s); BufEntry::BufEntry(const t_symbol *s,I fr,BL zero): - sym(s), //magic(LIBMAGIC), + sym(s), alloc(fr),len(fr),data(new S[fr]), refcnt(0),nxt(NULL) { if(zero) flext::ZeroMem(data,len*sizeof(*data)); -// FLEXT_ASSERT(!flext_base::GetThing(sym)); -// flext_base::SetThing(sym,this); } BufEntry::~BufEntry() @@ -88,6 +90,18 @@ static BufEntry *FindInLib(const t_symbol *s) return e?e:NULL; } +#ifdef FLEXT_DEBUG +static V DumpLib() +{ + post("Dump {"); + BufEntry *e; + for(e = libhead; e; e = e->nxt) { + post("\t%s -> refs:%i, alloc:%i, len:%i -> %p",flext::GetString(e->sym),e->refcnt,e->alloc,e->len,e->data); + } + post("}"); +} +#endif + VBuffer *BufLib::Get(const VSymbol &s,I chn,I len,I offs) { BufEntry *e = FindInLib(s.Symbol()); @@ -165,7 +179,8 @@ static V LibThr(flext::thr_params *) } #endif -static t_clock *libclk = NULL; +static flext::Timer *libclk = NULL; + static V LibTick(V *) { #ifdef FLEXT_THREADS @@ -175,8 +190,6 @@ static V LibTick(V *) #endif ++libtick; - clock_delay(libclk,LIBTICK); - } static const t_symbol *GetLibSym() @@ -193,19 +206,21 @@ static const t_symbol *GetLibSym() else { // allocate new symbol char tmp[20]; - #ifdef __MWERKS__ - std:: - #endif - sprintf(tmp,"vasp!%04i",libcnt); //! \todo what if libcnt has > 4 digits? + if(libcnt > 0xffff) + STD::sprintf(tmp,"vasp!%08x",libcnt); + else // better hash lookup for 4 digits + STD::sprintf(tmp,"vasp!%04x",libcnt); libcnt++; return gensym(tmp); } - - clock_delay(libclk,LIBTICK); } static V FreeLibSym(const t_symbol *sym) { +#ifdef FLEXT_DEBUG +// post("free %s",flext::GetString(sym)); +#endif + FreeEntry *f = new FreeEntry(sym); if(!freehead) freehead = f; else freetail->nxt = f; @@ -227,8 +242,9 @@ BufEntry *BufLib::NewImm(I fr,BL zero) } #endif if(!libclk) { - libclk = (t_clock *)clock_new(NULL,(t_method)LibTick); - clock_delay(libclk,LIBTICK); + libclk = new flext::Timer(true); + libclk->SetCallback(LibTick); + libclk->Periodic(LIBTICK); } const t_symbol *s = GetLibSym(); @@ -242,6 +258,10 @@ BufEntry *BufLib::NewImm(I fr,BL zero) else libhead = entry; libtail = entry; +#ifdef FLEXT_DEBUG +// DumpLib(); +#endif + #ifdef FLEXT_THREADS libmtx.Unlock(); #endif @@ -278,9 +298,9 @@ BufEntry *BufLib::Resize(BufEntry *e,I fr,BL keep,BL zero) -ImmBuf::ImmBuf(I len): +ImmBuf::ImmBuf(I len,BL zero): VBuffer(0,len), - entry(BufLib::NewImm(len)) + entry(BufLib::NewImm(len,zero)) {} ImmBuf::ImmBuf(BufEntry *e,I len,I offs): diff --git a/externals/grill/vasp/source/main.cpp b/externals/grill/vasp/source/main.cpp index 4efd6e36..6a1e01cf 100644 --- a/externals/grill/vasp/source/main.cpp +++ b/externals/grill/vasp/source/main.cpp @@ -12,11 +12,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "classes.h" -const C *VASP_VERSION = "0.1.3pre5"; +const C *VASP_VERSION = "0.1.3pre6"; #include "opfuns.h" -V lib_setup() +static V vasp_main() { post(""); post("-----------------------------------------"); @@ -207,7 +207,7 @@ V lib_setup() VASP__SETUP(cifft) } -FLEXT_LIB_SETUP(vasp,lib_setup) +FLEXT_LIB_SETUP(vasp,vasp_main) diff --git a/externals/grill/vasp/source/obj_imm.cpp b/externals/grill/vasp/source/obj_imm.cpp index 3e26677f..ce11d74c 100644 --- a/externals/grill/vasp/source/obj_imm.cpp +++ b/externals/grill/vasp/source/obj_imm.cpp @@ -38,7 +38,7 @@ class vasp_imm: public: vasp_imm(I argc,t_atom *argv): - frms(0) + frms(0),zero(true) { if(argc >= 1 && CanbeInt(argv[0])) m_frames(GetAInt(argv[0])); @@ -54,6 +54,7 @@ public: { FLEXT_CADDMETHOD(c,1,m_frames); FLEXT_CADDATTR_VAR(c,"frames",frms,m_frames); + FLEXT_CADDATTR_VAR1(c,"zero",zero); } V m_frames(I n) { frms = n; } @@ -67,7 +68,7 @@ public: else */ { - ImmBuf ibuf(frms); + ImmBuf ibuf(frms,zero); Vasp ret(frms,Vasp::Ref(ibuf)); ToOutVasp(0,ret); } @@ -76,17 +77,27 @@ public: post("%s - More than one vector in vasp!",thisName()); else { VBuffer *buf = ref.Buffer(0); - I len = buf->Length(),chns = buf->Channels(); - if(frms > len) len = frms; + const I len = buf->Length(),chns = buf->Channels(); + + // size of memory reservation (at least frms samples) + const I rlen = frms > len?frms:len; - ImmBuf imm(len); + ImmBuf imm(rlen,false); S *dst = imm.Pointer(); const S *src = buf->Pointer(); + +// post("!copy: src: %p,%i,%i -> dst: %p,%i",src,len,chns,dst,rlen); + register int i; _DE_LOOP(i,len, ( dst[i] = *src,src += chns ) ) + if(zero && rlen > len) ZeroSamples(dst+len,rlen-len); + + Vasp::Ref vr(imm); + +// post("!vr: %s,%i",vr.Ok()?vr.Symbol().Name():"***",vr.Offset()); - Vasp ret(len,Vasp::Ref(imm)); + Vasp ret(len,vr); ToOutVasp(0,ret); } } @@ -96,11 +107,13 @@ public: protected: I frms; + BL zero; private: FLEXT_CALLBACK_I(m_frames) FLEXT_CALLSET_I(m_frames); FLEXT_ATTRGET_I(frms); + FLEXT_ATTRVAR_B(zero); }; FLEXT_LIB_V("vasp, vasp.imm vasp.!",vasp_imm) diff --git a/externals/grill/vasp/source/vbuffer.h b/externals/grill/vasp/source/vbuffer.h index e616ad1c..a87685c9 100644 --- a/externals/grill/vasp/source/vbuffer.h +++ b/externals/grill/vasp/source/vbuffer.h @@ -107,7 +107,7 @@ class ImmBuf: public VBuffer { public: - ImmBuf(I len); + ImmBuf(I len,BL zero = true); ImmBuf(BufEntry *e,I len = -1,I offs = 0); virtual BL Ok() const { return entry != NULL; } -- cgit v1.2.1