diff options
author | Tim Blechmann <timblech@users.sourceforge.net> | 2006-05-21 18:34:34 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:12:02 +0200 |
commit | 13cba7a7997e318fbba01a36912219355e387d52 (patch) | |
tree | 77ec90e15c3a912a480d21958bdf1b57a7d7f14f /chaos/src/chaos_dsp.hpp | |
parent | cceea140611ff282d1513937f615abe2b8081ebc (diff) |
rewrote most stuff using templates
svn path=/trunk/externals/tb/; revision=5105
Diffstat (limited to 'chaos/src/chaos_dsp.hpp')
-rw-r--r-- | chaos/src/chaos_dsp.hpp | 171 |
1 files changed, 86 insertions, 85 deletions
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 system> class chaos_dsp +template <class system> +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>) \ \ -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<SYSTEM>(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 <class system> void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + 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 <class system> void chaos_dsp<system>::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<system>::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<system>::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 <class system> void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -308,7 +309,7 @@ void chaos_dsp<system>::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<system>::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 <class system> void chaos_dsp<system>::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -340,11 +341,11 @@ void chaos_dsp<system>::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 <class system> void chaos_dsp<system>::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<system>::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 <class system> void chaos_dsp<system>::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -419,14 +420,14 @@ void chaos_dsp<system>::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 <class system> void chaos_dsp<system>::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<system>::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; |