[PD-cvs] externals/tb/chaos/src chaos_dsp.hpp,1.11,1.12
Tim Blechmann
timblech at users.sourceforge.net
Sun Oct 9 12:21:38 CEST 2005
Update of /cvsroot/pure-data/externals/tb/chaos/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14428/src
Modified Files:
chaos_dsp.hpp
Log Message:
cleaner behaviour for high frequency resampling
Index: chaos_dsp.hpp
===================================================================
RCS file: /cvsroot/pure-data/externals/tb/chaos/src/chaos_dsp.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** chaos_dsp.hpp 9 Oct 2005 09:55:24 -0000 1.11
--- chaos_dsp.hpp 9 Oct 2005 10:21:36 -0000 1.12
***************
*** 37,42 ****
--- 37,46 ----
/* 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()
***************
*** 67,72 ****
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 */
--- 71,75 ----
float m_freq; /* frequency of oscillations */
float m_invfreq; /* inverse frequency */
! float m_phase; /* phase */
float m_sr; /* sample rate */
***************
*** 119,123 ****
}
}
!
}
--- 122,126 ----
}
}
! set_freq(m_freq);
}
***************
*** 134,151 ****
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.1)
{
! m_freq = f;
! m_invfreq = 1.f / f;
!
! m_routine = &thisType::m_signal_n_hf;
}
! else
! post("frequency out of range");
}
--- 137,175 ----
if( f <= m_sr * 0.1 )
{
! 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
{
! 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);
! }
}
!
! m_freq = f;
! m_invfreq = 1.f / f;
}
***************
*** 227,231 ****
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();
--- 251,255 ----
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();
***************
*** 248,252 ****
int outlets = m_system->get_num_eq();
! float phase = m_fphase;
int offset = 0;
--- 272,276 ----
int outlets = m_system->get_num_eq();
! float phase = m_phase;
int offset = 0;
***************
*** 268,272 ****
offset += next;
}
! m_fphase = phase;
}
--- 292,296 ----
offset += next;
}
! m_phase = phase;
}
***************
*** 274,282 ****
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 phase = m_phase;
int offset = 0;
--- 298,306 ----
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 phase = int(m_phase);
int offset = 0;
***************
*** 305,313 ****
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 phase = m_phase;
int i = 0;
--- 329,337 ----
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 phase = int(m_phase);
int i = 0;
***************
*** 342,352 ****
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 phase = m_phase;
int i = 0;
--- 366,416 ----
+
+ 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();
+
+ 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 <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 phase = int(m_phase);
int i = 0;
***************
*** 370,374 ****
float fseglen = (float)phase;
m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] -
! fseglen * m_slopes[j])
/ (fseglen * fseglen + fseglen);
}
--- 434,438 ----
float fseglen = (float)phase;
m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] -
! fseglen * m_slopes[j])
/ (fseglen * fseglen + fseglen);
}
***************
*** 392,393 ****
--- 456,509 ----
m_phase = phase;
}
+
+
+ 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();
+
+ 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;
+ }
More information about the Pd-cvs
mailing list