Update of /cvsroot/pure-data/externals/chaos/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21585
Modified Files: Makefile.am chaos.hpp chaos_base.hpp chaos_dsp.cpp chaos_dsp.hpp logistic_map.hpp lorenz.hpp main.cpp ode_base.cpp ode_base.hpp Log Message: xmas's changes
Index: ode_base.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/ode_base.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ode_base.hpp 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- ode_base.hpp 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 25,29 ****
class ode_base ! : protected chaos_base { public: --- 25,29 ----
class ode_base ! : public chaos_base { public: *************** *** 32,36 **** if (i >=0 && i <4) m_method = (unsigned char) i; ! post("no such method"); }
--- 32,37 ---- if (i >=0 && i <4) m_method = (unsigned char) i; ! else ! post("no such method"); }
*************** *** 40,66 **** }
! void set_dt(t_float f) ! { ! if (f >= 0) ! m_dt = (data_t)f; ! else ! post("invalid value for dt: %f", f); ! } ! ! t_float get_dt() { ! return (t_float) m_dt; }
! void m_step(); protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t m_dt; /* step width */
data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp;
! virtual void m_system (data_t* deriv, data_t* data);
void rk1 (); --- 41,62 ---- }
! CHAOS_SYSPAR_FUNCS_PRED(dt, m_pred_dt); ! ! bool m_pred_dt(t_float f) { ! return (f >= 0); }
! virtual void m_step(); protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */
data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp;
! virtual void m_system (data_t* deriv, data_t* data) ! { ! }
void rk1 (); *************** *** 69,81 **** };
! #define ODE_CALLBACKS \ ! CHAOS_CALLBACKS; \ ! FLEXT_CALLVAR_I(m_system->get_method, m_system->set_method); \ ! FLEXT_CALLVAR_F(m_system->get_dt, m_system->set_dt);
! #define ODE_ATTRIBUTES \ ! CHAOS_ATTRIBUTES; \ ! FLEXT_ADDATTR_VAR("method", m_system->get_method, m_system->set_method); \ ! FLEXT_ADDATTR_VAR("dt",m_system->get_dt, m_system->set_dt);
--- 65,77 ---- };
! #define ODE_CALLBACKS \ ! CHAOS_CALLBACKS; \ ! CHAOS_SYS_CALLBACKS_I(method); \ ! CHAOS_SYS_CALLBACKS(dt);
! #define ODE_ATTRIBUTES \ ! CHAOS_ATTRIBUTES; \ ! CHAOS_SYS_ATTRIBUTE(method); \ ! CHAOS_SYS_ATTRIBUTE(dt);
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/main.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** main.cpp 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- main.cpp 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 24,29 **** void chaos_library_setup() { ! post("chaos~ version"PACKAGE_VERSION"\n"); } ! FLEXT_LIB_SETUP(chaos, chaos_library_setup); --- 24,31 ---- void chaos_library_setup() { ! post("chaos~ version "PACKAGE_VERSION"\n"); ! ! FLEXT_DSP_SETUP(lorenz_dsp); } ! FLEXT_LIB_SETUP(chaos, chaos_library_setup);
Index: logistic_map.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/logistic_map.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** logistic_map.hpp 23 Dec 2004 10:07:17 -0000 1.2 --- logistic_map.hpp 24 Dec 2004 15:31:14 -0000 1.3 *************** *** 55,59 **** }
! CHAOS_SYSVAR_FUNCS_PRED(x, m_pred_x); bool m_pred_x(t_float f) --- 55,59 ---- }
! CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f)
Index: lorenz.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/lorenz.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** lorenz.hpp 23 Dec 2004 10:07:17 -0000 1.2 --- lorenz.hpp 24 Dec 2004 15:31:14 -0000 1.3 *************** *** 27,38 ****
class lorenz ! : protected ode_base { public: ! logistic() { m_num_eq = 3; m_data = new data_t[3];
CHAOS_SYS_INIT(x1,0.8); CHAOS_SYS_INIT(x2,0.8); --- 27,40 ----
class lorenz ! : public ode_base { public: ! lorenz() { m_num_eq = 3; m_data = new data_t[3];
+ CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,1); CHAOS_SYS_INIT(x1,0.8); CHAOS_SYS_INIT(x2,0.8); *************** *** 45,49 **** } ! ~logistic() { delete m_data; --- 47,51 ---- } ! ~lorenz() { delete m_data;
Index: chaos_base.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/chaos_base.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** chaos_base.hpp 23 Dec 2004 10:07:17 -0000 1.2 --- chaos_base.hpp 24 Dec 2004 15:31:14 -0000 1.3 *************** *** 1,3 **** ! a// // // chaos~ --- 1,3 ---- ! // // // chaos~ *************** *** 22,25 **** --- 22,26 ----
#include "chaos.hpp" + #include "chaos_defs.hpp"
class chaos_base *************** *** 37,41 **** }
! virtual void m_step();
data_t * m_data; // state of the system --- 38,44 ---- }
! virtual void m_step() ! { ! }
data_t * m_data; // state of the system *************** *** 46,141 ****
#define CHAOS_CALLBACKS \ - FLEXT_CALLGET_F(m_system->get_num_eq); - - #define CHAOS_ATTRIBUTES \ - FLEXT_ADDATTR_GET("dimension",m_system->get_num_eq); - - - - // macros for simplified system state functions - #define CHAOS_SYS_SETFUNC(NAME, NR) \ - void set_##NAME(t_float f) \ - { \ - m_data[NR] = (data_t) f; \ - } - - #define CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ - void set_##NAME(t_float f) \ - { \ - if ( PRED(f) ) \ - m_data[NR] = (data_t) f; \ - else \ - post("value for dimension " #NAME " %f out of range", f); \ - } - - #define CHAOS_SYS_GETFUNC(NAME, NR) \ - t_float get_##NAME() \ - { \ - return (t_float)m_data[NR]; \ - } - - /* to be called in the public part */ - #define CHAOS_SYSVAR_FUNCS_PRED(NAME, NR, PRED) \ - public: \ - CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ - CHAOS_SYS_GETFUNC(NAME, NR) - - #define CHAOS_SYSVAR_FUNCS(NAME, NR) \ public: \ ! CHAOS_SYS_SETFUNC(NAME, NR) \ ! CHAOS_SYS_GETFUNC(NAME, NR) ! ! ! ! // macros for simplified system parameter functions ! #define CHAOS_PAR_SETFUNC(NAME) \ ! void set_##NAME(t_float f) \ ! { \ ! m_##NAME = (data_t) f; \ ! } ! ! #define CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ ! void set_##NAME(t_float f) \ ! { \ ! if ( PRED(f) ) \ ! m_##NAME = (data_t) f; \ ! else \ ! post("value for parameter " #NAME " %f out of range", f); \ ! } ! ! #define CHAOS_PAR_GETFUNC(NAME) \ ! t_float get_##NAME() \ ! { \ ! return (t_float)m_##NAME; \ ! } ! ! ! #define CHAOS_SYSPAR_FUNCS_PRED(NAME, PRED) \ ! public: \ ! CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ ! CHAOS_PAR_GETFUNC(NAME) \ ! private: \ ! data_t m_##NAME; \ ! public: ! ! #define CHAOS_SYSPAR_FUNCS(NAME) \ ! public: \ ! CHAOS_PAR_SETFUNC(NAME) \ ! CHAOS_PAR_GETFUNC(NAME) \ ! private: \ ! data_t m_##NAME; \ ! public: ! ! ! #define CHAOS_SYS_CALLBACKS(NAME) \ ! FLEXT_CALLVAR_F(m_system->get_##NAME, m_system->set_##NAME); ! ! #define CHAOS_SYS_ATTRIBUTE(NAME) \ ! FLEXT_ADDATTR_VAR(#NAME,m_system->get_##NAME, m_system->set_##NAME);
! #define CHAOS_SYS_INIT(NAME, VALUE) \ ! set_##NAME(VALUE);
- #define CHAOS_PARAMETER(NAME) m_##NAME
--- 49,62 ----
#define CHAOS_CALLBACKS \ public: \ ! void get_dimension(int &i) \ ! { \ ! i = m_system->get_num_eq(); \ ! } \ ! FLEXT_CALLGET_I(get_dimension);
! #define CHAOS_ATTRIBUTES \ ! FLEXT_ADDATTR_GET("dimension",get_dimension);
Index: chaos.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/chaos.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** chaos.hpp 23 Dec 2004 10:07:17 -0000 1.2 --- chaos.hpp 24 Dec 2004 15:31:14 -0000 1.3 *************** *** 23,27 **** #define FLEXT_ATTRIBUTES 1
! //#include "flext.h"
/* internal we can work with a higher precision than pd */ --- 23,27 ---- #define FLEXT_ATTRIBUTES 1
! #include "flext.h"
/* internal we can work with a higher precision than pd */ *************** *** 32,35 **** --- 32,36 ---- #endif
+ #define __chaos_hpp #endif /* __chaos_hpp */
Index: chaos_dsp.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/chaos_dsp.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** chaos_dsp.cpp 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- chaos_dsp.cpp 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 21,193 ****
#include "chaos_dsp.hpp" - - void chaos_dsp::m_signal(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - if (m_freq >= m_sr * 0.5) - { - m_signal_(n, insigs, outsigs); - return; - } - - switch (m_method) - { - case 0: - m_signal_n(n, insigs, outsigs); - return; - case 1: - m_signal_l(n, insigs, outsigs); - return; - case 2: - m_signal_c(n, insigs, outsigs); - return; - } - } - - void chaos_dsp::m_signal_(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - int outlets = m_system->get_num_eq(); - - for (int i = 0; i!=n; ++i) - { - m_system->m_step(); - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - } - - } - - void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - ++i; - } - } - m_phase = phase; - } - - - /* linear and cubic interpolation adapted from supercollider by James McCartney */ - - void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - - for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_values[j]; - m_values[j]+=m_slopes[j]; - } - ++i; - } - } - m_phase = phase; - } - - - void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - phase = (phase > 2) ? phase : 2; - - for (int j = 0; j != outlets; ++j) - { - t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); - - m_values[j] = m_nextmidpts[j]; - m_nextmidpts[j] = (m_values[j] + value) * 0.5f; - - float fseglen = (float)phase; - m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) - / (fseglen * fseglen + fseglen); - - m_values[j] = value; - } - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_values[j]; - m_slopes[j]+=m_curves[j]; - m_values[j]+=m_slopes[j]; - } - ++i; - } - } - m_phase = phase; - } - - - void chaos_dsp::m_dsp(int n, t_sample *const *insigs, - t_sample *const *outsigs) - { - m_sr = Samplerate(); - } --- 21,22 ----
Index: Makefile.am =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile.am 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- Makefile.am 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 1,5 **** ! NAME = chaos~
! BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp
--- 1,6 ---- ! NAME = chaos
! BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ ! lorenz_dsp.cpp
*************** *** 18,22 **** TARGET =$(NAME).@EXTENSION@
! OBJECTS = $(patsubst %.cpp,./%.@OBJEXT@,$(BUILT_SOURCES))
SYSDIR = @SYSDIR@ --- 19,23 ---- TARGET =$(NAME).@EXTENSION@
! OBJECTS = $(patsubst %.cpp,%.@OBJEXT@,$(BUILT_SOURCES))
SYSDIR = @SYSDIR@ *************** *** 27,34 ****
all-local: $(OBJECTS) ! $(CXX) $(LDFLAGS) -shared ./*.@OBJEXT@ $(LIBS) -o ../$(TARGET) strip --strip-unneeded ../$(TARGET)
! ./%.@OBJEXT@ : %.cpp $(CXX) -c $(CXXFLAGS) $< -o $@
--- 28,35 ----
all-local: $(OBJECTS) ! $(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o ../$(TARGET) strip --strip-unneeded ../$(TARGET)
! %.@OBJEXT@ : %.cpp $(CXX) -c $(CXXFLAGS) $< -o $@
*************** *** 39,43 **** clean-local: rm -f ../$(TARGET) ! rm -f ../obj/*
install-exec-local: --- 40,44 ---- clean-local: rm -f ../$(TARGET) ! rm -f ./*.@OBJEXT@
install-exec-local:
Index: ode_base.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/ode_base.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ode_base.cpp 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- ode_base.cpp 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 84,88 **** break; case 2: ! rk3(); break; } --- 84,88 ---- break; case 2: ! rk4(); break; }
Index: chaos_dsp.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/chaos/src/chaos_dsp.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** chaos_dsp.hpp 21 Dec 2004 09:22:10 -0000 1.1.1.1 --- chaos_dsp.hpp 24 Dec 2004 15:31:14 -0000 1.2 *************** *** 21,30 **** #include "chaos_base.hpp"
! class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp);
! protected:
/* signal functions: */ --- 21,30 ---- #include "chaos_base.hpp"
! template <class system> class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp);
! public:
/* signal functions: */ *************** *** 39,47 **** virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs); -
/* local data for system, output and interpolation */ ! chaos_base * m_system; /* the system */
t_sample * m_values; /* actual value */ --- 39,51 ---- virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs);
+ virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) + { + m_sr = Samplerate(); + } + + /* local data for system, output and interpolation */ ! system * m_system; /* the system */
t_sample * m_values; /* actual value */ *************** *** 60,61 **** --- 64,274 ---- }; + + + /* create constructor / destructor */ \ + #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ + FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp<SYSTEM>) \ + \ + SYSTEM##_dsp(int argc, t_atom* argv ) \ + { \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + for (int i = 0; i != size; ++i) \ + AddOutSignal(); \ + \ + m_values = new t_float[size]; \ + m_slopes = new t_float[size]; \ + m_nextvalues = new t_float[size]; \ + m_nextmidpts = new t_float[size]; \ + m_curves = new t_float[size]; \ + \ + m_freq = GetAFloat(argv[0]); \ + m_method = (char)GetAFloat(argv[1]); \ + m_phase = 0; \ + \ + ATTRIBUTES; \ + } \ + \ + ~SYSTEM##_dsp() \ + { \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ + } + + + + + template <class system> + void chaos_dsp<system>::m_signal(int n, t_sample *const *insigs, + t_sample *const *outsigs) + { + if (m_freq >= m_sr * 0.5) + { + m_signal_(n, insigs, outsigs); + return; + } + + switch (m_method) + { + case 0: + m_signal_n(n, insigs, outsigs); + return; + case 1: + m_signal_l(n, insigs, outsigs); + return; + case 2: + m_signal_c(n, insigs, outsigs); + return; + } + } + + template <class system> + void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs, + t_sample *const *outsigs) + { + int outlets = m_system->get_num_eq(); + + for (int i = 0; i!=n; ++i) + { + m_system->m_step(); + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + } + + } + + template <class system> + void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs, + t_sample *const *outsigs) + { + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + ++i; + } + } + m_phase = phase; + } + + + /* linear and cubic interpolation adapted from supercollider by James McCartney */ + + template <class system> + void chaos_dsp<system>::m_signal_l(int n, t_sample *const *insigs, + t_sample *const *outsigs) + { + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + + for (int j = 0; j != outlets; ++j) + m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; + } + + + template <class system> + void chaos_dsp<system>::m_signal_c(int n, t_sample *const *insigs, + t_sample *const *outsigs) + { + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + phase = (phase > 2) ? phase : 2; + + for (int j = 0; j != outlets; ++j) + { + t_sample value = m_nextvalues[j]; + m_nextvalues[j]= m_system->get_data(j); + + m_values[j] = m_nextmidpts[j]; + m_nextmidpts[j] = (m_values[j] + value) * 0.5f; + + float fseglen = (float)phase; + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) + / (fseglen * fseglen + fseglen); + + m_values[j] = value; + } + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_slopes[j]+=m_curves[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; + }