From 9815096db22c73cacdbb65512d1b61d633db7fa8 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 2 Dec 2002 19:21:08 +0000 Subject: "version 0.1.1" svn path=/trunk/; revision=267 --- externals/grill/vasp/source/obj_peaks.cpp | 111 ++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 externals/grill/vasp/source/obj_peaks.cpp (limited to 'externals/grill/vasp/source/obj_peaks.cpp') diff --git a/externals/grill/vasp/source/obj_peaks.cpp b/externals/grill/vasp/source/obj_peaks.cpp new file mode 100644 index 00000000..1c1a218d --- /dev/null +++ b/externals/grill/vasp/source/obj_peaks.cpp @@ -0,0 +1,111 @@ +/* + +VASP modular - vector assembling signal processor / objects for Max/MSP and PD + +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 "classes.h" +#include "util.h" +#include + + +/*! \class vasp_qpeaks + \remark \b vasp.peaks? + \brief Get most pronounced peaks of a single vasp vector. + \since 0.0.6 + \param inlet vasp - is stored and output triggered + \param inlet bang - triggers output + \param inlet set - vasp to be stored + \retval outlet.0 list - peak positions + \retval outlet.1 list - peak values + + \note Outputs nothing if vasp is undefined or invalid + \note Only works for a vasp with one vector. No output otherwise. + \todo Units for peak position list +*/ +class vasp_qpeaks: + public vasp_op +{ + FLEXT_HEADER(vasp_qpeaks,vasp_op) + +public: + vasp_qpeaks(I argc,t_atom *argv): + peaks(1) + { + if(argc >= 1 && CanbeInt(argv[0])) + m_peaks(GetAInt(argv[0])); + else if(argc) + post("%s - Number argument invalid -> ignored",thisName()); + + AddInAnything(); + AddInInt(); + AddOutAnything(2); + SetupInOut(); + + FLEXT_ADDMETHOD(1,m_peaks); + } + + V m_peaks(I n) { peaks = n; } + + virtual V m_bang() + { + if(!ref.Ok()) + post("%s - Invalid vasp!",thisName()); + else if(ref.Vectors() > 1) + post("%s - More than one vector in vasp!",thisName()); + else { + VBuffer *buf = ref.Buffer(0); + I i,cnt = buf->Length(),pkfnd = 0; + S *p = buf->Pointer(); + + I mxpk = min(cnt,peaks); + t_atom *pos = new t_atom[mxpk],*lst = new t_atom[mxpk]; + for(i = 0; i < mxpk; ++i) SetFloat(lst[i],0); + + for(i = 0; i < cnt; ++i) { + const F v = fabs(p[i]); + + if(v && v > GetFloat(lst[mxpk-1])) { + I ix; + + for(ix = min(pkfnd-1,mxpk-1); ix >= 0; --ix) { + if(v > GetFloat(lst[ix])) { + if(ix < mxpk-1) { + pos[ix+1] = pos[ix]; + lst[ix+1] = lst[ix]; + } + } + else break; + } + ++ix; + + SetFloat(pos[ix],i); + SetFloat(lst[ix],v); + + if(++pkfnd > mxpk) pkfnd = mxpk; + } + } + + ToOutAnything(0,sym_list,pkfnd,pos); + ToOutAnything(1,sym_list,pkfnd,lst); + delete[] pos; + delete[] lst; + } + } + + virtual V m_help() { post("%s - Get list of most pronounced peaks of a vasp vector",thisName()); } + +protected: + I peaks; + +private: + FLEXT_CALLBACK_I(m_peaks); +}; + +FLEXT_LIB_V("vasp, vasp.peaks?",vasp_qpeaks) + + -- cgit v1.2.1