From 5233c01a26329306c9f1d08c1a39733aee2cc518 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 21 Dec 2004 09:22:10 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2423, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2424 --- chaos/AUTHORS | 3 + chaos/ChangeLog | 0 chaos/Makefile.am | 2 + chaos/NEWS | 0 chaos/README | 0 chaos/bootstrap.sh | 5 ++ chaos/configure.ac | 142 +++++++++++++++++++++++++++++ chaos/src/Makefile.am | 44 +++++++++ chaos/src/bernoulli_map.hpp | 75 ++++++++++++++++ chaos/src/bungalow_tent_map.hpp | 121 +++++++++++++++++++++++++ chaos/src/chaos.hpp | 35 ++++++++ chaos/src/chaos_base.cpp | 21 +++++ chaos/src/chaos_base.hpp | 55 ++++++++++++ chaos/src/chaos_dsp.cpp | 193 ++++++++++++++++++++++++++++++++++++++++ chaos/src/chaos_dsp.hpp | 61 +++++++++++++ chaos/src/circle_map.hpp | 106 ++++++++++++++++++++++ chaos/src/gauss_map.hpp | 77 ++++++++++++++++ chaos/src/henon_map.hpp | 121 +++++++++++++++++++++++++ chaos/src/ikeda_laser_map.hpp | 153 +++++++++++++++++++++++++++++++ chaos/src/logistic_map.hpp | 91 +++++++++++++++++++ chaos/src/lorenz.hpp | 150 +++++++++++++++++++++++++++++++ chaos/src/lozi_map.hpp | 126 ++++++++++++++++++++++++++ chaos/src/main.cpp | 29 ++++++ chaos/src/map_base.hpp | 40 +++++++++ chaos/src/ode_base.cpp | 90 +++++++++++++++++++ chaos/src/ode_base.hpp | 83 +++++++++++++++++ chaos/src/sine_map.hpp | 72 +++++++++++++++ chaos/src/standard_map.hpp | 130 +++++++++++++++++++++++++++ chaos/src/tent_map.hpp | 63 +++++++++++++ 29 files changed, 2088 insertions(+) create mode 100644 chaos/AUTHORS create mode 100644 chaos/ChangeLog create mode 100644 chaos/Makefile.am create mode 100644 chaos/NEWS create mode 100644 chaos/README create mode 100755 chaos/bootstrap.sh create mode 100644 chaos/configure.ac create mode 100644 chaos/src/Makefile.am create mode 100644 chaos/src/bernoulli_map.hpp create mode 100644 chaos/src/bungalow_tent_map.hpp create mode 100644 chaos/src/chaos.hpp create mode 100644 chaos/src/chaos_base.cpp create mode 100644 chaos/src/chaos_base.hpp create mode 100644 chaos/src/chaos_dsp.cpp create mode 100644 chaos/src/chaos_dsp.hpp create mode 100644 chaos/src/circle_map.hpp create mode 100644 chaos/src/gauss_map.hpp create mode 100644 chaos/src/henon_map.hpp create mode 100644 chaos/src/ikeda_laser_map.hpp create mode 100644 chaos/src/logistic_map.hpp create mode 100644 chaos/src/lorenz.hpp create mode 100644 chaos/src/lozi_map.hpp create mode 100644 chaos/src/main.cpp create mode 100644 chaos/src/map_base.hpp create mode 100644 chaos/src/ode_base.cpp create mode 100644 chaos/src/ode_base.hpp create mode 100644 chaos/src/sine_map.hpp create mode 100644 chaos/src/standard_map.hpp create mode 100644 chaos/src/tent_map.hpp (limited to 'chaos') diff --git a/chaos/AUTHORS b/chaos/AUTHORS new file mode 100644 index 0000000..022e6c0 --- /dev/null +++ b/chaos/AUTHORS @@ -0,0 +1,3 @@ +Tim Blechmann +Mike McGonagle +B. Bogart \ No newline at end of file diff --git a/chaos/ChangeLog b/chaos/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/chaos/Makefile.am b/chaos/Makefile.am new file mode 100644 index 0000000..5db2166 --- /dev/null +++ b/chaos/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = src +EXTRA_DIST = src \ No newline at end of file diff --git a/chaos/NEWS b/chaos/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/chaos/README b/chaos/README new file mode 100644 index 0000000..e69de29 diff --git a/chaos/bootstrap.sh b/chaos/bootstrap.sh new file mode 100755 index 0000000..695f2bd --- /dev/null +++ b/chaos/bootstrap.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +aclocal \ +&& automake-1.8 --gnu --add-missing \ +&& autoconf \ No newline at end of file diff --git a/chaos/configure.ac b/chaos/configure.ac new file mode 100644 index 0000000..c228f01 --- /dev/null +++ b/chaos/configure.ac @@ -0,0 +1,142 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(chaos~, 0.01, TimBlechmann@gmx.de, chaos~) +AM_INIT_AUTOMAKE + +dnl Checks for programs. +AC_PROG_MAKE_SET +AC_PROG_CC +AC_PROG_CXX + +dnl Checks for libraries. +AC_CHECK_LIB(m, sin) + +dnl Checks for header files. +AC_HEADER_STDC + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_C_INLINE +AC_TYPE_SIZE_T +AC_HEADER_TIME + + +dnl Checks for command line arguments +AC_ARG_WITH(flextdir, + [ --with-flextdir path to flext headers], + [ + flextdir=$withval + INCLUDEDIR="-I$withval $INCLUDEDIR" + ], + [echo "path to flext headers required" && exit 1]) + +AC_CHECK_FILE("$flextdir/flext.h",, + [echo "$flextdir/flext.h not found" && exit 1]) + + +AC_ARG_ENABLE(system, + [ --enable-system system (default: pd)], + [ + if test "enableval" == "max"; then + AC_DEFINE(FLEXT_SYS,1) + else + AC_DEFINE(FLEXT_SYS,2) + fi + system = $enabeval + ], + AC_DEFINE(FLEXT_SYS,2) + ) + + +AC_ARG_WITH(sysdir, + [ --with-sysdir path pd / max installation], + SYSDIR=$withval, + [echo "path to pd / max installation required" && exit 1]) + + +AC_ARG_ENABLE(static, + [ --enable-static static linking with libflext], + LDFLAGS="-Bstatic $LDFLAGS" + , + [ + AC_DEFINE(FLEXT_SHARED) + AC_DEFINE(FLEXT_THREADS) + LDFLAGS="-Bdynamic $LDFLAGS" + ] + ) + +AC_ARG_ENABLE(debug, + [ --enable-debug link with libflext_d library for debugging], + [ + LDFLAGS="-lflext_d $LDFLAGS" + CXXFLAGS="-g" + ], + [ + LDFLAGS="-lflext $LDFLAGS" + CXXFLAGS="-O3" + ]) + +dnl mtune will break gcc 3.3.x +AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3, G4, G5], + [ + case $enableval in + pentium3 | pentium3m) + OPT_FLAGS = "-mtune=$enableval -march=$enableval -mmmx -msse -mfpmath=sse";; + pentium2 | athlon | pentium-mmx) + OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx";; + pentium) + OPT_FLAGS="-mtune=$enableval -march=$enableval";; + pentium4 | pentium4m | pentium-m | prescott | nocona | athlon-xp | athlon-mp | athlon64 | opteron) + OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx -msse -msse2 -mfpmath=sse";; + G5 | G4) + OPT_FLAGS="-mtune=$enableval -march=$enableval -maltivec -faltivec -malign-natural";; + G3) + OPT_FLAGS="-mtune=$enableval -march=$enableval -malign-natural";; + *) + ;; + esac + ]) + +dnl select build +if test `uname -s` == "Linux"; then + dnl no max/msp for linux + OBJEXT=o + EXTENSION=pd_linux +fi + +if test `uname -s` == "Darwin"; then + dnl just a guess + if test "$system" = "max"; then + echo "build system doesn't support max, yet" && exit 1; + else + LDFLAGS="-bundle -bundle_loader $LDFLAGS" + FRAMEWORKS= + EXTENSION=pd_darwin + LIBS="gcc $LIBS" + fi + OBJEXT=o +fi + +if test `uname -s` == "Cygwin"; then + dnl just a guess + if test "$system" = "max"; then + echo "build system doesn't support max, yet" && exit 1; + else + EXTENSION=dll + LIBS="gcc $LIBS bin/pd bin/pthreadVC.dll" + LDFLAGS="-L$SYSDIR" + fi +fi + + +AC_SUBST(EXTENSION) +AC_SUBST(INCLUDEDIR) +AC_SUBST(CXXFLAGS) +AC_SUBST(OPT_FLAGS) +AC_SUBST(LDFLAGS) +AC_SUBST(DEFS) +AC_SUBST(LIBS) +AC_SUBST(OBJEXT) +AC_SUBST(FRAMEWORKS) +AC_SUBST(SYSDIR) +AC_OUTPUT([Makefile + src/Makefile]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am new file mode 100644 index 0000000..9f99c3f --- /dev/null +++ b/chaos/src/Makefile.am @@ -0,0 +1,44 @@ +NAME = chaos~ + +BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp + + +CXXFLAGS = @CXXFLAGS@ \ + @OPT_FLAGS@ \ + @INCLUDEDIR@ \ + $(DEFS) + +LDFLAGS = @LDFLAGS@ \ + $(patsubst %,-framework %,$(FRAMEWORKS)) + +LIBS = @LIBS@ + +FRAMEWORKS = @FRAMEWORKS@ + +TARGET =$(NAME).@EXTENSION@ + +OBJECTS = $(patsubst %.cpp,./%.@OBJEXT@,$(BUILT_SOURCES)) + +SYSDIR = @SYSDIR@ + + +# ----------------------------- targets -------------------------------- + + +all-local: $(OBJECTS) + $(CXX) $(LDFLAGS) -shared ./*.@OBJEXT@ $(LIBS) -o ../$(TARGET) + strip --strip-unneeded ../$(TARGET) + +./%.@OBJEXT@ : %.cpp + $(CXX) -c $(CXXFLAGS) $< -o $@ + +dist-hook: + rm -f ./*~ + rm -f ./*.@OBJEXT@ + +clean-local: + rm -f ../$(TARGET) + rm -f ../obj/* + +install-exec-local: + install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp new file mode 100644 index 0000000..b006c92 --- /dev/null +++ b/chaos/src/bernoulli_map.hpp @@ -0,0 +1,75 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// bernoulli map: x[n+1] = 2 * x[n] mod 1 +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class bernoulli: + protected map_base +{ +public: + bernoulli() + { + m_num_eq = 1: + m_data = new data_t[1]; + set_x(0.5f); + } + + ~bernoulli() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + + if (x < 0.5f) + m_data[0] = 2.f * x; + else + m_data[0] = 2.f * x - 1.f; + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } +}; + + +#define BERNOULLI_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define BERNOULLI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp new file mode 100644 index 0000000..6708eae --- /dev/null +++ b/chaos/src/bungalow_tent_map.hpp @@ -0,0 +1,121 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// bungalow_tent map: x[n+1] = 1 + 2 * r + 2 * (r + 1) * x[n] +// (for -1 <= x[n] < -0.5f) +// 1 + 2 * (1 - r) * (x[n]) +// (for -0.5 <= x[n] < 0) +// 1 + 2 * (r - 1) * (x[n]) +// (for 0 <= x[n] < 0.5) +// 1 + 2 * r - 2 * (r + 1) * (x[n]) +// (for 0.5 <= x[n] < 1) +// -1 <= x[n] < 1 +// -0.5 <= r < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class bungalow_tent: + protected map_base +{ +public: + bungalow_tent() + : m_r(0.5) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5f); + } + + ~bungalow_tent() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t r = m_r; + + if ( x < - 0.5) + { + m_data[0] = 1 + 2 * r + 2 * (r + 1) * x; + return; + } + if ( x < 0) + { + m_data[0] = 1 + 2 * (1 - r) * x; + return; + } + if ( x < 0.5) + { + m_data[0] = 1 + 2 * (r - 1) * x; + return; + } + else + { + m_data[0] = 1 + 2 * r - 2 * (r + 1) * x; + return; + } + + } + + void set_x(t_float f) + { + if ( (f > -1) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_r(t_float f) + { + if ( (f > -.5) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for r %f out of range", f); + } + + t_float get_r() + { + return (t_float)m_data[0]; + } + +private: + data_t m_r; + +}; + + +#define BUNGALOW_TENT_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ + + +#define BUNGALOW_TENT_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp new file mode 100644 index 0000000..d65ba5c --- /dev/null +++ b/chaos/src/chaos.hpp @@ -0,0 +1,35 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_hpp + +#define FLEXT_ATTRIBUTES 1 + +#include "flext.h" + +/* internal we can work with a higher precision than pd */ +#ifdef DOUBLE_PRECISION +typedef double data_t; +#else +typedef t_float data_t; +#endif + +#define __chaos_hpp +#endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.cpp b/chaos/src/chaos_base.cpp new file mode 100644 index 0000000..9f8cad3 --- /dev/null +++ b/chaos/src/chaos_base.cpp @@ -0,0 +1,21 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp new file mode 100644 index 0000000..231580b --- /dev/null +++ b/chaos/src/chaos_base.hpp @@ -0,0 +1,55 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_base_hpp + +#include "chaos.hpp" + +class chaos_base +{ + +public: + t_sample get_data(unsigned int i) + { + return (t_sample)m_data[i]; /* this is not save, but fast */ + } + + int get_num_eq() + { + return m_num_eq; + } + + /* prototype for system function */ + virtual void m_step(); + + data_t * m_data; // state of the system + +protected: + int m_num_eq; // number of equations of the system +}; + +#define CHAOS_CALLBACKS \ +FLEXT_CALLGET_F(m_system->get_num_eq); + +#define CHAOS_ATTRIBUTES \ +FLEXT_ADDATTR_GET("dimension",m_system->get_num_eq); + +#define __chaos_base_hpp +#endif /* __chaos_base_hpp */ diff --git a/chaos/src/chaos_dsp.cpp b/chaos/src/chaos_dsp.cpp new file mode 100644 index 0000000..790be06 --- /dev/null +++ b/chaos/src/chaos_dsp.cpp @@ -0,0 +1,193 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#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(); +} diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp new file mode 100644 index 0000000..12efaa8 --- /dev/null +++ b/chaos/src/chaos_dsp.hpp @@ -0,0 +1,61 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +class chaos_dsp + : public flext_dsp +{ + FLEXT_HEADER(chaos_dsp, flext_dsp); + +protected: + + /* signal functions: */ + /* for frequency = sr/2 */ + void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* sample & hold */ + void m_signal_n(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* linear interpolation */ + void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* cubic interpolatio */ + void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); + + 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 */ + t_sample * m_slopes; /* actual slope for cubic interpolation */ + + t_sample * m_nextvalues; + t_sample * m_nextmidpts; + t_sample * m_curves; + + /* local data for signal functions */ + float m_freq; /* frequency of oscillations */ + int m_phase; /* phase counter */ + float m_sr; /* sample rate */ + + char m_method; /* interpolation method */ + +}; diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp new file mode 100644 index 0000000..f1ef406 --- /dev/null +++ b/chaos/src/circle_map.hpp @@ -0,0 +1,106 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// circle_map map: x[n+1] = x[n] * omega - r / (2*pi) * sin (2 * pi * x [n]) +// +// taken from Willi-Hans Steeb: Chaos and Fractals + +class circle_map: + protected map_base +{ +public: + circle_map() + : m_omega(0.4), m_r(1) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~circle_map() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t omega = m_omega; + data_t r = m_r; + + m_data[0] = x + omega - r / (2.f * M_PI) * sin (2.f * M_PI * x); + } + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_r(t_float f) + { + m_r = (data_t) f; + } + + + t_float get_r() + { + return (t_float)m_r; + } + + + void set_omega (t_float f) + { + m_omega = (data_t) f; + } + + t_float get_omega() + { + return (t_float)m_omega; + } + + +private: + data_t m_omega; + data_t m_r; +}; + +#define CIRCLE_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_ATTRVAR_F(m_system->m_omega); \ +FLEXT_ATTRVAR_F(m_system->m_r); \ +FLEXT_CALLVAR_F(m_system->get_omega, m_system->set_omega); \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define CIRCLE_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR1("omega",m_system->m_omega); \ +FLEXT_ADDATTR_VAR1("r",m_system->m_r); \ +FLEXT_ADDATTR_VAR("omega",m_system->get_omega, m_system->set_omega); \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp new file mode 100644 index 0000000..e2316ec --- /dev/null +++ b/chaos/src/gauss_map.hpp @@ -0,0 +1,77 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// gauss map: x[n+1] = 0 (for x[n] = 0) +// fmod(1 / x[n]) (else) +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class gauss: + protected map_base +{ +public: + gauss() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~gauss() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data == 0) + m_data[0] = 0; + else + m_data[0] = fmod(1.f / data); + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +}; + +#define GAUSS_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define GAUSS_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + + diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp new file mode 100644 index 0000000..d29e8a7 --- /dev/null +++ b/chaos/src/henon_map.hpp @@ -0,0 +1,121 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// henon map: x[n+1] = y[n] + 1 - a * x[n] * x[n] +// y[n+1] = b * x[n] +// b != 0 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class henon: + protected map_base +{ +public: + henon() + : m_a(1.4), m_b(0.3) + { + m_num_eq = 2; + m_data = new data_t[1]; + set_x(0.f); + set_y(0.f); + } + + ~henon() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + m_data[0] = 1 + y - m_a * x * x; + m_data[1] = m_b * x; + + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_a(t_float f) + { + m_a = (data_t) f; + } + + t_float get_a() + { + return (t_float)m_a; + } + + + void set_b(t_float f) + { + if (f != 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + +private: + data_t m_a; + data_t m_b; +}; + + +#define HENON_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); + +#define HENON_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ +FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp new file mode 100644 index 0000000..39d75c4 --- /dev/null +++ b/chaos/src/ikeda_laser_map.hpp @@ -0,0 +1,153 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// ikeda laser map: z[n+1] = roh + c2 * z[n] * +// exp (j * (c1 - c3 / (1 + abs(z) * abs(z)))) +// z is complex +// +// equal: x[n+1] = roh + c2 * (x[n] * cos(tau) - y[n] * sin (tau)) +// y[n+1] = c2 * (x[n] * sin(tau) + y[n] * cos(tau)) +// tau = c1 - (c2 / (1 + x*x + y*y)) +// +// taken from Willi-Hans Steeb: Chaos and Fractals + +class ikeda: + protected map_base +{ +public: + ikeda() + : m_c1(0.4), m_c2(0.9), m_c3(9), m_roh(0.85) + { + m_num_eq = 2; + m_data = new data_t[2]; + set_x(0.5); + set_y(0.5); + } + + ~ikeda() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + data_t tau = m_c1 - m_c3 / (1 + x*x + y*y); + data_t cos_tau = cos(tau); + data_t sin_tau = sin(tau); + + m_data[0] = m_roh + m_c2 * (x * cos_tau - y * sin_tau); + m_data[1] = m_c2 * (x * sin_tau + y * cos_tau); + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_c1(t_float f) + { + m_c1 = (data_t) f; + } + + t_float get_c1() + { + return (t_float)m_c1; + } + + + void set_c2(t_float f) + { + m_c2[1] = (data_t) f; + } + + t_float get_c2() + { + return (t_float)m_c2; + } + + + void set_c3(t_float f) + { + m_c3 = (data_t) f; + } + + t_float get_c3() + { + return (t_float)m_c3; + } + + + void set_roh(t_float f) + { + m_roh = (data_t) f; + } + + t_float get_roh() + { + return (t_float)m_roh; + } + + +private: + data_t m_c1, m_c2, m_c3, m_roh; +}; + + +#define IKEDA_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_c1, m_system->set_c1); \ +FLEXT_CALLVAR_F(m_system->get_c2, m_system->set_c2); \ +FLEXT_CALLVAR_F(m_system->get_c3, m_system->set_c3); \ +FLEXT_CALLVAR_F(m_system->get_roh, m_system->set_roh); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); \ + + +#define IKEDA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("c1",m_system->get_c1, m_system->set_c1); \ +FLEXT_ADDATTR_VAR("c2",m_system->get_c2, m_system->set_c2); \ +FLEXT_ADDATTR_VAR("c3",m_system->get_c3, m_system->set_c3); \ +FLEXT_ADDATTR_VAR("roh",m_system->get_roh, m_system->set_roh); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp new file mode 100644 index 0000000..c443f45 --- /dev/null +++ b/chaos/src/logistic_map.hpp @@ -0,0 +1,91 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// logistic map: x[n+1] = alpha * x[n] * (1 - x[n]) +// 0 <= x[n] < 1 +// 0 <= alpha <= 4 + +class logistic: + protected map_base +{ +public: + logistic() + : m_alpha(3.8) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5f); + } + + ~logistic() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + data_t alpha = m_alpha; + m_data[0] = alpha * data * (1.f - data); + } + + void set_alpha(t_float f) + { + if ( (f > 0) && (f < 4)) + m_alpha = (data_t) f; + else + post("value for alpha %f out of range", f); + } + + t_float get_alpha() + { + return (t_float)m_alpha; + } + + void set_x(t_float f) + { + if ( (f > 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +private: + data_t m_alpha; +}; + +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_alpha, m_system->set_alpha); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("alpha",m_system->get_alpha, m_system->set_alpha); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + + diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp new file mode 100644 index 0000000..70dad4d --- /dev/null +++ b/chaos/src/lorenz.hpp @@ -0,0 +1,150 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// lorenz model: dx1/dt = sigma * (x2 - x1) +// dx2/dt = - x1 * x3 + r * x1 - x2 +// dx3/dt = x1 * x2 - b * x3 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class lorenz + : protected ode_base +{ +public: + logistic() + : m_sigma(16), m_b(4), m_r(40) + { + m_num_eq = 3; + m_data = new data_t[3]; + set_x1(0.8f); + set_x2(0.8f); + set_x3(0.8f); + set_method(0); + } + + ~logistic() + { + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0], x2 = data[1], x3 = data[2]; + + deriv[0] = m_sigma * (x2 - x1); + deriv[1] = - x1 * x3 + m_r * x1 - x2; + deriv[3] = x1 * x2 - m_b * x3; + } + + void set_x1(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x1() + { + return (t_float)m_data[0]; + } + + void set_x2(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_x2() + { + return (t_float)m_data[1]; + } + + void set_x3(t_float f) + { + m_data[2] = (data_t) f; + } + + t_float get_x3() + { + return (t_float)m_data[2]; + } + + + void set_sigma(t_float f) + { + if (f > 0) + m_sigma = (data_t) f; + else + post("value for sigma %f out of range", f); + } + + t_float get_sigma() + { + return (t_float)m_sigma; + } + + + void set_r(t_float f) + { + if (f > 0) + m_r = (data_t) f; + else + post("value for r %f out of range", f); + } + + t_float get_r() + { + return (t_float)m_r; + } + + void set_b(t_float f) + { + if (f > 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + + +private: + data_t m_sigma, m_r, m_b; +}; + + +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ +FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ +FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ +FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ +FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ +FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp new file mode 100644 index 0000000..50192c4 --- /dev/null +++ b/chaos/src/lozi_map.hpp @@ -0,0 +1,126 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// lozi map: x[n+1] = y[n] + 1 - a * abs(x[n]) +// y[n+1] = b * x[n] +// b != 0 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class lozi: + protected map_base +{ +public: + lozi() + : m_a(1.4), m_b(0.3) + { + m_num_eq = 2; + m_data = new data_t[1]; + set_x(0.5); + set_y(0.5); + } + + ~lozi() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + if (x > 0) + m_data[0] = 1 + y - m_a * x; + else + m_data[0] = 1 + y + m_a * x; + + m_data[1] = m_b * x; + + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_a(t_float f) + { + m_a = (data_t) f; + } + + t_float get_a() + { + return (t_float)m_a; + } + + + void set_b(t_float f) + { + if (f != 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + + +private: + data_t m_a; + data_t m_b; +}; + + +#define LOZI_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); + +#define LOZI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ +FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp new file mode 100644 index 0000000..df25010 --- /dev/null +++ b/chaos/src/main.cpp @@ -0,0 +1,29 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos.hpp" +#include "logistic_map.hpp" + +void chaos_library_setup() +{ + post("chaos~ version"PACKAGE_VERSION"\n"); +} + +FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp new file mode 100644 index 0000000..35c8460 --- /dev/null +++ b/chaos/src/map_base.hpp @@ -0,0 +1,40 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#ifndef __map_base_hpp + +#include "chaos_base.hpp" + +class map_base + : protected chaos_base +{ + +}; + +#define MAP_CALLBACKS \ +CHAOS_CALLBACKS + + +#define MAP_ATTRIBUTES \ +CHAOS_ATTRIBUTES; + +#define __map_base_hpp +#endif /* __map_base_hpp */ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp new file mode 100644 index 0000000..cfedeee --- /dev/null +++ b/chaos/src/ode_base.cpp @@ -0,0 +1,90 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +void ode_base::rk1() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += m_dt * m_k[0][i]; +} + + +void ode_base::rk2() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + m_k[0][i] = m_k[0][i] * 0.5 * m_dt + m_data[i]; + + m_system (m_k[1], m_k[0]); + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += m_dt * m_k[1][i]; +} + + +void ode_base::rk4() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[0][i] *= m_dt; + m_tmp[i] = m_data[i] + 0.5 * m_k[0][i]; + } + + m_system (m_k[1], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[1][i] *= m_dt; + m_tmp[i] = m_data[i] + 0.5 * m_k[1][i]; + } + + m_system (m_k[2], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[2][i] *= m_dt; + m_tmp[i] = m_data[i] + m_k[2][i]; + } + + m_system (m_k[3], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + m_k[3][i] *= m_dt; + + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += (m_k[0][i] + 2. * (m_k[1][i] + m_k[2][i]) + m_k[3][i]) + / 6.; +} + +void ode_base::m_step() +{ + switch (m_method) + { + case 0: + rk1(); + break; + case 1: + rk2(); + break; + case 2: + rk3(); + break; + } + +} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp new file mode 100644 index 0000000..5fdd6d1 --- /dev/null +++ b/chaos/src/ode_base.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#ifndef __ode_base_hpp + +#include "chaos_base.hpp" + +class ode_base + : protected chaos_base +{ +public: + void set_method(int i) + { + if (i >=0 && i <4) + m_method = (unsigned char) i; + post("no such method"); + } + + t_int get_method() + { + return (int) m_method; + } + + 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 (); + void rk2 (); + void rk4 (); +}; + +#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); + + +#define __ode_base_hpp +#endif /* __ode_base_hpp */ diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp new file mode 100644 index 0000000..dd62458 --- /dev/null +++ b/chaos/src/sine_map.hpp @@ -0,0 +1,72 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// sine map: x[n+1] = sin(pi * x) +// 0 <= x[n] <= 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class sine: + protected map_base +{ + +public: + sine() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~sine() + { + delete m_data; + } + + virtual void m_step() + { + m_data[0] = sin (M_PI * m_data[0]); + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f <= 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +}; + +#define SINE_CALLBACKS \ +MAP_CALLBACKS \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define SINE_ATTRIBUTES \ +MAP_ATTRIBUTES \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp new file mode 100644 index 0000000..5f77af9 --- /dev/null +++ b/chaos/src/standard_map.hpp @@ -0,0 +1,130 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// standard map: I[n+1] = I[n] + k * sin(theta[n]) +// theta[n+1] = theta[n] + I[n] + k * sin(theta[n]) +// 0 <= theta <= 2*pi +// taken from Willi-Hans Steeb: Chaos and Fractals + +class standard: + protected map_base +{ +public: + standard() + : m_k(0.8) + { + m_num_eq = 2; + m_data = new data_t[2]; + set_I(0.1); + set_theta(0.2); + } + + ~standard() + { + delete m_data; + } + + virtual void m_step() + { + data_t I = m_data[0]; + data_t theta = m_data[1]; + + m_data[0] = I + m_k * sin(theta); + theta = theta + I + k * sin(theta); + + if (y > 2 * M_PI) + { + do + { + y -= 2*M_PI; + } + while (y > 2 * M_PI); + goto put_data; + } + + if (y < 0) + { + do + { + y += 2*M_PI; + } + while (y < 0); + } + + put_data: + m_data[1] = theta; + } + + + void set_I(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_I() + { + return (t_float)m_data[0]; + } + + + void set_theta(t_float f) + { + if ( (f >= 0) && (f < 2*M_PI)) + m_data[1] = (data_t) f; + else + post("value for theta %f out of range", f); + } + + t_float get_theta() + { + return (t_float)m_data[1]; + } + + + void set_k(t_float f) + { + m_k = (data_t) f; + } + + t_float get_k() + { + return (t_float)m_k; + } + +private: + data_t m_k; +}; + + +#define STANDARD_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_I, m_system->set_I); \ +FLEXT_CALLVAR_F(m_system->get_theta, m_system->set_theta); \ +FLEXT_CALLVAR_F(m_system->get_k, m_system->set_k); + + +#define STANDARD_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("I",m_system->get_I, m_system->set_I); \ +FLEXT_ADDATTR_VAR("theta",m_system->get_theta, m_system->set_theta); \ +FLEXT_ADDATTR_VAR("k",m_system->get_k, m_system->set_k); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp new file mode 100644 index 0000000..16de333 --- /dev/null +++ b/chaos/src/tent_map.hpp @@ -0,0 +1,63 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// tent map: x[n+1] = 2 * x[n] (for 0 < x <= 0.5) +// 2 * (1 - x[n]) (else) +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class tent: + protected map_base +{ +public: + tent() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~tent() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data < 0.5f) + m_data[0] = 2.f * data; + else + m_data[0] = 2.f * (1.f - data); + } +}; + + +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + -- cgit v1.2.1 From 404bfef9e23dfc3166cb2005367e7e8a41863914 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 23 Dec 2004 10:07:17 +0000 Subject: base class macros svn path=/trunk/externals/tb/; revision=2426 --- chaos/src/bernoulli_map.hpp | 29 ++++----- chaos/src/bungalow_tent_map.hpp | 54 ++++++----------- chaos/src/chaos.hpp | 2 +- chaos/src/chaos_base.hpp | 92 +++++++++++++++++++++++++++- chaos/src/circle_map.hpp | 73 ++++++----------------- chaos/src/gauss_map.hpp | 29 ++++----- chaos/src/henon_map.hpp | 90 ++++++++-------------------- chaos/src/ikeda_laser_map.hpp | 126 +++++++++++---------------------------- chaos/src/logistic_map.hpp | 53 ++++++----------- chaos/src/lorenz.hpp | 129 +++++++++++----------------------------- chaos/src/lozi_map.hpp | 90 ++++++++-------------------- chaos/src/sine_map.hpp | 28 ++++----- chaos/src/standard_map.hpp | 68 +++++++-------------- chaos/src/tent_map.hpp | 21 ++++--- 14 files changed, 335 insertions(+), 549 deletions(-) (limited to 'chaos') diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index b006c92..50bca13 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -32,10 +32,10 @@ public: { m_num_eq = 1: m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(x,0.5) } - ~bernoulli() + ~Bernoulli() { delete m_data; } @@ -50,26 +50,19 @@ public: m_data[0] = 2.f * x - 1.f; } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x,0,m_pred_x); + bool m_pred_x(t_float f) { - if ( (f >= 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; + return (f >= 0) && (f < 1); } }; -#define BERNOULLI_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define BERNOULLI_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); -#define BERNOULLI_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define BERNOULLI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 6708eae..dfb6e25 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -37,11 +37,11 @@ class bungalow_tent: { public: bungalow_tent() - : m_r(0.5) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(r, 0.5); } ~bungalow_tent() @@ -52,7 +52,7 @@ public: virtual void m_step() { data_t x = m_data[0]; - data_t r = m_r; + data_t r = CHAOS_PARAMETER(r); if ( x < - 0.5) { @@ -77,45 +77,25 @@ public: } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) { - if ( (f > -1) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_r(t_float f) - { - if ( (f > -.5) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for r %f out of range", f); + return (f >= -1) && (f < 1); } - t_float get_r() + CHAOS_SYSVAR_FUNCS_PRED(r, 0, m_pred_r); + bool m_pred_r(t_float f) { - return (t_float)m_data[0]; + return (f >= -0.5) && (f < 1); } - -private: - data_t m_r; - }; +#define BUNGALOW_TENT_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(r); -#define BUNGALOW_TENT_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ - - -#define BUNGALOW_TENT_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define BUNGALOW_TENT_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x) \ +CHAOS_SYS_ATTRIBUTE(r) diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index d65ba5c..4f51902 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,7 +22,7 @@ #define FLEXT_ATTRIBUTES 1 -#include "flext.h" +//#include "flext.h" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 231580b..a42e275 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,4 +1,4 @@ -// +a// // // chaos~ // Copyright (C) 2004 Tim Blechmann @@ -36,7 +36,6 @@ public: return m_num_eq; } - /* prototype for system function */ virtual void m_step(); data_t * m_data; // state of the system @@ -51,5 +50,94 @@ 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 + + #define __chaos_base_hpp #endif /* __chaos_base_hpp */ diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index f1ef406..02817de 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -29,11 +29,12 @@ class circle_map: { public: circle_map() - : m_omega(0.4), m_r(1) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(omega, 0.4); + CHAOS_SYS_INIT(r, 1); + CHAOS_SYS_INIT(x, 0.5); } ~circle_map() @@ -44,63 +45,27 @@ public: virtual void m_step() { data_t x = m_data[0]; - data_t omega = m_omega; - data_t r = m_r; + data_t omega = CHAOS_PARAMETER(omega); + data_t r = CHAOS_PARAMETER(r); m_data[0] = x + omega - r / (2.f * M_PI) * sin (2.f * M_PI * x); } - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_r(t_float f) - { - m_r = (data_t) f; - } - - - t_float get_r() - { - return (t_float)m_r; - } - - - void set_omega (t_float f) - { - m_omega = (data_t) f; - } - - t_float get_omega() - { - return (t_float)m_omega; - } - - -private: - data_t m_omega; - data_t m_r; + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSPAR_FUNCS(r); + CHAOS_SYSPAR_FUNCS(omega); }; -#define CIRCLE_MAP_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_ATTRVAR_F(m_system->m_omega); \ -FLEXT_ATTRVAR_F(m_system->m_r); \ -FLEXT_CALLVAR_F(m_system->get_omega, m_system->set_omega); \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define CIRCLE_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(omega); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(x); + -#define CIRCLE_MAP_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR1("omega",m_system->m_omega); \ -FLEXT_ADDATTR_VAR1("r",m_system->m_r); \ -FLEXT_ADDATTR_VAR("omega",m_system->get_omega, m_system->set_omega); \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define CIRCLE_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(omega); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index e2316ec..537dcfb 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -33,7 +33,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x,0.5); } ~gauss() @@ -51,27 +51,20 @@ public: m_data[0] = fmod(1.f / data); } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) { - if ( (f >= 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; + return (f >= 0) && (f < 1); } - }; -#define GAUSS_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define GAUSS_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); + +#define GAUSS_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); -#define GAUSS_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index d29e8a7..0aecbee 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -30,12 +30,14 @@ class henon: { public: henon() - : m_a(1.4), m_b(0.3) { m_num_eq = 2; m_data = new data_t[1]; - set_x(0.f); - set_y(0.f); + + CHAOS_SYS_INIT(x,0); + CHAOS_SYS_INIT(y,0); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); } ~henon() @@ -48,74 +50,34 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; - m_data[0] = 1 + y - m_a * x * x; - m_data[1] = m_b * x; - + m_data[0] = 1 + y - CHAOS_PARAMETER(a) * x * x; + m_data[1] = CHAOS_PARAMETER(b) * x; } + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } + CHAOS_SYSPAR_FUNCS(a); - t_float get_y() + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + bool m_pred_b(t_float f) { - return (t_float)m_data[1]; + return (f != 0); } - - - void set_a(t_float f) - { - m_a = (data_t) f; - } - - t_float get_a() - { - return (t_float)m_a; - } - - - void set_b(t_float f) - { - if (f != 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - -private: - data_t m_a; - data_t m_b; }; -#define HENON_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); +#define HENON_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define HENON_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); -#define HENON_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ -FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 39d75c4..ccc14cc 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -36,12 +36,15 @@ class ikeda: { public: ikeda() - : m_c1(0.4), m_c2(0.9), m_c3(9), m_roh(0.85) { m_num_eq = 2; m_data = new data_t[2]; - set_x(0.5); - set_y(0.5); + CHAOS_SYS_INIT(c1,0.4); + CHAOS_SYS_INIT(c2,0.9); + CHAOS_SYS_INIT(c3,9); + CHAOS_SYS_INIT(roh,0.85); + CHAOS_SYS_INIT(x,0.5); + CHAOS_SYS_INIT(y,0.5); } ~ikeda() @@ -54,100 +57,41 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; - data_t tau = m_c1 - m_c3 / (1 + x*x + y*y); + data_t tau = CHAOS_PARAMETER(c1) - + CHAOS_PARAMETER(c3) / (1 + x*x + y*y); data_t cos_tau = cos(tau); data_t sin_tau = sin(tau); - m_data[0] = m_roh + m_c2 * (x * cos_tau - y * sin_tau); - m_data[1] = m_c2 * (x * sin_tau + y * cos_tau); + m_data[0] = CHAOS_PARAMETER(roh) + CHAOS_PARAMETER(c2) + * (x * cos_tau - y * sin_tau); + m_data[1] = CHAOS_PARAMETER(c2) * (x * sin_tau + y * cos_tau); } - - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_y() - { - return (t_float)m_data[1]; - } - - - void set_c1(t_float f) - { - m_c1 = (data_t) f; - } - - t_float get_c1() - { - return (t_float)m_c1; - } - - - void set_c2(t_float f) - { - m_c2[1] = (data_t) f; - } - - t_float get_c2() - { - return (t_float)m_c2; - } - - - void set_c3(t_float f) - { - m_c3 = (data_t) f; - } - - t_float get_c3() - { - return (t_float)m_c3; - } - - - void set_roh(t_float f) - { - m_roh = (data_t) f; - } - - t_float get_roh() - { - return (t_float)m_roh; - } - + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); -private: - data_t m_c1, m_c2, m_c3, m_roh; -}; + CHAOS_PAR_FUNCS(c1); + CHAOS_PAR_FUNCS(c2); + CHAOS_PAR_FUNCS(c3); + CHAOS_PAR_FUNCS(roh); - -#define IKEDA_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_c1, m_system->set_c1); \ -FLEXT_CALLVAR_F(m_system->get_c2, m_system->set_c2); \ -FLEXT_CALLVAR_F(m_system->get_c3, m_system->set_c3); \ -FLEXT_CALLVAR_F(m_system->get_roh, m_system->set_roh); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); \ +}; -#define IKEDA_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("c1",m_system->get_c1, m_system->set_c1); \ -FLEXT_ADDATTR_VAR("c2",m_system->get_c2, m_system->set_c2); \ -FLEXT_ADDATTR_VAR("c3",m_system->get_c3, m_system->set_c3); \ -FLEXT_ADDATTR_VAR("roh",m_system->get_roh, m_system->set_roh); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); +#define IKEDA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(c1); \ +CHAOS_SYS_CALLBACKS(c2); \ +CHAOS_SYS_CALLBACKS(c3); \ +CHAOS_SYS_CALLBACKS(roh); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define IKEDA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(c1); \ +CHAOS_SYS_ATTRIBUTE(c2); \ +CHAOS_SYS_ATTRIBUTE(c3); \ +CHAOS_SYS_ATTRIBUTE(roh); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index c443f45..e0111f7 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -29,11 +29,11 @@ class logistic: { public: logistic() - : m_alpha(3.8) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(alpha, 3.8); + CHAOS_SYS_INIT(x, 0.5); } ~logistic() @@ -44,48 +44,31 @@ public: virtual void m_step() { data_t data = m_data[0]; - data_t alpha = m_alpha; + data_t alpha = CHAOS_PARAMETER(alpha); m_data[0] = alpha * data * (1.f - data); } - void set_alpha(t_float f) + CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); + bool m_pred_alpha(t_float f) { - if ( (f > 0) && (f < 4)) - m_alpha = (data_t) f; - else - post("value for alpha %f out of range", f); + return (f > 0) && (f < 4); } - t_float get_alpha() + CHAOS_SYSVAR_FUNCS_PRED(x, m_pred_x); + + bool m_pred_x(t_float f) { - return (t_float)m_alpha; + return (f > 0) && (f < 1); } - - void set_x(t_float f) - { - if ( (f > 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - -private: - data_t m_alpha; }; -#define LOGISTIC_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_alpha, m_system->set_alpha); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); - -#define LOGISTIC_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("alpha",m_system->get_alpha, m_system->set_alpha); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(x); +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 70dad4d..e3e5ccd 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -30,13 +30,17 @@ class lorenz { public: logistic() - : m_sigma(16), m_b(4), m_r(40) { m_num_eq = 3; m_data = new data_t[3]; - set_x1(0.8f); - set_x2(0.8f); - set_x3(0.8f); + + CHAOS_SYS_INIT(x1,0.8); + CHAOS_SYS_INIT(x2,0.8); + CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(sigma,16); + CHAOS_SYS_INIT(b,4); + CHAOS_SYS_INIT(r,40); + set_method(0); } @@ -49,102 +53,41 @@ public: { data_t x1 = data[0], x2 = data[1], x3 = data[2]; - deriv[0] = m_sigma * (x2 - x1); - deriv[1] = - x1 * x3 + m_r * x1 - x2; - deriv[3] = x1 * x2 - m_b * x3; - } - - void set_x1(t_float f) - { - m_data[0] = (data_t) f; + deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); + deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; + deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } - t_float get_x1() - { - return (t_float)m_data[0]; - } - - void set_x2(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_x2() - { - return (t_float)m_data[1]; - } - - void set_x3(t_float f) - { - m_data[2] = (data_t) f; - } - - t_float get_x3() - { - return (t_float)m_data[2]; - } + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + CHAOS_SYSPAR_FUNCS_PRED(sigma, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred); - void set_sigma(t_float f) + bool m_pred (t_float f) { - if (f > 0) - m_sigma = (data_t) f; - else - post("value for sigma %f out of range", f); + return (f > 0); } - t_float get_sigma() - { - return (t_float)m_sigma; - } - - - void set_r(t_float f) - { - if (f > 0) - m_r = (data_t) f; - else - post("value for r %f out of range", f); - } - - t_float get_r() - { - return (t_float)m_r; - } - - void set_b(t_float f) - { - if (f > 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - - -private: - data_t m_sigma, m_r, m_b; }; -#define LORENZ_CALLBACKS \ -ODE_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ -FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ -FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); - -#define LORENZ_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ -FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ -FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ -FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); \ +CHAOS_SYS_CALLBACKS(sigma); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(b); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); \ +CHAOS_SYS_ATTRIBUTE(sigma); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(b); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 50192c4..8bee655 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -30,12 +30,13 @@ class lozi: { public: lozi() - : m_a(1.4), m_b(0.3) { m_num_eq = 2; m_data = new data_t[1]; - set_x(0.5); - set_y(0.5); + CHAOS_SYS_INIT(x,0); + CHAOS_SYS_INIT(y,0); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); } ~lozi() @@ -49,78 +50,37 @@ public: data_t y = m_data[1]; if (x > 0) - m_data[0] = 1 + y - m_a * x; + m_data[0] = 1 + y - CHAOS_PARAMETER(a) * x; else - m_data[0] = 1 + y + m_a * x; + m_data[0] = 1 + y + CHAOS_PARAMETER(a) * x; - m_data[1] = m_b * x; + m_data[1] = CHAOS_PARAMETER(b) * x; } + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_y() - { - return (t_float)m_data[1]; - } - + CHAOS_SYSPAR_FUNCS(a); - void set_a(t_float f) + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + bool m_pred_b(t_float f) { - m_a = (data_t) f; + return (f != 0); } - - t_float get_a() - { - return (t_float)m_a; - } - - - void set_b(t_float f) - { - if (f != 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - - -private: - data_t m_a; - data_t m_b; }; -#define LOZI_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); +#define LOZI_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); -#define LOZI_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ -FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); +#define LOZI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index dd62458..d083270 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -34,7 +34,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x,0); } ~sine() @@ -47,26 +47,20 @@ public: m_data[0] = sin (M_PI * m_data[0]); } - void set_x(t_float f) - { - if ( (f >= 0) && (f <= 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } + CHAOS_SYSVAR_FUNCS_PRED(x, m_pred); - t_float get_x() + bool m_pred(t_float f) { - return (t_float)m_data[0]; + return (f >= 0) && (f <= 1); } - }; -#define SINE_CALLBACKS \ -MAP_CALLBACKS \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define SINE_CALLBACKS \ +MAP_CALLBACKS \ +CHAOS_SYS_CALLBACKS(x); + +#define SINE_ATTRIBUTES \ +MAP_ATTRIBUTES \ +CHAOS_SYS_ATTRIBUTE(x); -#define SINE_ATTRIBUTES \ -MAP_ATTRIBUTES \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 5f77af9..9515efe 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -31,12 +31,13 @@ class standard: { public: standard() - : m_k(0.8) { m_num_eq = 2; m_data = new data_t[2]; - set_I(0.1); - set_theta(0.2); + + CHAOS_SYS_INIT(I,0.1); + CHAOS_SYS_INIT(theta,0.2); + CHAOS_SYS_INIT(k, 0.8); } ~standard() @@ -48,8 +49,9 @@ public: { data_t I = m_data[0]; data_t theta = m_data[1]; + data_t k = CHAOS_PARAMETER(k); - m_data[0] = I + m_k * sin(theta); + m_data[0] = I + k * sin(theta); theta = theta + I + k * sin(theta); if (y > 2 * M_PI) @@ -76,55 +78,27 @@ public: } - void set_I(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_I() - { - return (t_float)m_data[0]; - } - - - void set_theta(t_float f) - { - if ( (f >= 0) && (f < 2*M_PI)) - m_data[1] = (data_t) f; - else - post("value for theta %f out of range", f); - } - - t_float get_theta() - { - return (t_float)m_data[1]; - } - - - void set_k(t_float f) - { - m_k = (data_t) f; - } + CHAOS_SYSVAR_FUNCS(I, 0); - t_float get_k() + CHAOS_SYSVAR_FUNCS_PRED(theta, 1, m_pred_theta); + bool m_pred_theta(t_float f) { - return (t_float)m_k; + return (f >= 0) && (f < 2*M_PI); } -private: - data_t m_k; + CHAOS_SYSPAR_FUNCS(I, 1); }; -#define STANDARD_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_I, m_system->set_I); \ -FLEXT_CALLVAR_F(m_system->get_theta, m_system->set_theta); \ -FLEXT_CALLVAR_F(m_system->get_k, m_system->set_k); +#define STANDARD_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(I); \ +CHAOS_SYS_CALLBACKS(theta); \ +CHAOS_SYS_CALLBACKS(k); -#define STANDARD_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("I",m_system->get_I, m_system->set_I); \ -FLEXT_ADDATTR_VAR("theta",m_system->get_theta, m_system->set_theta); \ -FLEXT_ADDATTR_VAR("k",m_system->get_k, m_system->set_k); +#define STANDARD_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(I); \ +CHAOS_SYS_ATTRIBUTE(theta); \ +CHAOS_SYS_ATTRIBUTE(k); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 16de333..137599a 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -33,7 +33,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x, 0.5); } ~tent() @@ -50,14 +50,21 @@ public: else m_data[0] = 2.f * (1.f - data); } + + CHAOS_SYSPAR_FUNCS_PRED(x, m_pred_x); + bool m_pred_x(t_float f) + { + return (f >= 0) && (f < 1); + } }; -#define LOGISTIC_CALLBACKS \ -MAP_CALLBACKS \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS \ +CHAOS_SYS_CALLBACKS(x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES \ +CHAOS_SYS_ATTRIBUTE(x); -#define LOGISTIC_ATTRIBUTES \ -MAP_ATTRIBUTES \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); -- cgit v1.2.1 From 45932d6b4b33ecd4f4dc2e7eab9f210dfa46cc34 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 15:31:14 +0000 Subject: xmas's changes svn path=/trunk/externals/tb/; revision=2427 --- chaos/src/Makefile.am | 13 +-- chaos/src/chaos.hpp | 3 +- chaos/src/chaos_base.hpp | 103 +++------------------ chaos/src/chaos_dsp.cpp | 171 ---------------------------------- chaos/src/chaos_dsp.hpp | 223 ++++++++++++++++++++++++++++++++++++++++++++- chaos/src/logistic_map.hpp | 2 +- chaos/src/lorenz.hpp | 8 +- chaos/src/main.cpp | 6 +- chaos/src/ode_base.cpp | 2 +- chaos/src/ode_base.hpp | 42 ++++----- 10 files changed, 269 insertions(+), 304 deletions(-) (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 9f99c3f..43ad73b 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,6 +1,7 @@ -NAME = chaos~ +NAME = chaos -BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp +BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ + lorenz_dsp.cpp CXXFLAGS = @CXXFLAGS@ \ @@ -17,7 +18,7 @@ FRAMEWORKS = @FRAMEWORKS@ TARGET =$(NAME).@EXTENSION@ -OBJECTS = $(patsubst %.cpp,./%.@OBJEXT@,$(BUILT_SOURCES)) +OBJECTS = $(patsubst %.cpp,%.@OBJEXT@,$(BUILT_SOURCES)) SYSDIR = @SYSDIR@ @@ -26,10 +27,10 @@ SYSDIR = @SYSDIR@ all-local: $(OBJECTS) - $(CXX) $(LDFLAGS) -shared ./*.@OBJEXT@ $(LIBS) -o ../$(TARGET) + $(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o ../$(TARGET) strip --strip-unneeded ../$(TARGET) -./%.@OBJEXT@ : %.cpp +%.@OBJEXT@ : %.cpp $(CXX) -c $(CXXFLAGS) $< -o $@ dist-hook: @@ -38,7 +39,7 @@ dist-hook: clean-local: rm -f ../$(TARGET) - rm -f ../obj/* + rm -f ./*.@OBJEXT@ install-exec-local: install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 4f51902..65a9c46 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,7 +22,7 @@ #define FLEXT_ATTRIBUTES 1 -//#include "flext.h" +#include "flext.h" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION @@ -31,5 +31,6 @@ typedef double data_t; typedef t_float data_t; #endif + #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index a42e275..795383e 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,4 +1,4 @@ -a// +// // // chaos~ // Copyright (C) 2004 Tim Blechmann @@ -21,6 +21,7 @@ a// #ifndef __chaos_base_hpp #include "chaos.hpp" +#include "chaos_defs.hpp" class chaos_base { @@ -36,7 +37,9 @@ public: return m_num_eq; } - virtual void m_step(); + virtual void m_step() + { + } data_t * m_data; // state of the system @@ -45,98 +48,16 @@ protected: }; #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); +void get_dimension(int &i) \ +{ \ + i = m_system->get_num_eq(); \ +} \ +FLEXT_CALLGET_I(get_dimension); -#define CHAOS_SYS_INIT(NAME, VALUE) \ -set_##NAME(VALUE); +#define CHAOS_ATTRIBUTES \ +FLEXT_ADDATTR_GET("dimension",get_dimension); -#define CHAOS_PARAMETER(NAME) m_##NAME #define __chaos_base_hpp diff --git a/chaos/src/chaos_dsp.cpp b/chaos/src/chaos_dsp.cpp index 790be06..2040312 100644 --- a/chaos/src/chaos_dsp.cpp +++ b/chaos/src/chaos_dsp.cpp @@ -20,174 +20,3 @@ #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(); -} diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 12efaa8..65e6203 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -20,12 +20,12 @@ #include "chaos_base.hpp" -class chaos_dsp +template class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp); -protected: +public: /* signal functions: */ /* for frequency = sr/2 */ @@ -38,11 +38,15 @@ protected: void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); 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); - + virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) + { + m_sr = Samplerate(); + } + + /* local data for system, output and interpolation */ - chaos_base * m_system; /* the system */ + system * m_system; /* the system */ t_sample * m_values; /* actual value */ t_sample * m_slopes; /* actual slope for cubic interpolation */ @@ -59,3 +63,212 @@ protected: char m_method; /* interpolation method */ }; + + +/* create constructor / destructor */ \ +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +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 +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; + } +} + +template +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); + } + } + +} + +template +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 */ + +template +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; +} + + +template +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; +} diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index e0111f7..94b38d0 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -54,7 +54,7 @@ public: return (f > 0) && (f < 4); } - CHAOS_SYSVAR_FUNCS_PRED(x, m_pred_x); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e3e5ccd..700e4a1 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,14 +26,16 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : protected ode_base + : public ode_base { public: - logistic() + 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); CHAOS_SYS_INIT(x3,0.8); @@ -44,7 +46,7 @@ public: set_method(0); } - ~logistic() + ~lorenz() { delete m_data; } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index df25010..b0f2ad0 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,9 @@ void chaos_library_setup() { - post("chaos~ version"PACKAGE_VERSION"\n"); + post("chaos~ version "PACKAGE_VERSION"\n"); + + FLEXT_DSP_SETUP(lorenz_dsp); } - + FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index cfedeee..9665d83 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -83,7 +83,7 @@ void ode_base::m_step() rk2(); break; case 2: - rk3(); + rk4(); break; } diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 5fdd6d1..6fa7e27 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -24,14 +24,15 @@ #include "chaos_base.hpp" class ode_base - : protected chaos_base + : public chaos_base { public: void set_method(int i) { if (i >=0 && i <4) m_method = (unsigned char) i; - post("no such method"); + else + post("no such method"); } t_int get_method() @@ -39,44 +40,39 @@ public: return (int) m_method; } - 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() + CHAOS_SYSPAR_FUNCS_PRED(dt, m_pred_dt); + + bool m_pred_dt(t_float f) { - return (t_float) m_dt; + return (f >= 0); } - void m_step(); + virtual 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); + virtual void m_system (data_t* deriv, data_t* data) + { + } void rk1 (); void rk2 (); void rk4 (); }; -#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_CALLBACKS \ +CHAOS_CALLBACKS; \ +CHAOS_SYS_CALLBACKS_I(method); \ +CHAOS_SYS_CALLBACKS(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); +#define ODE_ATTRIBUTES \ +CHAOS_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(method); \ +CHAOS_SYS_ATTRIBUTE(dt); #define __ode_base_hpp -- cgit v1.2.1 From 5c3670b6322b60b8bc5f60e22d891fe39b854e3e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 23:20:22 +0000 Subject: more changes ... getting stable ... svn path=/trunk/externals/tb/; revision=2428 --- chaos/configure.ac | 5 ++++- chaos/src/Makefile.am | 2 +- chaos/src/chaos_dsp.hpp | 25 +++++++++++++++---------- chaos/src/logistic_map.hpp | 2 +- chaos/src/lorenz.hpp | 5 ++++- chaos/src/main.cpp | 2 +- chaos/src/map_base.hpp | 2 +- chaos/src/ode_base.hpp | 22 ++++++++++++++++++++++ 8 files changed, 49 insertions(+), 16 deletions(-) (limited to 'chaos') diff --git a/chaos/configure.ac b/chaos/configure.ac index c228f01..67bf056 100644 --- a/chaos/configure.ac +++ b/chaos/configure.ac @@ -49,7 +49,10 @@ AC_ARG_ENABLE(system, AC_ARG_WITH(sysdir, [ --with-sysdir path pd / max installation], - SYSDIR=$withval, + [ + SYSDIR=$withval + INCLUDEDIR="-I$withval $INCLUDEDIR" + ], [echo "path to pd / max installation required" && exit 1]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 43ad73b..efbb7f1 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,7 +1,7 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ - lorenz_dsp.cpp + lorenz_dsp.cpp logistic_dsp.cpp CXXFLAGS = @CXXFLAGS@ \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 65e6203..c340b88 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -60,12 +60,12 @@ public: int m_phase; /* phase counter */ float m_sr; /* sample rate */ - char m_method; /* interpolation method */ + int m_method; /* interpolation method */ }; -/* create constructor / destructor */ \ +/* create constructor / destructor */ #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ @@ -87,7 +87,10 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ m_freq = GetAFloat(argv[0]); \ m_method = (char)GetAFloat(argv[1]); \ m_phase = 0; \ - \ + \ + FLEXT_ADDATTR_VAR1("frequency",m_freq); \ + FLEXT_ADDATTR_VAR1("method",m_method); \ + \ ATTRIBUTES; \ } \ \ @@ -99,21 +102,23 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ delete m_nextvalues; \ delete m_nextmidpts; \ delete m_curves; \ -} - +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_I(m_method); template void chaos_dsp::m_signal(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { if (m_freq >= m_sr * 0.5) { m_signal_(n, insigs, outsigs); return; } - + switch (m_method) { case 0: @@ -157,7 +162,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); @@ -194,7 +199,7 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); @@ -233,7 +238,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 94b38d0..e72a3a7 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -25,7 +25,7 @@ // 0 <= alpha <= 4 class logistic: - protected map_base + public map_base { public: logistic() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 700e4a1..fdae428 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -32,7 +32,7 @@ public: lorenz() { m_num_eq = 3; - m_data = new data_t[3]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); CHAOS_SYS_INIT(dt,1); @@ -43,11 +43,14 @@ public: CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); + ode_base_alloc(); + set_method(0); } ~lorenz() { + ode_base_free(); delete m_data; } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index b0f2ad0..3a322f0 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -19,13 +19,13 @@ // Boston, MA 02111-1307, USA. #include "chaos.hpp" -#include "logistic_map.hpp" void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); FLEXT_DSP_SETUP(lorenz_dsp); + FLEXT_DSP_SETUP(logistic_dsp); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 35c8460..c88f9ba 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -24,7 +24,7 @@ #include "chaos_base.hpp" class map_base - : protected chaos_base + : public chaos_base { }; diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 6fa7e27..cc526ae 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -49,6 +49,28 @@ public: virtual void m_step(); + void ode_base_alloc() + { + int dimension = get_num_eq(); + + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[dimension]; + } + + m_tmp = new data_t[dimension]; + } + + void ode_base_free() + { + for (int i = 0; i != 3; ++i) + { + delete m_k[i]; + } + + delete m_tmp; + } + protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ -- cgit v1.2.1 From eced45909ba691a454fec179360ec1c2663f773a Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 25 Dec 2004 12:50:41 +0000 Subject: getting stable svn path=/trunk/externals/tb/; revision=2429 --- chaos/src/Makefile.am | 3 ++- chaos/src/chaos_dsp.hpp | 9 ++++----- chaos/src/lorenz.hpp | 8 ++++---- chaos/src/main.cpp | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index efbb7f1..e1018bd 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,7 +1,8 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ - lorenz_dsp.cpp logistic_dsp.cpp + lorenz_dsp.cpp lorenz_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp CXXFLAGS = @CXXFLAGS@ \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index c340b88..f03f7c9 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -185,8 +185,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, } -/* linear and cubic interpolation adapted from supercollider by James McCartney */ - +/* linear interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -226,6 +225,7 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } +/* linear interpolation adapted from Numerical Recipes In C */ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -253,10 +253,9 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, 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]) + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - + fseglen * m_slopes[j]) / (fseglen * fseglen + fseglen); - - m_values[j] = value; } } diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index fdae428..a31c151 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -35,10 +35,10 @@ public: m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,1); + CHAOS_SYS_INIT(dt,0.01); CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.8); - CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(x2,0.7); + CHAOS_SYS_INIT(x3,0.6); CHAOS_SYS_INIT(sigma,16); CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); @@ -60,7 +60,7 @@ public: deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; - deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; + deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } CHAOS_SYSVAR_FUNCS(x1, 0); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 3a322f0..42dc16d 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -25,7 +25,10 @@ void chaos_library_setup() post("chaos~ version "PACKAGE_VERSION"\n"); FLEXT_DSP_SETUP(lorenz_dsp); + FLEXT_SETUP(lorenz_msg); + FLEXT_DSP_SETUP(logistic_dsp); + FLEXT_SETUP(logistic_msg); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); -- cgit v1.2.1 From b2f2fd990f9059db784a7849726c6fc5006c70f9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 27 Dec 2004 14:44:11 +0000 Subject: a lot of new objects ... svn path=/trunk/externals/tb/; revision=2431 --- chaos/src/Makefile.am | 14 +++- chaos/src/bernoulli_dsp.cpp | 34 ++++++++++ chaos/src/bernoulli_map.hpp | 11 +-- chaos/src/bernoulli_msg.cpp | 34 ++++++++++ chaos/src/bungalow_tent_dsp.cpp | 34 ++++++++++ chaos/src/bungalow_tent_map.hpp | 6 +- chaos/src/bungalow_tent_msg.cpp | 34 ++++++++++ chaos/src/chaos_defs.hpp | 137 ++++++++++++++++++++++++++++++++++++++ chaos/src/chaos_dsp.hpp | 21 ++++-- chaos/src/chaos_msg.hpp | 68 +++++++++++++++++++ chaos/src/circle_map.hpp | 12 ++-- chaos/src/circle_map_dsp.cpp | 34 ++++++++++ chaos/src/circle_map_msg.cpp | 34 ++++++++++ chaos/src/gauss_map.hpp | 20 +++--- chaos/src/gauss_map_dsp.cpp | 34 ++++++++++ chaos/src/gauss_map_msg.cpp | 34 ++++++++++ chaos/src/henon_map.hpp | 2 +- chaos/src/henon_map_dsp.cpp | 34 ++++++++++ chaos/src/henon_map_msg.cpp | 34 ++++++++++ chaos/src/ikeda_laser_map.hpp | 20 +++--- chaos/src/ikeda_laser_map_dsp.cpp | 34 ++++++++++ chaos/src/ikeda_laser_map_msg.cpp | 34 ++++++++++ chaos/src/logistic_dsp.cpp | 34 ++++++++++ chaos/src/logistic_msg.cpp | 34 ++++++++++ chaos/src/lorenz_dsp.cpp | 34 ++++++++++ chaos/src/lorenz_msg.cpp | 34 ++++++++++ chaos/src/lozi_map.hpp | 12 ++-- chaos/src/lozi_map_dsp.cpp | 34 ++++++++++ chaos/src/lozi_map_msg.cpp | 34 ++++++++++ chaos/src/main.cpp | 34 +++++++++- chaos/src/sine_map.hpp | 14 ++-- chaos/src/sine_map_dsp.cpp | 34 ++++++++++ chaos/src/sine_map_msg.cpp | 34 ++++++++++ chaos/src/standard_map.hpp | 26 ++++---- chaos/src/standard_map_dsp.cpp | 34 ++++++++++ chaos/src/standard_map_msg.cpp | 34 ++++++++++ chaos/src/tent_map.hpp | 14 ++-- chaos/src/tent_map_dsp.cpp | 34 ++++++++++ chaos/src/tent_map_msg.cpp | 34 ++++++++++ 39 files changed, 1152 insertions(+), 75 deletions(-) create mode 100644 chaos/src/bernoulli_dsp.cpp create mode 100644 chaos/src/bernoulli_msg.cpp create mode 100644 chaos/src/bungalow_tent_dsp.cpp create mode 100644 chaos/src/bungalow_tent_msg.cpp create mode 100644 chaos/src/chaos_defs.hpp create mode 100644 chaos/src/chaos_msg.hpp create mode 100644 chaos/src/circle_map_dsp.cpp create mode 100644 chaos/src/circle_map_msg.cpp create mode 100644 chaos/src/gauss_map_dsp.cpp create mode 100644 chaos/src/gauss_map_msg.cpp create mode 100644 chaos/src/henon_map_dsp.cpp create mode 100644 chaos/src/henon_map_msg.cpp create mode 100644 chaos/src/ikeda_laser_map_dsp.cpp create mode 100644 chaos/src/ikeda_laser_map_msg.cpp create mode 100644 chaos/src/logistic_dsp.cpp create mode 100644 chaos/src/logistic_msg.cpp create mode 100644 chaos/src/lorenz_dsp.cpp create mode 100644 chaos/src/lorenz_msg.cpp create mode 100644 chaos/src/lozi_map_dsp.cpp create mode 100644 chaos/src/lozi_map_msg.cpp create mode 100644 chaos/src/sine_map_dsp.cpp create mode 100644 chaos/src/sine_map_msg.cpp create mode 100644 chaos/src/standard_map_dsp.cpp create mode 100644 chaos/src/standard_map_msg.cpp create mode 100644 chaos/src/tent_map_dsp.cpp create mode 100644 chaos/src/tent_map_msg.cpp (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index e1018bd..a524de5 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,9 +1,18 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ + bernoulli_dsp.cpp bernoulli_msg.cpp \ + bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ + circle_map_dsp.cpp circle_map_msg.cpp \ + gauss_map_dsp.cpp gauss_map_msg.cpp \ + henon_map_dsp.cpp henon_map_msg.cpp \ + ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp - + lozi_map_dsp.cpp lozi_map_msg.cpp \ + sine_map_dsp.cpp sine_map_msg.cpp \ + standard_map_dsp.cpp standard_map_msg.cpp \ + tent_map_dsp.cpp tent_map_msg.cpp CXXFLAGS = @CXXFLAGS@ \ @OPT_FLAGS@ \ @@ -37,6 +46,7 @@ all-local: $(OBJECTS) dist-hook: rm -f ./*~ rm -f ./*.@OBJEXT@ + rm ./Makefile clean-local: rm -f ../$(TARGET) diff --git a/chaos/src/bernoulli_dsp.cpp b/chaos/src/bernoulli_dsp.cpp new file mode 100644 index 0000000..8e8d0da --- /dev/null +++ b/chaos/src/bernoulli_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_dsp.hpp" + +class bernoulli_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(bernoulli, BERNOULLI_ATTRIBUTES); + + BERNOULLI_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("bernoulli~", bernoulli_dsp); diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 50bca13..25d19f8 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -25,17 +25,17 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bernoulli: - protected map_base + public map_base { public: bernoulli() { - m_num_eq = 1: + m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(x,0.5) + CHAOS_SYS_INIT(x,0.5); } - ~Bernoulli() + ~bernoulli() { delete m_data; } @@ -43,6 +43,9 @@ public: virtual void m_step() { data_t x = m_data[0]; + + if (x <= 0) + x = 0.00001; //stability if (x < 0.5f) m_data[0] = 2.f * x; diff --git a/chaos/src/bernoulli_msg.cpp b/chaos/src/bernoulli_msg.cpp new file mode 100644 index 0000000..8e07ed5 --- /dev/null +++ b/chaos/src/bernoulli_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_msg.hpp" + +class bernoulli_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(bernoulli, BERNOULLI_ATTRIBUTES); + + BERNOULLI_CALLBACKS; +}; + + + +FLEXT_LIB_V("bernoulli", bernoulli_msg); diff --git a/chaos/src/bungalow_tent_dsp.cpp b/chaos/src/bungalow_tent_dsp.cpp new file mode 100644 index 0000000..33bef1c --- /dev/null +++ b/chaos/src/bungalow_tent_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_dsp.hpp" + +class bungalow_tent_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); + + BUNGALOW_TENT_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("bungalow_tent~", bungalow_tent_dsp); diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index dfb6e25..185753a 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -33,14 +33,14 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bungalow_tent: - protected map_base + public map_base { public: bungalow_tent() { m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(x, 0.6); CHAOS_SYS_INIT(r, 0.5); } @@ -83,7 +83,7 @@ public: return (f >= -1) && (f < 1); } - CHAOS_SYSVAR_FUNCS_PRED(r, 0, m_pred_r); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); bool m_pred_r(t_float f) { return (f >= -0.5) && (f < 1); diff --git a/chaos/src/bungalow_tent_msg.cpp b/chaos/src/bungalow_tent_msg.cpp new file mode 100644 index 0000000..8c6b1be --- /dev/null +++ b/chaos/src/bungalow_tent_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_msg.hpp" + +class bungalow_tent_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); + + BUNGALOW_TENT_CALLBACKS; +}; + + + +FLEXT_LIB_V("bungalow_tent", bungalow_tent_msg); diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp new file mode 100644 index 0000000..ae86223 --- /dev/null +++ b/chaos/src/chaos_defs.hpp @@ -0,0 +1,137 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_defs_hpp + + +// 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) \ +CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ +CHAOS_SYS_GETFUNC(NAME, NR) + +#define CHAOS_SYSVAR_FUNCS(NAME, NR) \ +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) \ +CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYSPAR_FUNCS(NAME) \ +public: \ +CHAOS_PAR_SETFUNC(NAME) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYSPAR_FUNCS_I(NAME) \ +CHAOS_PAR_SETFUNC(NAME) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYS_CALLBACKS(NAME) \ +public:void get_##NAME(t_float &f) \ +{ \ + f = m_system->get_##NAME(); \ +} \ +void set_##NAME(t_float &f) \ +{ \ + m_system->set_##NAME(f); \ +} \ +FLEXT_CALLVAR_F(get_##NAME, set_##NAME); + +#define CHAOS_SYS_CALLBACKS_I(NAME) \ +public: \ +void get_##NAME(int &i) \ +{ \ + i = m_system->get_##NAME(); \ +} \ +void set_##NAME(int &i) \ +{ \ + m_system->set_##NAME(i); \ +} \ +FLEXT_CALLVAR_I(get_##NAME, set_##NAME); + + +#define CHAOS_SYS_ATTRIBUTE(NAME) \ +FLEXT_ADDATTR_VAR(#NAME,get_##NAME, set_##NAME); + +#define CHAOS_SYS_INIT(NAME, VALUE) \ +set_##NAME(VALUE); + +#define CHAOS_PARAMETER(NAME) m_##NAME + + + + + + +#define __chaos_defs_hpp +#endif /* __chaos_defs_hpp */ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index f03f7c9..1eff6fc 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -75,15 +75,25 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ \ 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]; \ \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + \ + \ m_freq = GetAFloat(argv[0]); \ m_method = (char)GetAFloat(argv[1]); \ m_phase = 0; \ @@ -185,7 +195,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, } -/* linear interpolation adapted from supercollider by James McCartney */ +/* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -225,7 +235,6 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } -/* linear interpolation adapted from Numerical Recipes In C */ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -250,7 +259,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, m_nextvalues[j]= m_system->get_data(j); m_values[j] = m_nextmidpts[j]; - m_nextmidpts[j] = (m_values[j] + value) * 0.5f; + m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; float fseglen = (float)phase; m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp new file mode 100644 index 0000000..78bca06 --- /dev/null +++ b/chaos/src/chaos_msg.hpp @@ -0,0 +1,68 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +template class chaos_msg + : public flext_base +{ + FLEXT_HEADER(chaos_msg, flext_base); + +public: + + /* local data for system, output and interpolation */ + system * m_system; /* the system */ + + void m_bang() + { + m_system->m_step(); + int outlets = m_system->get_num_eq(); + + while (outlets--) + { + ToOutFloat(outlets, m_system->get_data(outlets)); + } + } + + FLEXT_CALLBACK(m_bang); +}; + + +/* create constructor / destructor */ +#define CHAOS_MSG_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_msg, chaos_msg) \ + \ +SYSTEM##_msg(int argc, t_atom* argv ) \ +{ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + for (int i = 0; i != size; ++i) \ + AddOutFloat(); \ + \ + ATTRIBUTES; \ + FLEXT_ADDBANG(0, m_bang); \ +} \ + \ +~SYSTEM##_msg() \ +{ \ + delete m_system; \ +} diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 02817de..0e12ad0 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -20,21 +20,23 @@ #include "map_base.hpp" -// circle_map map: x[n+1] = x[n] * omega - r / (2*pi) * sin (2 * pi * x [n]) +#include + +// circle_map map: x[n+1] = x[n] + omega - r / (2*pi) * sin (2 * pi * x [n]) // // taken from Willi-Hans Steeb: Chaos and Fractals class circle_map: - protected map_base + public map_base { public: circle_map() { m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(omega, 0.4); - CHAOS_SYS_INIT(r, 1); - CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(omega, 0.1); + CHAOS_SYS_INIT(r, 3); + CHAOS_SYS_INIT(x, 0.4); } ~circle_map() diff --git a/chaos/src/circle_map_dsp.cpp b/chaos/src/circle_map_dsp.cpp new file mode 100644 index 0000000..fbd7c9d --- /dev/null +++ b/chaos/src/circle_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_dsp.hpp" + +class circle_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); + + CIRCLE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("circle_map~", circle_map_dsp); diff --git a/chaos/src/circle_map_msg.cpp b/chaos/src/circle_map_msg.cpp new file mode 100644 index 0000000..3e771b3 --- /dev/null +++ b/chaos/src/circle_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_msg.hpp" + +class circle_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); + + CIRCLE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("circle_map", circle_map_msg); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 537dcfb..523b1ca 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -20,23 +20,25 @@ #include "map_base.hpp" +#include + // gauss map: x[n+1] = 0 (for x[n] = 0) -// fmod(1 / x[n]) (else) +// fmod(1 / x[n], 1) (else) // 0 <= x[n] < 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class gauss: - protected map_base +class gauss_map: + public map_base { public: - gauss() + gauss_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x,0.5); } - ~gauss() + ~gauss_map() { delete m_data; } @@ -46,9 +48,9 @@ public: data_t data = m_data[0]; if (data == 0) - m_data[0] = 0; + m_data[0] = 0.001; else - m_data[0] = fmod(1.f / data); + m_data[0] = fmod(1.f / data, 1); } CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); @@ -58,11 +60,11 @@ public: } }; -#define GAUSS_CALLBACKS \ +#define GAUSS_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(x); -#define GAUSS_ATTRIBUTES \ +#define GAUSS_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/gauss_map_dsp.cpp b/chaos/src/gauss_map_dsp.cpp new file mode 100644 index 0000000..70e659d --- /dev/null +++ b/chaos/src/gauss_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_dsp.hpp" + +class gauss_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); + + GAUSS_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("gauss_map~", gauss_map_dsp); diff --git a/chaos/src/gauss_map_msg.cpp b/chaos/src/gauss_map_msg.cpp new file mode 100644 index 0000000..61e0379 --- /dev/null +++ b/chaos/src/gauss_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_msg.hpp" + +class gauss_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); + + GAUSS_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("gauss_map", gauss_map_msg); diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 0aecbee..9e379ae 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -26,7 +26,7 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class henon: - protected map_base + public map_base { public: henon() diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp new file mode 100644 index 0000000..f28e83f --- /dev/null +++ b/chaos/src/henon_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_dsp.hpp" + +class henon_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(henon, HENON_ATTRIBUTES); + + HENON_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("henon~", henon_dsp); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp new file mode 100644 index 0000000..10849fd --- /dev/null +++ b/chaos/src/henon_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_msg.hpp" + +class henon_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(henon, HENON_ATTRIBUTES); + + HENON_CALLBACKS; +}; + + + +FLEXT_LIB_V("henon", henon_msg); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index ccc14cc..e267204 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -31,11 +31,11 @@ // // taken from Willi-Hans Steeb: Chaos and Fractals -class ikeda: - protected map_base +class ikeda_laser_map: + public map_base { public: - ikeda() + ikeda_laser_map() { m_num_eq = 2; m_data = new data_t[2]; @@ -47,7 +47,7 @@ public: CHAOS_SYS_INIT(y,0.5); } - ~ikeda() + ~ikeda_laser_map() { delete m_data; } @@ -70,15 +70,15 @@ public: CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); - CHAOS_PAR_FUNCS(c1); - CHAOS_PAR_FUNCS(c2); - CHAOS_PAR_FUNCS(c3); - CHAOS_PAR_FUNCS(roh); + CHAOS_SYSPAR_FUNCS(c1); + CHAOS_SYSPAR_FUNCS(c2); + CHAOS_SYSPAR_FUNCS(c3); + CHAOS_SYSPAR_FUNCS(roh); }; -#define IKEDA_CALLBACKS \ +#define IKEDA_LASER_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(c1); \ CHAOS_SYS_CALLBACKS(c2); \ @@ -87,7 +87,7 @@ CHAOS_SYS_CALLBACKS(roh); \ CHAOS_SYS_CALLBACKS(x); \ CHAOS_SYS_CALLBACKS(y); -#define IKEDA_ATTRIBUTES \ +#define IKEDA_LASER_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(c1); \ CHAOS_SYS_ATTRIBUTE(c2); \ diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp new file mode 100644 index 0000000..cf7c9cf --- /dev/null +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_dsp.hpp" + +class ikeda_laser_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); + + IKEDA_LASER_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("ikeda~", ikeda_laser_map_dsp); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp new file mode 100644 index 0000000..d5f775a --- /dev/null +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_msg.hpp" + +class ikeda_laser_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); + + IKEDA_LASER_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("ikeda_laser_map", ikeda_laser_map_msg); diff --git a/chaos/src/logistic_dsp.cpp b/chaos/src/logistic_dsp.cpp new file mode 100644 index 0000000..1c20a05 --- /dev/null +++ b/chaos/src/logistic_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_dsp.hpp" + +class logistic_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(logistic, LOGISTIC_ATTRIBUTES); + + LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("logistic~", logistic_dsp); diff --git a/chaos/src/logistic_msg.cpp b/chaos/src/logistic_msg.cpp new file mode 100644 index 0000000..db7bcbf --- /dev/null +++ b/chaos/src/logistic_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_msg.hpp" + +class logistic_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(logistic, LOGISTIC_ATTRIBUTES); + + LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_V("logistic", logistic_msg); diff --git a/chaos/src/lorenz_dsp.cpp b/chaos/src/lorenz_dsp.cpp new file mode 100644 index 0000000..8dc3763 --- /dev/null +++ b/chaos/src/lorenz_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_dsp.hpp" + +class lorenz_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(lorenz, LORENZ_ATTRIBUTES); + + LORENZ_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("lorenz~", lorenz_dsp); diff --git a/chaos/src/lorenz_msg.cpp b/chaos/src/lorenz_msg.cpp new file mode 100644 index 0000000..6ad3ed9 --- /dev/null +++ b/chaos/src/lorenz_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_msg.hpp" + +class lorenz_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(lorenz, LORENZ_ATTRIBUTES); + + LORENZ_CALLBACKS; +}; + + + +FLEXT_LIB_V("lorenz", lorenz_msg); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 8bee655..37cab54 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -25,11 +25,11 @@ // b != 0 // taken from Willi-Hans Steeb: Chaos and Fractals -class lozi: - protected map_base +class lozi_map: + public map_base { public: - lozi() + lozi_map() { m_num_eq = 2; m_data = new data_t[1]; @@ -39,7 +39,7 @@ public: CHAOS_SYS_INIT(b,0.3); } - ~lozi() + ~lozi_map() { delete m_data; } @@ -71,14 +71,14 @@ public: }; -#define LOZI_CALLBACKS \ +#define LOZI_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(b); \ CHAOS_SYS_CALLBACKS(x); \ CHAOS_SYS_CALLBACKS(y); -#define LOZI_ATTRIBUTES \ +#define LOZI_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(b); \ diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp new file mode 100644 index 0000000..f8c4695 --- /dev/null +++ b/chaos/src/lozi_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_dsp.hpp" + +class lozi_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); + + LOZI_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("lozi~", lozi_map_dsp); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp new file mode 100644 index 0000000..947e772 --- /dev/null +++ b/chaos/src/lozi_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_msg.hpp" + +class lozi_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); + + LOZI_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("lozi", lozi_map_msg); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 42dc16d..16f2908 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,12 +23,42 @@ void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); + + FLEXT_DSP_SETUP(bernoulli_dsp); + FLEXT_SETUP(bernoulli_msg); + + FLEXT_DSP_SETUP(bungalow_tent_dsp); + FLEXT_SETUP(bungalow_tent_msg); + + FLEXT_DSP_SETUP(circle_map_dsp); + FLEXT_SETUP(circle_map_msg); + + FLEXT_DSP_SETUP(gauss_map_dsp); + FLEXT_SETUP(gauss_map_msg); + + FLEXT_DSP_SETUP(henon_dsp); + FLEXT_SETUP(henon_msg); + + FLEXT_DSP_SETUP(ikeda_laser_map_dsp); + FLEXT_SETUP(ikeda_laser_map_msg); + FLEXT_DSP_SETUP(logistic_dsp); + FLEXT_SETUP(logistic_msg); + FLEXT_DSP_SETUP(lorenz_dsp); FLEXT_SETUP(lorenz_msg); - FLEXT_DSP_SETUP(logistic_dsp); - FLEXT_SETUP(logistic_msg); + FLEXT_DSP_SETUP(lozi_map_dsp); + FLEXT_SETUP(lozi_map_msg); + + FLEXT_DSP_SETUP(sine_map_dsp); + FLEXT_SETUP(sine_map_msg); + + FLEXT_DSP_SETUP(standard_map_dsp); + FLEXT_SETUP(standard_map_msg); + + FLEXT_DSP_SETUP(tent_map_dsp); + FLEXT_SETUP(tent_map_msg); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index d083270..376a245 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -25,19 +25,19 @@ // 0 <= x[n] <= 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class sine: - protected map_base +class sine_map: + public map_base { public: - sine() + sine_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x,0); } - ~sine() + ~sine_map() { delete m_data; } @@ -47,7 +47,7 @@ public: m_data[0] = sin (M_PI * m_data[0]); } - CHAOS_SYSVAR_FUNCS_PRED(x, m_pred); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred); bool m_pred(t_float f) { @@ -55,11 +55,11 @@ public: } }; -#define SINE_CALLBACKS \ +#define SINE_MAP_CALLBACKS \ MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define SINE_ATTRIBUTES \ +#define SINE_MAP_ATTRIBUTES \ MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/sine_map_dsp.cpp b/chaos/src/sine_map_dsp.cpp new file mode 100644 index 0000000..a2d2929 --- /dev/null +++ b/chaos/src/sine_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_dsp.hpp" + +class sine_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(sine_map, SINE_MAP_ATTRIBUTES); + + SINE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("sine_map~", sine_map_dsp); diff --git a/chaos/src/sine_map_msg.cpp b/chaos/src/sine_map_msg.cpp new file mode 100644 index 0000000..1d9a90e --- /dev/null +++ b/chaos/src/sine_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_msg.hpp" + +class sine_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(sine_map, SINE_MAP_ATTRIBUTES); + + SINE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("sine_map", sine_map_msg); diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 9515efe..c0f0b8d 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -26,11 +26,11 @@ // 0 <= theta <= 2*pi // taken from Willi-Hans Steeb: Chaos and Fractals -class standard: - protected map_base +class standard_map: + public map_base { public: - standard() + standard_map() { m_num_eq = 2; m_data = new data_t[2]; @@ -40,7 +40,7 @@ public: CHAOS_SYS_INIT(k, 0.8); } - ~standard() + ~standard_map() { delete m_data; } @@ -54,23 +54,23 @@ public: m_data[0] = I + k * sin(theta); theta = theta + I + k * sin(theta); - if (y > 2 * M_PI) + if (theta > 2 * M_PI) { do { - y -= 2*M_PI; + theta -= 2*M_PI; } - while (y > 2 * M_PI); + while (theta > 2 * M_PI); goto put_data; } - if (y < 0) + if (theta < 0) { do { - y += 2*M_PI; + theta += 2*M_PI; } - while (y < 0); + while (theta < 0); } put_data: @@ -86,18 +86,18 @@ public: return (f >= 0) && (f < 2*M_PI); } - CHAOS_SYSPAR_FUNCS(I, 1); + CHAOS_SYSPAR_FUNCS(k); }; -#define STANDARD_CALLBACKS \ +#define STANDARD_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(I); \ CHAOS_SYS_CALLBACKS(theta); \ CHAOS_SYS_CALLBACKS(k); -#define STANDARD_ATTRIBUTES \ +#define STANDARD_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(I); \ CHAOS_SYS_ATTRIBUTE(theta); \ diff --git a/chaos/src/standard_map_dsp.cpp b/chaos/src/standard_map_dsp.cpp new file mode 100644 index 0000000..fa7d3be --- /dev/null +++ b/chaos/src/standard_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_dsp.hpp" + +class standard_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); + + STANDARD_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("standard_map~", standard_map_dsp); diff --git a/chaos/src/standard_map_msg.cpp b/chaos/src/standard_map_msg.cpp new file mode 100644 index 0000000..fdd3bda --- /dev/null +++ b/chaos/src/standard_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_msg.hpp" + +class standard_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); + + STANDARD_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("standard_map", standard_map_msg); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 137599a..9ab59ec 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -25,18 +25,18 @@ // 0 <= x[n] < 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class tent: - protected map_base +class tent_map: + public map_base { public: - tent() + tent_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x, 0.5); } - ~tent() + ~tent_map() { delete m_data; } @@ -59,12 +59,12 @@ public: }; -#define LOGISTIC_CALLBACKS \ +#define TENT_MAP_CALLBACKS \ MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define LOGISTIC_ATTRIBUTES \ +#define TENT_MAP_ATTRIBUTES \ MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); - + diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp new file mode 100644 index 0000000..10fe609 --- /dev/null +++ b/chaos/src/tent_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_dsp.hpp" + +class tent_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(tent_map, TENT_MAP_ATTRIBUTES); + + TENT_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("tent~", tent_map_dsp); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp new file mode 100644 index 0000000..60c3c63 --- /dev/null +++ b/chaos/src/tent_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_msg.hpp" + +class tent_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(tent_map, TENT_MAP_ATTRIBUTES); + + TENT_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("tent", tent_map_msg); -- cgit v1.2.1 From 6963657b3f3ee4321394953a2cc67cd7386cce2d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 27 Dec 2004 22:55:41 +0000 Subject: additions and better code reuse svn path=/trunk/externals/tb/; revision=2433 --- chaos/src/Makefile.am | 4 ++ chaos/src/bernoulli_dsp.cpp | 12 +--- chaos/src/bungalow_tent_dsp.cpp | 12 +--- chaos/src/bungalow_tent_msg.cpp | 12 +--- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 1 - chaos/src/chaos_defs.hpp | 42 ++++++++++++- chaos/src/circle_map_dsp.cpp | 12 +--- chaos/src/circle_map_msg.cpp | 12 +--- chaos/src/coupled_logistic.hpp | 82 ++++++++++++++++++++++++++ chaos/src/coupled_logistic_dsp.cpp | 25 ++++++++ chaos/src/coupled_logistic_msg.cpp | 34 +++++++++++ chaos/src/driven_anharmonic.hpp | 111 +++++++++++++++++++++++++++++++++++ chaos/src/driven_anharmonic_dsp.cpp | 25 ++++++++ chaos/src/driven_anharmonic_msg.cpp | 25 ++++++++ chaos/src/driven_van_der_pol.hpp | 95 ++++++++++++++++++++++++++++++ chaos/src/driven_van_der_pol_dsp.cpp | 25 ++++++++ chaos/src/driven_van_der_pol_msg.cpp | 25 ++++++++ chaos/src/gauss_map_dsp.cpp | 12 +--- chaos/src/gauss_map_msg.cpp | 12 +--- chaos/src/henon_map_dsp.cpp | 12 +--- chaos/src/henon_map_msg.cpp | 12 +--- chaos/src/ikeda_laser_map_dsp.cpp | 10 +--- chaos/src/ikeda_laser_map_msg.cpp | 12 +--- chaos/src/logistic_dsp.cpp | 12 +--- chaos/src/logistic_msg.cpp | 12 +--- chaos/src/lorenz.hpp | 2 - chaos/src/lorenz_dsp.cpp | 12 +--- chaos/src/lorenz_msg.cpp | 12 +--- chaos/src/lozi_map_dsp.cpp | 12 +--- chaos/src/lozi_map_msg.cpp | 12 +--- chaos/src/main.cpp | 52 ++++++---------- chaos/src/roessler.hpp | 89 ++++++++++++++++++++++++++++ chaos/src/roessler_dsp.cpp | 24 ++++++++ chaos/src/roessler_msg.cpp | 24 ++++++++ chaos/src/sine_map_dsp.cpp | 11 +--- chaos/src/sine_map_msg.cpp | 12 +--- chaos/src/standard_map_dsp.cpp | 11 +--- chaos/src/standard_map_msg.cpp | 12 +--- chaos/src/tent_map_dsp.cpp | 10 +--- chaos/src/tent_map_msg.cpp | 12 +--- 41 files changed, 670 insertions(+), 286 deletions(-) create mode 100644 chaos/src/coupled_logistic.hpp create mode 100644 chaos/src/coupled_logistic_dsp.cpp create mode 100644 chaos/src/coupled_logistic_msg.cpp create mode 100644 chaos/src/driven_anharmonic.hpp create mode 100644 chaos/src/driven_anharmonic_dsp.cpp create mode 100644 chaos/src/driven_anharmonic_msg.cpp create mode 100644 chaos/src/driven_van_der_pol.hpp create mode 100644 chaos/src/driven_van_der_pol_dsp.cpp create mode 100644 chaos/src/driven_van_der_pol_msg.cpp create mode 100644 chaos/src/roessler.hpp create mode 100644 chaos/src/roessler_dsp.cpp create mode 100644 chaos/src/roessler_msg.cpp (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index a524de5..6812701 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -4,12 +4,16 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ bernoulli_dsp.cpp bernoulli_msg.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ + coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ + driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ + driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ gauss_map_dsp.cpp gauss_map_msg.cpp \ henon_map_dsp.cpp henon_map_msg.cpp \ ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ + roessler_dsp.cpp roessler_msg.cpp \ sine_map_dsp.cpp sine_map_msg.cpp \ standard_map_dsp.cpp standard_map_msg.cpp \ tent_map_dsp.cpp tent_map_msg.cpp diff --git a/chaos/src/bernoulli_dsp.cpp b/chaos/src/bernoulli_dsp.cpp index 8e8d0da..3cf9480 100644 --- a/chaos/src/bernoulli_dsp.cpp +++ b/chaos/src/bernoulli_dsp.cpp @@ -21,14 +21,4 @@ #include "bernoulli_map.hpp" #include "chaos_dsp.hpp" -class bernoulli_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(bernoulli, BERNOULLI_ATTRIBUTES); - - BERNOULLI_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("bernoulli~", bernoulli_dsp); +CHAOS_DSP_CLASS(bernoulli, BERNOULLI); diff --git a/chaos/src/bungalow_tent_dsp.cpp b/chaos/src/bungalow_tent_dsp.cpp index 33bef1c..111a96a 100644 --- a/chaos/src/bungalow_tent_dsp.cpp +++ b/chaos/src/bungalow_tent_dsp.cpp @@ -21,14 +21,4 @@ #include "bungalow_tent_map.hpp" #include "chaos_dsp.hpp" -class bungalow_tent_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); - - BUNGALOW_TENT_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("bungalow_tent~", bungalow_tent_dsp); +CHAOS_DSP_CLASS(bungalow_tent,BUNGALOW_TENT); diff --git a/chaos/src/bungalow_tent_msg.cpp b/chaos/src/bungalow_tent_msg.cpp index 8c6b1be..6c3ae7e 100644 --- a/chaos/src/bungalow_tent_msg.cpp +++ b/chaos/src/bungalow_tent_msg.cpp @@ -21,14 +21,4 @@ #include "bungalow_tent_map.hpp" #include "chaos_msg.hpp" -class bungalow_tent_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); - - BUNGALOW_TENT_CALLBACKS; -}; - - - -FLEXT_LIB_V("bungalow_tent", bungalow_tent_msg); +CHAOS_MSG_CLASS(bungalow_tent, BUNGALOW_TENT); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 65a9c46..4bf3ea3 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -23,6 +23,7 @@ #define FLEXT_ATTRIBUTES 1 #include "flext.h" +#include "chaos_defs.hpp" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 795383e..ce6fc11 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -21,7 +21,6 @@ #ifndef __chaos_base_hpp #include "chaos.hpp" -#include "chaos_defs.hpp" class chaos_base { diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index ae86223..b4c2b46 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -131,7 +131,47 @@ set_##NAME(VALUE); - +/* macros for class generation */ +#define CHAOS_DSP_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_dsp: \ + public chaos_dsp \ +{ \ + CHAOS_DSP_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_DSP_V(#CLASSNAME"~", CLASSNAME##_dsp); + +#define CHAOS_DSP_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_dsp: \ + public chaos_dsp \ +{ \ + CHAOS_DSP_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_DSP_V(#NAME, CLASSNAME##_dsp); + + +#define CHAOS_MSG_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_msg: \ + public chaos_msg \ +{ \ + CHAOS_MSG_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#CLASSNAME, CLASSNAME##_msg); + +#define CHAOS_MSG_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_msg: \ + public chaos_msg \ +{ \ + CHAOS_MSG_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#NAME, CLASSNAME##_msg); + +#define CHAOS_ADD(NAME) \ +FLEXT_DSP_SETUP(NAME##_dsp); \ +FLEXT_SETUP(NAME##_msg); #define __chaos_defs_hpp #endif /* __chaos_defs_hpp */ diff --git a/chaos/src/circle_map_dsp.cpp b/chaos/src/circle_map_dsp.cpp index fbd7c9d..e5ddef4 100644 --- a/chaos/src/circle_map_dsp.cpp +++ b/chaos/src/circle_map_dsp.cpp @@ -21,14 +21,4 @@ #include "circle_map.hpp" #include "chaos_dsp.hpp" -class circle_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); - - CIRCLE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("circle_map~", circle_map_dsp); +CHAOS_DSP_CLASS(circle_map, CIRCLE_MAP) diff --git a/chaos/src/circle_map_msg.cpp b/chaos/src/circle_map_msg.cpp index 3e771b3..7fa6c9b 100644 --- a/chaos/src/circle_map_msg.cpp +++ b/chaos/src/circle_map_msg.cpp @@ -21,14 +21,4 @@ #include "circle_map.hpp" #include "chaos_msg.hpp" -class circle_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); - - CIRCLE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("circle_map", circle_map_msg); +CHAOS_MSG_CLASS(circle_map, CIRCLE_MAP); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp new file mode 100644 index 0000000..eb5b326 --- /dev/null +++ b/chaos/src/coupled_logistic.hpp @@ -0,0 +1,82 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) +// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[t] - y[t]) +// 1 <= r <= 4 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class coupled_logistic: + public map_base +{ +public: + coupled_logistic() + { + m_num_eq = 2; + m_data = new data_t[2]; + CHAOS_SYS_INIT(e, 0.06); + CHAOS_SYS_INIT(r, 3.7); + CHAOS_SYS_INIT(x, 0.1); + CHAOS_SYS_INIT(x, 0.2); + } + + ~coupled_logistic() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + data_t e = CHAOS_PARAMETER(e); + data_t r = CHAOS_PARAMETER(r); + m_data[0] = r * x * (1.f - x) + e * (y - x); + m_data[1] = r * y * (1.f - y) + e * (x - y); + } + + CHAOS_SYSPAR_FUNCS(e); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); + bool m_pred_r(t_float f) + { + return (f > 0) && (f < 4); + } + + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 0); + +}; + +#define COUPLED_LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(e); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define COUPLED_LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(e); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); + diff --git a/chaos/src/coupled_logistic_dsp.cpp b/chaos/src/coupled_logistic_dsp.cpp new file mode 100644 index 0000000..166ca79 --- /dev/null +++ b/chaos/src/coupled_logistic_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(coupled_logistic, COUPLED_LOGISTIC) + diff --git a/chaos/src/coupled_logistic_msg.cpp b/chaos/src/coupled_logistic_msg.cpp new file mode 100644 index 0000000..994a79d --- /dev/null +++ b/chaos/src/coupled_logistic_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_msg.hpp" + +class coupled_logistic_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(coupled_logistic, COUPLED_LOGISTIC_ATTRIBUTES); + + COUPLED_LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_V("coupled_logistic", coupled_logistic_msg); diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp new file mode 100644 index 0000000..8c319e9 --- /dev/null +++ b/chaos/src/driven_anharmonic.hpp @@ -0,0 +1,111 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" +#include + +// driven anharmonic: +// d2u/dt2 + a * du/dt + b*u + c * u*u*u = k1 + k2*cos(Omega*t) +// equivalent: +// du1/dt = u2 +// du2/dt = -a*u2 - b*u1 -c*u*u*u + k1 + k2*cos(Omega*t) +// taken from Willi-Hans Steeb: Chaos and Fractals + +class driven_anharmonic + : public ode_base +{ +public: + driven_anharmonic() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,0.01); + + CHAOS_SYS_INIT(u1,0); + CHAOS_SYS_INIT(u2,1); + + CHAOS_SYS_INIT(a,1); + CHAOS_SYS_INIT(b,-10); + CHAOS_SYS_INIT(c,100); + CHAOS_SYS_INIT(Omega,3.5); + CHAOS_SYS_INIT(k1,0.01); + CHAOS_SYS_INIT(k2,1); + + ode_base_alloc(); + m_t = 0; + } + + ~driven_anharmonic() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1]; + + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * u2 - CHAOS_PARAMETER(b) * u1 - + CHAOS_PARAMETER(c) * u1*u1*u1 + CHAOS_PARAMETER(k1) + + CHAOS_PARAMETER(k2) * cos (CHAOS_PARAMETER(Omega) * m_t); + m_t += m_dt; + + if (m_t > 2 * M_PI) + m_t = fmod(m_t, 2*M_PI); + } + + data_t m_t; + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); + CHAOS_SYSPAR_FUNCS(k1); + CHAOS_SYSPAR_FUNCS(k2); + CHAOS_SYSPAR_FUNCS(Omega); +}; + + +#define DRIVEN_ANHARMONIC_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); \ +CHAOS_SYS_CALLBACKS(k1); \ +CHAOS_SYS_CALLBACKS(k2); \ +CHAOS_SYS_CALLBACKS(Omega); + +#define DRIVEN_ANHARMONIC_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); \ +CHAOS_SYS_ATTRIBUTE(k1); \ +CHAOS_SYS_ATTRIBUTE(k2); \ +CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_anharmonic_dsp.cpp b/chaos/src/driven_anharmonic_dsp.cpp new file mode 100644 index 0000000..c26deaf --- /dev/null +++ b/chaos/src/driven_anharmonic_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); + diff --git a/chaos/src/driven_anharmonic_msg.cpp b/chaos/src/driven_anharmonic_msg.cpp new file mode 100644 index 0000000..934b0f0 --- /dev/null +++ b/chaos/src/driven_anharmonic_msg.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); + diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp new file mode 100644 index 0000000..23386b3 --- /dev/null +++ b/chaos/src/driven_van_der_pol.hpp @@ -0,0 +1,95 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" +#include + +// driven van_der_pol: +// d2u/dt2 + a*(u*u -1)*du/dt + u = k * cos(Omega*t) +// equivalent: +// du1/dt = u2 +// du2/dt = -a*(u1*u1 - 1)*u2 - u1 + k*cos(u3) +// du3/dt = Omega +// taken from Willi-Hans Steeb: Chaos and Fractals + +class driven_van_der_pol + : public ode_base +{ +public: + driven_van_der_pol() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,0.01); + + CHAOS_SYS_INIT(u1,0.8); + CHAOS_SYS_INIT(u2,0.6); + CHAOS_SYS_INIT(u3,0.4); + + CHAOS_SYS_INIT(a,5); + CHAOS_SYS_INIT(Omega,2.466); + CHAOS_SYS_INIT(k,5); + + ode_base_alloc(); + } + + ~driven_van_der_pol() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1], u3 = data[2]; + + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + + CHAOS_PARAMETER(k)*cos(u3); + deriv[2] = CHAOS_PARAMETER(Omega); + } + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + CHAOS_SYSVAR_FUNCS(u3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(k); + CHAOS_SYSPAR_FUNCS(Omega); +}; + + +#define DRIVEN_VAN_DER_POL_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(k); \ +CHAOS_SYS_CALLBACKS(Omega); + +#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(k); \ +CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_van_der_pol_dsp.cpp b/chaos/src/driven_van_der_pol_dsp.cpp new file mode 100644 index 0000000..e0787ae --- /dev/null +++ b/chaos/src/driven_van_der_pol_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); + diff --git a/chaos/src/driven_van_der_pol_msg.cpp b/chaos/src/driven_van_der_pol_msg.cpp new file mode 100644 index 0000000..488d96e --- /dev/null +++ b/chaos/src/driven_van_der_pol_msg.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); + diff --git a/chaos/src/gauss_map_dsp.cpp b/chaos/src/gauss_map_dsp.cpp index 70e659d..f9d849e 100644 --- a/chaos/src/gauss_map_dsp.cpp +++ b/chaos/src/gauss_map_dsp.cpp @@ -21,14 +21,4 @@ #include "gauss_map.hpp" #include "chaos_dsp.hpp" -class gauss_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); - - GAUSS_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("gauss_map~", gauss_map_dsp); +CHAOS_DSP_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/gauss_map_msg.cpp b/chaos/src/gauss_map_msg.cpp index 61e0379..6d00da6 100644 --- a/chaos/src/gauss_map_msg.cpp +++ b/chaos/src/gauss_map_msg.cpp @@ -21,14 +21,4 @@ #include "gauss_map.hpp" #include "chaos_msg.hpp" -class gauss_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); - - GAUSS_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("gauss_map", gauss_map_msg); +CHAOS_MSG_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp index f28e83f..f7e6103 100644 --- a/chaos/src/henon_map_dsp.cpp +++ b/chaos/src/henon_map_dsp.cpp @@ -21,14 +21,4 @@ #include "henon_map.hpp" #include "chaos_dsp.hpp" -class henon_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(henon, HENON_ATTRIBUTES); - - HENON_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("henon~", henon_dsp); +CHAOS_DSP_CLASS_NAME(henon, HENON, "henon~"); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp index 10849fd..22cddde 100644 --- a/chaos/src/henon_map_msg.cpp +++ b/chaos/src/henon_map_msg.cpp @@ -21,14 +21,4 @@ #include "henon_map.hpp" #include "chaos_msg.hpp" -class henon_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(henon, HENON_ATTRIBUTES); - - HENON_CALLBACKS; -}; - - - -FLEXT_LIB_V("henon", henon_msg); +CHAOS_MSG_CLASS_NAME(henon, HENON, "henon"); diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp index cf7c9cf..ea18e21 100644 --- a/chaos/src/ikeda_laser_map_dsp.cpp +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -21,14 +21,6 @@ #include "ikeda_laser_map.hpp" #include "chaos_dsp.hpp" -class ikeda_laser_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); - IKEDA_LASER_MAP_CALLBACKS; -}; +CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda"); - - -FLEXT_LIB_DSP_V("ikeda~", ikeda_laser_map_dsp); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp index d5f775a..1659159 100644 --- a/chaos/src/ikeda_laser_map_msg.cpp +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -21,14 +21,4 @@ #include "ikeda_laser_map.hpp" #include "chaos_msg.hpp" -class ikeda_laser_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); - - IKEDA_LASER_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("ikeda_laser_map", ikeda_laser_map_msg); +CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda~"); diff --git a/chaos/src/logistic_dsp.cpp b/chaos/src/logistic_dsp.cpp index 1c20a05..6a88748 100644 --- a/chaos/src/logistic_dsp.cpp +++ b/chaos/src/logistic_dsp.cpp @@ -21,14 +21,4 @@ #include "logistic_map.hpp" #include "chaos_dsp.hpp" -class logistic_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(logistic, LOGISTIC_ATTRIBUTES); - - LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("logistic~", logistic_dsp); +CHAOS_DSP_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/logistic_msg.cpp b/chaos/src/logistic_msg.cpp index db7bcbf..60fef89 100644 --- a/chaos/src/logistic_msg.cpp +++ b/chaos/src/logistic_msg.cpp @@ -21,14 +21,4 @@ #include "logistic_map.hpp" #include "chaos_msg.hpp" -class logistic_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(logistic, LOGISTIC_ATTRIBUTES); - - LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_V("logistic", logistic_msg); +CHAOS_MSG_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index a31c151..c876b4a 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -44,8 +44,6 @@ public: CHAOS_SYS_INIT(r,40); ode_base_alloc(); - - set_method(0); } ~lorenz() diff --git a/chaos/src/lorenz_dsp.cpp b/chaos/src/lorenz_dsp.cpp index 8dc3763..e1b8ad1 100644 --- a/chaos/src/lorenz_dsp.cpp +++ b/chaos/src/lorenz_dsp.cpp @@ -21,14 +21,4 @@ #include "lorenz.hpp" #include "chaos_dsp.hpp" -class lorenz_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(lorenz, LORENZ_ATTRIBUTES); - - LORENZ_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("lorenz~", lorenz_dsp); +CHAOS_DSP_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lorenz_msg.cpp b/chaos/src/lorenz_msg.cpp index 6ad3ed9..09b02e8 100644 --- a/chaos/src/lorenz_msg.cpp +++ b/chaos/src/lorenz_msg.cpp @@ -21,14 +21,4 @@ #include "lorenz.hpp" #include "chaos_msg.hpp" -class lorenz_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(lorenz, LORENZ_ATTRIBUTES); - - LORENZ_CALLBACKS; -}; - - - -FLEXT_LIB_V("lorenz", lorenz_msg); +CHAOS_MSG_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp index f8c4695..0448412 100644 --- a/chaos/src/lozi_map_dsp.cpp +++ b/chaos/src/lozi_map_dsp.cpp @@ -21,14 +21,4 @@ #include "lozi_map.hpp" #include "chaos_dsp.hpp" -class lozi_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); - - LOZI_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("lozi~", lozi_map_dsp); +CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp index 947e772..099cbec 100644 --- a/chaos/src/lozi_map_msg.cpp +++ b/chaos/src/lozi_map_msg.cpp @@ -21,14 +21,4 @@ #include "lozi_map.hpp" #include "chaos_msg.hpp" -class lozi_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); - - LOZI_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("lozi", lozi_map_msg); +CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 16f2908..84589f8 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -19,46 +19,28 @@ // Boston, MA 02111-1307, USA. #include "chaos.hpp" +#include "chaos_defs.hpp" void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); - FLEXT_DSP_SETUP(bernoulli_dsp); - FLEXT_SETUP(bernoulli_msg); - - FLEXT_DSP_SETUP(bungalow_tent_dsp); - FLEXT_SETUP(bungalow_tent_msg); - - FLEXT_DSP_SETUP(circle_map_dsp); - FLEXT_SETUP(circle_map_msg); - - FLEXT_DSP_SETUP(gauss_map_dsp); - FLEXT_SETUP(gauss_map_msg); - - FLEXT_DSP_SETUP(henon_dsp); - FLEXT_SETUP(henon_msg); - - FLEXT_DSP_SETUP(ikeda_laser_map_dsp); - FLEXT_SETUP(ikeda_laser_map_msg); - - FLEXT_DSP_SETUP(logistic_dsp); - FLEXT_SETUP(logistic_msg); - - FLEXT_DSP_SETUP(lorenz_dsp); - FLEXT_SETUP(lorenz_msg); - - FLEXT_DSP_SETUP(lozi_map_dsp); - FLEXT_SETUP(lozi_map_msg); - - FLEXT_DSP_SETUP(sine_map_dsp); - FLEXT_SETUP(sine_map_msg); - - FLEXT_DSP_SETUP(standard_map_dsp); - FLEXT_SETUP(standard_map_msg); - - FLEXT_DSP_SETUP(tent_map_dsp); - FLEXT_SETUP(tent_map_msg); + CHAOS_ADD(bernoulli); + CHAOS_ADD(bungalow_tent); + CHAOS_ADD(circle_map); + CHAOS_ADD(coupled_logistic); + CHAOS_ADD(driven_anharmonic); + CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(gauss_map); + CHAOS_ADD(henon); + CHAOS_ADD(ikeda_laser_map); + CHAOS_ADD(logistic); + CHAOS_ADD(lorenz); + CHAOS_ADD(lozi_map); + CHAOS_ADD(roesser); + CHAOS_ADD(sine_map); + CHAOS_ADD(standard_map); + CHAOS_ADD(tent_map); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp new file mode 100644 index 0000000..85272ee --- /dev/null +++ b/chaos/src/roessler.hpp @@ -0,0 +1,89 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// roessler model: dx1/dt = - (x2 + x3) +// dx2/dt = x1 + a * x2 +// dx3/dt = b + (x1 - c) * x3 +// taken from Peitgen / Jürgens / Saupe: Chaos and Fractals + +class roessler + : public ode_base +{ +public: + roessler() + { + m_num_eq = 3; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(x1,0); + CHAOS_SYS_INIT(x2,0); + CHAOS_SYS_INIT(x3,0); + CHAOS_SYS_INIT(a,4); + CHAOS_SYS_INIT(b,4); + CHAOS_SYS_INIT(c,4); + + ode_base_alloc(); + } + + ~roessler() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0], x2 = data[1], x3 = data[2]; + + deriv[0] = - (x2 - x1); + deriv[1] = x1 + CHAOS_PARAMETER(a) * x2; + deriv[2] = CHAOS_PARAMETER(b) + (x1 - CHAOS_PARAMETER(c)) * x3; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); +}; + + +#define ROESSLER_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + +#define ROESSLER_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); diff --git a/chaos/src/roessler_dsp.cpp b/chaos/src/roessler_dsp.cpp new file mode 100644 index 0000000..e5ee834 --- /dev/null +++ b/chaos/src/roessler_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(roessler,ROESSLER); diff --git a/chaos/src/roessler_msg.cpp b/chaos/src/roessler_msg.cpp new file mode 100644 index 0000000..aad1bf6 --- /dev/null +++ b/chaos/src/roessler_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(roessler,ROESSLER); diff --git a/chaos/src/sine_map_dsp.cpp b/chaos/src/sine_map_dsp.cpp index a2d2929..b1ca11e 100644 --- a/chaos/src/sine_map_dsp.cpp +++ b/chaos/src/sine_map_dsp.cpp @@ -21,14 +21,5 @@ #include "sine_map.hpp" #include "chaos_dsp.hpp" -class sine_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(sine_map, SINE_MAP_ATTRIBUTES); - SINE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("sine_map~", sine_map_dsp); +CHAOS_DSP_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/sine_map_msg.cpp b/chaos/src/sine_map_msg.cpp index 1d9a90e..aacc51c 100644 --- a/chaos/src/sine_map_msg.cpp +++ b/chaos/src/sine_map_msg.cpp @@ -21,14 +21,4 @@ #include "sine_map.hpp" #include "chaos_msg.hpp" -class sine_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(sine_map, SINE_MAP_ATTRIBUTES); - - SINE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("sine_map", sine_map_msg); +CHAOS_MSG_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/standard_map_dsp.cpp b/chaos/src/standard_map_dsp.cpp index fa7d3be..c16276c 100644 --- a/chaos/src/standard_map_dsp.cpp +++ b/chaos/src/standard_map_dsp.cpp @@ -21,14 +21,5 @@ #include "standard_map.hpp" #include "chaos_dsp.hpp" -class standard_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); - STANDARD_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("standard_map~", standard_map_dsp); +CHAOS_DSP_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/standard_map_msg.cpp b/chaos/src/standard_map_msg.cpp index fdd3bda..92c1084 100644 --- a/chaos/src/standard_map_msg.cpp +++ b/chaos/src/standard_map_msg.cpp @@ -21,14 +21,4 @@ #include "standard_map.hpp" #include "chaos_msg.hpp" -class standard_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); - - STANDARD_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("standard_map", standard_map_msg); +CHAOS_MSG_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp index 10fe609..44c909d 100644 --- a/chaos/src/tent_map_dsp.cpp +++ b/chaos/src/tent_map_dsp.cpp @@ -21,14 +21,6 @@ #include "tent_map.hpp" #include "chaos_dsp.hpp" -class tent_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(tent_map, TENT_MAP_ATTRIBUTES); - TENT_MAP_CALLBACKS; -}; - - -FLEXT_LIB_DSP_V("tent~", tent_map_dsp); +CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, "tent~"); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp index 60c3c63..3da82ab 100644 --- a/chaos/src/tent_map_msg.cpp +++ b/chaos/src/tent_map_msg.cpp @@ -21,14 +21,4 @@ #include "tent_map.hpp" #include "chaos_msg.hpp" -class tent_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(tent_map, TENT_MAP_ATTRIBUTES); - - TENT_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("tent", tent_map_msg); +CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, "tent"); -- cgit v1.2.1 From 43dd4efedf1ecfe721cde5830bdcee67ffa48907 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 28 Dec 2004 12:38:45 +0000 Subject: a few new attractors ... svn path=/trunk/externals/tb/; revision=2434 --- chaos/src/Makefile.am | 5 ++ chaos/src/chaos.hpp | 4 +- chaos/src/chaos_defs.hpp | 1 + chaos/src/chaos_dsp.hpp | 160 +++++++++++++++++++++++++++------------- chaos/src/duffing_map.hpp | 76 +++++++++++++++++++ chaos/src/duffing_map_dsp.cpp | 24 ++++++ chaos/src/duffing_map_msg.cpp | 24 ++++++ chaos/src/latoocarfian.hpp | 98 ++++++++++++++++++++++++ chaos/src/latoocarfian_dsp.cpp | 24 ++++++ chaos/src/latoocarfian_msg.cpp | 24 ++++++ chaos/src/latoomutalpha.hpp | 88 ++++++++++++++++++++++ chaos/src/latoomutalpha_dsp.cpp | 24 ++++++ chaos/src/latoomutalpha_msg.cpp | 24 ++++++ chaos/src/latoomutbeta.hpp | 83 +++++++++++++++++++++ chaos/src/latoomutbeta_dsp.cpp | 24 ++++++ chaos/src/latoomutbeta_msg.cpp | 24 ++++++ chaos/src/latoomutgamma.hpp | 83 +++++++++++++++++++++ chaos/src/latoomutgamma_dsp.cpp | 24 ++++++ chaos/src/latoomutgamma_msg.cpp | 24 ++++++ chaos/src/logistic_map.hpp | 2 +- chaos/src/main.cpp | 7 +- 21 files changed, 792 insertions(+), 55 deletions(-) create mode 100644 chaos/src/duffing_map.hpp create mode 100644 chaos/src/duffing_map_dsp.cpp create mode 100644 chaos/src/duffing_map_msg.cpp create mode 100644 chaos/src/latoocarfian.hpp create mode 100644 chaos/src/latoocarfian_dsp.cpp create mode 100644 chaos/src/latoocarfian_msg.cpp create mode 100644 chaos/src/latoomutalpha.hpp create mode 100644 chaos/src/latoomutalpha_dsp.cpp create mode 100644 chaos/src/latoomutalpha_msg.cpp create mode 100644 chaos/src/latoomutbeta.hpp create mode 100644 chaos/src/latoomutbeta_dsp.cpp create mode 100644 chaos/src/latoomutbeta_msg.cpp create mode 100644 chaos/src/latoomutgamma.hpp create mode 100644 chaos/src/latoomutgamma_dsp.cpp create mode 100644 chaos/src/latoomutgamma_msg.cpp (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 6812701..cbaa287 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -7,9 +7,14 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ + duffing_map_dsp.cpp duffing_map_msg.cpp \ gauss_map_dsp.cpp gauss_map_msg.cpp \ henon_map_dsp.cpp henon_map_msg.cpp \ ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ + latoocarfian_dsp.cpp latoocarfian_msg.cpp \ + latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ + latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ + latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 4bf3ea3..231ecdc 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -28,8 +28,10 @@ /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; +#define CHAOS_ABS(x) fabs(x) #else -typedef t_float data_t; +typedef float data_t; +#define CHAOS_ABS(x) fabsf(x) #endif diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index b4c2b46..08c47d4 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -106,6 +106,7 @@ void set_##NAME(t_float &f) \ m_system->set_##NAME(f); \ } \ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); + #define CHAOS_SYS_CALLBACKS_I(NAME) \ public: \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 1eff6fc..c2f78b3 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -60,62 +60,118 @@ public: int m_phase; /* phase counter */ float m_sr; /* sample rate */ - int m_method; /* interpolation method */ + int m_imethod; /* interpolation method */ + + int get_imethod(int &i) + { + i = m_imethod; + } + + void set_imethod(int i) + { + if( (i >= 0) && (i <= 2) ) + m_imethod = i; + else + { + post("interpolation method out of range"); + return; + } + if( i != 2) + { + for (int j = 0; j != m_system->get_num_eq(); ++j) + { + m_nextvalues[i] = 0; + m_nextmidpts[i] = 0; + m_curves[i] = 0; + } + } + + } + + int get_freq(float &f) + { + f = m_freq; + } + + void set_freq(float f) + { + if( (f >= 0) && (f <= m_sr*0.5) ) + m_freq = f; + else + post("frequency out of range"); + } + FLEXT_CALLVAR_F(get_freq, set_freq); + FLEXT_CALLVAR_I(get_imethod, set_imethod); }; /* create constructor / destructor */ -#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ -FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ - \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - 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]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - \ - \ - m_freq = GetAFloat(argv[0]); \ - m_method = (char)GetAFloat(argv[1]); \ - m_phase = 0; \ - \ - FLEXT_ADDATTR_VAR1("frequency",m_freq); \ - FLEXT_ADDATTR_VAR1("method",m_method); \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ -{ \ - delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ -} \ - \ -FLEXT_ATTRVAR_F(m_freq); \ -FLEXT_ATTRVAR_I(m_method); +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +SYSTEM##_dsp(int argc, t_atom* argv ) \ +{ \ + m_sr = 44100; /* assume default sampling rate (for max frequency) */ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + 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]; \ + \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ + \ + if (argc > 0) \ + { \ + CHAOS_SYS_INIT(freq, GetAInt(argv[0])); \ + } \ + else \ + { \ + CHAOS_SYS_INIT(freq, 440); \ + } \ + \ + if (argc > 1) \ + { \ + CHAOS_SYS_INIT(imethod, GetAInt(argv[1])); \ + } \ + else \ + { \ + CHAOS_SYS_INIT(imethod, 0); \ + } \ + \ + m_phase = 0; \ + \ + ATTRIBUTES; \ +} \ + \ +~SYSTEM##_dsp() \ +{ \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_I(m_imethod); @@ -129,7 +185,7 @@ void chaos_dsp::m_signal(int n, t_sample *const *insigs, return; } - switch (m_method) + switch (m_imethod) { case 0: m_signal_n(n, insigs, outsigs); diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp new file mode 100644 index 0000000..71b8cbd --- /dev/null +++ b/chaos/src/duffing_map.hpp @@ -0,0 +1,76 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// duffing map: x1[n+1] = x2[n] +// x2[n+1] = -b*x1[n] + a*x2[n] - pow(x2,3) +// +// taken from Viktor Avrutin: AnT-Demos-4.669 + +class duffing_map: + public map_base +{ +public: + duffing_map() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x1, 0.5); + CHAOS_SYS_INIT(x2, 0.5); + CHAOS_SYS_INIT(a, 0.5); + CHAOS_SYS_INIT(b, 0.5); + } + + ~duffing_map() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + + m_data[0] = x2; + m_data[1] = - CHAOS_PARAMETER(b)*x1 + CHAOS_PARAMETER(a)*x2 + - x2*x2*x2; + } + + CHAOS_SYSVAR_FUNCS(x1,0); + CHAOS_SYSVAR_FUNCS(x2,1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + +#define DUFFING_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + +#define DUFFING_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/duffing_map_dsp.cpp b/chaos/src/duffing_map_dsp.cpp new file mode 100644 index 0000000..39e1439 --- /dev/null +++ b/chaos/src/duffing_map_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(duffing_map,DUFFING_MAP); diff --git a/chaos/src/duffing_map_msg.cpp b/chaos/src/duffing_map_msg.cpp new file mode 100644 index 0000000..a18817f --- /dev/null +++ b/chaos/src/duffing_map_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(duffing_map,DUFFING_MAP); diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp new file mode 100644 index 0000000..c2a31a1 --- /dev/null +++ b/chaos/src/latoocarfian.hpp @@ -0,0 +1,98 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model: x1[n+1] = sin(x2[n]*b) + c*sin(x1[n]*b) +// x2[n+1] = sin(x1[n]*a) + d*sin(x2[n]*a) +// -3 < a,b < 3 +// -0.5 < c,d < 1.5 +// taken from Pickover: Chaos In Wonderland + +class latoocarfian + : public map_base +{ +public: + latoocarfian() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(c,0.765145); + CHAOS_SYS_INIT(d,0.744728); + } + + ~latoocarfian() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), + c = CHAOS_PARAMETER(c), d = CHAOS_PARAMETER(d); + + m_data[0] = sin(x2*b) + c*sin(x1*b); + m_data[1] = sin(x1*a) + d*sin(x2*a); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS_PRED(a,m_pred_1); + CHAOS_SYSPAR_FUNCS_PRED(b,m_pred_1); + CHAOS_SYSPAR_FUNCS_PRED(c,m_pred_2); + CHAOS_SYSPAR_FUNCS_PRED(d,m_pred_2); + + bool m_pred_1(t_float f) + { + return (f > -3.f) && (f < 3.f); + } + + bool m_pred_2(t_float f) + { + return (f > -0.5) && (f < 1.5); + } +}; + + +#define LATOOCARFIAN_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); \ +CHAOS_SYS_CALLBACKS(d); + +#define LATOOCARFIAN_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); \ +CHAOS_SYS_ATTRIBUTE(d); diff --git a/chaos/src/latoocarfian_dsp.cpp b/chaos/src/latoocarfian_dsp.cpp new file mode 100644 index 0000000..81c773d --- /dev/null +++ b/chaos/src/latoocarfian_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoocarfian,LATOOCARFIAN); diff --git a/chaos/src/latoocarfian_msg.cpp b/chaos/src/latoocarfian_msg.cpp new file mode 100644 index 0000000..92be013 --- /dev/null +++ b/chaos/src/latoocarfian_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoocarfian,LATOOCARFIAN); diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp new file mode 100644 index 0000000..6926d1b --- /dev/null +++ b/chaos/src/latoomutalpha.hpp @@ -0,0 +1,88 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation alpha: +// x1[n+1] = sin(x2[n]*b) + pow(sin(x1[n]*b),2) + pow(sin(x1[n]*b),3) +// x2[n+1] = sin(x1[n]*a) + pow(sin(x2[n]*a),2) + pow(sin(x2[n]*c),3) +// taken from Pickover: Chaos In Wonderland + +class latoomutalpha + : public map_base +{ +public: + latoomutalpha() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.2); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(c,0.765145); + } + + ~latoomutalpha() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), + c = CHAOS_PARAMETER(c); + data_t tmp1, tmp2; + + tmp1 = sin(x1*b); + m_data[0] = sin(x2*b) + tmp1*tmp1 + tmp1*tmp1*tmp1; + tmp1 = sin(x2*a); + tmp2 = sin(x2*c); + m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); +}; + + +#define LATOOMUTALPHA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + + +#define LATOOMUTALPHA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); diff --git a/chaos/src/latoomutalpha_dsp.cpp b/chaos/src/latoomutalpha_dsp.cpp new file mode 100644 index 0000000..c028ac6 --- /dev/null +++ b/chaos/src/latoomutalpha_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutalpha,LATOOMUTALPHA); diff --git a/chaos/src/latoomutalpha_msg.cpp b/chaos/src/latoomutalpha_msg.cpp new file mode 100644 index 0000000..0726708 --- /dev/null +++ b/chaos/src/latoomutalpha_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutalpha,LATOOMUTALPHA); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp new file mode 100644 index 0000000..4940be1 --- /dev/null +++ b/chaos/src/latoomutbeta.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation beta: +// x1[n+1] = sin(x2[n]*b) + pow(sin(x1[n]*b),2) +// x2[n+1] = sin(x1[n]*a) + pow(sin(x2[n]*a),2) +// taken from Pickover: Chaos In Wonderland + +class latoomutbeta + : public map_base +{ +public: + latoomutbeta() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.5); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + } + + ~latoomutbeta() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; + + tmp = sin(x1*b); + m_data[0] = sin(x2*b) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = sin(x1*a) + tmp*tmp; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + + +#define LATOOMUTBETA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + + +#define LATOOMUTBETA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/latoomutbeta_dsp.cpp b/chaos/src/latoomutbeta_dsp.cpp new file mode 100644 index 0000000..b0f803e --- /dev/null +++ b/chaos/src/latoomutbeta_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutbeta,LATOOMUTBETA); diff --git a/chaos/src/latoomutbeta_msg.cpp b/chaos/src/latoomutbeta_msg.cpp new file mode 100644 index 0000000..41e5aaf --- /dev/null +++ b/chaos/src/latoomutbeta_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutbeta,LATOOMUTBETA); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp new file mode 100644 index 0000000..b4f3bf8 --- /dev/null +++ b/chaos/src/latoomutgamma.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation gamma: +// x1[n+1] = abs(sin(x2[n]*b)) + pow(sin(x1[n]*b),2) +// x2[n+1] = abs(sin(x1[n]*a)) + pow(sin(x2[n]*a),2) +// taken from Pickover: Chaos In Wonderland + +class latoomutgamma + : public map_base +{ +public: + latoomutgamma() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.5); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + } + + ~latoomutgamma() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; + + tmp = sin(x1*b); + m_data[0] = CHAOS_ABS(sin(x2*b)) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + + +#define LATOOMUTGAMMA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + + +#define LATOOMUTGAMMA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/latoomutgamma_dsp.cpp b/chaos/src/latoomutgamma_dsp.cpp new file mode 100644 index 0000000..dbe625d --- /dev/null +++ b/chaos/src/latoomutgamma_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutgamma,LATOOMUTGAMMA); diff --git a/chaos/src/latoomutgamma_msg.cpp b/chaos/src/latoomutgamma_msg.cpp new file mode 100644 index 0000000..1b1c20d --- /dev/null +++ b/chaos/src/latoomutgamma_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutgamma,LATOOMUTGAMMA); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index e72a3a7..1808baa 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -31,7 +31,7 @@ public: logistic() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5); } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 84589f8..eabb8d4 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -31,13 +31,18 @@ void chaos_library_setup() CHAOS_ADD(coupled_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); CHAOS_ADD(henon); CHAOS_ADD(ikeda_laser_map); + CHAOS_ADD(latoocarfian); + CHAOS_ADD(latoomutalpha); + CHAOS_ADD(latoomutbeta); + CHAOS_ADD(latoomutgamma); CHAOS_ADD(logistic); CHAOS_ADD(lorenz); CHAOS_ADD(lozi_map); - CHAOS_ADD(roesser); + CHAOS_ADD(roessler); CHAOS_ADD(sine_map); CHAOS_ADD(standard_map); CHAOS_ADD(tent_map); -- cgit v1.2.1 From 2a0d532e5965402f19f74f70dfdcc7efd1055b15 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 1 Jan 2005 11:06:58 +0000 Subject: speedup using function pointers svn path=/trunk/externals/tb/; revision=2439 --- chaos/src/Makefile.am | 1 + chaos/src/bernoulli_map.hpp | 2 +- chaos/src/bungalow_tent_map.hpp | 2 +- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 17 +++++- chaos/src/chaos_dsp.hpp | 70 ++++++++++++------------ chaos/src/chaos_msg.hpp | 2 +- chaos/src/chua.hpp | 109 ++++++++++++++++++++++++++++++++++++++ chaos/src/chua_dsp.cpp | 24 +++++++++ chaos/src/chua_msg.cpp | 24 +++++++++ chaos/src/circle_map.hpp | 2 +- chaos/src/coupled_logistic.hpp | 2 +- chaos/src/gauss_map.hpp | 2 +- chaos/src/henon_map.hpp | 2 +- chaos/src/henon_map_dsp.cpp | 2 +- chaos/src/henon_map_msg.cpp | 2 +- chaos/src/ikeda_laser_map.hpp | 2 +- chaos/src/ikeda_laser_map_dsp.cpp | 2 +- chaos/src/ikeda_laser_map_msg.cpp | 2 +- chaos/src/logistic_map.hpp | 14 +++-- chaos/src/lozi_map.hpp | 2 +- chaos/src/lozi_map_dsp.cpp | 2 +- chaos/src/lozi_map_msg.cpp | 2 +- chaos/src/main.cpp | 1 + chaos/src/map_base.hpp | 5 +- chaos/src/ode_base.cpp | 16 ------ chaos/src/ode_base.hpp | 20 ++++++- chaos/src/roessler.hpp | 1 + chaos/src/sine_map.hpp | 2 +- chaos/src/standard_map.hpp | 2 +- chaos/src/tent_map.hpp | 23 ++++---- chaos/src/tent_map_dsp.cpp | 2 +- chaos/src/tent_map_msg.cpp | 2 +- 33 files changed, 273 insertions(+), 91 deletions(-) create mode 100644 chaos/src/chua.hpp create mode 100644 chaos/src/chua_dsp.cpp create mode 100644 chaos/src/chua_msg.cpp (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index cbaa287..213e313 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -5,6 +5,7 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ + chua_dsp.cpp chua_msg.cpp \ driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ duffing_map_dsp.cpp duffing_map_msg.cpp \ diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 25d19f8..821f24f 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -31,7 +31,7 @@ public: bernoulli() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0.5); } diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 185753a..0dfe709 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -39,7 +39,7 @@ public: bungalow_tent() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x, 0.6); CHAOS_SYS_INIT(r, 0.5); } diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 231ecdc..a1a3467 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -24,6 +24,7 @@ #include "flext.h" #include "chaos_defs.hpp" +#include /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index ce6fc11..a2072d0 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -36,16 +36,31 @@ public: return m_num_eq; } - virtual void m_step() + void m_perform() { + m_step(); + m_verify(); } + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0; +#endif + } + }; + data_t * m_data; // state of the system protected: + virtual void m_step(); int m_num_eq; // number of equations of the system }; + #define CHAOS_CALLBACKS \ public: \ void get_dimension(int &i) \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index c2f78b3..9704432 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -37,13 +37,17 @@ public: /* cubic interpolatio */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs); + virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) + { + (this->*m_routine)(n,insigs,outsigs); + } virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) { m_sr = Samplerate(); } - + + void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ system * m_system; /* the system */ @@ -57,12 +61,13 @@ public: /* local data for signal functions */ float m_freq; /* frequency of oscillations */ + float m_invfreq; /* inverse frequency */ int m_phase; /* phase counter */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ - int get_imethod(int &i) + void get_imethod(int &i) { i = m_imethod; } @@ -70,7 +75,21 @@ public: void set_imethod(int i) { if( (i >= 0) && (i <= 2) ) + { m_imethod = i; + switch (i) + { + case 0: + m_routine = &thisType::m_signal_n; + break; + case 1: + m_routine = &thisType::m_signal_l; + break; + case 2: + m_routine = &thisType::m_signal_c; + break; + } + } else { post("interpolation method out of range"); @@ -88,7 +107,7 @@ public: } - int get_freq(float &f) + void get_freq(float &f) { f = m_freq; } @@ -96,7 +115,10 @@ public: void set_freq(float f) { if( (f >= 0) && (f <= m_sr*0.5) ) + { m_freq = f; + m_invfreq = 1.f / f; + } else post("frequency out of range"); } @@ -112,7 +134,7 @@ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ SYSTEM##_dsp(int argc, t_atom* argv ) \ { \ - m_sr = 44100; /* assume default sampling rate (for max frequency) */ \ + m_sr = 44100; /* assume default sampling rate */ \ m_system = new SYSTEM; \ \ int size = m_system->get_num_eq(); \ @@ -175,30 +197,6 @@ FLEXT_ATTRVAR_I(m_imethod); -template -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_imethod) - { - 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 void chaos_dsp::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -207,7 +205,7 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, for (int i = 0; i!=n; ++i) { - m_system->m_step(); + m_system->m_perform(); for (int j = 0; j != outlets; ++j) { outsigs[j][i] = m_system->get_data(j); @@ -230,8 +228,8 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); } int next = (phase < n) ? phase : n; @@ -266,8 +264,8 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; @@ -305,8 +303,8 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 78bca06..3f80101 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -32,7 +32,7 @@ public: void m_bang() { - m_system->m_step(); + m_system->m_perform(); int outlets = m_system->get_num_eq(); while (outlets--) diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp new file mode 100644 index 0000000..a5db1cb --- /dev/null +++ b/chaos/src/chua.hpp @@ -0,0 +1,109 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// chua system: dx1/dt = alpha * (x2 - x1 - h(x1)) +// dx2/dt = x1 - x2 + x3 +// dx3/dt = - beta * x2 +// +// with h(x) = b*x + a - b (for x > 1) +// a*x (for -1 <= x <= 1 +// b*x - a + b (for x < -1) +// +// taken from Viktor Avrutin: lecture note + +class chua: + public ode_base +{ +public: + chua() + { + m_num_eq = 3; + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x1,1); + CHAOS_SYS_INIT(x2,1); + CHAOS_SYS_INIT(x3,1); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); + CHAOS_SYS_INIT(alpha,0.3); + CHAOS_SYS_INIT(beta,0.3); + + ode_base_alloc(); + } + + ~chua() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0]; + data_t x2 = data[1]; + data_t x3 = data[2]; + + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + + data_t h; + + if (x1 > 1) + h = b*x1 + a - b; + else if (x1 < -1) + h = b*x1 - a + b; + else + h = a*x1; + + deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); + deriv[1] = x1 - x2 + x3; + deriv[2] = - CHAOS_PARAMETER(beta) * x2; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(alpha); + CHAOS_SYSPAR_FUNCS(beta); +}; + + +#define CHUA_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(beta); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); + +#define CHUA_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(beta); \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); diff --git a/chaos/src/chua_dsp.cpp b/chaos/src/chua_dsp.cpp new file mode 100644 index 0000000..6ae151c --- /dev/null +++ b/chaos/src/chua_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(chua,CHUA); diff --git a/chaos/src/chua_msg.cpp b/chaos/src/chua_msg.cpp new file mode 100644 index 0000000..b00aa7f --- /dev/null +++ b/chaos/src/chua_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(chua,CHUA); diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 0e12ad0..91f11d6 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -33,7 +33,7 @@ public: circle_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(omega, 0.1); CHAOS_SYS_INIT(r, 3); CHAOS_SYS_INIT(x, 0.4); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index eb5b326..85b6928 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -32,7 +32,7 @@ public: coupled_logistic() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(e, 0.06); CHAOS_SYS_INIT(r, 3.7); CHAOS_SYS_INIT(x, 0.1); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 523b1ca..4d62654 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -34,7 +34,7 @@ public: gauss_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0.5); } diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 9e379ae..b43034a 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -32,7 +32,7 @@ public: henon() { m_num_eq = 2; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); CHAOS_SYS_INIT(y,0); diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp index f7e6103..7d73412 100644 --- a/chaos/src/henon_map_dsp.cpp +++ b/chaos/src/henon_map_dsp.cpp @@ -21,4 +21,4 @@ #include "henon_map.hpp" #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(henon, HENON, "henon~"); +CHAOS_DSP_CLASS_NAME(henon, HENON, henon~); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp index 22cddde..e70624f 100644 --- a/chaos/src/henon_map_msg.cpp +++ b/chaos/src/henon_map_msg.cpp @@ -21,4 +21,4 @@ #include "henon_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(henon, HENON, "henon"); +CHAOS_MSG_CLASS_NAME(henon, HENON, henon); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index e267204..c62bc15 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -38,7 +38,7 @@ public: ikeda_laser_map() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(c1,0.4); CHAOS_SYS_INIT(c2,0.9); CHAOS_SYS_INIT(c3,9); diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp index ea18e21..fe2339b 100644 --- a/chaos/src/ikeda_laser_map_dsp.cpp +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -22,5 +22,5 @@ #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda"); +CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda~); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp index 1659159..e1c318d 100644 --- a/chaos/src/ikeda_laser_map_msg.cpp +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -21,4 +21,4 @@ #include "ikeda_laser_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda~"); +CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 1808baa..ef2f603 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -21,7 +21,7 @@ #include "map_base.hpp" // logistic map: x[n+1] = alpha * x[n] * (1 - x[n]) -// 0 <= x[n] < 1 +// 0 < x[n] < 1 // 0 <= alpha <= 4 class logistic: @@ -43,9 +43,9 @@ public: virtual void m_step() { - data_t data = m_data[0]; + data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); - m_data[0] = alpha * data * (1.f - data); + m_data[0] = alpha * x * (1.f - x); } CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); @@ -60,6 +60,14 @@ public: { return (f > 0) && (f < 1); } + + virtual void m_verify() + { + data_t x = m_data[0]; + if (m_pred_x(x)) + return; + m_data[0] = 0.5; + } }; #define LOGISTIC_CALLBACKS \ diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 37cab54..9219390 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -32,7 +32,7 @@ public: lozi_map() { m_num_eq = 2; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); CHAOS_SYS_INIT(y,0); CHAOS_SYS_INIT(a,1.4); diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp index 0448412..06c603d 100644 --- a/chaos/src/lozi_map_dsp.cpp +++ b/chaos/src/lozi_map_dsp.cpp @@ -21,4 +21,4 @@ #include "lozi_map.hpp" #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); +CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, lozi~); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp index 099cbec..719cf61 100644 --- a/chaos/src/lozi_map_msg.cpp +++ b/chaos/src/lozi_map_msg.cpp @@ -21,4 +21,4 @@ #include "lozi_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); +CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, lozi); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index eabb8d4..dcb7ea8 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -29,6 +29,7 @@ void chaos_library_setup() CHAOS_ADD(bungalow_tent); CHAOS_ADD(circle_map); CHAOS_ADD(coupled_logistic); + CHAOS_ADD(chua); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); CHAOS_ADD(duffing_map); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index c88f9ba..e71fe61 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -26,7 +26,10 @@ class map_base : public chaos_base { - +protected: + virtual void m_step() + { + } }; #define MAP_CALLBACKS \ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index 9665d83..2830c2f 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -72,19 +72,3 @@ void ode_base::rk4() / 6.; } -void ode_base::m_step() -{ - switch (m_method) - { - case 0: - rk1(); - break; - case 1: - rk2(); - break; - case 2: - rk4(); - break; - } - -} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index cc526ae..a15dc08 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -30,7 +30,20 @@ public: void set_method(int i) { if (i >=0 && i <4) + { m_method = (unsigned char) i; + switch (i) + { + case 0: + m_routine = &ode_base::rk1; + break; + case 1: + m_routine = &ode_base::rk2; + break; + case 2: + m_routine = &ode_base::rk4; + } + } else post("no such method"); } @@ -47,7 +60,10 @@ public: return (f >= 0); } - virtual void m_step(); + virtual void m_step() + { + (this->*m_routine)(); + } void ode_base_alloc() { @@ -67,11 +83,11 @@ public: { delete m_k[i]; } - delete m_tmp; } protected: + void (ode_base::*m_routine)(); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ data_t* m_k[3]; /* temporary arrays for runge kutta */ diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 85272ee..4b36666 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -41,6 +41,7 @@ public: CHAOS_SYS_INIT(a,4); CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(c,4); + CHAOS_SYS_INIT(dt,0.01); ode_base_alloc(); } diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 376a245..8746345 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -33,7 +33,7 @@ public: sine_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index c0f0b8d..cadcf1e 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -33,7 +33,7 @@ public: standard_map() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(I,0.1); CHAOS_SYS_INIT(theta,0.2); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 9ab59ec..8c00a19 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -20,10 +20,10 @@ #include "map_base.hpp" -// tent map: x[n+1] = 2 * x[n] (for 0 < x <= 0.5) -// 2 * (1 - x[n]) (else) -// 0 <= x[n] < 1 -// taken from Willi-Hans Steeb: Chaos and Fractals +// tent map: x[n+1] = 1 - 2*abs(x[n]) +// -1 < x[n] < 1 +// taken from Julien C. Sprott, Strange Attractors: Creating Patterns in Chaos + class tent_map: public map_base @@ -32,8 +32,8 @@ public: tent_map() { m_num_eq = 1; - m_data = new data_t[1]; - CHAOS_SYS_INIT(x, 0.5); + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x, 0.6); } ~tent_map() @@ -44,17 +44,14 @@ public: virtual void m_step() { data_t data = m_data[0]; - - if (data < 0.5f) - m_data[0] = 2.f * data; - else - m_data[0] = 2.f * (1.f - data); + + m_data[0] = 1 - 2*CHAOS_ABS(data); } - CHAOS_SYSPAR_FUNCS_PRED(x, m_pred_x); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { - return (f >= 0) && (f < 1); + return (f > -1) && (f < 1); } }; diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp index 44c909d..0abf7d5 100644 --- a/chaos/src/tent_map_dsp.cpp +++ b/chaos/src/tent_map_dsp.cpp @@ -23,4 +23,4 @@ -CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, "tent~"); +CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, tent~); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp index 3da82ab..b2d5d8d 100644 --- a/chaos/src/tent_map_msg.cpp +++ b/chaos/src/tent_map_msg.cpp @@ -21,4 +21,4 @@ #include "tent_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, "tent"); +CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, tent); -- cgit v1.2.1 From 29520a2b958bcefe3dd774bd71a7b9e0fd2fa18e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 13 Jan 2005 13:39:57 +0000 Subject: smooth interpolation changing svn path=/trunk/externals/tb/; revision=2500 --- chaos/src/chaos_dsp.hpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 9704432..879eb49 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -74,6 +74,7 @@ public: void set_imethod(int i) { + int imethod = m_imethod; if( (i >= 0) && (i <= 2) ) { m_imethod = i; @@ -95,13 +96,21 @@ public: post("interpolation method out of range"); return; } - if( i != 2) + + if (imethod == 0) + for (int j = 0; j != m_system->get_num_eq(); ++j) + { + m_values[j] = m_system->get_data(j); + m_slopes[j] = 0; + } + + if( i == 2) { for (int j = 0; j != m_system->get_num_eq(); ++j) { - m_nextvalues[i] = 0; - m_nextmidpts[i] = 0; - m_curves[i] = 0; + m_phase = 0; /* reschedule to avoid click, find a better way later*/ + m_nextvalues[j] = m_values[j]; + m_nextmidpts[j] = m_values[j]; } } @@ -221,9 +230,8 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, int outlets = m_system->get_num_eq(); int phase = m_phase; - - int i = 0; - + + int offset = 0; while (n) { if (phase == 0) @@ -236,19 +244,15 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, n -= next; phase -=next; - while (next--) + for (int i = 0; i != outlets; ++i) { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - ++i; + SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); } + offset += next; } m_phase = phase; } - /* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, -- cgit v1.2.1 From 2393d5bab1917825e806871d9050ca54dc3041f3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 12 Feb 2005 08:58:21 +0000 Subject: stability improvement and others svn path=/trunk/externals/tb/; revision=2568 --- chaos/src/Makefile.am | 2 +- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 2 +- chaos/src/driven_anharmonic.hpp | 2 +- chaos/src/latoocarfian.hpp | 12 ++++++++++++ chaos/src/latoomutalpha.hpp | 12 ++++++++++++ chaos/src/latoomutbeta.hpp | 13 +++++++++++++ chaos/src/latoomutgamma.hpp | 13 +++++++++++++ chaos/src/main.cpp | 3 ++- 9 files changed, 56 insertions(+), 4 deletions(-) (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 213e313..2b87927 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,6 +1,6 @@ NAME = chaos -BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ +BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ bernoulli_dsp.cpp bernoulli_msg.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index a1a3467..0f87b51 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,6 +22,7 @@ #define FLEXT_ATTRIBUTES 1 +#define _USE_MATH_DEFINES /* tg says: define this before including cmath */ #include "flext.h" #include "chaos_defs.hpp" #include diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index a2072d0..3e11201 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -56,7 +56,7 @@ public: data_t * m_data; // state of the system protected: - virtual void m_step(); + virtual void m_step() = 0; int m_num_eq; // number of equations of the system }; diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 8c319e9..56d81e0 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -71,7 +71,7 @@ public: m_t += m_dt; if (m_t > 2 * M_PI) - m_t = fmod(m_t, 2*M_PI); + m_t = fmod(m_t, (data_t)2*M_PI); } data_t m_t; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index c2a31a1..1fe1b9a 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -76,6 +76,18 @@ public: { return (f > -0.5) && (f < 1.5); } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; }; diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 6926d1b..015eddf 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -61,6 +61,18 @@ public: m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; } + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index 4940be1..fac43d6 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -58,6 +58,19 @@ public: m_data[1] = sin(x1*a) + tmp*tmp; } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index b4f3bf8..d83059e 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -58,6 +58,19 @@ public: m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index dcb7ea8..c78a7b5 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,8 @@ void chaos_library_setup() { - post("chaos~ version "PACKAGE_VERSION"\n"); + post("chaos~ version "PACKAGE_VERSION", compiled on "__DATE__" \n"); + CHAOS_ADD(bernoulli); CHAOS_ADD(bungalow_tent); -- cgit v1.2.1 From 5e3a5a223c834adc8b27d76cbe4b1e57f73b6cc0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 11 May 2005 20:26:46 +0000 Subject: thnx thomas svn path=/trunk/externals/tb/; revision=2960 --- chaos/src/driven_anharmonic.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chaos') diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 56d81e0..f4c8da4 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -71,7 +71,7 @@ public: m_t += m_dt; if (m_t > 2 * M_PI) - m_t = fmod(m_t, (data_t)2*M_PI); + m_t = fmod(m_t, (data_t)(M_PI*2)); } data_t m_t; -- cgit v1.2.1 From 0a333caec5eb5ed2a97d4d1b5fbde37724280fdc Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 11 May 2005 20:28:00 +0000 Subject: add flext build system support svn path=/trunk/externals/tb/; revision=2961 --- chaos/package.txt | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 chaos/package.txt (limited to 'chaos') diff --git a/chaos/package.txt b/chaos/package.txt new file mode 100644 index 0000000..cd87590 --- /dev/null +++ b/chaos/package.txt @@ -0,0 +1,86 @@ +NAME=chaos + +SRCDIR=src + +#PRECOMPILE=chaos.hpp + +SRCS= \ +main.cpp \ +bernoulli_dsp.cpp \ +bernoulli_msg.cpp \ +bungalow_tent_dsp.cpp \ +bungalow_tent_msg.cpp \ +chaos_base.cpp \ +chaos_dsp.cpp \ +chua_dsp.cpp \ +chua_msg.cpp \ +circle_map_dsp.cpp \ +circle_map_msg.cpp \ +coupled_logistic_dsp.cpp \ +coupled_logistic_msg.cpp \ +driven_anharmonic_dsp.cpp \ +driven_anharmonic_msg.cpp \ +driven_van_der_pol_dsp.cpp \ +driven_van_der_pol_msg.cpp \ +duffing_map_dsp.cpp \ +duffing_map_msg.cpp \ +gauss_map_dsp.cpp \ +gauss_map_msg.cpp \ +henon_map_dsp.cpp \ +henon_map_msg.cpp \ +ikeda_laser_map_dsp.cpp \ +ikeda_laser_map_msg.cpp \ +latoocarfian_dsp.cpp \ +latoocarfian_msg.cpp \ +latoomutalpha_dsp.cpp \ +latoomutalpha_msg.cpp \ +latoomutbeta_dsp.cpp \ +latoomutbeta_msg.cpp \ +latoomutgamma_dsp.cpp \ +latoomutgamma_msg.cpp \ +logistic_dsp.cpp \ +logistic_msg.cpp \ +lorenz_dsp.cpp \ +lorenz_msg.cpp \ +lozi_map_dsp.cpp \ +lozi_map_msg.cpp \ +ode_base.cpp \ +roessler_dsp.cpp \ +roessler_msg.cpp \ +sine_map_dsp.cpp \ +sine_map_msg.cpp \ +standard_map_dsp.cpp \ +standard_map_msg.cpp \ +tent_map_dsp.cpp \ +tent_map_msg.cpp \ + +HDRS= \ +bernoulli_map.hpp \ +bungalow_tent_map.hpp \ +chaos.hpp \ +chaos_base.hpp \ +chaos_defs.hpp \ +chaos_dsp.hpp \ +chaos_msg.hpp \ +chua.hpp \ +circle_map.hpp \ +coupled_logistic.hpp \ +driven_anharmonic.hpp \ +driven_van_der_pol.hpp \ +duffing_map.hpp \ +gauss_map.hpp \ +henon_map.hpp \ +ikeda_laser_map.hpp \ +latoocarfian.hpp \ +latoomutalpha.hpp \ +latoomutbeta.hpp \ +latoomutgamma.hpp \ +logistic_map.hpp \ +lorenz.hpp \ +lozi_map.hpp \ +map_base.hpp \ +ode_base.hpp \ +roessler.hpp \ +sine_map.hpp \ +standard_map.hpp \ +tent_map.hpp -- cgit v1.2.1 From 2434290915cda6ed855e4dc2249312153b995817 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Jun 2005 12:52:17 +0000 Subject: changed initialisation svn path=/trunk/externals/tb/; revision=3145 --- chaos/src/Makefile.am | 4 +- chaos/src/bernoulli_map.hpp | 11 ++-- chaos/src/bungalow_tent_map.hpp | 12 ++-- chaos/src/chaos_base.hpp | 26 ++++++-- chaos/src/chaos_defs.hpp | 43 +++++++++++- chaos/src/chaos_dsp.hpp | 138 +++++++++++++++++++++------------------ chaos/src/chua.hpp | 22 ++++--- chaos/src/circle_map.hpp | 15 +++-- chaos/src/coupled_logistic.hpp | 38 ++++++++--- chaos/src/driven_anharmonic.hpp | 26 ++++---- chaos/src/driven_van_der_pol.hpp | 22 +++---- chaos/src/duffing_map.hpp | 16 +++-- chaos/src/gauss_map.hpp | 10 +-- chaos/src/henon_map.hpp | 16 +++-- chaos/src/ikeda_laser_map.hpp | 21 +++--- chaos/src/latoocarfian.hpp | 20 +++--- chaos/src/latoomutalpha.hpp | 20 +++--- chaos/src/latoomutbeta.hpp | 16 +++-- chaos/src/latoomutgamma.hpp | 16 +++-- chaos/src/logistic_map.hpp | 10 +-- chaos/src/lorenz.hpp | 25 +++---- chaos/src/lozi_map.hpp | 24 ++++--- chaos/src/main.cpp | 2 +- chaos/src/roessler.hpp | 24 +++---- chaos/src/sine_map.hpp | 10 +-- chaos/src/standard_map.hpp | 14 ++-- chaos/src/tent_map.hpp | 10 +-- 27 files changed, 371 insertions(+), 240 deletions(-) (limited to 'chaos') diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 2b87927..e85310c 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -16,13 +16,13 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp logistic_search.cpp\ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ roessler_dsp.cpp roessler_msg.cpp \ sine_map_dsp.cpp sine_map_msg.cpp \ standard_map_dsp.cpp standard_map_msg.cpp \ - tent_map_dsp.cpp tent_map_msg.cpp + tent_map_dsp.cpp tent_map_msg.cpp CXXFLAGS = @CXXFLAGS@ \ @OPT_FLAGS@ \ diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 821f24f..31db7f7 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -28,16 +28,19 @@ class bernoulli: public map_base { public: + bernoulli() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0.5,0); + + CHAOS_POSTCONSTRUCTOR; } ~bernoulli() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 0dfe709..5da431d 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -38,15 +38,17 @@ class bungalow_tent: public: bungalow_tent() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x, 0.6); - CHAOS_SYS_INIT(r, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.6,0); + CHAOS_PAR_INIT(r, 0.5); + + CHAOS_POSTCONSTRUCTOR; } ~bungalow_tent() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 3e11201..959afdf 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -21,6 +21,9 @@ #ifndef __chaos_base_hpp #include "chaos.hpp" +#include + +#define MAXDIMENSION 5 // this should be enough for the first class chaos_base { @@ -42,6 +45,9 @@ public: m_verify(); } + std::map attr_ind; + + // check the integrity of the system virtual void m_verify() { for (int i = 0; i != get_num_eq(); ++i) @@ -52,14 +58,25 @@ public: #endif } }; - - data_t * m_data; // state of the system + + data_t m_data[MAXDIMENSION]; // state of the system protected: - virtual void m_step() = 0; - int m_num_eq; // number of equations of the system + virtual void m_step() = 0; // iteration + int m_num_eq; // number of equations of the system + flext::AtomList Parameter; // parameter + flext::AtomList System; // system }; +#define CHAOS_PRECONSTRUCTOR \ + /* dummy */ + +#define CHAOS_POSTCONSTRUCTOR \ +m_num_eq = System.Count(); + +#define CHAOS_DESTRUCTOR \ + + #define CHAOS_CALLBACKS \ public: \ @@ -69,6 +86,7 @@ void get_dimension(int &i) \ } \ FLEXT_CALLGET_I(get_dimension); + #define CHAOS_ATTRIBUTES \ FLEXT_ADDATTR_GET("dimension",get_dimension); diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index 08c47d4..d9f60d8 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -124,9 +124,24 @@ FLEXT_CALLVAR_I(get_##NAME, set_##NAME); #define CHAOS_SYS_ATTRIBUTE(NAME) \ FLEXT_ADDATTR_VAR(#NAME,get_##NAME, set_##NAME); -#define CHAOS_SYS_INIT(NAME, VALUE) \ + +#define CHAOS_INIT(NAME, VALUE) \ set_##NAME(VALUE); +#define CHAOS_SYS_INIT(NAME, VALUE, INDEX) \ +set_##NAME(VALUE); \ +t_atom atom_##NAME; \ +flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ +System.Append(atom_##NAME); \ +attr_ind[flext::MakeSymbol(#NAME)] = INDEX; + +#define CHAOS_PAR_INIT(NAME, VALUE) \ +set_##NAME(VALUE); \ +t_atom atom_##NAME; \ +flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ +Parameter.Append(atom_##NAME); + + #define CHAOS_PARAMETER(NAME) m_##NAME @@ -142,6 +157,7 @@ class CLASSNAME##_dsp: \ }; \ FLEXT_LIB_DSP_V(#CLASSNAME"~", CLASSNAME##_dsp); + #define CHAOS_DSP_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ class CLASSNAME##_dsp: \ public chaos_dsp \ @@ -161,6 +177,7 @@ class CLASSNAME##_msg: \ }; \ FLEXT_LIB_V(#CLASSNAME, CLASSNAME##_msg); + #define CHAOS_MSG_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ class CLASSNAME##_msg: \ public chaos_msg \ @@ -170,9 +187,31 @@ class CLASSNAME##_msg: \ }; \ FLEXT_LIB_V(#NAME, CLASSNAME##_msg); +#define CHAOS_SEARCH_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_search: \ + public chaos_search \ +{ \ + CHAOS_SEARCH_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#CLASSNAME"_search", CLASSNAME##_search); + + +#define CHAOS_SEARCH_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_msg: \ + public chaos_search \ +{ \ + CHAOS_SEARCH_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#NAME, CLASSNAME##_msg); + + + #define CHAOS_ADD(NAME) \ FLEXT_DSP_SETUP(NAME##_dsp); \ -FLEXT_SETUP(NAME##_msg); +FLEXT_SETUP(NAME##_msg); \ +FLEXT_SETUP(NAME##_search); #define __chaos_defs_hpp #endif /* __chaos_defs_hpp */ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 879eb49..bb3c5fa 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -104,7 +104,7 @@ public: m_slopes[j] = 0; } - if( i == 2) + if(i == 2 && imethod != 2) { for (int j = 0; j != m_system->get_num_eq(); ++j) { @@ -125,9 +125,17 @@ public: { if( (f >= 0) && (f <= m_sr*0.5) ) { + if (m_freq == -1) + set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } + else if (f == -1) + { + m_freq = -1; + + m_routine = &thisType::m_signal_; + } else post("frequency out of range"); } @@ -138,70 +146,70 @@ public: /* create constructor / destructor */ -#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ -FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ - \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_sr = 44100; /* assume default sampling rate */ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - 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]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ - FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ - \ - if (argc > 0) \ - { \ - CHAOS_SYS_INIT(freq, GetAInt(argv[0])); \ - } \ - else \ - { \ - CHAOS_SYS_INIT(freq, 440); \ - } \ - \ - if (argc > 1) \ - { \ - CHAOS_SYS_INIT(imethod, GetAInt(argv[1])); \ - } \ - else \ - { \ - CHAOS_SYS_INIT(imethod, 0); \ - } \ - \ - m_phase = 0; \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ -{ \ - delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ -} \ - \ -FLEXT_ATTRVAR_F(m_freq); \ +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +SYSTEM##_dsp(int argc, t_atom* argv ) \ +{ \ + m_sr = 44100; /* assume default sampling rate */ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + 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]; \ + \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ + \ + if (argc > 0) \ + { \ + CHAOS_INIT(freq, GetAInt(argv[0])); \ + } \ + else \ + { \ + CHAOS_INIT(freq, 440); \ + } \ + \ + if (argc > 1) \ + { \ + CHAOS_INIT(imethod, GetAInt(argv[1])); \ + } \ + else \ + { \ + CHAOS_INIT(imethod, 0); \ + } \ + \ + m_phase = 0; \ + \ + ATTRIBUTES; \ +} \ + \ +~SYSTEM##_dsp() \ +{ \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ FLEXT_ATTRVAR_I(m_imethod); diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index a5db1cb..e54df47 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -36,15 +36,18 @@ class chua: public: chua() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x1,1); - CHAOS_SYS_INIT(x2,1); - CHAOS_SYS_INIT(x3,1); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); - CHAOS_SYS_INIT(alpha,0.3); - CHAOS_SYS_INIT(beta,0.3); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x1,1,0); + CHAOS_SYS_INIT(x2,1,1); + CHAOS_SYS_INIT(x3,1,2); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + CHAOS_PAR_INIT(alpha,0.3); + CHAOS_PAR_INIT(beta,0.3); + + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } @@ -52,7 +55,6 @@ public: ~chua() { ode_base_free(); - delete m_data; } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 91f11d6..b6442a8 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -32,16 +32,19 @@ class circle_map: public: circle_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(omega, 0.1); - CHAOS_SYS_INIT(r, 3); - CHAOS_SYS_INIT(x, 0.4); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.4,0); + + CHAOS_PAR_INIT(omega, 0.1); + CHAOS_PAR_INIT(r, 3); + + CHAOS_POSTCONSTRUCTOR; } ~circle_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 85b6928..7cc8602 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -21,7 +21,7 @@ #include "map_base.hpp" // coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) -// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[t] - y[t]) +// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[n] - y[n]) // 1 <= r <= 4 // taken from Willi-Hans Steeb: Chaos and Fractals @@ -31,17 +31,19 @@ class coupled_logistic: public: coupled_logistic() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(e, 0.06); - CHAOS_SYS_INIT(r, 3.7); - CHAOS_SYS_INIT(x, 0.1); - CHAOS_SYS_INIT(x, 0.2); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(e, 0.06); + CHAOS_PAR_INIT(r, 3.7); + + CHAOS_SYS_INIT(x, 0.1,0); + CHAOS_SYS_INIT(y, 0.2,1); + + CHAOS_POSTCONSTRUCTOR; } ~coupled_logistic() { - delete m_data; } virtual void m_step() @@ -61,8 +63,24 @@ public: return (f > 0) && (f < 4); } - CHAOS_SYSVAR_FUNCS(x, 0); - CHAOS_SYSVAR_FUNCS(y, 0); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_xy); + CHAOS_SYSVAR_FUNCS_PRED(y, 0, m_pred_xy); + + bool m_pred_xy(t_float f) + { + return (f > 0) && (f < 1); + } + + virtual void m_verify() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + if (!m_pred_xy(x)) + m_data[0] = 0.5; + if (!m_pred_xy(y)) + m_data[1] = 0.5; + } + }; diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index f4c8da4..16e053b 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -34,22 +34,22 @@ class driven_anharmonic public: driven_anharmonic() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0); - CHAOS_SYS_INIT(u2,1); + CHAOS_SYS_INIT(u1,0,0); + CHAOS_SYS_INIT(u2,1,1); - CHAOS_SYS_INIT(a,1); - CHAOS_SYS_INIT(b,-10); - CHAOS_SYS_INIT(c,100); - CHAOS_SYS_INIT(Omega,3.5); - CHAOS_SYS_INIT(k1,0.01); - CHAOS_SYS_INIT(k2,1); + CHAOS_PAR_INIT(a,1); + CHAOS_PAR_INIT(b,-10); + CHAOS_PAR_INIT(c,100); + CHAOS_PAR_INIT(Omega,3.5); + CHAOS_PAR_INIT(k1,0.01); + CHAOS_PAR_INIT(k2,1); + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); m_t = 0; } @@ -57,7 +57,7 @@ public: ~driven_anharmonic() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 23386b3..65290ee 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -35,27 +35,27 @@ class driven_van_der_pol public: driven_van_der_pol() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0.8); - CHAOS_SYS_INIT(u2,0.6); - CHAOS_SYS_INIT(u3,0.4); + CHAOS_SYS_INIT(u1,0.8, 0); + CHAOS_SYS_INIT(u2,0.6, 1); + CHAOS_SYS_INIT(u3,0.4, 2); - CHAOS_SYS_INIT(a,5); - CHAOS_SYS_INIT(Omega,2.466); - CHAOS_SYS_INIT(k,5); + CHAOS_PAR_INIT(a,5); + CHAOS_PAR_INIT(Omega,2.466); + CHAOS_PAR_INIT(k,5); + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } ~driven_van_der_pol() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 71b8cbd..5110873 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -31,17 +31,19 @@ class duffing_map: public: duffing_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x1, 0.5); - CHAOS_SYS_INIT(x2, 0.5); - CHAOS_SYS_INIT(a, 0.5); - CHAOS_SYS_INIT(b, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x1, 0.5, 0); + CHAOS_SYS_INIT(x2, 0.5, 1); + CHAOS_PAR_INIT(a, 0.5); + CHAOS_PAR_INIT(b, 0.5); + + CHAOS_POSTCONSTRUCTOR; } ~duffing_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 4d62654..1e023d2 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -33,14 +33,16 @@ class gauss_map: public: gauss_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0.5, 0); + + CHAOS_POSTCONSTRUCTOR; } ~gauss_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index b43034a..73aed66 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -31,18 +31,20 @@ class henon: public: henon() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0); - CHAOS_SYS_INIT(y,0); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); + CHAOS_SYS_INIT(x,0,0); + CHAOS_SYS_INIT(y,0,1); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + + CHAOS_POSTCONSTRUCTOR; } ~henon() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index c62bc15..ece0b9f 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -37,19 +37,22 @@ class ikeda_laser_map: public: ikeda_laser_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(c1,0.4); - CHAOS_SYS_INIT(c2,0.9); - CHAOS_SYS_INIT(c3,9); - CHAOS_SYS_INIT(roh,0.85); - CHAOS_SYS_INIT(x,0.5); - CHAOS_SYS_INIT(y,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(c1,0.4); + CHAOS_PAR_INIT(c2,0.9); + CHAOS_PAR_INIT(c3,9); + CHAOS_PAR_INIT(roh,0.85); + + CHAOS_SYS_INIT(x,0.5,0); + CHAOS_SYS_INIT(y,0.5,1); + + CHAOS_POSTCONSTRUCTOR; } ~ikeda_laser_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 1fe1b9a..9884fd1 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -33,20 +33,22 @@ class latoocarfian public: latoocarfian() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); - CHAOS_SYS_INIT(c,0.765145); - CHAOS_SYS_INIT(d,0.744728); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + CHAOS_PAR_INIT(c,0.765145); + CHAOS_PAR_INIT(d,0.744728); + + CHAOS_POSTCONSTRUCTOR; } ~latoocarfian() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 015eddf..ca99c12 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -32,19 +32,21 @@ class latoomutalpha public: latoomutalpha() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.2); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); - CHAOS_SYS_INIT(c,0.765145); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.2,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + CHAOS_PAR_INIT(c,0.765145); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutalpha() { - delete m_data; + } virtual void m_step() @@ -68,7 +70,7 @@ public: { #ifndef DOUBLE_PRECISION if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; + m_data[i] = 0.5; #endif } }; diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index fac43d6..e27e5a2 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -32,18 +32,20 @@ class latoomutbeta public: latoomutbeta() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.5); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutbeta() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index d83059e..fcdf6a6 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -32,18 +32,20 @@ class latoomutgamma public: latoomutgamma() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.5); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutgamma() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index ef2f603..16e824e 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -30,10 +30,12 @@ class logistic: public: logistic() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(alpha, 3.8); - CHAOS_SYS_INIT(x, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(alpha, 3.8); + CHAOS_SYS_INIT(x, 0.5,0); + + CHAOS_POSTCONSTRUCTOR; } ~logistic() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index c876b4a..ee4e516 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -31,25 +31,28 @@ class lorenz public: lorenz() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); - CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.7); - CHAOS_SYS_INIT(x3,0.6); - CHAOS_SYS_INIT(sigma,16); - CHAOS_SYS_INIT(b,4); - CHAOS_SYS_INIT(r,40); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + CHAOS_SYS_INIT(x1,0.8,0); + CHAOS_SYS_INIT(x2,0.7,1); + CHAOS_SYS_INIT(x3,0.6,2); + + CHAOS_PAR_INIT(sigma,16); + CHAOS_PAR_INIT(b,4); + CHAOS_PAR_INIT(r,40); + + CHAOS_POSTCONSTRUCTOR; + ode_base_alloc(); } ~lorenz() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 9219390..3358cf5 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -31,17 +31,20 @@ class lozi_map: public: lozi_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0); - CHAOS_SYS_INIT(y,0); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0,0); + CHAOS_SYS_INIT(y,0,1); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + + CHAOS_POSTCONSTRUCTOR; } ~lozi_map() { - delete m_data; + } virtual void m_step() @@ -57,7 +60,12 @@ public: m_data[1] = CHAOS_PARAMETER(b) * x; } - + virtual void m_verify() + { + if (PD_BIGORSMALL(m_data[0])) + m_data[0] = 1; + } + CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index c78a7b5..f781f7d 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,7 @@ void chaos_library_setup() { - post("chaos~ version "PACKAGE_VERSION", compiled on "__DATE__" \n"); + post("chaos~ version 0.01, compiled on "__DATE__" \n"); CHAOS_ADD(bernoulli); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 4b36666..3603a58 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -31,25 +31,27 @@ class roessler public: roessler() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(x1,0); - CHAOS_SYS_INIT(x2,0); - CHAOS_SYS_INIT(x3,0); - CHAOS_SYS_INIT(a,4); - CHAOS_SYS_INIT(b,4); - CHAOS_SYS_INIT(c,4); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + CHAOS_SYS_INIT(x1,0,0); + CHAOS_SYS_INIT(x2,0,1); + CHAOS_SYS_INIT(x3,0,2); + + CHAOS_PAR_INIT(a,4); + CHAOS_PAR_INIT(b,4); + CHAOS_PAR_INIT(c,4); + + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } ~roessler() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 8746345..21c7e39 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -32,14 +32,16 @@ class sine_map: public: sine_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0,0); + + CHAOS_POSTCONSTRUCTOR; } ~sine_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index cadcf1e..663280a 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -32,17 +32,19 @@ class standard_map: public: standard_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(I,0.1,0); + CHAOS_SYS_INIT(theta,0.2,1); + + CHAOS_PAR_INIT(k, 0.8); - CHAOS_SYS_INIT(I,0.1); - CHAOS_SYS_INIT(theta,0.2); - CHAOS_SYS_INIT(k, 0.8); + CHAOS_POSTCONSTRUCTOR; } ~standard_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 8c00a19..e23fb73 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -31,14 +31,16 @@ class tent_map: public: tent_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x, 0.6); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.6,0); + + CHAOS_POSTCONSTRUCTOR; } ~tent_map() { - delete m_data; + } virtual void m_step() -- cgit v1.2.1 From d1ed55f96f9cecc818844006fb36cd58ca70da5e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 16 Jun 2005 13:02:02 +0000 Subject: - parameter searching (broken) - misc. updates svn path=/trunk/externals/tb/; revision=3192 --- chaos/src/bernoulli_search.cpp | 24 ++++ chaos/src/bungalow_tent_search.cpp | 24 ++++ chaos/src/chaos.hpp | 17 +++ chaos/src/chaos_base.hpp | 16 ++- chaos/src/chaos_defs.hpp | 6 +- chaos/src/chaos_dsp.hpp | 55 +++++++-- chaos/src/chaos_search.hpp | 191 ++++++++++++++++++++++++++++++++ chaos/src/chua.hpp | 83 ++++++++++++-- chaos/src/chua_search.cpp | 24 ++++ chaos/src/circle_map_search.cpp | 24 ++++ chaos/src/coupled_logistic.hpp | 12 +- chaos/src/coupled_logistic_msg.cpp | 14 +-- chaos/src/coupled_logistic_search.cpp | 24 ++++ chaos/src/delayed_logistic.hpp | 92 +++++++++++++++ chaos/src/delayed_logistic__search.cpp | 24 ++++ chaos/src/delayed_logistic_dsp.cpp | 23 ++++ chaos/src/delayed_logistic_msg.cpp | 23 ++++ chaos/src/delayed_logistic_search.cpp | 24 ++++ chaos/src/driven_anharmonic_search.cpp | 24 ++++ chaos/src/driven_van_der_pol.hpp | 13 ++- chaos/src/driven_van_der_pol_search.cpp | 24 ++++ chaos/src/duffing_map_search.cpp | 24 ++++ chaos/src/gauss_map_search.cpp | 24 ++++ chaos/src/gaussian_map.hpp | 84 ++++++++++++++ chaos/src/gaussian_map_dsp.cpp | 23 ++++ chaos/src/gaussian_map_msg.cpp | 23 ++++ chaos/src/gaussian_map_search.cpp | 24 ++++ chaos/src/henon_map_search.cpp | 24 ++++ chaos/src/hydrogen.hpp | 156 ++++++++++++++++++++++++++ chaos/src/hydrogen_dsp.cpp | 23 ++++ chaos/src/hydrogen_msg.cpp | 23 ++++ chaos/src/hydrogen_search.cpp | 24 ++++ chaos/src/ikeda_laser_map_search.cpp | 24 ++++ chaos/src/latoocarfian.hpp | 12 +- chaos/src/latoocarfian_search.cpp | 24 ++++ chaos/src/latoomutalpha.hpp | 16 +-- chaos/src/latoomutalpha_search.cpp | 24 ++++ chaos/src/latoomutbeta.hpp | 13 +-- chaos/src/latoomutbeta_search.cpp | 24 ++++ chaos/src/latoomutgamma.hpp | 14 +-- chaos/src/latoomutgamma_search.cpp | 24 ++++ chaos/src/logistic_map.hpp | 4 +- chaos/src/logistic_search.cpp | 24 ++++ chaos/src/lorenz.hpp | 10 ++ chaos/src/lorenz_search.cpp | 24 ++++ chaos/src/lozi_map.hpp | 5 - chaos/src/lozi_map_search.cpp | 24 ++++ chaos/src/main.cpp | 3 + chaos/src/ode_base.hpp | 9 +- chaos/src/roessler.hpp | 10 +- chaos/src/roessler_search.cpp | 24 ++++ chaos/src/sine_map_search.cpp | 24 ++++ chaos/src/standard_map_search.cpp | 24 ++++ chaos/src/tent_map_search.cpp | 24 ++++ 54 files changed, 1504 insertions(+), 93 deletions(-) create mode 100644 chaos/src/bernoulli_search.cpp create mode 100644 chaos/src/bungalow_tent_search.cpp create mode 100644 chaos/src/chaos_search.hpp create mode 100644 chaos/src/chua_search.cpp create mode 100644 chaos/src/circle_map_search.cpp create mode 100644 chaos/src/coupled_logistic_search.cpp create mode 100644 chaos/src/delayed_logistic.hpp create mode 100644 chaos/src/delayed_logistic__search.cpp create mode 100644 chaos/src/delayed_logistic_dsp.cpp create mode 100644 chaos/src/delayed_logistic_msg.cpp create mode 100644 chaos/src/delayed_logistic_search.cpp create mode 100644 chaos/src/driven_anharmonic_search.cpp create mode 100644 chaos/src/driven_van_der_pol_search.cpp create mode 100644 chaos/src/duffing_map_search.cpp create mode 100644 chaos/src/gauss_map_search.cpp create mode 100644 chaos/src/gaussian_map.hpp create mode 100644 chaos/src/gaussian_map_dsp.cpp create mode 100644 chaos/src/gaussian_map_msg.cpp create mode 100644 chaos/src/gaussian_map_search.cpp create mode 100644 chaos/src/henon_map_search.cpp create mode 100644 chaos/src/hydrogen.hpp create mode 100644 chaos/src/hydrogen_dsp.cpp create mode 100644 chaos/src/hydrogen_msg.cpp create mode 100644 chaos/src/hydrogen_search.cpp create mode 100644 chaos/src/ikeda_laser_map_search.cpp create mode 100644 chaos/src/latoocarfian_search.cpp create mode 100644 chaos/src/latoomutalpha_search.cpp create mode 100644 chaos/src/latoomutbeta_search.cpp create mode 100644 chaos/src/latoomutgamma_search.cpp create mode 100644 chaos/src/logistic_search.cpp create mode 100644 chaos/src/lorenz_search.cpp create mode 100644 chaos/src/lozi_map_search.cpp create mode 100644 chaos/src/roessler_search.cpp create mode 100644 chaos/src/sine_map_search.cpp create mode 100644 chaos/src/standard_map_search.cpp create mode 100644 chaos/src/tent_map_search.cpp (limited to 'chaos') diff --git a/chaos/src/bernoulli_search.cpp b/chaos/src/bernoulli_search.cpp new file mode 100644 index 0000000..e4fc398 --- /dev/null +++ b/chaos/src/bernoulli_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(bernoulli, BERNOULLI); diff --git a/chaos/src/bungalow_tent_search.cpp b/chaos/src/bungalow_tent_search.cpp new file mode 100644 index 0000000..d76d195 --- /dev/null +++ b/chaos/src/bungalow_tent_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(bungalow_tent, BUNGALOW_TENT); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 0f87b51..2e2eb8b 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -27,6 +27,8 @@ #include "chaos_defs.hpp" #include +#include + /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; @@ -36,6 +38,21 @@ typedef float data_t; #define CHAOS_ABS(x) fabsf(x) #endif +inline data_t chaos_mod(data_t x, data_t y) +{ +#ifdef DOUBLE_PRECISION + return fmod(x,y); +#else + return fmodf(x,y); +#endif +} + +inline data_t rand_range(data_t low, data_t high) +{ + return low + ( (rand() * (high - low)) / RAND_MAX); +} + + #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 959afdf..5e2a99f 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -29,26 +29,32 @@ class chaos_base { public: - t_sample get_data(unsigned int i) + inline t_sample get_data(unsigned int i) { return (t_sample)m_data[i]; /* this is not save, but fast */ } - int get_num_eq() + inline int get_num_eq() { return m_num_eq; } - void m_perform() + inline void m_perform() { m_step(); + m_bash_denormals(); m_verify(); } - std::map attr_ind; + std::map attr_ind; + // TableAnyMap attr_ind; /* thomas fragen :-) */ // check the integrity of the system virtual void m_verify() + { + } + + inline void m_bash_denormals() { for (int i = 0; i != get_num_eq(); ++i) { @@ -58,7 +64,7 @@ public: #endif } }; - + data_t m_data[MAXDIMENSION]; // state of the system protected: diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index d9f60d8..bf8607c 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -97,7 +97,8 @@ data_t m_##NAME; #define CHAOS_SYS_CALLBACKS(NAME) \ -public:void get_##NAME(t_float &f) \ +public: \ +void get_##NAME(t_float &f) \ { \ f = m_system->get_##NAME(); \ } \ @@ -135,6 +136,9 @@ flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ System.Append(atom_##NAME); \ attr_ind[flext::MakeSymbol(#NAME)] = INDEX; +#define CHAOS_SYS_INIT_HIDDEN(NAME, VALUE, INDEX) \ +set_##NAME(VALUE); + #define CHAOS_PAR_INIT(NAME, VALUE) \ set_##NAME(VALUE); \ t_atom atom_##NAME; \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index bb3c5fa..16e2820 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -28,13 +28,15 @@ template class chaos_dsp public: /* signal functions: */ - /* for frequency = sr/2 */ + /* for frequency = sr */ void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); /* sample & hold */ void m_signal_n(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* sample & hold for high frequencies */ + void m_signal_n_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* linear interpolation */ void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); - /* cubic interpolatio */ + /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) @@ -45,8 +47,9 @@ public: virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) { m_sr = Samplerate(); + set_freq(m_freq); /* maybe we have to change the interpolation mode */ } - + void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ @@ -63,6 +66,7 @@ public: float m_freq; /* frequency of oscillations */ float m_invfreq; /* inverse frequency */ int m_phase; /* phase counter */ + float m_fphase; /* phase for high frequency linear interpolation */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ @@ -123,18 +127,22 @@ public: void set_freq(float f) { - if( (f >= 0) && (f <= m_sr*0.5) ) + if (f < 0) /* we can't go back in time :-) */ + f = -f; + + if( f <= m_sr * 0.5 ) { - if (m_freq == -1) + if (m_freq >= m_sr * 0.5) set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } - else if (f == -1) + else if (f > m_sr * 0.5) { - m_freq = -1; + m_freq = f; + m_invfreq = 1.f / f; - m_routine = &thisType::m_signal_; + m_routine = &thisType::m_signal_n_hf; } else post("frequency out of range"); @@ -145,6 +153,7 @@ public: }; + /* create constructor / destructor */ #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ @@ -228,9 +237,39 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, outsigs[j][i] = m_system->get_data(j); } } +} + + +template +void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + float phase = m_fphase; + + int offset = 0; + while (n) + { + while (phase <= 0) + { + m_system->m_perform(); + phase += m_sr * m_invfreq; + } + int next = (phase < n) ? int(ceilf (phase)) : n; + n -= next; + phase -=next; + + for (int i = 0; i != outlets; ++i) + { + SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + } + offset += next; + } + m_fphase = phase; } + template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp new file mode 100644 index 0000000..a7fc44d --- /dev/null +++ b/chaos/src/chaos_search.hpp @@ -0,0 +1,191 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +template class chaos_search + : public flext_base +{ + FLEXT_HEADER(chaos_search, flext_base); + +public: + + /* local data for system, output and interpolation */ + system * m_system; /* the system */ + + + data_t min[MAXDIMENSION]; /* minimal coordinates */ + data_t max[MAXDIMENSION]; /* maximal coordinates */ + data_t final[MAXDIMENSION]; /* initial coordinates for outlet */ + + data_t ly; /* lyapunov exponent */ + + int m_transient_steps; /* steps before starting the analysis */ + int m_asymptotic_steps; /* steps for the analysis */ + + + void get_tsteps(int &i) + { + i = m_transient_steps; + } + + void set_tsteps(int i) + { + if (i > 0) + m_transient_steps = i; + else + m_transient_steps = 0; + } + + void get_asteps(int &i) + { + i = m_asymptotic_steps; + } + + void set_asteps(int &i) + { + if (i > 0) + m_asymptotic_steps = i; + else + m_asymptotic_steps = 0; + } + + void print_results(void) + { + /* - send parameters to 1 + - send initial coordinates to 2 + - send minimal coordinates to 3 + - send lyapunov exponent to 4 + */ + + for (std::map::iterator it = m_system->attr_ind.begin(); + it != m_system->attr_ind.end(); ++it) + { + post("key %s", it->first->s_name); + post("value %f", m_system->get_data(it->second)); + } + } + + void m_search(); + + FLEXT_CALLBACK(m_bang); + FLEXT_CALLVAR_I(get_tsteps, set_tsteps); + FLEXT_CALLVAR_I(get_asteps, set_asteps); + FLEXT_THREAD(m_search); +}; + + +/* create constructor / destructor */ + +#define CHAOS_SEARCH_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_search, chaos_search) \ + \ +SYSTEM##_search(int argc, t_atom* argv ) \ +{ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + \ + m_asymptotic_steps = 10000; \ + m_transient_steps = 100; \ + \ + AddOutList("parameters"); \ + AddOutList("initial coordinates"); \ + AddOutList("minimal coordinates"); \ + AddOutList("maximal coordinates"); \ + AddOutFloat("lyapunov exponent"); \ + \ + FLEXT_ADDATTR_VAR("transient_steps", get_tsteps, set_tsteps); \ + FLEXT_ADDATTR_VAR("steps", get_asteps, set_asteps); \ + ATTRIBUTES; \ + FLEXT_ADDMETHOD_(0,"search", m_search); \ +} \ + \ +~SYSTEM##_search() \ +{ \ + delete m_system; \ +} \ + \ +FLEXT_ATTRVAR_I(m_transient_steps); \ +FLEXT_ATTRVAR_I(m_asymptotic_steps); + + + +template +void chaos_search::m_search() +{ + int dimensions = m_system->get_num_eq(); + + ly = 0; + data_t diff_old = 0.1; + data_t last[MAXDIMENSION]; + + /* transient dynamics */ + for (int i = 0; i != m_transient_steps; ++i) + { + m_system->m_perform(); + } + + for (int i = 0; i != dimensions; ++i) + { + last[i] = min[i] = max[i] = m_system->m_data[i]; + } + + /* now we start the analysis */ + + for (int i = 0; i != m_asymptotic_steps; ++i) + { + + m_system->m_perform(); + + data_t diff = 0; + for (int j = 0; j != dimensions; ++j) + { + /* update min/max */ + data_t datum = m_system->m_data[j]; + if (datum > max[j]) + max[j] = datum; + else if (datum < min[j]) + min[j] = datum; + + /* sum up diff */ + diff += (last[j] - datum) * (last[j] - datum); + + last[j] = datum; + } + diff = sqrt(diff); + + if (diff < 0) + diff = -diff; + + ly += log(diff / diff_old); + diff_old = diff; + + /* todo: maybe some overflow checking */ + if (diff == 0) + break; + } + + + ly /= m_asymptotic_steps; + + print_results(); +} diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index e54df47..3d44708 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -28,7 +28,7 @@ // a*x (for -1 <= x <= 1 // b*x - a + b (for x < -1) // -// taken from Viktor Avrutin: lecture note +// taken from Viktor Avrutin: lecture notes class chua: public ode_base @@ -38,14 +38,17 @@ public: { CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,1,0); + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.05); + + CHAOS_SYS_INIT(x1,1,1); CHAOS_SYS_INIT(x2,1,1); - CHAOS_SYS_INIT(x3,1,2); + CHAOS_SYS_INIT(x3,1,1); - CHAOS_PAR_INIT(a,1.4); - CHAOS_PAR_INIT(b,0.3); - CHAOS_PAR_INIT(alpha,0.3); - CHAOS_PAR_INIT(beta,0.3); + CHAOS_PAR_INIT(a,140); + CHAOS_PAR_INIT(b,30); + CHAOS_PAR_INIT(alpha,30); + CHAOS_PAR_INIT(beta,30); CHAOS_POSTCONSTRUCTOR; @@ -79,12 +82,74 @@ public: deriv[2] = - CHAOS_PARAMETER(beta) * x2; } + virtual void m_verify() + { + data_t x1 = m_data[0]; + data_t x2 = m_data[1]; + data_t x3 = m_data[2]; + + if ( CHAOS_ABS(x3) < 1e-10) + x3 = 0; + + if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ + { + reset(); + return; + } + else + { + data_t c = m_c; + if (m_c) + { + data_t mc = - c; + if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ + { + reset(); + return; + } + if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ + { + reset(); + return; + } + } + } + } + + inline void reset() + { + m_data[0] = rand_range(-1,1); + m_data[1] = rand_range(-1,1); + m_data[2] = rand_range(-1,1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); CHAOS_SYSVAR_FUNCS(x3, 2); - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(b); + /* due to stability issues, we hook into the predicates */ + data_t m_c; + bool m_pred_a(data_t a) + { + data_t b = CHAOS_PARAMETER(b); + m_c = (b - a) / (b + 1); + return true; + } + + bool m_pred_b(data_t b) + { + if (b == -1) + m_c = 0; + else + { + data_t a = CHAOS_PARAMETER(a); + m_c = (b - a) / (b + 1); + } + return true; + } + + CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); CHAOS_SYSPAR_FUNCS(alpha); CHAOS_SYSPAR_FUNCS(beta); }; diff --git a/chaos/src/chua_search.cpp b/chaos/src/chua_search.cpp new file mode 100644 index 0000000..65e8719 --- /dev/null +++ b/chaos/src/chua_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(chua, CHUA); diff --git a/chaos/src/circle_map_search.cpp b/chaos/src/circle_map_search.cpp new file mode 100644 index 0000000..a34bbf8 --- /dev/null +++ b/chaos/src/circle_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(circle_map, CIRCLE_MAP); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 7cc8602..d94ceee 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -22,7 +22,7 @@ // coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) // y[n+1] = r * y[n] * (1 - y[n]) + e * (x[n] - y[n]) -// 1 <= r <= 4 +// 0 <= r <= 4 // taken from Willi-Hans Steeb: Chaos and Fractals class coupled_logistic: @@ -54,6 +54,7 @@ public: data_t r = CHAOS_PARAMETER(r); m_data[0] = r * x * (1.f - x) + e * (y - x); m_data[1] = r * y * (1.f - y) + e * (x - y); + m_verify(); } CHAOS_SYSPAR_FUNCS(e); @@ -76,9 +77,14 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; if (!m_pred_xy(x)) - m_data[0] = 0.5; + m_data[0] = rand_range(0,0.08); if (!m_pred_xy(y)) - m_data[1] = 0.5; + m_data[1] = rand_range(0,0.08); + if (x == y) + { + m_data[0] += rand_range(0,0.2); + m_data[1] += -rand_range(0,0.2); + } } diff --git a/chaos/src/coupled_logistic_msg.cpp b/chaos/src/coupled_logistic_msg.cpp index 994a79d..15ef289 100644 --- a/chaos/src/coupled_logistic_msg.cpp +++ b/chaos/src/coupled_logistic_msg.cpp @@ -1,7 +1,7 @@ // // // chaos~ -// Copyright (C) 2004 Tim Blechmann +// Copyright (C) 2005 Tim Blechmann // // 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 @@ -21,14 +21,4 @@ #include "coupled_logistic.hpp" #include "chaos_msg.hpp" -class coupled_logistic_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(coupled_logistic, COUPLED_LOGISTIC_ATTRIBUTES); - - COUPLED_LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_V("coupled_logistic", coupled_logistic_msg); +CHAOS_MSG_CLASS(coupled_logistic,COUPLED_LOGISTIC) diff --git a/chaos/src/coupled_logistic_search.cpp b/chaos/src/coupled_logistic_search.cpp new file mode 100644 index 0000000..f75938f --- /dev/null +++ b/chaos/src/coupled_logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(coupled_logistic, COUPLED_LOGISTIC); diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp new file mode 100644 index 0000000..c78785f --- /dev/null +++ b/chaos/src/delayed_logistic.hpp @@ -0,0 +1,92 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// delayed logistic map: x[n+1] = alpha * x[n] * (1 - x[n-1]) +// 0 < x[n] < 1 +// 0 <= alpha <= 4 +// taken from E. Atlee Jackson: Perspective of nonlinear dynamics (Vol. 2) + +class delayed_logistic: + public map_base +{ +public: + delayed_logistic() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.5, 0); + + CHAOS_PAR_INIT(alpha, 3.8); + + CHAOS_POSTCONSTRUCTOR; + + m_delayed = get_x(); /* the initial state of the delay */ + } + + ~delayed_logistic() + { + + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t alpha = CHAOS_PARAMETER(alpha); + data_t delayed = m_delayed; + + m_delayed = x; + m_data[0] = alpha * x * (1.f - delayed); + + } + data_t m_delayed; + + CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); + bool m_pred_alpha(t_float f) + { + return (f > 0) && (f < 4); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f > 0) && (f < 1); + } + + virtual void m_verify() + { + data_t x = m_data[0]; + if (m_pred_x(x)) + return; + m_data[0] = 0.5; + } +}; + +#define DELAYED_LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(x); + +#define DELAYED_LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(x); + diff --git a/chaos/src/delayed_logistic__search.cpp b/chaos/src/delayed_logistic__search.cpp new file mode 100644 index 0000000..c082637 --- /dev/null +++ b/chaos/src/delayed_logistic__search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic_.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(delayed_logistic_, DELAYED_LOGISTIC_); diff --git a/chaos/src/delayed_logistic_dsp.cpp b/chaos/src/delayed_logistic_dsp.cpp new file mode 100644 index 0000000..1dec6d0 --- /dev/null +++ b/chaos/src/delayed_logistic_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(delayed_logistic,DELAYED_LOGISTIC); diff --git a/chaos/src/delayed_logistic_msg.cpp b/chaos/src/delayed_logistic_msg.cpp new file mode 100644 index 0000000..10c1b89 --- /dev/null +++ b/chaos/src/delayed_logistic_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(delayed_logistic,DELAYED_LOGISTIC); diff --git a/chaos/src/delayed_logistic_search.cpp b/chaos/src/delayed_logistic_search.cpp new file mode 100644 index 0000000..462e6bf --- /dev/null +++ b/chaos/src/delayed_logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(delayed_logistic, DELAYED_LOGISTIC); diff --git a/chaos/src/driven_anharmonic_search.cpp b/chaos/src/driven_anharmonic_search.cpp new file mode 100644 index 0000000..f05ff85 --- /dev/null +++ b/chaos/src/driven_anharmonic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 65290ee..6156eb0 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -37,7 +37,7 @@ public: { CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); CHAOS_SYS_INIT(u1,0.8, 0); @@ -68,9 +68,16 @@ public: deriv[2] = CHAOS_PARAMETER(Omega); } + virtual void m_verify() + { + /* make sure to stay in the range of 2 pi */ + if (m_data[2] > 2*M_PI) + m_data[2] = chaos_mod(m_data[2], 2*M_PI); + } + CHAOS_SYSVAR_FUNCS(u1, 0); CHAOS_SYSVAR_FUNCS(u2, 1); - CHAOS_SYSVAR_FUNCS(u3, 2); + CHAOS_SYSVAR_FUNCS(u3, 2); CHAOS_SYSPAR_FUNCS(a); CHAOS_SYSPAR_FUNCS(k); @@ -82,6 +89,7 @@ public: ODE_CALLBACKS; \ CHAOS_SYS_CALLBACKS(u1); \ CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(u3); \ CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(k); \ CHAOS_SYS_CALLBACKS(Omega); @@ -90,6 +98,7 @@ CHAOS_SYS_CALLBACKS(Omega); ODE_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(u1); \ CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(u3); \ CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(k); \ CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_van_der_pol_search.cpp b/chaos/src/driven_van_der_pol_search.cpp new file mode 100644 index 0000000..63cc308 --- /dev/null +++ b/chaos/src/driven_van_der_pol_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); diff --git a/chaos/src/duffing_map_search.cpp b/chaos/src/duffing_map_search.cpp new file mode 100644 index 0000000..d6d3168 --- /dev/null +++ b/chaos/src/duffing_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(duffing_map, DUFFING_MAP); diff --git a/chaos/src/gauss_map_search.cpp b/chaos/src/gauss_map_search.cpp new file mode 100644 index 0000000..db8206a --- /dev/null +++ b/chaos/src/gauss_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp new file mode 100644 index 0000000..5f5a4b1 --- /dev/null +++ b/chaos/src/gaussian_map.hpp @@ -0,0 +1,84 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + + +// gaussian map: x[n+1] = exp(-b * x[n] * x[n]) + c +// +// taken from Robert C. Hilborn: Chaos and Nonlinear Dynamics + +class gaussian_map: + public map_base +{ +public: + gaussian_map() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.5, 0); + + CHAOS_PAR_INIT(b,7); + CHAOS_PAR_INIT(c,0.5); + + CHAOS_POSTCONSTRUCTOR; + } + + ~gaussian_map() + { + + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data == 0) + m_data[0] = 0.001; + else + m_data[0] = exp(-CHAOS_PARAMETER(b) * data * data) + + CHAOS_PARAMETER(c); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f >= 0) && (f < 1); + } + + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); + +}; + +#define GAUSSIAN_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + +#define GAUSSIAN_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); + + + diff --git a/chaos/src/gaussian_map_dsp.cpp b/chaos/src/gaussian_map_dsp.cpp new file mode 100644 index 0000000..d548dc0 --- /dev/null +++ b/chaos/src/gaussian_map_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(gaussian_map,GAUSSIAN_MAP); diff --git a/chaos/src/gaussian_map_msg.cpp b/chaos/src/gaussian_map_msg.cpp new file mode 100644 index 0000000..e5aede1 --- /dev/null +++ b/chaos/src/gaussian_map_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(gaussian_map,GAUSSIAN_MAP); diff --git a/chaos/src/gaussian_map_search.cpp b/chaos/src/gaussian_map_search.cpp new file mode 100644 index 0000000..16efd8e --- /dev/null +++ b/chaos/src/gaussian_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(gaussian_map, GAUSSIAN_MAP); diff --git a/chaos/src/henon_map_search.cpp b/chaos/src/henon_map_search.cpp new file mode 100644 index 0000000..d7f3712 --- /dev/null +++ b/chaos/src/henon_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(henon, HENON); diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp new file mode 100644 index 0000000..886539c --- /dev/null +++ b/chaos/src/hydrogen.hpp @@ -0,0 +1,156 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#include "ode_base.hpp" + +// hydrogen atom in a magnetic field + +class hydrogen + : public ode_base +{ + + +public: + hydrogen() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(mu,0.8, 0); + CHAOS_SYS_INIT(muv,0.6, 1); + CHAOS_SYS_INIT(nu,0.4, 2); + CHAOS_SYS_INIT(nuv,0.4, 3); + + CHAOS_PAR_INIT(etilde,-0.3); + + CHAOS_POSTCONSTRUCTOR; + ode_base_alloc(); + reset = 0; + } + + ~hydrogen() + { + ode_base_free(); + } + + virtual void m_system(data_t* deriv, data_t* data) + { + if (reset) + { + (this->*reset)(); + reset = 0; + } + + data_t mu = m_data[0], muv = m_data[1], nu = m_data[2], nuv = m_data[3]; + data_t E = CHAOS_PARAMETER(etilde); + + deriv[0] = muv; + deriv[1] = 2* E * mu - 0.25 * mu * nu * nu * (2*mu*mu+nu*nu); + deriv[2] = nuv; + deriv[3] = 2* E * nu - 0.25 * nu * mu * mu * (2*nu*nu+mu*mu); + } + + virtual void m_verify() + { + /* make sure to stay in the range of 2 pi */ + for (int i = 0; i != get_num_eq(); ++ i) + { + if (m_data[i] > 1) + m_data[i] = 1; + else if (m_data[i] < -1) + m_data[i] = -1; + } + } + + void reset_nuv() + { + data_t mu = m_data[0], muv = m_data[1], nu = m_data[2]; + data_t E = CHAOS_PARAMETER(etilde); + + m_data[1]= sqrt ( 2 * E * (mu*mu + nu*nu) - muv*muv - ( mu*mu * nu*nu * + ( mu*mu + nu*nu )) * 0.25); + +// if (fabs((data[3]))<1e-5) +// data[3]=0; + } + + void reset_muv() + { + data_t mu = m_data[0], nu = m_data[2], nuv = m_data[3]; + data_t E = CHAOS_PARAMETER(etilde); + + m_data[1]= sqrt ( 2 * E * (mu*mu + nu*nu) - nuv*nuv - ( mu*mu * nu*nu * + ( mu*mu + nu*nu )) * 0.25); + +// if (fabs((data[1]))<1e-5) +// data[1]=0; + } + + + /* hook into the predicate to reset the system */ + bool m_pred_pos(t_float f) + { + if (fabs(f) > 1) + return false; + reset = &hydrogen::reset_nuv; + return true; + } + + bool m_pred_nuv(t_float f) + { + reset = &hydrogen::reset_muv; + return true; + } + + bool m_pred_muv(t_float f) + { + reset = &hydrogen::reset_nuv; + return true; + } + + void (hydrogen::*reset)(void); + + CHAOS_SYSVAR_FUNCS_PRED(mu, 0, m_pred_pos); + CHAOS_SYSVAR_FUNCS_PRED(muv, 1, m_pred_nuv); + CHAOS_SYSVAR_FUNCS_PRED(nu, 2, m_pred_pos); + CHAOS_SYSVAR_FUNCS_PRED(nuv, 3, m_pred_muv); + + CHAOS_SYSPAR_FUNCS(etilde); +}; + + +#define HYDROGEN_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(mu); \ +CHAOS_SYS_CALLBACKS(muv); \ +CHAOS_SYS_CALLBACKS(nu); \ +CHAOS_SYS_CALLBACKS(nuv); \ +CHAOS_SYS_CALLBACKS(etilde); + +#define HYDROGEN_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(mu); \ +CHAOS_SYS_ATTRIBUTE(muv); \ +CHAOS_SYS_ATTRIBUTE(nu); \ +CHAOS_SYS_ATTRIBUTE(nuv); \ +CHAOS_SYS_ATTRIBUTE(etilde); diff --git a/chaos/src/hydrogen_dsp.cpp b/chaos/src/hydrogen_dsp.cpp new file mode 100644 index 0000000..118cbc4 --- /dev/null +++ b/chaos/src/hydrogen_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(hydrogen,HYDROGEN); diff --git a/chaos/src/hydrogen_msg.cpp b/chaos/src/hydrogen_msg.cpp new file mode 100644 index 0000000..b4da4b3 --- /dev/null +++ b/chaos/src/hydrogen_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(hydrogen,HYDROGEN); diff --git a/chaos/src/hydrogen_search.cpp b/chaos/src/hydrogen_search.cpp new file mode 100644 index 0000000..ab7e1c4 --- /dev/null +++ b/chaos/src/hydrogen_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(hydrogen, HYDROGEN); diff --git a/chaos/src/ikeda_laser_map_search.cpp b/chaos/src/ikeda_laser_map_search.cpp new file mode 100644 index 0000000..1370329 --- /dev/null +++ b/chaos/src/ikeda_laser_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(ikeda_laser_map, IKEDA_LASER_MAP); diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 9884fd1..9bfba90 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -82,14 +82,10 @@ public: /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } }; diff --git a/chaos/src/latoocarfian_search.cpp b/chaos/src/latoocarfian_search.cpp new file mode 100644 index 0000000..c057301 --- /dev/null +++ b/chaos/src/latoocarfian_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoocarfian, LATOOCARFIAN); diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ca99c12..ff0cf9f 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -62,19 +62,15 @@ public: tmp2 = sin(x2*c); m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; } - + /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.5; -#endif - } - }; - + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutalpha_search.cpp b/chaos/src/latoomutalpha_search.cpp new file mode 100644 index 0000000..0dfecc3 --- /dev/null +++ b/chaos/src/latoomutalpha_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutalpha, LATOOMUTALPHA); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index e27e5a2..a3562c8 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -60,18 +60,13 @@ public: m_data[1] = sin(x1*a) + tmp*tmp; } - /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutbeta_search.cpp b/chaos/src/latoomutbeta_search.cpp new file mode 100644 index 0000000..1fecfa5 --- /dev/null +++ b/chaos/src/latoomutbeta_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutbeta, LATOOMUTBETA); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index fcdf6a6..b9c8c08 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -64,15 +64,11 @@ public: /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; - + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutgamma_search.cpp b/chaos/src/latoomutgamma_search.cpp new file mode 100644 index 0000000..16e05c9 --- /dev/null +++ b/chaos/src/latoomutgamma_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutgamma, LATOOMUTGAMMA); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 16e824e..c01abcc 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -51,14 +51,14 @@ public: } CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); - bool m_pred_alpha(t_float f) + bool m_pred_alpha(data_t f) { return (f > 0) && (f < 4); } CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); - bool m_pred_x(t_float f) + bool m_pred_x(data_t f) { return (f > 0) && (f < 1); } diff --git a/chaos/src/logistic_search.cpp b/chaos/src/logistic_search.cpp new file mode 100644 index 0000000..aaea340 --- /dev/null +++ b/chaos/src/logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index ee4e516..e94f027 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -63,6 +63,16 @@ public: deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } + + + /* function has a fix point for x1 == x2 == x3 == 0 */ + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/lorenz_search.cpp b/chaos/src/lorenz_search.cpp new file mode 100644 index 0000000..a7a9509 --- /dev/null +++ b/chaos/src/lorenz_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 3358cf5..b30a95b 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -60,11 +60,6 @@ public: m_data[1] = CHAOS_PARAMETER(b) * x; } - virtual void m_verify() - { - if (PD_BIGORSMALL(m_data[0])) - m_data[0] = 1; - } CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); diff --git a/chaos/src/lozi_map_search.cpp b/chaos/src/lozi_map_search.cpp new file mode 100644 index 0000000..02f2db5 --- /dev/null +++ b/chaos/src/lozi_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(lozi_map, LOZI_MAP); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index f781f7d..53bd62e 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -31,11 +31,14 @@ void chaos_library_setup() CHAOS_ADD(circle_map); CHAOS_ADD(coupled_logistic); CHAOS_ADD(chua); + CHAOS_ADD(delayed_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); + CHAOS_ADD(gaussian_map); CHAOS_ADD(henon); + CHAOS_ADD(hydrogen); CHAOS_ADD(ikeda_laser_map); CHAOS_ADD(latoocarfian); CHAOS_ADD(latoomutalpha); diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index a15dc08..b7139d2 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -68,7 +68,7 @@ public: void ode_base_alloc() { int dimension = get_num_eq(); - + for (int i = 0; i != 3; ++i) { m_k[i] = new data_t[dimension]; @@ -87,15 +87,14 @@ public: } protected: - void (ode_base::*m_routine)(); + void (ode_base::*m_routine)(void); + 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) - { - } + virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1 (); void rk2 (); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 3603a58..e2c55e0 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -34,11 +34,11 @@ public: CHAOS_PRECONSTRUCTOR; CHAOS_PAR_INIT(method,0); - CHAOS_PAR_INIT(dt,0.01); + CHAOS_PAR_INIT(dt,0.001); - CHAOS_SYS_INIT(x1,0,0); - CHAOS_SYS_INIT(x2,0,1); - CHAOS_SYS_INIT(x3,0,2); + CHAOS_SYS_INIT(x1,0.2,0); + CHAOS_SYS_INIT(x2,0.1,1); + CHAOS_SYS_INIT(x3,0.3,2); CHAOS_PAR_INIT(a,4); CHAOS_PAR_INIT(b,4); @@ -58,7 +58,7 @@ public: { data_t x1 = data[0], x2 = data[1], x3 = data[2]; - deriv[0] = - (x2 - x1); + deriv[0] = - (x2 + x3); deriv[1] = x1 + CHAOS_PARAMETER(a) * x2; deriv[2] = CHAOS_PARAMETER(b) + (x1 - CHAOS_PARAMETER(c)) * x3; } diff --git a/chaos/src/roessler_search.cpp b/chaos/src/roessler_search.cpp new file mode 100644 index 0000000..65596d0 --- /dev/null +++ b/chaos/src/roessler_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(roessler, ROESSLER); diff --git a/chaos/src/sine_map_search.cpp b/chaos/src/sine_map_search.cpp new file mode 100644 index 0000000..94fd2b9 --- /dev/null +++ b/chaos/src/sine_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/standard_map_search.cpp b/chaos/src/standard_map_search.cpp new file mode 100644 index 0000000..62bb535 --- /dev/null +++ b/chaos/src/standard_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/tent_map_search.cpp b/chaos/src/tent_map_search.cpp new file mode 100644 index 0000000..ac44587 --- /dev/null +++ b/chaos/src/tent_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(tent_map, TENT_MAP); -- cgit v1.2.1 From 4d376dc11618b760ff2dac83f32d0a052250ab6c Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 16 Jun 2005 13:04:10 +0000 Subject: linux only scons script svn path=/trunk/externals/tb/; revision=3193 --- chaos/SConstruct | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 chaos/SConstruct (limited to 'chaos') diff --git a/chaos/SConstruct b/chaos/SConstruct new file mode 100644 index 0000000..3dcf513 --- /dev/null +++ b/chaos/SConstruct @@ -0,0 +1,43 @@ +systems = Split("""bernoulli + bungalow_tent + circle_map + coupled_logistic + chua + delayed_logistic + driven_anharmonic + driven_van_der_pol + duffing_map + gauss_map + gaussian_map + henon_map + hydrogen + ikeda_laser_map + latoocarfian + latoomutalpha + latoomutbeta + latoomutgamma + logistic + lorenz + lozi_map + roessler + sine_map + standard_map + tent_map""") + +sources = [] + +env = Environment(CCFLAGS = '-O3 -g -mtune=pentium-m -march=pentium-m -mmmx -msse -msse2 -mfpmath=sse -I~/pd/devel/pd/src/ -I/usr/local/include/flext -DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') + +for system in systems: + sources.append(system+"_dsp.cpp") + sources.append(system+"_msg.cpp") + sources.append(system+"_search.cpp") +sources += Split("main.cpp ode_base.cpp") + +sources = map(lambda x: "./src/"+x, sources) + +chaos = env.SharedLibrary('chaos', sources, LIBS = 'flext-pd_d', + SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +env.Install('/usr/local/lib/pd/extra',chaos) +env.Alias('install', '/usr/local/lib/pd/extra') -- cgit v1.2.1 From f1c4f4640db0f0446accfbf7013b7b7b53a86c55 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 Aug 2005 14:57:28 +0000 Subject: different range svn path=/trunk/externals/tb/; revision=3439 --- chaos/src/latoomutgamma.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chaos') diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index b9c8c08..daf3608 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -66,7 +66,7 @@ public: { if (m_data[0] == 0 && m_data[1] == 0) for (int i = 0; i != 2; ++i) - m_data[i] = rand_range(0,0.1); + m_data[i] = rand_range(-1,1); } CHAOS_SYSVAR_FUNCS(x1, 0); -- cgit v1.2.1 From d79c9f0eeaac84d67504c9b439d9248919f3325f Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 7 Oct 2005 10:36:22 +0000 Subject: updated for added files svn path=/trunk/externals/tb/; revision=3675 --- chaos/package.txt | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'chaos') diff --git a/chaos/package.txt b/chaos/package.txt index cd87590..a32c803 100644 --- a/chaos/package.txt +++ b/chaos/package.txt @@ -1,6 +1,6 @@ NAME=chaos - SRCDIR=src +BUILDTYPE=multi #PRECOMPILE=chaos.hpp @@ -8,51 +8,83 @@ SRCS= \ main.cpp \ bernoulli_dsp.cpp \ bernoulli_msg.cpp \ +bernoulli_search.cpp \ bungalow_tent_dsp.cpp \ bungalow_tent_msg.cpp \ +bungalow_tent_search.cpp \ chaos_base.cpp \ chaos_dsp.cpp \ chua_dsp.cpp \ chua_msg.cpp \ +chua_search.cpp \ circle_map_dsp.cpp \ circle_map_msg.cpp \ +circle_map_search.cpp \ coupled_logistic_dsp.cpp \ coupled_logistic_msg.cpp \ +coupled_logistic_search.cpp \ +delayed_logistic_dsp.cpp \ +delayed_logistic_msg.cpp \ +delayed_logistic_search.cpp \ driven_anharmonic_dsp.cpp \ driven_anharmonic_msg.cpp \ +driven_anharmonic_search.cpp \ driven_van_der_pol_dsp.cpp \ driven_van_der_pol_msg.cpp \ +driven_van_der_pol_search.cpp \ duffing_map_dsp.cpp \ duffing_map_msg.cpp \ +duffing_map_search.cpp \ gauss_map_dsp.cpp \ gauss_map_msg.cpp \ +gauss_map_search.cpp \ +gaussian_map_dsp.cpp \ +gaussian_map_msg.cpp \ +gaussian_map_search.cpp \ henon_map_dsp.cpp \ henon_map_msg.cpp \ +henon_map_search.cpp \ +hydrogen_dsp.cpp \ +hydrogen_msg.cpp \ +hydrogen_search.cpp \ ikeda_laser_map_dsp.cpp \ ikeda_laser_map_msg.cpp \ +ikeda_laser_map_search.cpp \ latoocarfian_dsp.cpp \ latoocarfian_msg.cpp \ +latoocarfian_search.cpp \ latoomutalpha_dsp.cpp \ latoomutalpha_msg.cpp \ +latoomutalpha_search.cpp \ latoomutbeta_dsp.cpp \ latoomutbeta_msg.cpp \ +latoomutbeta_search.cpp \ latoomutgamma_dsp.cpp \ latoomutgamma_msg.cpp \ +latoomutgamma_search.cpp \ logistic_dsp.cpp \ logistic_msg.cpp \ +logistic_search.cpp \ lorenz_dsp.cpp \ lorenz_msg.cpp \ +lorenz_search.cpp \ lozi_map_dsp.cpp \ lozi_map_msg.cpp \ +lozi_map_search.cpp \ ode_base.cpp \ roessler_dsp.cpp \ roessler_msg.cpp \ +roessler_search.cpp \ sine_map_dsp.cpp \ sine_map_msg.cpp \ +sine_map_search.cpp \ standard_map_dsp.cpp \ standard_map_msg.cpp \ +standard_map_search.cpp \ tent_map_dsp.cpp \ tent_map_msg.cpp \ +tent_map_search.cpp \ + HDRS= \ bernoulli_map.hpp \ @@ -62,14 +94,18 @@ chaos_base.hpp \ chaos_defs.hpp \ chaos_dsp.hpp \ chaos_msg.hpp \ +chaos_search.hpp \ chua.hpp \ circle_map.hpp \ coupled_logistic.hpp \ +delayed_logistic.hpp \ driven_anharmonic.hpp \ driven_van_der_pol.hpp \ duffing_map.hpp \ gauss_map.hpp \ +gaussian_map.hpp \ henon_map.hpp \ +hydrogen.hpp \ ikeda_laser_map.hpp \ latoocarfian.hpp \ latoomutalpha.hpp \ -- cgit v1.2.1 From 94ab8a946255bda2bb28cb94c064e3b899774bc5 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 09:55:24 +0000 Subject: more flext-like dsp callbacks svn path=/trunk/externals/tb/; revision=3686 --- chaos/src/chaos_dsp.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 16e2820..821b544 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -39,15 +39,16 @@ public: /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) + virtual void CbSignal() { - (this->*m_routine)(n,insigs,outsigs); + (this->*m_routine)(Blocksize(),InSig(),OutSig()); } - virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) + virtual bool CbDsp() { m_sr = Samplerate(); set_freq(m_freq); /* maybe we have to change the interpolation mode */ + return true; } void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); @@ -130,14 +131,14 @@ public: if (f < 0) /* we can't go back in time :-) */ f = -f; - if( f <= m_sr * 0.5 ) + if( f <= m_sr * 0.1 ) { if (m_freq >= m_sr * 0.5) set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } - else if (f > m_sr * 0.5) + else if (f > m_sr * 0.1) { m_freq = f; m_invfreq = 1.f / f; -- cgit v1.2.1 From 95a84bbdd0149e0824310521066058c9f6f097a0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 10:21:36 +0000 Subject: cleaner behaviour for high frequency resampling svn path=/trunk/externals/tb/; revision=3687 --- chaos/src/chaos_dsp.hpp | 164 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 140 insertions(+), 24 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 821b544..ddb8fe4 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -36,8 +36,12 @@ public: void m_signal_n_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* linear interpolation */ void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* linear interpolation for high frequencies */ + void m_signal_l_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* cubic interpolation for high frequencies */ + void m_signal_c_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); virtual void CbSignal() { @@ -66,8 +70,7 @@ public: /* local data for signal functions */ float m_freq; /* frequency of oscillations */ float m_invfreq; /* inverse frequency */ - int m_phase; /* phase counter */ - float m_fphase; /* phase for high frequency linear interpolation */ + float m_phase; /* phase */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ @@ -118,7 +121,7 @@ public: m_nextmidpts[j] = m_values[j]; } } - + set_freq(m_freq); } void get_freq(float &f) @@ -133,20 +136,41 @@ public: if( f <= m_sr * 0.1 ) { - if (m_freq >= m_sr * 0.5) - set_imethod(m_imethod); - m_freq = f; - m_invfreq = 1.f / f; + switch(m_imethod) + { + case 0: + m_routine = &thisType::m_signal_n; + break; + case 1: + m_routine = &thisType::m_signal_l; + break; + case 2: + m_routine = &thisType::m_signal_c; + break; + default: + assert(false); + } } - else if (f > m_sr * 0.1) + else { - m_freq = f; - m_invfreq = 1.f / f; - - m_routine = &thisType::m_signal_n_hf; + switch(m_imethod) + { + case 0: + m_routine = &thisType::m_signal_n_hf; + break; + case 1: + m_routine = &thisType::m_signal_l_hf; + break; + case 2: + m_routine = &thisType::m_signal_c_hf; + break; + default: + assert(false); + } } - else - post("frequency out of range"); + + m_freq = f; + m_invfreq = 1.f / f; } FLEXT_CALLVAR_F(get_freq, set_freq); @@ -226,7 +250,7 @@ FLEXT_ATTRVAR_I(m_imethod); template void chaos_dsp::m_signal_(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); @@ -247,7 +271,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { int outlets = m_system->get_num_eq(); - float phase = m_fphase; + float phase = m_phase; int offset = 0; while (n) @@ -267,17 +291,17 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, } offset += next; } - m_fphase = phase; + m_phase = phase; } template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int offset = 0; while (n) @@ -304,11 +328,11 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, /* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int i = 0; @@ -341,13 +365,53 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } + +template +void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + float phase = int(m_phase); + + int i = 0; + + while (n) + { + if (phase == 0) + { + m_system->m_perform(); + phase = int (m_sr * m_invfreq); + + for (int j = 0; j != outlets; ++j) + m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + } + + int next = (phase < n) ? int(ceilf (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 void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int i = 0; @@ -369,7 +433,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, float fseglen = (float)phase; m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - - fseglen * m_slopes[j]) + fseglen * m_slopes[j]) / (fseglen * fseglen + fseglen); } } @@ -391,3 +455,55 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, } m_phase = phase; } + + +template +void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + float phase = m_phase; + + int i = 0; + + while (n) + { + if (phase == 0) + { + m_system->m_perform(); + phase = int (m_sr * m_invfreq); + 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_nextvalues[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); + } + } + + int next = (phase < n) ? int(ceilf (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; +} -- cgit v1.2.1 From 8fb0d8ac8ed684a2084769cb0986effec439626f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 10:23:37 +0000 Subject: more tweaking svn path=/trunk/externals/tb/; revision=3688 --- chaos/src/chaos_dsp.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chaos') diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index ddb8fe4..78c4130 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -134,7 +134,7 @@ public: if (f < 0) /* we can't go back in time :-) */ f = -f; - if( f <= m_sr * 0.1 ) + if( f <= m_sr * 0.01 ) { switch(m_imethod) { -- cgit v1.2.1 From ef53e19b3d9019b1b1f3345390f55ae9229ce390 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 22 Oct 2005 15:11:45 +0000 Subject: cleanups and new system svn path=/trunk/externals/tb/; revision=3750 --- chaos/src/bernoulli_map.hpp | 7 +--- chaos/src/bungalow_tent_map.hpp | 7 +--- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 24 +++++------- chaos/src/chaos_dsp.hpp | 10 ++--- chaos/src/chua.hpp | 10 +---- chaos/src/circle_map.hpp | 5 +-- chaos/src/coupled_logistic.hpp | 7 +--- chaos/src/delayed_logistic.hpp | 8 +--- chaos/src/driven_anharmonic.hpp | 9 +---- chaos/src/driven_van_der_pol.hpp | 10 +---- chaos/src/duffing_map.hpp | 7 +--- chaos/src/gauss_map.hpp | 7 +--- chaos/src/gaussian_map.hpp | 7 +--- chaos/src/henon_map.hpp | 7 +--- chaos/src/hydrogen.hpp | 8 +--- chaos/src/ikeda_laser_map.hpp | 8 +--- chaos/src/latoocarfian.hpp | 8 +--- chaos/src/latoomutalpha.hpp | 7 +--- chaos/src/latoomutbeta.hpp | 7 +--- chaos/src/latoomutgamma.hpp | 7 +--- chaos/src/linear_congruental.hpp | 68 +++++++++++++++++++++++++++++++++ chaos/src/linear_congruental_dsp.cpp | 23 +++++++++++ chaos/src/linear_congruental_msg.cpp | 23 +++++++++++ chaos/src/linear_congruental_search.cpp | 24 ++++++++++++ chaos/src/logistic_map.hpp | 8 +--- chaos/src/lorenz.hpp | 11 +----- chaos/src/lozi_map.hpp | 7 +--- chaos/src/main.cpp | 5 ++- chaos/src/map_base.hpp | 5 +++ chaos/src/ode_base.hpp | 41 ++++++++++---------- chaos/src/roessler.hpp | 10 +---- chaos/src/sine_map.hpp | 7 +--- chaos/src/standard_map.hpp | 7 +--- chaos/src/tent_map.hpp | 11 ++---- 35 files changed, 234 insertions(+), 187 deletions(-) create mode 100644 chaos/src/linear_congruental.hpp create mode 100644 chaos/src/linear_congruental_dsp.cpp create mode 100644 chaos/src/linear_congruental_msg.cpp create mode 100644 chaos/src/linear_congruental_search.cpp (limited to 'chaos') diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 31db7f7..f084c67 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -29,13 +29,10 @@ class bernoulli: { public: - bernoulli() + bernoulli(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0.5,0); - - CHAOS_POSTCONSTRUCTOR; } ~bernoulli() diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 5da431d..4d4836b 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -36,14 +36,11 @@ class bungalow_tent: public map_base { public: - bungalow_tent() + bungalow_tent(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.6,0); CHAOS_PAR_INIT(r, 0.5); - - CHAOS_POSTCONSTRUCTOR; } ~bungalow_tent() diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 2e2eb8b..bb9971d 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -24,6 +24,7 @@ #define _USE_MATH_DEFINES /* tg says: define this before including cmath */ #include "flext.h" +#include "assert.h" #include "chaos_defs.hpp" #include diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 5e2a99f..5c87bed 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -27,14 +27,20 @@ class chaos_base { - public: + chaos_base(int n): + m_num_eq(n) + { + m_data = new data_t[n]; + } + + inline t_sample get_data(unsigned int i) { return (t_sample)m_data[i]; /* this is not save, but fast */ } - inline int get_num_eq() + inline int get_num_eq() const { return m_num_eq; } @@ -65,25 +71,15 @@ public: } }; - data_t m_data[MAXDIMENSION]; // state of the system + data_t * m_data; // state of the system protected: virtual void m_step() = 0; // iteration - int m_num_eq; // number of equations of the system + const int m_num_eq; // number of equations of the system flext::AtomList Parameter; // parameter flext::AtomList System; // system }; -#define CHAOS_PRECONSTRUCTOR \ - /* dummy */ - -#define CHAOS_POSTCONSTRUCTOR \ -m_num_eq = System.Count(); - -#define CHAOS_DESTRUCTOR \ - - - #define CHAOS_CALLBACKS \ public: \ void get_dimension(int &i) \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 78c4130..e86fc30 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -236,11 +236,11 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ ~SYSTEM##_dsp() \ { \ delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ + delete[] m_values; \ + delete[] m_slopes; \ + delete[] m_nextvalues; \ + delete[] m_nextmidpts; \ + delete[] m_curves; \ } \ \ FLEXT_ATTRVAR_F(m_freq); \ diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index 3d44708..997116c 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -34,10 +34,9 @@ class chua: public ode_base { public: - chua() + chua(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.05); @@ -49,15 +48,10 @@ public: CHAOS_PAR_INIT(b,30); CHAOS_PAR_INIT(alpha,30); CHAOS_PAR_INIT(beta,30); - - CHAOS_POSTCONSTRUCTOR; - - ode_base_alloc(); } ~chua() { - ode_base_free(); } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index b6442a8..0a52993 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -31,15 +31,12 @@ class circle_map: { public: circle_map() + : map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.4,0); CHAOS_PAR_INIT(omega, 0.1); CHAOS_PAR_INIT(r, 3); - - CHAOS_POSTCONSTRUCTOR; } ~circle_map() diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index d94ceee..2e4b160 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -29,17 +29,14 @@ class coupled_logistic: public map_base { public: - coupled_logistic() + coupled_logistic(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(e, 0.06); CHAOS_PAR_INIT(r, 3.7); CHAOS_SYS_INIT(x, 0.1,0); CHAOS_SYS_INIT(y, 0.2,1); - - CHAOS_POSTCONSTRUCTOR; } ~coupled_logistic() diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index c78785f..47360e7 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -29,16 +29,12 @@ class delayed_logistic: public map_base { public: - delayed_logistic() + delayed_logistic(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.5, 0); - CHAOS_PAR_INIT(alpha, 3.8); - CHAOS_POSTCONSTRUCTOR; - m_delayed = get_x(); /* the initial state of the delay */ } diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 16e053b..2d72071 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -32,10 +32,9 @@ class driven_anharmonic : public ode_base { public: - driven_anharmonic() + driven_anharmonic(): + ode_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -49,15 +48,11 @@ public: CHAOS_PAR_INIT(k1,0.01); CHAOS_PAR_INIT(k2,1); - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); m_t = 0; } ~driven_anharmonic() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 6156eb0..e538185 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -33,10 +33,9 @@ class driven_van_der_pol : public ode_base { public: - driven_van_der_pol() + driven_van_der_pol(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -47,15 +46,10 @@ public: CHAOS_PAR_INIT(a,5); CHAOS_PAR_INIT(Omega,2.466); CHAOS_PAR_INIT(k,5); - - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); } ~driven_van_der_pol() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 5110873..f0e3001 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -29,16 +29,13 @@ class duffing_map: public map_base { public: - duffing_map() + duffing_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1, 0.5, 0); CHAOS_SYS_INIT(x2, 0.5, 1); CHAOS_PAR_INIT(a, 0.5); CHAOS_PAR_INIT(b, 0.5); - - CHAOS_POSTCONSTRUCTOR; } ~duffing_map() diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 1e023d2..641b93a 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -31,13 +31,10 @@ class gauss_map: public map_base { public: - gauss_map() + gauss_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0.5, 0); - - CHAOS_POSTCONSTRUCTOR; } ~gauss_map() diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index 5f5a4b1..9b2b8ca 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -29,16 +29,13 @@ class gaussian_map: public map_base { public: - gaussian_map() + gaussian_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.5, 0); CHAOS_PAR_INIT(b,7); CHAOS_PAR_INIT(c,0.5); - - CHAOS_POSTCONSTRUCTOR; } ~gaussian_map() diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 73aed66..bb1c6c7 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -29,17 +29,14 @@ class henon: public map_base { public: - henon() + henon(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); CHAOS_PAR_INIT(a,1.4); CHAOS_PAR_INIT(b,0.3); - - CHAOS_POSTCONSTRUCTOR; } ~henon() diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp index 886539c..6df6088 100644 --- a/chaos/src/hydrogen.hpp +++ b/chaos/src/hydrogen.hpp @@ -29,10 +29,9 @@ class hydrogen public: - hydrogen() + hydrogen(): + ode_base(4) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -43,14 +42,11 @@ public: CHAOS_PAR_INIT(etilde,-0.3); - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); reset = 0; } ~hydrogen() { - ode_base_free(); } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index ece0b9f..3c4d587 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -35,10 +35,9 @@ class ikeda_laser_map: public map_base { public: - ikeda_laser_map() + ikeda_laser_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(c1,0.4); CHAOS_PAR_INIT(c2,0.9); CHAOS_PAR_INIT(c3,9); @@ -46,13 +45,10 @@ public: CHAOS_SYS_INIT(x,0.5,0); CHAOS_SYS_INIT(y,0.5,1); - - CHAOS_POSTCONSTRUCTOR; } ~ikeda_laser_map() { - } virtual void m_step() diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 9bfba90..eec6116 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -31,10 +31,9 @@ class latoocarfian : public map_base { public: - latoocarfian() + latoocarfian(): + map_base(2) { - CHAOS_PRECONSTRUCTOR - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0,1); @@ -42,13 +41,10 @@ public: CHAOS_PAR_INIT(b,2.879879); CHAOS_PAR_INIT(c,0.765145); CHAOS_PAR_INIT(d,0.744728); - - CHAOS_POSTCONSTRUCTOR; } ~latoocarfian() { - } virtual void m_step() diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ff0cf9f..ac4f28d 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -30,18 +30,15 @@ class latoomutalpha : public map_base { public: - latoomutalpha() + latoomutalpha(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.2,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); CHAOS_PAR_INIT(c,0.765145); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutalpha() diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index a3562c8..3a048cd 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -30,17 +30,14 @@ class latoomutbeta : public map_base { public: - latoomutbeta() + latoomutbeta(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutbeta() diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index daf3608..5e55225 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -30,17 +30,14 @@ class latoomutgamma : public map_base { public: - latoomutgamma() + latoomutgamma(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutgamma() diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp new file mode 100644 index 0000000..bc3536a --- /dev/null +++ b/chaos/src/linear_congruental.hpp @@ -0,0 +1,68 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// tent map: x[n+1] = A*x[n] + B mod C +// +// taken from Julien C. Sprott, Chaos and Time-Series Analysis + +class linear_congruental: + public map_base +{ +public: + linear_congruental(): + map_base(1) + { + CHAOS_SYS_INIT(x, 0, 0); + + CHAOS_PAR_INIT(A, 1741); + CHAOS_PAR_INIT(B, 54773); + CHAOS_PAR_INIT(C, 259200); + } + + virtual void m_step() + { + data_t x = m_data[0]; + + m_data[0] = chaos_mod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); + } + + CHAOS_SYSVAR_FUNCS(x,0); + + CHAOS_SYSPAR_FUNCS(A); + CHAOS_SYSPAR_FUNCS(B); + CHAOS_SYSPAR_FUNCS(C); +}; + +#define LINEAR_CONGRUENTAL_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(A); \ +CHAOS_SYS_CALLBACKS(B); \ +CHAOS_SYS_CALLBACKS(C); \ +CHAOS_SYS_CALLBACKS(x); + +#define LINEAR_CONGRUENTAL_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(A); \ +CHAOS_SYS_ATTRIBUTE(B); \ +CHAOS_SYS_ATTRIBUTE(C); \ +CHAOS_SYS_ATTRIBUTE(x); + diff --git a/chaos/src/linear_congruental_dsp.cpp b/chaos/src/linear_congruental_dsp.cpp new file mode 100644 index 0000000..df36059 --- /dev/null +++ b/chaos/src/linear_congruental_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(linear_congruental,LINEAR_CONGRUENTAL); diff --git a/chaos/src/linear_congruental_msg.cpp b/chaos/src/linear_congruental_msg.cpp new file mode 100644 index 0000000..5b15d99 --- /dev/null +++ b/chaos/src/linear_congruental_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(linear_congruental,LINEAR_CONGRUENTAL); diff --git a/chaos/src/linear_congruental_search.cpp b/chaos/src/linear_congruental_search.cpp new file mode 100644 index 0000000..f3a09a2 --- /dev/null +++ b/chaos/src/linear_congruental_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(linear_congruental, LINEAR_CONGRUENTAL); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index c01abcc..3e0ef24 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -28,19 +28,15 @@ class logistic: public map_base { public: - logistic() + logistic(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5,0); - - CHAOS_POSTCONSTRUCTOR; } ~logistic() { - delete m_data; } virtual void m_step() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e94f027..b27f954 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -29,10 +29,9 @@ class lorenz : public ode_base { public: - lorenz() + lorenz(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -43,16 +42,10 @@ public: CHAOS_PAR_INIT(sigma,16); CHAOS_PAR_INIT(b,4); CHAOS_PAR_INIT(r,40); - - CHAOS_POSTCONSTRUCTOR; - - ode_base_alloc(); } ~lorenz() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index b30a95b..dee6b0d 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -29,17 +29,14 @@ class lozi_map: public map_base { public: - lozi_map() + lozi_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); CHAOS_PAR_INIT(a,1.4); CHAOS_PAR_INIT(b,0.3); - - CHAOS_POSTCONSTRUCTOR; } ~lozi_map() diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 53bd62e..0126f32 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,8 @@ void chaos_library_setup() { - post("chaos~ version 0.01, compiled on "__DATE__" \n"); + post("chaos~ version 0.01, compiled on "__DATE__); + post("(C)2005 Tim Blechmann, www.mokabar.tk\n\n"); CHAOS_ADD(bernoulli); @@ -34,6 +35,7 @@ void chaos_library_setup() CHAOS_ADD(delayed_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(duffing); CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); CHAOS_ADD(gaussian_map); @@ -44,6 +46,7 @@ void chaos_library_setup() CHAOS_ADD(latoomutalpha); CHAOS_ADD(latoomutbeta); CHAOS_ADD(latoomutgamma); + CHAOS_ADD(linear_congruental); CHAOS_ADD(logistic); CHAOS_ADD(lorenz); CHAOS_ADD(lozi_map); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index e71fe61..1395bb8 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -27,6 +27,11 @@ class map_base : public chaos_base { protected: + map_base(int n): + chaos_base(n) + { + } + virtual void m_step() { } diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b7139d2..11811f7 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -27,6 +27,26 @@ class ode_base : public chaos_base { public: + ode_base(int n): + chaos_base (n) + { + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[n]; + } + m_tmp = new data_t[n]; + + } + + ~ode_base() + { + for (int i = 0; i != 3; ++i) + { + delete[] m_k[i]; + } + delete[] m_tmp; + } + void set_method(int i) { if (i >=0 && i <4) @@ -65,27 +85,6 @@ public: (this->*m_routine)(); } - void ode_base_alloc() - { - int dimension = get_num_eq(); - - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[dimension]; - } - - m_tmp = new data_t[dimension]; - } - - void ode_base_free() - { - for (int i = 0; i != 3; ++i) - { - delete m_k[i]; - } - delete m_tmp; - } - protected: void (ode_base::*m_routine)(void); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index e2c55e0..fd65d4e 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -29,10 +29,9 @@ class roessler : public ode_base { public: - roessler() + roessler(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.001); @@ -43,15 +42,10 @@ public: CHAOS_PAR_INIT(a,4); CHAOS_PAR_INIT(b,4); CHAOS_PAR_INIT(c,4); - - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); } ~roessler() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 21c7e39..3d69065 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -30,13 +30,10 @@ class sine_map: { public: - sine_map() + sine_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); - - CHAOS_POSTCONSTRUCTOR; } ~sine_map() diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 663280a..4df1eb9 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -30,16 +30,13 @@ class standard_map: public map_base { public: - standard_map() + standard_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(I,0.1,0); CHAOS_SYS_INIT(theta,0.2,1); CHAOS_PAR_INIT(k, 0.8); - - CHAOS_POSTCONSTRUCTOR; } ~standard_map() diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index e23fb73..9bd8e62 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -29,15 +29,12 @@ class tent_map: public map_base { public: - tent_map() + tent_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.6,0); - - CHAOS_POSTCONSTRUCTOR; } - + ~tent_map() { @@ -49,7 +46,7 @@ public: m_data[0] = 1 - 2*CHAOS_ABS(data); } - + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { -- cgit v1.2.1 From d981b7feb7183a325d44f22ece4c963366658cef Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:24:31 +0000 Subject: updated build system svn path=/trunk/externals/tb/; revision=3810 --- chaos/SConstruct | 196 ++++++++++++++++++++++++++++++++++++++++++------------ chaos/package.txt | 6 ++ 2 files changed, 159 insertions(+), 43 deletions(-) (limited to 'chaos') diff --git a/chaos/SConstruct b/chaos/SConstruct index 3dcf513..499e76a 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -1,43 +1,153 @@ -systems = Split("""bernoulli - bungalow_tent - circle_map - coupled_logistic - chua - delayed_logistic - driven_anharmonic - driven_van_der_pol - duffing_map - gauss_map - gaussian_map - henon_map - hydrogen - ikeda_laser_map - latoocarfian - latoomutalpha - latoomutbeta - latoomutgamma - logistic - lorenz - lozi_map - roessler - sine_map - standard_map - tent_map""") - -sources = [] - -env = Environment(CCFLAGS = '-O3 -g -mtune=pentium-m -march=pentium-m -mmmx -msse -msse2 -mfpmath=sse -I~/pd/devel/pd/src/ -I/usr/local/include/flext -DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') - -for system in systems: - sources.append(system+"_dsp.cpp") - sources.append(system+"_msg.cpp") - sources.append(system+"_search.cpp") -sources += Split("main.cpp ode_base.cpp") - -sources = map(lambda x: "./src/"+x, sources) - -chaos = env.SharedLibrary('chaos', sources, LIBS = 'flext-pd_d', - SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') - -env.Install('/usr/local/lib/pd/extra',chaos) -env.Alias('install', '/usr/local/lib/pd/extra') +# scons script for flext build system +# Copyright (C) 2005 Tim Blechmann +# +# 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; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import sys + +env = Environment(CCFLAGS = '-DFLEXT_SYS_PD -DFLEXT_THREADS') + +env.SConsignFile() +env.CacheDir('./obj') + +opt = Options(['options.cache']) +opt.AddOptions( + BoolOption('debug', 'Build with debugging symbols', False), + ('optimize', 'Optimize for specific architecture', None), + ('icc', 'Build with intel c compiler', False), + BoolOption('simd', 'build with simd instructions', False), + ('prefix', 'install prefix', '/usr/local'), + ('flext_path', 'flext path', None), + ('pd_path', 'pd path', None), + ) + +opt.Update(env) + +opt.Save('options.cache',env) +Help(opt.GenerateHelpText(env)) + + +if env.Dictionary().has_key('icc') and env['icc']: + env.Replace(CC="icc", + SHCC="icc", + CXX="icc", + LINK="icc", + SHCXX="icc", + SHLINK="icc", + ) + env.Append(LINKFLAGS="-static-libcxa") + + env.Append(CCFLAGS=' -ip') + env.Append(LINKFLAGS='-ip') + print "Using intel c compiler" + + +if env.Dictionary().has_key('flext_path'): + env.Append(CPPPATH=[env['flext_path']]) +else: + env.Append(CPPPATH=['../../grill/flext/source']) + + +if env.Dictionary().has_key('pd_path'): + env.Append(CPPPATH=[env['pd_path']]) + +if env.Dictionary().has_key('optimize'): + if env['optimize']: + env.Append(CCFLAGS=' -O3 '+env['optimize']) + env.Append(LINKFLAGS=' -O3 '+env['optimize']) + +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + +if env.Dictionary().has_key('debug') and env['debug']: + env.Append(CCFLAGS=' -g ') + env.Append(CPPDEFINES=['_DEBUG']) + env.Append(LIBS = 'flext-pd') + env.Append(LINKFLAGS=' -g') +else: + env.Append(CPPDEFINES=['FLEXT_SHARED']) + env.Append(LIBS = 'flext-pd') + env.Append(CPPDEFINES="NDEBUG") + +###################################################################### +# +# read package.txt +# + +packagefile = open('./package.txt', 'r') + +desc = {} +line = packagefile.readline() +while line != "": + line = line.strip() + if len(line) > 0 and line[0] != '#' : + var, data = line.split('=') + + if len(data) == 0: + line = packagefile.readline() + continue + + while data [-1] == '\\': + nextline = packagefile.readline() + nextline = nextline.strip() + data = data + " " + nextline + + data = data.replace("\\", "") + desc[var] = data + + + line = packagefile.readline() +packagefile.close() + + +name = desc["NAME"] +if not desc.has_key("SRCDIR"): + desc["SRCDIR"] = "." + +sources = map (lambda x: desc["SRCDIR"] + '/' + x, + desc["SRCS"].split()) + +if desc.has_key("INCPATH"): + env.Append(CPPPATH=desc["INCPATH"].strip().replace("-I", "").split()) + + + +###################################################################### +# +# run custom.py +# +try: + sys.path.append("./build/") + import custom + try: + env, sources, headers = custom.custom(env,desc,sources) + except: + env, sources = custom.custom(env,desc,sources) +except: + pass + + + +###################################################################### +# +# build +# + +external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +prefix = env['prefix'] +env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', prefix+'/lib/pd/extra') diff --git a/chaos/package.txt b/chaos/package.txt index a32c803..c132783 100644 --- a/chaos/package.txt +++ b/chaos/package.txt @@ -32,6 +32,9 @@ driven_anharmonic_search.cpp \ driven_van_der_pol_dsp.cpp \ driven_van_der_pol_msg.cpp \ driven_van_der_pol_search.cpp \ +duffing_dsp.cpp \ +duffing_msg.cpp \ +duffing_search.cpp \ duffing_map_dsp.cpp \ duffing_map_msg.cpp \ duffing_map_search.cpp \ @@ -62,6 +65,9 @@ latoomutbeta_search.cpp \ latoomutgamma_dsp.cpp \ latoomutgamma_msg.cpp \ latoomutgamma_search.cpp \ +linear_congruental_dsp.cpp \ +linear_congruental_msg.cpp \ +linear_congruental_search.cpp \ logistic_dsp.cpp \ logistic_msg.cpp \ logistic_search.cpp \ -- cgit v1.2.1 From f29a18911ce09a638646d90d1f72838313419380 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:28:21 +0000 Subject: added new system svn path=/trunk/externals/tb/; revision=3811 --- chaos/src/chaos_msg.hpp | 12 +++--- chaos/src/duffing.hpp | 98 ++++++++++++++++++++++++++++++++++++++++++++ chaos/src/duffing_dsp.cpp | 23 +++++++++++ chaos/src/duffing_msg.cpp | 23 +++++++++++ chaos/src/duffing_search.cpp | 24 +++++++++++ chaos/src/main.cpp | 2 +- 6 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 chaos/src/duffing.hpp create mode 100644 chaos/src/duffing_dsp.cpp create mode 100644 chaos/src/duffing_msg.cpp create mode 100644 chaos/src/duffing_search.cpp (limited to 'chaos') diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 3f80101..357ff6a 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -25,6 +25,11 @@ template class chaos_msg { FLEXT_HEADER(chaos_msg, flext_base); + ~chaos_msg() + { + delete m_system; + } + public: /* local data for system, output and interpolation */ @@ -59,10 +64,5 @@ SYSTEM##_msg(int argc, t_atom* argv ) \ AddOutFloat(); \ \ ATTRIBUTES; \ - FLEXT_ADDBANG(0, m_bang); \ -} \ - \ -~SYSTEM##_msg() \ -{ \ - delete m_system; \ + FLEXT_ADDBANG(0, m_bang); \ } diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp new file mode 100644 index 0000000..6cdafd6 --- /dev/null +++ b/chaos/src/duffing.hpp @@ -0,0 +1,98 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// duffing equation: dx/dt = y +// dy/dt = x * (1 - x^2) + R*cos(omega * t) - gamma * y +// + + +class duffing: + public ode_base +{ +public: + duffing(): + ode_base(2) + { + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(x, 0.5, 0); + CHAOS_SYS_INIT(y, 0.5, 1); + + CHAOS_PAR_INIT(R, 0.4); + CHAOS_PAR_INIT(omega, 1); + CHAOS_PAR_INIT(gamma, 0.25); + + t = 0; + } + + ~duffing() + { + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x = data[0], y = data[1]; + + deriv[0] = y; + deriv[1] = x * (1 - x*x) + + CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - + CHAOS_PARAMETER(gamma) * y; + t += CHAOS_PARAMETER(dt); + t = chaos_mod(t, M_PI); + } + + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + + + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(y,1); + + CHAOS_SYSPAR_FUNCS(R); + CHAOS_SYSPAR_FUNCS(omega); + CHAOS_SYSPAR_FUNCS(gamma); + +private: + data_t t; +}; + +#define DUFFING_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); \ +CHAOS_SYS_CALLBACKS(R); \ +CHAOS_SYS_CALLBACKS(gamma); \ +CHAOS_SYS_CALLBACKS(omega); + +#define DUFFING_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); \ +CHAOS_SYS_ATTRIBUTE(R); \ +CHAOS_SYS_ATTRIBUTE(gamma); \ +CHAOS_SYS_ATTRIBUTE(omega); + diff --git a/chaos/src/duffing_dsp.cpp b/chaos/src/duffing_dsp.cpp new file mode 100644 index 0000000..c2c89c1 --- /dev/null +++ b/chaos/src/duffing_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(duffing,DUFFING); diff --git a/chaos/src/duffing_msg.cpp b/chaos/src/duffing_msg.cpp new file mode 100644 index 0000000..08f4109 --- /dev/null +++ b/chaos/src/duffing_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(duffing,DUFFING); diff --git a/chaos/src/duffing_search.cpp b/chaos/src/duffing_search.cpp new file mode 100644 index 0000000..13d5cdd --- /dev/null +++ b/chaos/src/duffing_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(duffing, DUFFING); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 0126f32..354f68a 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,7 @@ void chaos_library_setup() { - post("chaos~ version 0.01, compiled on "__DATE__); + post("\nchaos~ version 0.01, compiled on "__DATE__); post("(C)2005 Tim Blechmann, www.mokabar.tk\n\n"); -- cgit v1.2.1 From 449a8062d986c8f59c2ffeef9241b52a159651aa Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:56:23 +0000 Subject: small build fix svn path=/trunk/externals/tb/; revision=3812 --- chaos/SConstruct | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'chaos') diff --git a/chaos/SConstruct b/chaos/SConstruct index 499e76a..2c682b8 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -64,14 +64,14 @@ else: if env.Dictionary().has_key('pd_path'): env.Append(CPPPATH=[env['pd_path']]) +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + if env.Dictionary().has_key('optimize'): if env['optimize']: env.Append(CCFLAGS=' -O3 '+env['optimize']) env.Append(LINKFLAGS=' -O3 '+env['optimize']) -if env.Dictionary().has_key('simd') and env['simd']: - env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') - if env.Dictionary().has_key('debug') and env['debug']: env.Append(CCFLAGS=' -g ') env.Append(CPPDEFINES=['_DEBUG']) -- cgit v1.2.1 From b5e8ffd7605b53f368c81ddae06dd997f57a4ca3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Jan 2006 20:48:29 +0000 Subject: fixed bug svn path=/trunk/externals/tb/; revision=4378 --- chaos/src/chaos_dsp.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index e86fc30..786bee3 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -372,16 +372,16 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { int outlets = m_system->get_num_eq(); - float phase = int(m_phase); + float phase = m_phase; int i = 0; while (n) { - if (phase == 0) + if (phase <= 0) { m_system->m_perform(); - phase = int (m_sr * m_invfreq); + phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; -- cgit v1.2.1 From e97a3414a2d0609a15d7323ce53faa4b1eaad18b Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 14 Jan 2006 22:06:38 +0000 Subject: removing autobuild system ... updating scons build system svn path=/trunk/externals/tb/; revision=4403 --- chaos/AUTHORS | 3 -- chaos/ChangeLog | 0 chaos/Makefile.am | 2 - chaos/NEWS | 0 chaos/README | 0 chaos/SConstruct | 19 ++++--- chaos/bootstrap.sh | 5 -- chaos/configure.ac | 145 -------------------------------------------------- chaos/src/Makefile.am | 66 ----------------------- 9 files changed, 12 insertions(+), 228 deletions(-) delete mode 100644 chaos/AUTHORS delete mode 100644 chaos/ChangeLog delete mode 100644 chaos/Makefile.am delete mode 100644 chaos/NEWS delete mode 100644 chaos/README delete mode 100755 chaos/bootstrap.sh delete mode 100644 chaos/configure.ac delete mode 100644 chaos/src/Makefile.am (limited to 'chaos') diff --git a/chaos/AUTHORS b/chaos/AUTHORS deleted file mode 100644 index 022e6c0..0000000 --- a/chaos/AUTHORS +++ /dev/null @@ -1,3 +0,0 @@ -Tim Blechmann -Mike McGonagle -B. Bogart \ No newline at end of file diff --git a/chaos/ChangeLog b/chaos/ChangeLog deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/Makefile.am b/chaos/Makefile.am deleted file mode 100644 index 5db2166..0000000 --- a/chaos/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = src -EXTRA_DIST = src \ No newline at end of file diff --git a/chaos/NEWS b/chaos/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/README b/chaos/README deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/SConstruct b/chaos/SConstruct index 2c682b8..e02934e 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -27,8 +27,9 @@ opt = Options(['options.cache']) opt.AddOptions( BoolOption('debug', 'Build with debugging symbols', False), ('optimize', 'Optimize for specific architecture', None), - ('icc', 'Build with intel c compiler', False), + BoolOption('icc', 'Build with intel c compiler', False), BoolOption('simd', 'build with simd instructions', False), + BoolOption('cmem', 'build with normal memory allocation', True), ('prefix', 'install prefix', '/usr/local'), ('flext_path', 'flext path', None), ('pd_path', 'pd path', None), @@ -39,8 +40,7 @@ opt.Update(env) opt.Save('options.cache',env) Help(opt.GenerateHelpText(env)) - -if env.Dictionary().has_key('icc') and env['icc']: +if env['icc']: env.Replace(CC="icc", SHCC="icc", CXX="icc", @@ -55,6 +55,10 @@ if env.Dictionary().has_key('icc') and env['icc']: print "Using intel c compiler" +if env['cmem']: + env.Append(CPPDEFINES=['FLEXT_USE_CMEM']) + + if env.Dictionary().has_key('flext_path'): env.Append(CPPPATH=[env['flext_path']]) else: @@ -75,13 +79,14 @@ if env.Dictionary().has_key('optimize'): if env.Dictionary().has_key('debug') and env['debug']: env.Append(CCFLAGS=' -g ') env.Append(CPPDEFINES=['_DEBUG']) - env.Append(LIBS = 'flext-pd') + env.Append(LIBS = 'flext-pd_d') env.Append(LINKFLAGS=' -g') else: - env.Append(CPPDEFINES=['FLEXT_SHARED']) env.Append(LIBS = 'flext-pd') env.Append(CPPDEFINES="NDEBUG") +env.Append(CPPDEFINES=['FLEXT_SHARED']) + ###################################################################### # # read package.txt @@ -149,5 +154,5 @@ except: external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') prefix = env['prefix'] -env.Install(prefix+'/lib/pd/extra',external) -env.Alias('install', prefix+'/lib/pd/extra') +install = env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', install) diff --git a/chaos/bootstrap.sh b/chaos/bootstrap.sh deleted file mode 100755 index 695f2bd..0000000 --- a/chaos/bootstrap.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh - -aclocal \ -&& automake-1.8 --gnu --add-missing \ -&& autoconf \ No newline at end of file diff --git a/chaos/configure.ac b/chaos/configure.ac deleted file mode 100644 index 67bf056..0000000 --- a/chaos/configure.ac +++ /dev/null @@ -1,145 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. -AC_INIT(chaos~, 0.01, TimBlechmann@gmx.de, chaos~) -AM_INIT_AUTOMAKE - -dnl Checks for programs. -AC_PROG_MAKE_SET -AC_PROG_CC -AC_PROG_CXX - -dnl Checks for libraries. -AC_CHECK_LIB(m, sin) - -dnl Checks for header files. -AC_HEADER_STDC - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_SIZE_T -AC_HEADER_TIME - - -dnl Checks for command line arguments -AC_ARG_WITH(flextdir, - [ --with-flextdir path to flext headers], - [ - flextdir=$withval - INCLUDEDIR="-I$withval $INCLUDEDIR" - ], - [echo "path to flext headers required" && exit 1]) - -AC_CHECK_FILE("$flextdir/flext.h",, - [echo "$flextdir/flext.h not found" && exit 1]) - - -AC_ARG_ENABLE(system, - [ --enable-system system (default: pd)], - [ - if test "enableval" == "max"; then - AC_DEFINE(FLEXT_SYS,1) - else - AC_DEFINE(FLEXT_SYS,2) - fi - system = $enabeval - ], - AC_DEFINE(FLEXT_SYS,2) - ) - - -AC_ARG_WITH(sysdir, - [ --with-sysdir path pd / max installation], - [ - SYSDIR=$withval - INCLUDEDIR="-I$withval $INCLUDEDIR" - ], - [echo "path to pd / max installation required" && exit 1]) - - -AC_ARG_ENABLE(static, - [ --enable-static static linking with libflext], - LDFLAGS="-Bstatic $LDFLAGS" - , - [ - AC_DEFINE(FLEXT_SHARED) - AC_DEFINE(FLEXT_THREADS) - LDFLAGS="-Bdynamic $LDFLAGS" - ] - ) - -AC_ARG_ENABLE(debug, - [ --enable-debug link with libflext_d library for debugging], - [ - LDFLAGS="-lflext_d $LDFLAGS" - CXXFLAGS="-g" - ], - [ - LDFLAGS="-lflext $LDFLAGS" - CXXFLAGS="-O3" - ]) - -dnl mtune will break gcc 3.3.x -AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3, G4, G5], - [ - case $enableval in - pentium3 | pentium3m) - OPT_FLAGS = "-mtune=$enableval -march=$enableval -mmmx -msse -mfpmath=sse";; - pentium2 | athlon | pentium-mmx) - OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx";; - pentium) - OPT_FLAGS="-mtune=$enableval -march=$enableval";; - pentium4 | pentium4m | pentium-m | prescott | nocona | athlon-xp | athlon-mp | athlon64 | opteron) - OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx -msse -msse2 -mfpmath=sse";; - G5 | G4) - OPT_FLAGS="-mtune=$enableval -march=$enableval -maltivec -faltivec -malign-natural";; - G3) - OPT_FLAGS="-mtune=$enableval -march=$enableval -malign-natural";; - *) - ;; - esac - ]) - -dnl select build -if test `uname -s` == "Linux"; then - dnl no max/msp for linux - OBJEXT=o - EXTENSION=pd_linux -fi - -if test `uname -s` == "Darwin"; then - dnl just a guess - if test "$system" = "max"; then - echo "build system doesn't support max, yet" && exit 1; - else - LDFLAGS="-bundle -bundle_loader $LDFLAGS" - FRAMEWORKS= - EXTENSION=pd_darwin - LIBS="gcc $LIBS" - fi - OBJEXT=o -fi - -if test `uname -s` == "Cygwin"; then - dnl just a guess - if test "$system" = "max"; then - echo "build system doesn't support max, yet" && exit 1; - else - EXTENSION=dll - LIBS="gcc $LIBS bin/pd bin/pthreadVC.dll" - LDFLAGS="-L$SYSDIR" - fi -fi - - -AC_SUBST(EXTENSION) -AC_SUBST(INCLUDEDIR) -AC_SUBST(CXXFLAGS) -AC_SUBST(OPT_FLAGS) -AC_SUBST(LDFLAGS) -AC_SUBST(DEFS) -AC_SUBST(LIBS) -AC_SUBST(OBJEXT) -AC_SUBST(FRAMEWORKS) -AC_SUBST(SYSDIR) -AC_OUTPUT([Makefile - src/Makefile]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am deleted file mode 100644 index e85310c..0000000 --- a/chaos/src/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -NAME = chaos - -BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ - bernoulli_dsp.cpp bernoulli_msg.cpp \ - bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ - circle_map_dsp.cpp circle_map_msg.cpp \ - coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ - chua_dsp.cpp chua_msg.cpp \ - driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ - driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ - duffing_map_dsp.cpp duffing_map_msg.cpp \ - gauss_map_dsp.cpp gauss_map_msg.cpp \ - henon_map_dsp.cpp henon_map_msg.cpp \ - ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ - latoocarfian_dsp.cpp latoocarfian_msg.cpp \ - latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ - latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ - latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp logistic_search.cpp\ - lorenz_dsp.cpp lorenz_msg.cpp \ - lozi_map_dsp.cpp lozi_map_msg.cpp \ - roessler_dsp.cpp roessler_msg.cpp \ - sine_map_dsp.cpp sine_map_msg.cpp \ - standard_map_dsp.cpp standard_map_msg.cpp \ - tent_map_dsp.cpp tent_map_msg.cpp - -CXXFLAGS = @CXXFLAGS@ \ - @OPT_FLAGS@ \ - @INCLUDEDIR@ \ - $(DEFS) - -LDFLAGS = @LDFLAGS@ \ - $(patsubst %,-framework %,$(FRAMEWORKS)) - -LIBS = @LIBS@ - -FRAMEWORKS = @FRAMEWORKS@ - -TARGET =$(NAME).@EXTENSION@ - -OBJECTS = $(patsubst %.cpp,%.@OBJEXT@,$(BUILT_SOURCES)) - -SYSDIR = @SYSDIR@ - - -# ----------------------------- targets -------------------------------- - - -all-local: $(OBJECTS) - $(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o ../$(TARGET) - strip --strip-unneeded ../$(TARGET) - -%.@OBJEXT@ : %.cpp - $(CXX) -c $(CXXFLAGS) $< -o $@ - -dist-hook: - rm -f ./*~ - rm -f ./*.@OBJEXT@ - rm ./Makefile - -clean-local: - rm -f ../$(TARGET) - rm -f ./*.@OBJEXT@ - -install-exec-local: - install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file -- cgit v1.2.1 From 13cba7a7997e318fbba01a36912219355e387d52 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 18:34:34 +0000 Subject: rewrote most stuff using templates svn path=/trunk/externals/tb/; revision=5105 --- chaos/src/bernoulli_map.hpp | 10 +-- chaos/src/bungalow_tent_map.hpp | 10 +-- chaos/src/chaos_base.hpp | 37 +++------ chaos/src/chaos_defs.hpp | 8 +- chaos/src/chaos_dsp.hpp | 171 ++++++++++++++++++++------------------- chaos/src/chaos_msg.hpp | 38 +++++---- chaos/src/chaos_search.hpp | 28 +++---- chaos/src/chua.hpp | 9 +-- chaos/src/circle_map.hpp | 7 +- chaos/src/coupled_logistic.hpp | 19 ++--- chaos/src/delayed_logistic.hpp | 10 +-- chaos/src/driven_anharmonic.hpp | 10 +-- chaos/src/driven_van_der_pol.hpp | 9 +-- chaos/src/duffing.hpp | 8 +- chaos/src/duffing_map.hpp | 10 +-- chaos/src/gauss_map.hpp | 9 +-- chaos/src/gaussian_map.hpp | 10 +-- chaos/src/henon_map.hpp | 9 +-- chaos/src/hydrogen.hpp | 8 +- chaos/src/ikeda_laser_map.hpp | 9 +-- chaos/src/latoocarfian.hpp | 9 +-- chaos/src/latoomutalpha.hpp | 9 +-- chaos/src/latoomutbeta.hpp | 10 +-- chaos/src/latoomutgamma.hpp | 12 +-- chaos/src/linear_congruental.hpp | 5 +- chaos/src/logistic_map.hpp | 5 +- chaos/src/lorenz.hpp | 5 +- chaos/src/lozi_map.hpp | 10 +-- chaos/src/map_base.hpp | 16 +--- chaos/src/ode_base.cpp | 51 ------------ chaos/src/ode_base.hpp | 96 ++++++++++++++-------- chaos/src/roessler.hpp | 10 +-- chaos/src/sine_map.hpp | 5 +- chaos/src/standard_map.hpp | 5 +- chaos/src/tent_map.hpp | 9 +-- 35 files changed, 260 insertions(+), 426 deletions(-) (limited to 'chaos') diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index f084c67..c720e1b 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -25,21 +25,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bernoulli: - public map_base + public map_base<1> { public: - bernoulli(): - map_base(1) + bernoulli() { CHAOS_SYS_INIT(x,0.5,0); } - ~bernoulli() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 4d4836b..fd098f3 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -33,21 +33,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bungalow_tent: - public map_base + public map_base<1> { public: - bungalow_tent(): - map_base(1) + bungalow_tent() { CHAOS_SYS_INIT(x, 0.6,0); CHAOS_PAR_INIT(r, 0.5); } - ~bungalow_tent() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 5c87bed..4b984d9 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,7 +1,7 @@ // // // chaos~ -// Copyright (C) 2004 Tim Blechmann +// Copyright (C) 2004, 2006 Tim Blechmann // // 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 @@ -23,26 +23,23 @@ #include "chaos.hpp" #include -#define MAXDIMENSION 5 // this should be enough for the first - +template class chaos_base { public: - chaos_base(int n): - m_num_eq(n) + chaos_base() { - m_data = new data_t[n]; } - inline t_sample get_data(unsigned int i) { + assert(i attr_ind; - // TableAnyMap attr_ind; /* thomas fragen :-) */ // check the integrity of the system - virtual void m_verify() + inline void m_verify() { } inline void m_bash_denormals() { - for (int i = 0; i != get_num_eq(); ++i) + for (int i = 0; i != dimensions; ++i) { #ifndef DOUBLE_PRECISION if (PD_BIGORSMALL(m_data[i])) @@ -71,28 +67,13 @@ public: } }; - data_t * m_data; // state of the system + data_t m_data[dimensions]; // state of the system protected: - virtual void m_step() = 0; // iteration - const int m_num_eq; // number of equations of the system + virtual void m_step() = 0; // iteration flext::AtomList Parameter; // parameter flext::AtomList System; // system }; -#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); - - - #define __chaos_base_hpp #endif /* __chaos_base_hpp */ diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index bf8607c..c4e68a5 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -100,11 +100,11 @@ data_t m_##NAME; public: \ void get_##NAME(t_float &f) \ { \ - f = m_system->get_##NAME(); \ + f = m_system.get_##NAME(); \ } \ void set_##NAME(t_float &f) \ { \ - m_system->set_##NAME(f); \ + m_system.set_##NAME(f); \ } \ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); @@ -113,11 +113,11 @@ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); public: \ void get_##NAME(int &i) \ { \ - i = m_system->get_##NAME(); \ + i = m_system.get_##NAME(); \ } \ void set_##NAME(int &i) \ { \ - m_system->set_##NAME(i); \ + m_system.set_##NAME(i); \ } \ FLEXT_CALLVAR_I(get_##NAME, set_##NAME); diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 786bee3..9f6dd75 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -20,13 +20,68 @@ #include "chaos_base.hpp" -template class chaos_dsp +template +class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp); +protected: + chaos_dsp(int argc, t_atom* argv) + { + m_sr = 44100; /* assume default sampling rate */ + int size = m_system.get_num_eq(); + + 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]; + + /* create inlets and zero arrays*/ + for (int i = 0; i != size; ++i) + { + AddOutSignal(); + m_values[i] = 0; + m_slopes[i] = 0; + m_nextvalues[i] = 0; + m_nextmidpts[i] = 0; + m_curves[i] = 0; + } + + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); + + if (argc > 0) + { + CHAOS_INIT(freq, GetAInt(argv[0])); + } + else + { + CHAOS_INIT(freq, 440); + } + + if (argc > 1) + { + CHAOS_INIT(imethod, GetAInt(argv[1])); + } + else + { + CHAOS_INIT(imethod, 0); + } + m_phase = 0; + } + + ~chaos_dsp() + { + delete[] m_values; + delete[] m_slopes; + delete[] m_nextvalues; + delete[] m_nextmidpts; + delete[] m_curves; + } + public: - /* signal functions: */ /* for frequency = sr */ void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); @@ -58,7 +113,7 @@ public: void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ t_sample * m_values; /* actual value */ t_sample * m_slopes; /* actual slope for cubic interpolation */ @@ -106,15 +161,15 @@ public: } if (imethod == 0) - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { - m_values[j] = m_system->get_data(j); + m_values[j] = m_system.get_data(j); m_slopes[j] = 0; } if(i == 2 && imethod != 2) { - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { m_phase = 0; /* reschedule to avoid click, find a better way later*/ m_nextvalues[j] = m_values[j]; @@ -183,67 +238,13 @@ public: #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_sr = 44100; /* assume default sampling rate */ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - 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]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ - FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ - \ - if (argc > 0) \ - { \ - CHAOS_INIT(freq, GetAInt(argv[0])); \ - } \ - else \ - { \ - CHAOS_INIT(freq, 440); \ - } \ - \ - if (argc > 1) \ - { \ - CHAOS_INIT(imethod, GetAInt(argv[1])); \ - } \ - else \ - { \ - CHAOS_INIT(imethod, 0); \ - } \ - \ - m_phase = 0; \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ +SYSTEM##_dsp(int argc, t_atom* argv): \ + chaos_dsp(argc, argv) \ { \ - delete m_system; \ - delete[] m_values; \ - delete[] m_slopes; \ - delete[] m_nextvalues; \ - delete[] m_nextmidpts; \ - delete[] m_curves; \ + ATTRIBUTES; \ } \ \ -FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_F(m_freq); \ FLEXT_ATTRVAR_I(m_imethod); @@ -252,14 +253,14 @@ template void chaos_dsp::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); for (int i = 0; i!=n; ++i) { - m_system->m_perform(); + m_system.m_perform(); for (int j = 0; j != outlets; ++j) { - outsigs[j][i] = m_system->get_data(j); + outsigs[j][i] = m_system.get_data(j); } } } @@ -269,7 +270,7 @@ template void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -278,7 +279,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { while (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase += m_sr * m_invfreq; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -287,7 +288,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -299,7 +300,7 @@ template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -308,7 +309,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); } @@ -318,7 +319,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -330,7 +331,7 @@ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -340,11 +341,11 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? phase : n; @@ -370,7 +371,7 @@ template void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -380,11 +381,11 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { if (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -409,7 +410,7 @@ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -419,14 +420,14 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); 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_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; @@ -461,7 +462,7 @@ template void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -471,14 +472,14 @@ void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); 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_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 357ff6a..9025273 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -20,29 +20,34 @@ #include "chaos_base.hpp" -template class chaos_msg - : public flext_base +template +class chaos_msg: + public flext_base { FLEXT_HEADER(chaos_msg, flext_base); - ~chaos_msg() - { - delete m_system; - } +protected: + chaos_msg(int argc, t_atom* argv) + { + int size = m_system.get_num_eq(); + + for (int i = 0; i != size; ++i) + AddOutFloat(); + FLEXT_ADDBANG(0, m_bang); + } public: - /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ void m_bang() { - m_system->m_perform(); - int outlets = m_system->get_num_eq(); + m_system.m_perform(); + int outlets = m_system.get_num_eq(); while (outlets--) { - ToOutFloat(outlets, m_system->get_data(outlets)); + ToOutFloat(outlets, m_system.get_data(outlets)); } } @@ -54,15 +59,8 @@ public: #define CHAOS_MSG_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_msg, chaos_msg) \ \ -SYSTEM##_msg(int argc, t_atom* argv ) \ +SYSTEM##_msg(int argc, t_atom* argv ): \ +chaos_msg(argc, argv) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - for (int i = 0; i != size; ++i) \ - AddOutFloat(); \ - \ ATTRIBUTES; \ - FLEXT_ADDBANG(0, m_bang); \ } diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp index a7fc44d..1b812a0 100644 --- a/chaos/src/chaos_search.hpp +++ b/chaos/src/chaos_search.hpp @@ -20,6 +20,8 @@ #include "chaos_base.hpp" +#define MAXDIMENSION 5 + template class chaos_search : public flext_base { @@ -28,7 +30,7 @@ template class chaos_search public: /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ data_t min[MAXDIMENSION]; /* minimal coordinates */ @@ -75,11 +77,11 @@ public: - send lyapunov exponent to 4 */ - for (std::map::iterator it = m_system->attr_ind.begin(); - it != m_system->attr_ind.end(); ++it) + for (std::map::iterator it = m_system.attr_ind.begin(); + it != m_system.attr_ind.end(); ++it) { post("key %s", it->first->s_name); - post("value %f", m_system->get_data(it->second)); + post("value %f", m_system.get_data(it->second)); } } @@ -99,9 +101,7 @@ FLEXT_HEADER(SYSTEM##_search, chaos_search) \ \ SYSTEM##_search(int argc, t_atom* argv ) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ + int size = m_system.get_num_eq(); \ \ \ m_asymptotic_steps = 10000; \ @@ -119,10 +119,6 @@ SYSTEM##_search(int argc, t_atom* argv ) \ FLEXT_ADDMETHOD_(0,"search", m_search); \ } \ \ -~SYSTEM##_search() \ -{ \ - delete m_system; \ -} \ \ FLEXT_ATTRVAR_I(m_transient_steps); \ FLEXT_ATTRVAR_I(m_asymptotic_steps); @@ -132,7 +128,7 @@ FLEXT_ATTRVAR_I(m_asymptotic_steps); template void chaos_search::m_search() { - int dimensions = m_system->get_num_eq(); + int dimensions = m_system.get_num_eq(); ly = 0; data_t diff_old = 0.1; @@ -141,12 +137,12 @@ void chaos_search::m_search() /* transient dynamics */ for (int i = 0; i != m_transient_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); } for (int i = 0; i != dimensions; ++i) { - last[i] = min[i] = max[i] = m_system->m_data[i]; + last[i] = min[i] = max[i] = m_system.m_data[i]; } /* now we start the analysis */ @@ -154,13 +150,13 @@ void chaos_search::m_search() for (int i = 0; i != m_asymptotic_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); data_t diff = 0; for (int j = 0; j != dimensions; ++j) { /* update min/max */ - data_t datum = m_system->m_data[j]; + data_t datum = m_system.m_data[j]; if (datum > max[j]) max[j] = datum; else if (datum < min[j]) diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index 997116c..f8c6e31 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -31,11 +31,10 @@ // taken from Viktor Avrutin: lecture notes class chua: - public ode_base + public ode_base<3> { public: - chua(): - ode_base(3) + chua() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.05); @@ -50,10 +49,6 @@ public: CHAOS_PAR_INIT(beta,30); } - ~chua() - { - } - virtual void m_system(data_t* deriv, data_t* data) { data_t x1 = data[0]; diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 0a52993..294b7d6 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class circle_map: - public map_base + public map_base<1> { public: circle_map() - : map_base(1) { CHAOS_SYS_INIT(x, 0.4,0); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(r, 3); } - ~circle_map() - { - - } virtual void m_step() { diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 2e4b160..048aae1 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class coupled_logistic: - public map_base + public map_base<2> { public: - coupled_logistic(): - map_base(2) + coupled_logistic() { CHAOS_PAR_INIT(e, 0.06); CHAOS_PAR_INIT(r, 3.7); @@ -39,11 +38,7 @@ public: CHAOS_SYS_INIT(y, 0.2,1); } - ~coupled_logistic() - { - } - - virtual void m_step() + virtual inline void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -56,7 +51,7 @@ public: CHAOS_SYSPAR_FUNCS(e); CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); - bool m_pred_r(t_float f) + static bool m_pred_r(t_float f) { return (f > 0) && (f < 4); } @@ -64,12 +59,12 @@ public: CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_xy); CHAOS_SYSVAR_FUNCS_PRED(y, 0, m_pred_xy); - bool m_pred_xy(t_float f) + static bool m_pred_xy(t_float f) { return (f > 0) && (f < 1); } - virtual void m_verify() + inline void m_verify() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -83,8 +78,6 @@ public: m_data[1] += -rand_range(0,0.2); } } - - }; #define COUPLED_LOGISTIC_CALLBACKS \ diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index 47360e7..3db7e27 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -26,11 +26,10 @@ // taken from E. Atlee Jackson: Perspective of nonlinear dynamics (Vol. 2) class delayed_logistic: - public map_base + public map_base<1> { public: - delayed_logistic(): - map_base(1) + delayed_logistic() { CHAOS_SYS_INIT(x, 0.5, 0); CHAOS_PAR_INIT(alpha, 3.8); @@ -38,10 +37,7 @@ public: m_delayed = get_x(); /* the initial state of the delay */ } - ~delayed_logistic() - { - - } + virtual void m_step() { diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 2d72071..7d6bfd6 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -29,11 +29,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_anharmonic - : public ode_base + : public ode_base<2> { public: - driven_anharmonic(): - ode_base(2) + driven_anharmonic() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -50,10 +49,7 @@ public: m_t = 0; } - - ~driven_anharmonic() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index e538185..3c034d2 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -30,11 +30,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_van_der_pol - : public ode_base + : public ode_base<3> { public: - driven_van_der_pol(): - ode_base(3) + driven_van_der_pol() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -48,9 +47,7 @@ public: CHAOS_PAR_INIT(k,5); } - ~driven_van_der_pol() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp index 6cdafd6..ee7f7fb 100644 --- a/chaos/src/duffing.hpp +++ b/chaos/src/duffing.hpp @@ -26,11 +26,10 @@ class duffing: - public ode_base + public ode_base<2> { public: - duffing(): - ode_base(2) + duffing() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: t = 0; } - ~duffing() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index f0e3001..46fecbf 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -26,11 +26,10 @@ // taken from Viktor Avrutin: AnT-Demos-4.669 class duffing_map: - public map_base + public map_base<2> { public: - duffing_map(): - map_base(2) + duffing_map() { CHAOS_SYS_INIT(x1, 0.5, 0); CHAOS_SYS_INIT(x2, 0.5, 1); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(b, 0.5); } - ~duffing_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 641b93a..d013bae 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -28,19 +28,14 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class gauss_map: - public map_base + public map_base<1> { public: - gauss_map(): - map_base(1) + gauss_map() { CHAOS_SYS_INIT(x,0.5, 0); } - ~gauss_map() - { - - } virtual void m_step() { diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index 9b2b8ca..c6aaf1e 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -26,11 +26,10 @@ // taken from Robert C. Hilborn: Chaos and Nonlinear Dynamics class gaussian_map: - public map_base + public map_base<1> { public: - gaussian_map(): - map_base(1) + gaussian_map() { CHAOS_SYS_INIT(x, 0.5, 0); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(c,0.5); } - ~gaussian_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index bb1c6c7..014fa68 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class henon: - public map_base + public map_base<2> { public: - henon(): - map_base(2) + henon() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~henon() - { - - } virtual void m_step() { diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp index 6df6088..cec6ae3 100644 --- a/chaos/src/hydrogen.hpp +++ b/chaos/src/hydrogen.hpp @@ -24,13 +24,12 @@ // hydrogen atom in a magnetic field class hydrogen - : public ode_base + : public ode_base<4> { public: - hydrogen(): - ode_base(4) + hydrogen() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: reset = 0; } - ~hydrogen() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 3c4d587..60e3a77 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -32,11 +32,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class ikeda_laser_map: - public map_base + public map_base<1> { public: - ikeda_laser_map(): - map_base(1) + ikeda_laser_map() { CHAOS_PAR_INIT(c1,0.4); CHAOS_PAR_INIT(c2,0.9); @@ -47,10 +46,6 @@ public: CHAOS_SYS_INIT(y,0.5,1); } - ~ikeda_laser_map() - { - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index eec6116..47abc33 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -28,11 +28,10 @@ // taken from Pickover: Chaos In Wonderland class latoocarfian - : public map_base + : public map_base<2> { public: - latoocarfian(): - map_base(2) + latoocarfian() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0,1); @@ -42,10 +41,6 @@ public: CHAOS_PAR_INIT(c,0.765145); CHAOS_PAR_INIT(d,0.744728); } - - ~latoocarfian() - { - } virtual void m_step() { diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ac4f28d..255829a 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutalpha - : public map_base + : public map_base<2> { public: - latoomutalpha(): - map_base(2) + latoomutalpha() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.2,1); @@ -41,10 +40,6 @@ public: CHAOS_PAR_INIT(c,0.765145); } - ~latoomutalpha() - { - - } virtual void m_step() { diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index 3a048cd..d663761 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutbeta - : public map_base + : public map_base<2> { public: - latoomutbeta(): - map_base(2) + latoomutbeta() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -40,11 +39,6 @@ public: CHAOS_PAR_INIT(b,2.879879); } - ~latoomutbeta() - { - - } - virtual void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 5e55225..022e651 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutgamma - : public map_base + : public map_base<2> { public: - latoomutgamma(): - map_base(2) + latoomutgamma() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); } - - ~latoomutgamma() - { - - } virtual void m_step() { @@ -59,7 +53,7 @@ public: /* function has a fix point for x1 == x2 == 0 */ - virtual void m_verify() + void m_verify() { if (m_data[0] == 0 && m_data[1] == 0) for (int i = 0; i != 2; ++i) diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index bc3536a..f6ce961 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -25,11 +25,10 @@ // taken from Julien C. Sprott, Chaos and Time-Series Analysis class linear_congruental: - public map_base + public map_base<2> { public: - linear_congruental(): - map_base(1) + linear_congruental() { CHAOS_SYS_INIT(x, 0, 0); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 3e0ef24..7880d21 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -25,11 +25,10 @@ // 0 <= alpha <= 4 class logistic: - public map_base + public map_base<1> { public: - logistic(): - map_base(1) + logistic() { CHAOS_PAR_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5,0); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index b27f954..cf0fa14 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : public ode_base + : public ode_base<3> { public: - lorenz(): - ode_base(3) + lorenz() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index dee6b0d..24096a6 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lozi_map: - public map_base + public map_base<2> { public: - lozi_map(): - map_base(2) + lozi_map() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~lozi_map() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 1395bb8..92016b1 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -23,26 +23,18 @@ #include "chaos_base.hpp" +template class map_base - : public chaos_base + : public chaos_base { protected: - map_base(int n): - chaos_base(n) - { - } - virtual void m_step() { } }; -#define MAP_CALLBACKS \ -CHAOS_CALLBACKS - - -#define MAP_ATTRIBUTES \ -CHAOS_ATTRIBUTES; +#define MAP_CALLBACKS +#define MAP_ATTRIBUTES #define __map_base_hpp #endif /* __map_base_hpp */ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index 2830c2f..004a1b3 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -20,55 +20,4 @@ #include "ode_base.hpp" -void ode_base::rk1() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[0][i]; -} - - -void ode_base::rk2() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_k[0][i] = m_k[0][i] * 0.5 * m_dt + m_data[i]; - - m_system (m_k[1], m_k[0]); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[1][i]; -} - - -void ode_base::rk4() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[0][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[0][i]; - } - - m_system (m_k[1], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[1][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[1][i]; - } - - m_system (m_k[2], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[2][i] *= m_dt; - m_tmp[i] = m_data[i] + m_k[2][i]; - } - - m_system (m_k[3], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - m_k[3][i] *= m_dt; - - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += (m_k[0][i] + 2. * (m_k[1][i] + m_k[2][i]) + m_k[3][i]) - / 6.; -} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 11811f7..b198dc5 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -23,45 +23,27 @@ #include "chaos_base.hpp" -class ode_base - : public chaos_base +template +class ode_base: + public chaos_base { public: - ode_base(int n): - chaos_base (n) - { - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[n]; - } - m_tmp = new data_t[n]; - - } - ~ode_base() - { - for (int i = 0; i != 3; ++i) - { - delete[] m_k[i]; - } - delete[] m_tmp; - } - void set_method(int i) { - if (i >=0 && i <4) + if (i >= 0 && i < 4) { m_method = (unsigned char) i; switch (i) { case 0: - m_routine = &ode_base::rk1; + m_routine = &ode_base::rk1; break; case 1: - m_routine = &ode_base::rk2; + m_routine = &ode_base::rk2; break; case 2: - m_routine = &ode_base::rk4; + m_routine = &ode_base::rk4; } } else @@ -86,27 +68,75 @@ public: } protected: - void (ode_base::*m_routine)(void); + void (ode_base::*m_routine)(void); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t* m_k[3]; /* temporary arrays for runge kutta */ - data_t* m_tmp; + data_t m_k0[dimensions]; + data_t m_k1[dimensions]; + data_t m_k2[dimensions]; + data_t m_k3[dimensions]; + data_t m_tmp[dimensions]; +// data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; - void rk1 (); - void rk2 (); - void rk4 (); + void rk1() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k0[i]; + } + + void rk2() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; +// +// m_system (m_k1, m_k0); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k1[i]; + } + + void rk4() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k0[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; +// } +// +// m_system (m_k1, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k1[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; +// } +// +// m_system (m_k2, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k2[i] *= m_dt; +// m_tmp[i] = m_data[i] + m_k2[i]; +// } +// +// m_system (m_k3, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// m_k3[i] *= m_dt; +// +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) +// / 6.; + } }; #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); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index fd65d4e..aa03a47 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -23,14 +23,13 @@ // roessler model: dx1/dt = - (x2 + x3) // dx2/dt = x1 + a * x2 // dx3/dt = b + (x1 - c) * x3 -// taken from Peitgen / Jürgens / Saupe: Chaos and Fractals +// taken from Peitgen / J�rgens / Saupe: Chaos and Fractals class roessler - : public ode_base + : public ode_base<3> { public: - roessler(): - ode_base(3) + roessler() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.001); @@ -44,9 +43,6 @@ public: CHAOS_PAR_INIT(c,4); } - ~roessler() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 3d69065..8a11281 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -26,12 +26,11 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class sine_map: - public map_base + public map_base<1> { public: - sine_map(): - map_base(1) + sine_map() { CHAOS_SYS_INIT(x,0,0); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 4df1eb9..8798edc 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class standard_map: - public map_base + public map_base<2> { public: - standard_map(): - map_base(2) + standard_map() { CHAOS_SYS_INIT(I,0.1,0); CHAOS_SYS_INIT(theta,0.2,1); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 9bd8e62..2e716ac 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -26,19 +26,14 @@ class tent_map: - public map_base + public map_base<1> { public: - tent_map(): - map_base(1) + tent_map() { CHAOS_SYS_INIT(x, 0.6,0); } - ~tent_map() - { - - } virtual void m_step() { -- cgit v1.2.1 From 2c157bd8aa1f5387169cc0c0910d36c8068c4068 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 19:17:04 +0000 Subject: improved inlining for maps svn path=/trunk/externals/tb/; revision=5106 --- chaos/src/bernoulli_map.hpp | 2 +- chaos/src/bungalow_tent_map.hpp | 2 +- chaos/src/chaos_base.hpp | 14 +++++++------- chaos/src/chaos_dsp.hpp | 36 +++++++++++++++++++++++++++++------- chaos/src/chaos_msg.hpp | 6 +++++- chaos/src/chaos_search.hpp | 9 ++++++--- chaos/src/circle_map.hpp | 2 +- chaos/src/delayed_logistic.hpp | 2 +- chaos/src/duffing_map.hpp | 2 +- chaos/src/gauss_map.hpp | 2 +- chaos/src/gaussian_map.hpp | 2 +- chaos/src/henon_map.hpp | 2 +- chaos/src/ikeda_laser_map.hpp | 2 +- chaos/src/latoocarfian.hpp | 2 +- chaos/src/latoomutalpha.hpp | 2 +- chaos/src/latoomutbeta.hpp | 2 +- chaos/src/latoomutgamma.hpp | 2 +- chaos/src/linear_congruental.hpp | 2 +- chaos/src/logistic_map.hpp | 2 +- chaos/src/lozi_map.hpp | 2 +- chaos/src/map_base.hpp | 2 +- chaos/src/ode_base.hpp | 2 +- chaos/src/sine_map.hpp | 2 +- chaos/src/standard_map.hpp | 2 +- chaos/src/tent_map.hpp | 2 +- 25 files changed, 68 insertions(+), 39 deletions(-) (limited to 'chaos') diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index c720e1b..781011b 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -34,7 +34,7 @@ public: CHAOS_SYS_INIT(x,0.5,0); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index fd098f3..492b6d5 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -42,7 +42,7 @@ public: CHAOS_PAR_INIT(r, 0.5); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t r = CHAOS_PARAMETER(r); diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 4b984d9..d18a507 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -42,12 +42,12 @@ public: return dimensions; } - inline void m_perform() - { - m_step(); - m_bash_denormals(); - m_verify(); - } +// inline void m_perform() +// { +// m_step(); +// m_bash_denormals(); +// m_verify(); +// } std::map attr_ind; @@ -70,7 +70,7 @@ public: data_t m_data[dimensions]; // state of the system protected: - virtual void m_step() = 0; // iteration +// void m_step() = 0; // iteration flext::AtomList Parameter; // parameter flext::AtomList System; // system }; diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 9f6dd75..6ca9ce4 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -257,7 +257,10 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, for (int i = 0; i!=n; ++i) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + for (int j = 0; j != outlets; ++j) { outsigs[j][i] = m_system.get_data(j); @@ -279,7 +282,10 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { while (phase <= 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase += m_sr * m_invfreq; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -309,7 +315,10 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); } @@ -341,7 +350,10 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) @@ -381,7 +393,10 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { if (phase <= 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) @@ -420,7 +435,10 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; @@ -472,7 +490,11 @@ void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 9025273..915d6a1 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -42,7 +42,11 @@ public: void m_bang() { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + + int outlets = m_system.get_num_eq(); while (outlets--) diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp index 1b812a0..fded6bc 100644 --- a/chaos/src/chaos_search.hpp +++ b/chaos/src/chaos_search.hpp @@ -137,7 +137,9 @@ void chaos_search::m_search() /* transient dynamics */ for (int i = 0; i != m_transient_steps; ++i) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); } for (int i = 0; i != dimensions; ++i) @@ -149,8 +151,9 @@ void chaos_search::m_search() for (int i = 0; i != m_asymptotic_steps; ++i) { - - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); data_t diff = 0; for (int j = 0; j != dimensions; ++j) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 294b7d6..c58391a 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -39,7 +39,7 @@ public: } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t omega = CHAOS_PARAMETER(omega); diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index 3db7e27..d7f7539 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 46fecbf..2670b7d 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index d013bae..7e16bea 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -37,7 +37,7 @@ public: } - virtual void m_step() + void m_step() { data_t data = m_data[0]; diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index c6aaf1e..7793814 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t data = m_data[0]; diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 014fa68..b7ca5bf 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -39,7 +39,7 @@ public: } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 60e3a77..534a9de 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -46,7 +46,7 @@ public: CHAOS_SYS_INIT(y,0.5,1); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 47abc33..1329bd3 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -42,7 +42,7 @@ public: CHAOS_PAR_INIT(d,0.744728); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 255829a..bfe76e4 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -41,7 +41,7 @@ public: } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index d663761..c1a42b5 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -39,7 +39,7 @@ public: CHAOS_PAR_INIT(b,2.879879); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 022e651..0120745 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -39,7 +39,7 @@ public: CHAOS_PAR_INIT(b,2.879879); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index f6ce961..25bc837 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -37,7 +37,7 @@ public: CHAOS_PAR_INIT(C, 259200); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 7880d21..2d19855 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -38,7 +38,7 @@ public: { } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 24096a6..07656d2 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -38,7 +38,7 @@ public: CHAOS_PAR_INIT(b,0.3); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 92016b1..afc89fb 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -28,7 +28,7 @@ class map_base : public chaos_base { protected: - virtual void m_step() + void m_step() { } }; diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b198dc5..f46332c 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -62,7 +62,7 @@ public: return (f >= 0); } - virtual void m_step() + void m_step() { (this->*m_routine)(); } diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 8a11281..d7043f4 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -40,7 +40,7 @@ public: } - virtual void m_step() + void m_step() { m_data[0] = sin (M_PI * m_data[0]); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 8798edc..399484b 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -43,7 +43,7 @@ public: } - virtual void m_step() + void m_step() { data_t I = m_data[0]; data_t theta = m_data[1]; diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 2e716ac..f8f2c29 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -35,7 +35,7 @@ public: } - virtual void m_step() + void m_step() { data_t data = m_data[0]; -- cgit v1.2.1 From 47603a7ffe9d354ef5a2af7981504527a9e742da Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 10 Aug 2006 21:23:33 +0000 Subject: max/msp fix (thanks to thomas for mentioning this) svn path=/trunk/externals/tb/; revision=5551 --- chaos/src/chaos.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index bb9971d..971d503 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -30,6 +30,11 @@ #include +#if FLEXT_SYS != FLEXT_SYS_PD +#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \ + (((*(unsigned int*)&(f))&0x60000000)==0x60000000)) +#endif + /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; @@ -42,15 +47,15 @@ typedef float data_t; inline data_t chaos_mod(data_t x, data_t y) { #ifdef DOUBLE_PRECISION - return fmod(x,y); + return fmod(x,y); #else - return fmodf(x,y); + return fmodf(x,y); #endif } inline data_t rand_range(data_t low, data_t high) { - return low + ( (rand() * (high - low)) / RAND_MAX); + return low + ( (rand() * (high - low)) / RAND_MAX); } -- cgit v1.2.1 From fae4d2ec359b596a775973956daf4636856f0141 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 6 Sep 2006 20:32:21 +0000 Subject: cleanups svn path=/trunk/externals/tb/; revision=5880 --- chaos/src/chaos.hpp | 13 -- chaos/src/chua.hpp | 262 +++++++++++++++++++-------------------- chaos/src/driven_van_der_pol.hpp | 108 ++++++++-------- chaos/src/duffing.hpp | 124 +++++++++--------- chaos/src/latoomutgamma.hpp | 94 +++++++------- chaos/src/linear_congruental.hpp | 66 +++++----- chaos/src/ode_base.hpp | 79 ++++++------ chaos/src/tent_map.hpp | 58 ++++----- 8 files changed, 395 insertions(+), 409 deletions(-) (limited to 'chaos') diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 971d503..259f56e 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -38,27 +38,14 @@ /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; -#define CHAOS_ABS(x) fabs(x) #else typedef float data_t; -#define CHAOS_ABS(x) fabsf(x) #endif -inline data_t chaos_mod(data_t x, data_t y) -{ -#ifdef DOUBLE_PRECISION - return fmod(x,y); -#else - return fmodf(x,y); -#endif -} - inline data_t rand_range(data_t low, data_t high) { return low + ( (rand() * (high - low)) / RAND_MAX); } - - #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index f8c6e31..7669a24 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -23,143 +23,143 @@ // chua system: dx1/dt = alpha * (x2 - x1 - h(x1)) // dx2/dt = x1 - x2 + x3 // dx3/dt = - beta * x2 -// +// // with h(x) = b*x + a - b (for x > 1) // a*x (for -1 <= x <= 1 // b*x - a + b (for x < -1) -// +// // taken from Viktor Avrutin: lecture notes class chua: - public ode_base<3> + public ode_base<3> { public: - chua() - { - CHAOS_PAR_INIT(method,2); - CHAOS_PAR_INIT(dt,0.05); - - CHAOS_SYS_INIT(x1,1,1); - CHAOS_SYS_INIT(x2,1,1); - CHAOS_SYS_INIT(x3,1,1); - - CHAOS_PAR_INIT(a,140); - CHAOS_PAR_INIT(b,30); - CHAOS_PAR_INIT(alpha,30); - CHAOS_PAR_INIT(beta,30); - } - - virtual void m_system(data_t* deriv, data_t* data) - { - data_t x1 = data[0]; - data_t x2 = data[1]; - data_t x3 = data[2]; - - data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); - - data_t h; - - if (x1 > 1) - h = b*x1 + a - b; - else if (x1 < -1) - h = b*x1 - a + b; - else - h = a*x1; - - deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); - deriv[1] = x1 - x2 + x3; - deriv[2] = - CHAOS_PARAMETER(beta) * x2; - } - - virtual void m_verify() - { - data_t x1 = m_data[0]; - data_t x2 = m_data[1]; - data_t x3 = m_data[2]; - - if ( CHAOS_ABS(x3) < 1e-10) - x3 = 0; - - if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ - { - reset(); - return; - } - else - { - data_t c = m_c; - if (m_c) - { - data_t mc = - c; - if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ - { - reset(); - return; - } - if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ - { - reset(); - return; - } - } - } - } - - inline void reset() - { - m_data[0] = rand_range(-1,1); - m_data[1] = rand_range(-1,1); - m_data[2] = rand_range(-1,1); - } - - CHAOS_SYSVAR_FUNCS(x1, 0); - CHAOS_SYSVAR_FUNCS(x2, 1); - CHAOS_SYSVAR_FUNCS(x3, 2); - - /* due to stability issues, we hook into the predicates */ - data_t m_c; - bool m_pred_a(data_t a) - { - data_t b = CHAOS_PARAMETER(b); - m_c = (b - a) / (b + 1); - return true; - } - - bool m_pred_b(data_t b) - { - if (b == -1) - m_c = 0; - else - { - data_t a = CHAOS_PARAMETER(a); - m_c = (b - a) / (b + 1); - } - return true; - } - - CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); - CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); - CHAOS_SYSPAR_FUNCS(alpha); - CHAOS_SYSPAR_FUNCS(beta); + chua() + { + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.05); + + CHAOS_SYS_INIT(x1,1,1); + CHAOS_SYS_INIT(x2,1,1); + CHAOS_SYS_INIT(x3,1,1); + + CHAOS_PAR_INIT(a,140); + CHAOS_PAR_INIT(b,30); + CHAOS_PAR_INIT(alpha,30); + CHAOS_PAR_INIT(beta,30); + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0]; + data_t x2 = data[1]; + data_t x3 = data[2]; + + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + + data_t h; + + if (x1 > 1) + h = b*x1 + a - b; + else if (x1 < -1) + h = b*x1 - a + b; + else + h = a*x1; + + deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); + deriv[1] = x1 - x2 + x3; + deriv[2] = - CHAOS_PARAMETER(beta) * x2; + } + + virtual void m_verify() + { + data_t x1 = m_data[0]; + data_t x2 = m_data[1]; + data_t x3 = m_data[2]; + + if ( std::abs(x3) < 1e-10) + x3 = 0; + + if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ + { + reset(); + return; + } + else + { + data_t c = m_c; + if (m_c) + { + data_t mc = - c; + if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ + { + reset(); + return; + } + if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ + { + reset(); + return; + } + } + } + } + + inline void reset() + { + m_data[0] = rand_range(-1,1); + m_data[1] = rand_range(-1,1); + m_data[2] = rand_range(-1,1); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + /* due to stability issues, we hook into the predicates */ + data_t m_c; + bool m_pred_a(data_t a) + { + data_t b = CHAOS_PARAMETER(b); + m_c = (b - a) / (b + 1); + return true; + } + + bool m_pred_b(data_t b) + { + if (b == -1) + m_c = 0; + else + { + data_t a = CHAOS_PARAMETER(a); + m_c = (b - a) / (b + 1); + } + return true; + } + + CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + CHAOS_SYSPAR_FUNCS(alpha); + CHAOS_SYSPAR_FUNCS(beta); }; -#define CHUA_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(alpha); \ -CHAOS_SYS_CALLBACKS(beta); \ -CHAOS_SYS_CALLBACKS(a); \ -CHAOS_SYS_CALLBACKS(b); \ -CHAOS_SYS_CALLBACKS(x1); \ -CHAOS_SYS_CALLBACKS(x2); \ +#define CHUA_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(beta); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ CHAOS_SYS_CALLBACKS(x3); -#define CHUA_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(a); \ -CHAOS_SYS_ATTRIBUTE(b); \ -CHAOS_SYS_ATTRIBUTE(alpha); \ -CHAOS_SYS_ATTRIBUTE(beta); \ -CHAOS_SYS_ATTRIBUTE(x1); \ -CHAOS_SYS_ATTRIBUTE(x2); \ +#define CHUA_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(beta); \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ CHAOS_SYS_ATTRIBUTE(x3); diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 3c034d2..31c2e2d 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -30,66 +30,66 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_van_der_pol - : public ode_base<3> + : public ode_base<3> { public: - driven_van_der_pol() - { - CHAOS_PAR_INIT(method,2); - CHAOS_PAR_INIT(dt,0.01); + driven_van_der_pol() + { + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0.8, 0); - CHAOS_SYS_INIT(u2,0.6, 1); - CHAOS_SYS_INIT(u3,0.4, 2); + CHAOS_SYS_INIT(u1,0.8, 0); + CHAOS_SYS_INIT(u2,0.6, 1); + CHAOS_SYS_INIT(u3,0.4, 2); - CHAOS_PAR_INIT(a,5); - CHAOS_PAR_INIT(Omega,2.466); - CHAOS_PAR_INIT(k,5); - } - + CHAOS_PAR_INIT(a,5); + CHAOS_PAR_INIT(Omega,2.466); + CHAOS_PAR_INIT(k,5); + } - virtual void m_system(data_t* deriv, data_t* data) - { - data_t u1 = data[0], u2 = data[1], u3 = data[2]; - - deriv[0] = u2; - deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + - CHAOS_PARAMETER(k)*cos(u3); - deriv[2] = CHAOS_PARAMETER(Omega); - } - - virtual void m_verify() - { - /* make sure to stay in the range of 2 pi */ - if (m_data[2] > 2*M_PI) - m_data[2] = chaos_mod(m_data[2], 2*M_PI); - } - CHAOS_SYSVAR_FUNCS(u1, 0); - CHAOS_SYSVAR_FUNCS(u2, 1); - CHAOS_SYSVAR_FUNCS(u3, 2); + void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1], u3 = data[2]; - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(k); - CHAOS_SYSPAR_FUNCS(Omega); + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + + CHAOS_PARAMETER(k)*cos(u3); + deriv[2] = CHAOS_PARAMETER(Omega); + } + + void m_verify() + { + /* make sure to stay in the range of 2 pi */ + if (m_data[2] > 2*M_PI) + m_data[2] = std::fmod(m_data[2], data_t(2*M_PI)); + } + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + CHAOS_SYSVAR_FUNCS(u3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(k); + CHAOS_SYSPAR_FUNCS(Omega); }; -#define DRIVEN_VAN_DER_POL_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(u1); \ -CHAOS_SYS_CALLBACKS(u2); \ -CHAOS_SYS_CALLBACKS(u3); \ -CHAOS_SYS_CALLBACKS(a); \ -CHAOS_SYS_CALLBACKS(k); \ +#define DRIVEN_VAN_DER_POL_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(u3); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(k); \ CHAOS_SYS_CALLBACKS(Omega); -#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(u1); \ -CHAOS_SYS_ATTRIBUTE(u2); \ -CHAOS_SYS_ATTRIBUTE(u3); \ -CHAOS_SYS_ATTRIBUTE(a); \ -CHAOS_SYS_ATTRIBUTE(k); \ +#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(u3); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(k); \ CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp index ee7f7fb..b5d931c 100644 --- a/chaos/src/duffing.hpp +++ b/chaos/src/duffing.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2005 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -22,73 +22,73 @@ // duffing equation: dx/dt = y // dy/dt = x * (1 - x^2) + R*cos(omega * t) - gamma * y -// +// class duffing: - public ode_base<2> + public ode_base<2> { public: - duffing() - { - CHAOS_PAR_INIT(method,0); - CHAOS_PAR_INIT(dt,0.01); - - CHAOS_SYS_INIT(x, 0.5, 0); - CHAOS_SYS_INIT(y, 0.5, 1); - - CHAOS_PAR_INIT(R, 0.4); - CHAOS_PAR_INIT(omega, 1); - CHAOS_PAR_INIT(gamma, 0.25); - - t = 0; - } - - - virtual void m_system(data_t* deriv, data_t* data) - { - data_t x = data[0], y = data[1]; - - deriv[0] = y; - deriv[1] = x * (1 - x*x) + - CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - - CHAOS_PARAMETER(gamma) * y; - t += CHAOS_PARAMETER(dt); - t = chaos_mod(t, M_PI); - } - - virtual void m_verify() - { - if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) - for (int i = 0; i != 3; ++i) - m_data[i] = rand_range(0,3); - } - - - CHAOS_SYSVAR_FUNCS(x,0); - CHAOS_SYSVAR_FUNCS(y,1); - - CHAOS_SYSPAR_FUNCS(R); - CHAOS_SYSPAR_FUNCS(omega); - CHAOS_SYSPAR_FUNCS(gamma); + duffing() + { + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(x, 0.5, 0); + CHAOS_SYS_INIT(y, 0.5, 1); + + CHAOS_PAR_INIT(R, 0.4); + CHAOS_PAR_INIT(omega, 1); + CHAOS_PAR_INIT(gamma, 0.25); + + t = 0; + } + + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x = data[0], y = data[1]; + + deriv[0] = y; + deriv[1] = x * (1 - x*x) + + CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - + CHAOS_PARAMETER(gamma) * y; + t += CHAOS_PARAMETER(dt); + t = std::fmod(t, data_t(M_PI)); + } + + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + + + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(y,1); + + CHAOS_SYSPAR_FUNCS(R); + CHAOS_SYSPAR_FUNCS(omega); + CHAOS_SYSPAR_FUNCS(gamma); private: - data_t t; + data_t t; }; -#define DUFFING_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(x); \ -CHAOS_SYS_CALLBACKS(y); \ -CHAOS_SYS_CALLBACKS(R); \ -CHAOS_SYS_CALLBACKS(gamma); \ +#define DUFFING_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); \ +CHAOS_SYS_CALLBACKS(R); \ +CHAOS_SYS_CALLBACKS(gamma); \ CHAOS_SYS_CALLBACKS(omega); -#define DUFFING_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(x); \ -CHAOS_SYS_ATTRIBUTE(y); \ -CHAOS_SYS_ATTRIBUTE(R); \ -CHAOS_SYS_ATTRIBUTE(gamma); \ +#define DUFFING_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); \ +CHAOS_SYS_ATTRIBUTE(R); \ +CHAOS_SYS_ATTRIBUTE(gamma); \ CHAOS_SYS_ATTRIBUTE(omega); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 0120745..040a071 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -27,59 +27,59 @@ // taken from Pickover: Chaos In Wonderland class latoomutgamma - : public map_base<2> + : public map_base<2> { public: - latoomutgamma() - { - CHAOS_SYS_INIT(x1,0.5,0); - CHAOS_SYS_INIT(x2,0.5,1); - - CHAOS_PAR_INIT(a,-0.966918); - CHAOS_PAR_INIT(b,2.879879); - } + latoomutgamma() + { + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); - void m_step() - { - data_t x1 = m_data[0], x2 = m_data[1]; - data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); - data_t tmp; - - tmp = sin(x1*b); - m_data[0] = CHAOS_ABS(sin(x2*b)) + tmp*tmp; - tmp = sin(x2*a); - m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; - } + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + } + void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; - /* function has a fix point for x1 == x2 == 0 */ - void m_verify() - { - if (m_data[0] == 0 && m_data[1] == 0) - for (int i = 0; i != 2; ++i) - m_data[i] = rand_range(-1,1); - } - - CHAOS_SYSVAR_FUNCS(x1, 0); - CHAOS_SYSVAR_FUNCS(x2, 1); + tmp = sin(x1*b); + m_data[0] = std::abs(sin(x2*b)) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = std::abs(sin(x1*a)) + tmp*tmp; + } - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(b); + + /* function has a fix point for x1 == x2 == 0 */ + void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(-1,1); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); }; -#define LATOOMUTGAMMA_CALLBACKS \ -MAP_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(x1); \ -CHAOS_SYS_CALLBACKS(x2); \ -CHAOS_SYS_CALLBACKS(a); \ +#define LATOOMUTGAMMA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(b); -#define LATOOMUTGAMMA_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(x1); \ -CHAOS_SYS_ATTRIBUTE(x2); \ -CHAOS_SYS_ATTRIBUTE(a); \ +#define LATOOMUTGAMMA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(b); diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index 25bc837..9c6310f 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -25,43 +25,43 @@ // taken from Julien C. Sprott, Chaos and Time-Series Analysis class linear_congruental: - public map_base<2> + public map_base<2> { public: - linear_congruental() - { - CHAOS_SYS_INIT(x, 0, 0); - - CHAOS_PAR_INIT(A, 1741); - CHAOS_PAR_INIT(B, 54773); - CHAOS_PAR_INIT(C, 259200); - } + linear_congruental() + { + CHAOS_SYS_INIT(x, 0, 0); + + CHAOS_PAR_INIT(A, 1741); + CHAOS_PAR_INIT(B, 54773); + CHAOS_PAR_INIT(C, 259200); + } - void m_step() - { - data_t x = m_data[0]; + void m_step() + { + data_t x = m_data[0]; - m_data[0] = chaos_mod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); - } + m_data[0] = std::fmod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); + } - CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(x,0); - CHAOS_SYSPAR_FUNCS(A); - CHAOS_SYSPAR_FUNCS(B); - CHAOS_SYSPAR_FUNCS(C); + CHAOS_SYSPAR_FUNCS(A); + CHAOS_SYSPAR_FUNCS(B); + CHAOS_SYSPAR_FUNCS(C); }; -#define LINEAR_CONGRUENTAL_CALLBACKS \ -MAP_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(A); \ -CHAOS_SYS_CALLBACKS(B); \ -CHAOS_SYS_CALLBACKS(C); \ +#define LINEAR_CONGRUENTAL_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(A); \ +CHAOS_SYS_CALLBACKS(B); \ +CHAOS_SYS_CALLBACKS(C); \ CHAOS_SYS_CALLBACKS(x); -#define LINEAR_CONGRUENTAL_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(A); \ -CHAOS_SYS_ATTRIBUTE(B); \ -CHAOS_SYS_ATTRIBUTE(C); \ +#define LINEAR_CONGRUENTAL_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(A); \ +CHAOS_SYS_ATTRIBUTE(B); \ +CHAOS_SYS_ATTRIBUTE(C); \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index f46332c..42478bc 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -76,59 +76,58 @@ protected: data_t m_k1[dimensions]; data_t m_k2[dimensions]; data_t m_k3[dimensions]; - data_t m_tmp[dimensions]; -// data_t m_tmp[dimensions]; + data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k0[i]; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k0[i]; } void rk2() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; -// -// m_system (m_k1, m_k0); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k1[i]; + for (int i = 0; i != dimensions; ++i) + m_k0[i] = m_k0[i] * 0.5 * m_dt + chaos_base::m_data[i]; + + m_system (m_k0, chaos_base::m_data); + m_system (m_k1, m_k0); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k1[i]; } void rk4() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k0[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; -// } -// -// m_system (m_k1, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k1[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; -// } -// -// m_system (m_k2, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k2[i] *= m_dt; -// m_tmp[i] = m_data[i] + m_k2[i]; -// } -// -// m_system (m_k3, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// m_k3[i] *= m_dt; -// -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) -// / 6.; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + { + m_k0[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k0[i]; + } + + m_system (m_k1, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k1[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k1[i]; + } + + m_system (m_k2, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k2[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + m_k2[i]; + } + + m_system (m_k3, m_tmp); + for (int i = 0; i != dimensions; ++i) + m_k3[i] *= m_dt; + + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) + / 6.; } }; diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index f8f2c29..b0961ee 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // 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; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -26,36 +26,36 @@ class tent_map: - public map_base<1> + public map_base<1> { public: - tent_map() - { - CHAOS_SYS_INIT(x, 0.6,0); - } - - - void m_step() - { - data_t data = m_data[0]; - - m_data[0] = 1 - 2*CHAOS_ABS(data); - } - - CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); - bool m_pred_x(t_float f) - { - return (f > -1) && (f < 1); - } + tent_map() + { + CHAOS_SYS_INIT(x, 0.6,0); + } + + + void m_step() + { + data_t data = m_data[0]; + + m_data[0] = 1 - 2*std::abs(data); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f > -1) && (f < 1); + } }; -#define TENT_MAP_CALLBACKS \ -MAP_CALLBACKS \ +#define TENT_MAP_CALLBACKS \ +MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define TENT_MAP_ATTRIBUTES \ -MAP_ATTRIBUTES \ +#define TENT_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); - + -- cgit v1.2.1