aboutsummaryrefslogtreecommitdiff
path: root/sc4pd
diff options
context:
space:
mode:
authorTim Blechmann <timblech@users.sourceforge.net>2004-08-02 21:13:50 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:11:56 +0200
commit78431322cc77b9654fa4a2e2b1b42a9310cb9141 (patch)
treebaabc265e33cb6a62a200d227b0983b52b3ed882 /sc4pd
parent1bf32780fe1281eda6deb51f661f2f234a16fd1f (diff)
lag
svn path=/trunk/externals/tb/; revision=1905
Diffstat (limited to 'sc4pd')
-rwxr-xr-xsc4pd/make-files.txt2
-rw-r--r--sc4pd/pd/lag.pd17
-rw-r--r--sc4pd/source/Decay2.cpp1
-rw-r--r--sc4pd/source/Lag.cpp124
-rw-r--r--sc4pd/source/main.cpp4
-rw-r--r--sc4pd/source/sc4pd.hpp4
6 files changed, 147 insertions, 5 deletions
diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt
index 5a2aaf7..922e05c 100755
--- a/sc4pd/make-files.txt
+++ b/sc4pd/make-files.txt
@@ -9,4 +9,4 @@ 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 \ No newline at end of file
+ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ No newline at end of file
diff --git a/sc4pd/pd/lag.pd b/sc4pd/pd/lag.pd
new file mode 100644
index 0000000..206a07b
--- /dev/null
+++ b/sc4pd/pd/lag.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/source/Decay2.cpp b/sc4pd/source/Decay2.cpp
index 557f057..001eb31 100644
--- a/sc4pd/source/Decay2.cpp
+++ b/sc4pd/source/Decay2.cpp
@@ -146,6 +146,7 @@ void Decay2_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out)
(m_decayTime * Samplerate()));
m_b1b = m_attackTime == 0.f ? 0.f : exp(log001 /
(m_attackTime * Samplerate()));
+ changed = false;
}
/* todo: does it make sense to implement a message-based Decay2?
diff --git a/sc4pd/source/Lag.cpp b/sc4pd/source/Lag.cpp
new file mode 100644
index 0000000..81482a8
--- /dev/null
+++ b/sc4pd/source/Lag.cpp
@@ -0,0 +1,124 @@
+/* sc4pd
+ Lag~, Lag
+
+ 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: VA: Live from the Vision Festival
+
+*/
+
+#include "sc4pd.hpp"
+
+/* ------------------------ Lag~ -----------------------------*/
+
+class Lag_ar
+ :public flext_dsp
+{
+ FLEXT_HEADER(Lag_ar,flext_dsp);
+
+public:
+ Lag_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_y1;
+ float m_lag;
+ bool changed;
+};
+
+FLEXT_LIB_DSP_V("Lag~",Lag_ar);
+
+Lag_ar::Lag_ar(int argc,t_atom * argv)
+{
+ FLEXT_ADDMETHOD_(0,"lagTime",m_set);
+
+ AtomList Args(argc,argv);
+
+ m_lag = sc_getfloatarg(Args,0);
+
+ AddOutSignal();
+
+ m_y1 = 0.f;
+}
+
+void Lag_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 Lag_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nout = *out;
+ t_sample *nin = *in;
+
+ float y1 = m_y1;
+ 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 y0 = ZXP(nin);
+ ZXP(nout) = y1 = y0 + b1 * (y1 - y0);
+ b1 += b1_slope;
+ }
+ changed = false;
+ }
+ else
+ {
+ for (int i = 0; i!= n;++i)
+ {
+ float y0 = ZXP(nin);
+ ZXP(nout) = y1 = y0 + b1 * (y1 - y0);
+ }
+ }
+ m_y1 = zapgremlins(y1);
+}
+
+void Lag_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 Lag make sense? */
diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp
index 1f76f4c..681c165 100644
--- a/sc4pd/source/main.cpp
+++ b/sc4pd/source/main.cpp
@@ -58,7 +58,7 @@ void sc4pd_library_setup()
" ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), "
"sqrdif(~),\n"
" sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n"
- " Integrator(~), Decay~, Decay2~\n"
+ " Integrator(~), Decay~, Decay2~, Lag~\n"
);
//initialize objects
@@ -196,6 +196,8 @@ void sc4pd_library_setup()
FLEXT_DSP_SETUP(Decay_ar);
FLEXT_DSP_SETUP(Decay2_ar);
+
+ FLEXT_DSP_SETUP(Lag_ar);
}
FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup);
diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp
index 214b80c..d26e09e 100644
--- a/sc4pd/source/sc4pd.hpp
+++ b/sc4pd/source/sc4pd.hpp
@@ -48,9 +48,7 @@
// calculate a slope for control rate interpolation to audio rate.
//#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor)
#undef CALCSLOPE
-#define CALCSLOPE(next,prev) ((next - prev) * 1/Blocksize())
-
-
+#define CALCSLOPE(next,prev) ((next - prev) * 1/ Blocksize())
/* to make sure the behaviour is consistent: */