From d0ae3caca5828675335d3b19ab5dd987e7369b23 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 16:21:44 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1857, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=1858 --- sc4pd/source/Median.cpp | 220 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 sc4pd/source/Median.cpp (limited to 'sc4pd/source/Median.cpp') diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp new file mode 100644 index 0000000..77b0a5d --- /dev/null +++ b/sc4pd/source/Median.cpp @@ -0,0 +1,220 @@ +/* sc4pd + Median, Median~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Morton Feldman: For John Cage + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Median(~) ---------------------------------*/ + + +const int kMAXMEDIANSIZE = 32; + +class median_shared +{ +public: + + inline void Init(long size, float value); + inline float Insert(float value); + +private: + float m_medianValue[kMAXMEDIANSIZE]; + long m_medianAge[kMAXMEDIANSIZE]; + long m_medianSize, m_medianIndex; +}; + +void median_shared::Init(long size, float value) +{ + // initialize the arrays with the first value + m_medianSize = size; + for (int i=0; i>1] + + last = m_medianSize - 1; + // find oldest bin and age the other bins. + for (i=0; i m_medianValue[pos+1]) { + m_medianValue[pos] = m_medianValue[pos+1]; + m_medianAge[pos] = m_medianAge[pos+1]; + pos++; + } + m_medianValue[pos] = value; + m_medianAge[pos] = 0; // this is the newest bin, age = 0 + return m_medianValue[m_medianSize>>1]; +} + + +/* ------------------------ Median~ -----------------------------------*/ + +class Median_ar + :public flext_dsp +{ + FLEXT_HEADER(Median_ar,flext_dsp); + +public: + Median_ar(int argc, t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + +private: + FLEXT_CALLBACK_F(m_set); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_DSP_V("Median~",Median_ar); + +Median_ar::Median_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + AddOutSignal(); +} + +void Median_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + Median.Init(m_size,0); //how is this done in SuperCollider? +} + +void Median_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = Median.Insert(*(nin)++); + } +} + + +/* ------------------------ Median ------------------------------------*/ + +class Median_kr + :public flext_dsp +{ + FLEXT_HEADER(Median_kr,flext_dsp); + +public: + Median_kr(int argc, t_atom * argv); + +protected: + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_V("Median",Median_kr); + +Median_kr::Median_kr(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD(0,m_perform); + + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + float m_set=sc_getfloatarg(Args,1); + + Median.Init(m_size,m_set); + AddOutSignal(); +} + +void Median_kr::m_perform(float f) +{ + ToOutFloat(0,Median.Insert(f)); +} -- cgit v1.2.1 From 5e1268fb9920b248ee377797b130605f669c6dee Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 2 Aug 2004 19:18:22 +0000 Subject: main header file svn path=/trunk/externals/tb/; revision=1903 --- sc4pd/source/Median.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'sc4pd/source/Median.cpp') diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index 77b0a5d..f15ce63 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Median(~) ---------------------------------*/ -- cgit v1.2.1 From 89f570e5ebeab979202acf679974bafd05072692 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 14:01:31 +0000 Subject: sc4pd_dsp class and other changes svn path=/trunk/externals/tb/; revision=1912 --- sc4pd/source/Median.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sc4pd/source/Median.cpp') diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index f15ce63..f89f934 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -107,9 +107,9 @@ inline float median_shared::Insert(float value) /* ------------------------ Median~ -----------------------------------*/ class Median_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Median_ar,flext_dsp); + FLEXT_HEADER(Median_ar,sc4pd_dsp); public: Median_ar(int argc, t_atom * argv); @@ -166,9 +166,9 @@ void Median_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) /* ------------------------ Median ------------------------------------*/ class Median_kr - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Median_kr,flext_dsp); + FLEXT_HEADER(Median_kr,sc4pd_dsp); public: Median_kr(int argc, t_atom * argv); -- cgit v1.2.1 From 7087c18fec98b899854bd8672dfcc7f52a02e8cb Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 12 Jan 2005 11:24:27 +0000 Subject: bugfix svn path=/trunk/externals/tb/; revision=2493 --- sc4pd/source/Median.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sc4pd/source/Median.cpp') diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index f89f934..4383a1b 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -199,12 +199,12 @@ Median_kr::Median_kr(int argc,t_atom * argv) AtomList Args(argc,argv); - m_size=sc_getfloatarg(Args,0); + m_size=(int)sc_getfloatarg(Args,0); float m_set=sc_getfloatarg(Args,1); Median.Init(m_size,m_set); - AddOutSignal(); + AddOutFloat(); } void Median_kr::m_perform(float f) -- cgit v1.2.1