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