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/src/chaos_dsp.hpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 chaos/src/chaos_dsp.hpp (limited to 'chaos/src/chaos_dsp.hpp') 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 */ + +}; -- 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/chaos_dsp.hpp | 223 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 218 insertions(+), 5 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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; +} -- 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/src/chaos_dsp.hpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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); -- 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/chaos_dsp.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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; } } -- 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/chaos_dsp.hpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'chaos/src/chaos_dsp.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] - -- 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/chaos_dsp.hpp | 160 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 52 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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); -- 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/chaos_dsp.hpp | 70 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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) -- 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/src/chaos_dsp.hpp') 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 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/chaos_dsp.hpp | 138 +++++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 65 deletions(-) (limited to 'chaos/src/chaos_dsp.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); -- 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/chaos_dsp.hpp | 55 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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) -- 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/src/chaos_dsp.hpp') 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/src/chaos_dsp.hpp') 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/src/chaos_dsp.hpp') 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/chaos_dsp.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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); \ -- 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/src/chaos_dsp.hpp') 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 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/chaos_dsp.hpp | 171 ++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 85 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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; -- 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/chaos_dsp.hpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'chaos/src/chaos_dsp.hpp') 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; -- cgit v1.2.1