From b85f8bc7af3fda0f31af1c79a9f25145b8004705 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 3 Aug 2004 09:56:19 +0000 Subject: works of one morning svn path=/trunk/externals/tb/; revision=1906 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 3 +- sc4pd/pd/delayn.pd | 11 +++ sc4pd/pd/lag2.pd | 17 ++++ sc4pd/pd/lag3.pd | 17 ++++ sc4pd/pd/linexp.pd | 17 ++++ sc4pd/source/DelayN.cpp | 239 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/DelayUnit.cpp | 77 +++++++++++++++ sc4pd/source/DelayUnit.hpp | 58 +++++++++++ sc4pd/source/Lag2.cpp | 132 +++++++++++++++++++++++++ sc4pd/source/Lag3.cpp | 137 ++++++++++++++++++++++++++ sc4pd/source/LinExp.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 12 ++- sc4pd/source/sc4pd.hpp | 19 ++++ sc4pd/source/template.cpp | 8 +- 15 files changed, 962 insertions(+), 10 deletions(-) create mode 100644 sc4pd/pd/delayn.pd create mode 100644 sc4pd/pd/lag2.pd create mode 100644 sc4pd/pd/lag3.pd create mode 100644 sc4pd/pd/linexp.pd create mode 100644 sc4pd/source/DelayN.cpp create mode 100644 sc4pd/source/DelayUnit.cpp create mode 100644 sc4pd/source/DelayUnit.hpp create mode 100644 sc4pd/source/Lag2.cpp create mode 100644 sc4pd/source/Lag3.cpp create mode 100644 sc4pd/source/LinExp.cpp (limited to 'sc4pd') diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 9b46ed4..1e95392 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) -# CXX=icc + CXX=icc # where does the PD installation reside? diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 922e05c..78ed170 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -9,4 +9,5 @@ SRCS= \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ - LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ No newline at end of file + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ + Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp \ No newline at end of file diff --git a/sc4pd/pd/delayn.pd b/sc4pd/pd/delayn.pd new file mode 100644 index 0000000..37b0c29 --- /dev/null +++ b/sc4pd/pd/delayn.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 77 138 DelayN~ 1 3; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 90 233 dac~; +#X msg 185 88 delaytime \$1; +#X obj 79 57 Dust~ 4; +#X connect 0 0 2 0; +#X connect 1 0 3 0; +#X connect 3 0 0 0; +#X connect 4 0 0 0; +#X connect 4 0 2 1; diff --git a/sc4pd/pd/lag2.pd b/sc4pd/pd/lag2.pd new file mode 100644 index 0000000..0398109 --- /dev/null +++ b/sc4pd/pd/lag2.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 257 82 hsl 128 15 1e-04 1 1 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 254 102 lagTime \$1; +#X obj 155 61 WhiteNoise~; +#X obj 156 130 Lag2~ 0.0004; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 6 0 1 0; diff --git a/sc4pd/pd/lag3.pd b/sc4pd/pd/lag3.pd new file mode 100644 index 0000000..206a07b --- /dev/null +++ b/sc4pd/pd/lag3.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 257 82 hsl 128 15 1e-04 1 1 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 254 102 lagTime \$1; +#X obj 155 61 WhiteNoise~; +#X obj 156 130 Lag~ 0.0004; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 6 0 1 0; diff --git a/sc4pd/pd/linexp.pd b/sc4pd/pd/linexp.pd new file mode 100644 index 0000000..5a7fc04 --- /dev/null +++ b/sc4pd/pd/linexp.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 31 230 dac~; +#X obj 111 223 print~; +#X obj 116 196 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 27 86 osc~ 440; +#X obj 27 142 LinExp~ 0 1 0.001 2; +#X floatatom 252 204 5 0 0 0 - - -; +#X obj 246 151 LinExp 0 100 0.001 2; +#X floatatom 248 123 5 0 0 0 - - -; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 4 0 1 0; +#X connect 6 0 5 0; +#X connect 7 0 6 0; diff --git a/sc4pd/source/DelayN.cpp b/sc4pd/source/DelayN.cpp new file mode 100644 index 0000000..176c6c3 --- /dev/null +++ b/sc4pd/source/DelayN.cpp @@ -0,0 +1,239 @@ +/* sc4pd + DelayN~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class DelayN_ar : private DelayUnit_ar +{ + FLEXT_HEADER(DelayN_ar,DelayUnit_ar); + + DelayN_ar (int argc, t_atom *argv); + ~DelayN_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + changed = false; + DelayUnit_Reset(m_maxdelaytime, m_delaytime); + post("start"); + } + + void m_set(float f) + { + m_delaytime=f; + changed = true; + } + +private: + bool changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("DelayN~",DelayN_ar); + +DelayN_ar::DelayN_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_set); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("2 arguments are needed"); + return; + } + + m_delaytime = sc_getfloatarg(Args,0); + m_maxdelaytime = sc_getfloatarg(Args,1); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +DelayN_ar::~DelayN_ar () +{ + DelayUnit_Dtor(); +} + +void DelayN_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long irdphase = iwrphase - (long)dsamp; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase < 0) + { + ZXP(nout) = 0.f; + } + else + { + ZXP(nout) = dlybuf[irdphase & mask]; + } + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyN = dlybuf1 + m_idelaylen; + long remain = n; + + while (remain) + { + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyrd = dlybuf1 + (irdphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + if (irdphase < 0) + { + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = 0.f; + } + } + else + { + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = ZXP(dlyrd); + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + } + + m_iwrphase = iwrphase; + + m_numoutput += n; + + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void DelayN_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + dsamp += dsamp_slope; + ++iwrphase; + long irdphase = iwrphase - (long)dsamp; + ZXP(nout) = dlybuf[irdphase & mask]; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyN = dlybuf1 + m_idelaylen; + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = ZXP(dlyrd); + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + iwrphase += n; + } + m_iwrphase = iwrphase; +} + +/* todo: DelayN for control rate ? */ diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp new file mode 100644 index 0000000..7f96677 --- /dev/null +++ b/sc4pd/source/DelayUnit.cpp @@ -0,0 +1,77 @@ +/* sc4pd + public class for several delay objects + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +void DelayUnit_ar::DelayUnit_AllocDelayLine() +{ + long delaybufsize = (long)ceil(m_maxdelaytime * Samplerate() + 1.f); + delaybufsize = delaybufsize + Blocksize(); + delaybufsize = NEXTPOWEROFTWO(delaybufsize); // round up to next power of two + m_fdelaylen = m_idelaylen = delaybufsize; + + delete m_dlybuf; + m_dlybuf = new float[delaybufsize] ; + m_mask = delaybufsize - 1; +} + +void DelayUnit_ar::DelayUnit_Dtor() +{ + delete m_dlybuf; +} + +float DelayUnit_ar::CalcDelay(float delaytime) +{ + float next_dsamp = delaytime * Samplerate(); + return sc_clip(next_dsamp, 1.f, m_fdelaylen); +} + +void DelayUnit_ar::DelayUnit_Reset(float f, float g) +{ + m_maxdelaytime = f; + m_delaytime = g; + m_dlybuf = 0; + + DelayUnit_AllocDelayLine(); + + m_dsamp = CalcDelay(m_delaytime); + + m_numoutput = 0; + m_iwrphase = 0; +} diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp new file mode 100644 index 0000000..d794031 --- /dev/null +++ b/sc4pd/source/DelayUnit.hpp @@ -0,0 +1,58 @@ +/* sc4pd + public class for several delay objects + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" + +class DelayUnit_ar : public flext_dsp +{ + FLEXT_HEADER(DelayUnit_ar, flext_dsp); +public: + /* functions */ + void DelayUnit_AllocDelayLine(); + void DelayUnit_Reset(float maxdelaytime, float delaytime); + float CalcDelay(float delaytime); + void DelayUnit_Dtor(); + + /* data */ + float *m_dlybuf; + float m_dsamp, m_fdelaylen; + float m_delaytime, m_maxdelaytime; + long m_iwrphase, m_idelaylen, m_mask; + long m_numoutput; +}; + +/* todo: a delay for control messages? */ diff --git a/sc4pd/source/Lag2.cpp b/sc4pd/source/Lag2.cpp new file mode 100644 index 0000000..2e3096b --- /dev/null +++ b/sc4pd/source/Lag2.cpp @@ -0,0 +1,132 @@ +/* sc4pd + Lag2~, Lag2 + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: DKV Trio: Baraka + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Lag2~ -----------------------------*/ + +class Lag2_ar + :public flext_dsp +{ + FLEXT_HEADER(Lag2_ar,flext_dsp); + +public: + Lag2_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1, n_b1; + float m_y1a, m_y1b; + float m_lag; + bool changed; +}; + +FLEXT_LIB_DSP_V("Lag2~",Lag2_ar); + +Lag2_ar::Lag2_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"lagTime",m_set); + + AtomList Args(argc,argv); + + m_lag = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_b1 = 0.f; + m_y1a = 0.f; + m_y1b = 0.f; +} + +void Lag2_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + changed = false; + m_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); +} + +void Lag2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1a = m_y1a; + float y1b = m_y1b; + float b1 = m_b1; + + if (changed) + { + float b1_slope = CALCSLOPE(m_b1, n_b1); + m_b1 = n_b1; + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + ZXP(nout) = y1b; + b1 += b1_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + ZXP(nout) = y1b; + } + } + m_y1a = zapgremlins(y1a); + m_y1b = zapgremlins(y1b); +} + +void Lag2_ar::m_set(float f) +{ + m_lag = f; + n_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); + changed = true; +} + +/* todo: does a control rate Lag2 make sense? */ diff --git a/sc4pd/source/Lag3.cpp b/sc4pd/source/Lag3.cpp new file mode 100644 index 0000000..bedd625 --- /dev/null +++ b/sc4pd/source/Lag3.cpp @@ -0,0 +1,137 @@ +/* sc4pd + Lag3~, Lag3 + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: DKV Trio: Baraka + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Lag3~ -----------------------------*/ + +class Lag3_ar + :public flext_dsp +{ + FLEXT_HEADER(Lag3_ar,flext_dsp); + +public: + Lag3_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1, n_b1; + float m_y1a, m_y1b,m_y1c; + float m_lag; + bool changed; +}; + +FLEXT_LIB_DSP_V("Lag3~",Lag3_ar); + +Lag3_ar::Lag3_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"lagTime",m_set); + + AtomList Args(argc,argv); + + m_lag = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_b1 = 0.f; + m_y1a = 0.f; + m_y1b = 0.f; + m_y1c = 0.f; +} + +void Lag3_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + changed = false; + m_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); +} + +void Lag3_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1a = m_y1a; + float y1b = m_y1b; + float y1c = m_y1c; + float b1 = m_b1; + + if (changed) + { + float b1_slope = CALCSLOPE(m_b1, n_b1); + m_b1 = n_b1; + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + y1c = y1b + b1 * (y1c - y1b); + ZXP(nout) = y1c; + b1 += b1_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + y1c = y1b + b1 * (y1c - y1b); + ZXP(nout) = y1c; + } + } + m_y1a = zapgremlins(y1a); + m_y1b = zapgremlins(y1b); + m_y1b = zapgremlins(y1c); +} + +void Lag3_ar::m_set(float f) +{ + m_lag = f; + n_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); + changed = true; +} + +/* todo: does a control rate Lag3 make sense? */ diff --git a/sc4pd/source/LinExp.cpp b/sc4pd/source/LinExp.cpp new file mode 100644 index 0000000..6be19f3 --- /dev/null +++ b/sc4pd/source/LinExp.cpp @@ -0,0 +1,223 @@ +/* sc4pd + LinExp~, LinExp + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: The Ex & Tom Cora - And The Weathermen Shrug + Their Shoulders + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ LinExp~ -----------------------------*/ + +class LinExp_ar + :public flext_dsp +{ + FLEXT_HEADER(LinExp_ar,flext_dsp); + +public: + LinExp_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set_srclo(float f) + { + m_srclo = f; + m_reset(); + } + + void m_set_srchi(float f) + { + m_srchi = f; + m_reset(); + } + + void m_set_dstlo(float f) + { + m_dstlo = f; + m_reset(); + } + + void m_set_dsthi(float f) + { + m_dsthi = f; + m_reset(); + } + + void m_reset() + { + m_dstratio = m_dsthi/m_dstlo; + m_rsrcrange = 1. / (m_srchi - m_srclo); + m_rrminuslo = m_rsrcrange * -m_srclo; + } + +private: + FLEXT_CALLBACK_F(m_set_srclo); + FLEXT_CALLBACK_F(m_set_srchi); + FLEXT_CALLBACK_F(m_set_dstlo); + FLEXT_CALLBACK_F(m_set_dsthi); + float m_dstratio, m_rsrcrange, m_rrminuslo, m_dstlo; + float m_srclo, m_srchi, m_dsthi; //we will be able to reset the values +}; + +FLEXT_LIB_DSP_V("LinExp~",LinExp_ar); + +LinExp_ar::LinExp_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"srclo",m_set_srclo); + FLEXT_ADDMETHOD_(0,"srchi",m_set_srchi); + FLEXT_ADDMETHOD_(0,"dstlo",m_set_dstlo); + FLEXT_ADDMETHOD_(0,"dsthi",m_set_dsthi); + + AtomList Args(argc,argv); + + if (Args.Count() != 4) + post("4 arguments are required"); + else + { + m_srclo = sc_getfloatarg(Args,0); + m_srchi = sc_getfloatarg(Args,1); + m_dstlo = sc_getfloatarg(Args,2); + m_dsthi = sc_getfloatarg(Args,3); + + m_reset(); + AddOutSignal(); + } +} + +void LinExp_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float dstlo = m_dstlo; + float dstratio = m_dstratio; + float rsrcrange = m_rsrcrange; + float rrminuslo = m_rrminuslo; + + for (int i = 0; i!= n;++i) + { + ZXP(nout) = dstlo * pow(dstratio, ZXP(nin) * rsrcrange + rrminuslo); + } +} + +/* ------------------------ LinExp ------------------------------*/ + +class LinExp_kr + :public flext_base +{ + FLEXT_HEADER(LinExp_kr,flext_base); + +public: + LinExp_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + + void m_set_srclo(float f) + { + m_srclo = f; + m_reset(); + } + + void m_set_srchi(float f) + { + m_srchi = f; + m_reset(); + } + + void m_set_dstlo(float f) + { + m_dstlo = f; + m_reset(); + } + + void m_set_dsthi(float f) + { + m_dsthi = f; + m_reset(); + } + + void m_reset() + { + m_dstratio = m_dsthi/m_dstlo; + m_rsrcrange = 1. / (m_srchi - m_srclo); + m_rrminuslo = m_rsrcrange * -m_srclo; + } + +private: + FLEXT_CALLBACK_F(m_set_srclo); + FLEXT_CALLBACK_F(m_set_srchi); + FLEXT_CALLBACK_F(m_set_dstlo); + FLEXT_CALLBACK_F(m_set_dsthi); + float m_dstratio, m_rsrcrange, m_rrminuslo, m_dstlo; + float m_srclo, m_srchi, m_dsthi; //we will be able to reset the values + + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("LinExp",LinExp_kr); + +LinExp_kr::LinExp_kr(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"srclo",m_set_srclo); + FLEXT_ADDMETHOD_(0,"srchi",m_set_srchi); + FLEXT_ADDMETHOD_(0,"dstlo",m_set_dstlo); + FLEXT_ADDMETHOD_(0,"dsthi",m_set_dsthi); + + AtomList Args(argc,argv); + + if (Args.Count() != 4) + post("4 arguments are required"); + else + { + m_srclo = sc_getfloatarg(Args,0); + m_srchi = sc_getfloatarg(Args,1); + m_dstlo = sc_getfloatarg(Args,2); + m_dsthi = sc_getfloatarg(Args,3); + + m_reset(); + + AddInFloat(); + AddOutFloat(); + } +} + +void LinExp_kr::m_perform(float f) +{ + ToOutFloat(0,m_dstlo * pow(m_dstratio, f * m_rsrcrange + m_rrminuslo)); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 681c165..568d130 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,8 @@ void sc4pd_library_setup() " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" - " Integrator(~), Decay~, Decay2~, Lag~\n" + " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~)" + "DelayN~\n" ); //initialize objects @@ -198,6 +199,15 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Decay2_ar); FLEXT_DSP_SETUP(Lag_ar); + + FLEXT_DSP_SETUP(Lag2_ar); + + FLEXT_DSP_SETUP(Lag3_ar); + + FLEXT_DSP_SETUP(LinExp_ar); + FLEXT_SETUP(LinExp_kr); + + FLEXT_DSP_SETUP(DelayN_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index d26e09e..f1f90e2 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -34,6 +34,9 @@ */ +#ifndef _SC4PD_HPP +#define _SC$PD_HPP + #include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) @@ -51,8 +54,24 @@ #define CALCSLOPE(next,prev) ((next - prev) * 1/ Blocksize()) + +//#define SAMPLERATE (unit->mRate->mSampleRate) +#undef SAMPLERATE +#define SAMPLERATE Samplerate() + +//#define BUFLENGTH (unit->mBufLength) +#undef BUFLENGTH +#define BUFLENGTH Blocksize() + + + /* to make sure the behaviour is consistent: */ #undef ZXP #define ZXP(z) (*(z)++) + + + + +#endif diff --git a/sc4pd/source/template.cpp b/sc4pd/source/template.cpp index 0682c24..15d9f06 100644 --- a/sc4pd/source/template.cpp +++ b/sc4pd/source/template.cpp @@ -34,10 +34,4 @@ */ -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - +#include "sc4pd.hpp" -- cgit v1.2.1