aboutsummaryrefslogtreecommitdiff
path: root/chaos/src/chaos_dsp.hpp
diff options
context:
space:
mode:
authorTim Blechmann <timblech@users.sourceforge.net>2005-06-16 13:02:02 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:11:59 +0200
commitd1ed55f96f9cecc818844006fb36cd58ca70da5e (patch)
tree4d1ed404ba54ad7f360cec5ad3d0b38ec4b24840 /chaos/src/chaos_dsp.hpp
parent2434290915cda6ed855e4dc2249312153b995817 (diff)
- parameter searching (broken)
- misc. updates svn path=/trunk/externals/tb/; revision=3192
Diffstat (limited to 'chaos/src/chaos_dsp.hpp')
-rw-r--r--chaos/src/chaos_dsp.hpp55
1 files changed, 47 insertions, 8 deletions
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 system> 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<SYSTEM>) \
@@ -228,9 +237,39 @@ void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs,
outsigs[j][i] = m_system->get_data(j);
}
}
+}
+
+
+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();
+ 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 <class system>
void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs,
t_sample *const *outsigs)