From 96b9d4ab74d9b0d9bb073932f7e804585f1a7c80 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 17 Jul 2004 17:27:17 +0000 Subject: one more object and some changes svn path=/trunk/externals/tb/; revision=1870 --- sc4pd/source/Logistic.cpp | 205 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 sc4pd/source/Logistic.cpp (limited to 'sc4pd/source/Logistic.cpp') diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp new file mode 100644 index 0000000..9a475e0 --- /dev/null +++ b/sc4pd/source/Logistic.cpp @@ -0,0 +1,205 @@ +/* sc4pd + Logistic, Logistic~ + + 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: Fred Frith: Gravity + +*/ + +#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 + + +/* ------------------------ Logistic~ -------------------------------*/ + +class Logistic_ar: + public flext_dsp +{ + FLEXT_HEADER(Logistic_ar,flext_dsp); + +public: + Logistic_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_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_freq = sc_min(f,m_sr); + } + + void m_param(float f) + { + m_paramf = f; + } + +private: + int m_freq; + float m_paramf; + + int m_sr; + double m_y1; + int m_counter; + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_param); +}; + +FLEXT_LIB_DSP_V("Logistic~",Logistic_ar); + +Logistic_ar::Logistic_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"parameter",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_paramf = sc_getfloatarg(Args,1); + m_y1 = sc_getfloatarg(Args,2); + + m_sr=48000; // this is just a guess (i'll think about this later) + + AddOutSignal(); +} + +void Logistic_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); + m_paramf = sc_min(m_paramf,m_sr); +} + + +void Logistic_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + if(m_sr == m_paramf) + { + /* it might be possible to implement this without the branch */ + + double y1 = m_y1; + double paramf = m_paramf; + for (int i = 0; i!= n;++i) + { + (*(nout)++)= y1 = paramf * y1 * (1.0 - y1); + } + m_y1 = y1; + } + else + { + double y1 = m_y1; + double paramf = m_paramf; + int counter = m_counter; + int remain = n; + do + { + if (counter<=0) + { + counter = (int)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(1, counter); + y1 = paramf * y1 * (1.0 - y1); + } + + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=y1; + } + } + while(remain); + m_y1 = y1; + m_counter = counter; + } +} + + +/* ------------------------ Logistic ---------------------------------*/ + +class Logistic_kr: + public flext_base +{ + FLEXT_HEADER(Logistic_kr,flext_base); + +public: + Logistic_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_param(float f) + { + m_paramf = f; + } + +private: + float m_paramf; + double m_y1; + + FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_F(m_param); +}; + +FLEXT_LIB_V("Logistic",Logistic_kr); + +Logistic_kr::Logistic_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"parameter",m_param); + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + m_paramf = sc_getfloatarg(Args,0); + m_y1 = sc_getfloatarg(Args,1); + + AddOutFloat(); +} + +void Logistic_kr::m_perform() +{ + m_y1 = m_paramf * m_y1 * (1.0 - m_y1); + ToOutFloat(0,m_y1); +} -- 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/Logistic.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'sc4pd/source/Logistic.cpp') diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp index 9a475e0..89c6c2e 100644 --- a/sc4pd/source/Logistic.cpp +++ b/sc4pd/source/Logistic.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" /* ------------------------ Logistic~ -------------------------------*/ -- 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/Logistic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sc4pd/source/Logistic.cpp') diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp index 89c6c2e..a956fda 100644 --- a/sc4pd/source/Logistic.cpp +++ b/sc4pd/source/Logistic.cpp @@ -41,9 +41,9 @@ /* ------------------------ Logistic~ -------------------------------*/ class Logistic_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Logistic_ar,flext_dsp); + FLEXT_HEADER(Logistic_ar,sc4pd_dsp); public: Logistic_ar(int argc, t_atom *argv); -- cgit v1.2.1