aboutsummaryrefslogtreecommitdiff
path: root/sc4pd/source
diff options
context:
space:
mode:
authorTim Blechmann <timblech@users.sourceforge.net>2004-09-09 08:45:18 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:11:57 +0200
commit8e34dec617b67c4b8d8928188d175f850d6a69c4 (patch)
tree8a991c190bba8ee387e33f99830cbc88bb3dd8b0 /sc4pd/source
parent1a1d31d95b241dff59a11311b70be603742eeb32 (diff)
lfdnoises and interpolating vector/scalar operations
svn path=/trunk/externals/tb/; revision=2021
Diffstat (limited to 'sc4pd/source')
-rw-r--r--sc4pd/source/LFDNoise0.cpp166
-rw-r--r--sc4pd/source/LFDNoise1.cpp172
-rw-r--r--sc4pd/source/LFDNoise2.cpp188
-rw-r--r--sc4pd/source/main.cpp19
-rw-r--r--sc4pd/source/sc*.cpp113
-rw-r--r--sc4pd/source/sc+.cpp113
-rw-r--r--sc4pd/source/sc-.cpp142
-rw-r--r--sc4pd/source/sc4pd.hpp2
-rw-r--r--sc4pd/source/scdiv.cpp142
-rw-r--r--sc4pd/source/support.cpp24
-rw-r--r--sc4pd/source/support.hpp26
11 files changed, 1073 insertions, 34 deletions
diff --git a/sc4pd/source/LFDNoise0.cpp b/sc4pd/source/LFDNoise0.cpp
new file mode 100644
index 0000000..316b5a4
--- /dev/null
+++ b/sc4pd/source/LFDNoise0.cpp
@@ -0,0 +1,166 @@
+/* sc4pd
+ LFDNoise0~
+
+ 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
+
+ *
+ * DynNoiseUGens.cpp
+ * xSC3plugins
+ *
+ * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004.
+ * Copyright (c) 2004 HfbK. All rights reserved.
+ *
+ *
+
+ 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: Phil Minton & Veryan Weston: Ways Past
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ LFDNoise0~ -------------------------------*/
+
+class LFDNoise0_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(LFDNoise0_ar,sc4pd_dsp);
+
+public:
+ LFDNoise0_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_seed(int i)
+ {
+ rgen.init(i);
+ }
+
+ void m_set(float f)
+ {
+ m_freq = f;
+ }
+
+private:
+ RGen rgen;
+ float m_freq;
+ float m_level;
+ float m_phase;
+ float m_smpdur;
+
+ bool m_ar;
+
+ FLEXT_CALLBACK_I(m_seed);
+ FLEXT_CALLBACK_F(m_set);
+};
+
+FLEXT_LIB_DSP_V("LFDNoise0~",LFDNoise0_ar);
+
+LFDNoise0_ar::LFDNoise0_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD_(0,"seed",m_seed);
+ FLEXT_ADDMETHOD_(0,"set",m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_freq = sc_getfloatarg(Args,0);
+
+ m_phase=0.f;
+ m_level=0.f;
+
+ rgen.init(timeseed());
+
+ m_ar = sc_ar(Args);
+
+ if (m_ar)
+ AddInSignal("freqency");
+ else
+ AddInSignal("\"set\" frequency");
+ AddOutSignal();
+}
+
+void LFDNoise0_ar::m_dsp(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ m_smpdur = sc_sampledur();
+}
+
+
+void LFDNoise0_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nout = *out;
+
+ float level = m_level;
+ float phase = m_phase;
+
+ RGET;
+
+ if (m_ar)
+ {
+ t_sample *nin = *in;
+ float smpdur = m_smpdur;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= ZXP(nin) * smpdur;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ level = frand2(s1,s2,s3);
+ }
+ ZXP(nout) = level;
+ }
+ }
+ else
+ {
+ float dphase = m_smpdur * m_freq;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= dphase;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ level = frand2(s1,s2,s3);
+ }
+ ZXP(nout) = level;
+ }
+ }
+
+
+ m_level = level;
+ m_phase = phase;
+
+ RPUT;
+}
+
+
diff --git a/sc4pd/source/LFDNoise1.cpp b/sc4pd/source/LFDNoise1.cpp
new file mode 100644
index 0000000..8336b80
--- /dev/null
+++ b/sc4pd/source/LFDNoise1.cpp
@@ -0,0 +1,172 @@
+/* sc4pd
+ LFDNoise1~
+
+ 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
+
+ *
+ * DynNoiseUGens.cpp
+ * xSC3plugins
+ *
+ * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004.
+ * Copyright (c) 2004 HfbK. All rights reserved.
+ *
+ *
+
+ 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: Phil Minton & Veryan Weston: Ways Past
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ LFDNoise1~ -------------------------------*/
+
+class LFDNoise1_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(LFDNoise1_ar,sc4pd_dsp);
+
+public:
+ LFDNoise1_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_seed(int i)
+ {
+ rgen.init(i);
+ }
+
+ void m_set(float f)
+ {
+ m_freq = f;
+ }
+
+private:
+ RGen rgen;
+ float m_freq;
+ float m_prevlevel;
+ float m_nextlevel;
+ float m_phase;
+ float m_smpdur;
+
+ bool m_ar;
+
+ FLEXT_CALLBACK_I(m_seed);
+ FLEXT_CALLBACK_F(m_set);
+};
+
+FLEXT_LIB_DSP_V("LFDNoise1~",LFDNoise1_ar);
+
+LFDNoise1_ar::LFDNoise1_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD_(0,"seed",m_seed);
+ FLEXT_ADDMETHOD_(0,"set",m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_freq = sc_getfloatarg(Args,0);
+
+ rgen.init(timeseed());
+
+ m_phase=0.f;
+ m_prevlevel=0.f;
+ m_nextlevel = rgen.frand2();
+
+
+ m_ar = sc_ar(Args);
+
+ if (m_ar)
+ AddInSignal("freqency");
+ else
+ AddInSignal("\"set\" frequency");
+ AddOutSignal();
+}
+
+void LFDNoise1_ar::m_dsp(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ m_smpdur = sc_sampledur();
+}
+
+
+void LFDNoise1_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nout = *out;
+
+ float prevLevel = m_prevlevel;
+ float nextLevel = m_nextlevel;
+ float phase = m_phase;
+
+ RGET;
+
+ if (m_ar)
+ {
+ t_sample *nin = *in;
+ float smpdur = m_smpdur;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= ZXP(nin) * smpdur;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ prevLevel = nextLevel;
+ nextLevel = frand2(s1,s2,s3);
+ }
+ ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) );
+ }
+ }
+ else
+ {
+ float dphase = m_smpdur * m_freq;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= dphase;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ prevLevel = nextLevel;
+ nextLevel = frand2(s1,s2,s3);
+ }
+ ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) );
+ }
+ }
+
+ m_prevlevel = prevLevel;
+ m_nextlevel = nextLevel;
+ m_phase = phase;
+
+ RPUT;
+}
+
+
diff --git a/sc4pd/source/LFDNoise2.cpp b/sc4pd/source/LFDNoise2.cpp
new file mode 100644
index 0000000..136b1c9
--- /dev/null
+++ b/sc4pd/source/LFDNoise2.cpp
@@ -0,0 +1,188 @@
+/* sc4pd
+ LFDNoise2~
+
+ 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
+
+ *
+ * DynNoiseUGens.cpp
+ * xSC3plugins
+ *
+ * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004.
+ * Copyright (c) 2004 HfbK. All rights reserved.
+ *
+ *
+
+ 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: Phil Minton & Veryan Weston: Ways Past
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ LFDNoise2~ -------------------------------*/
+
+class LFDNoise2_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(LFDNoise2_ar,sc4pd_dsp);
+
+public:
+ LFDNoise2_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_seed(int i)
+ {
+ rgen.init(i);
+ }
+
+ void m_set(float f)
+ {
+ m_freq = f;
+ }
+
+private:
+ RGen rgen;
+ float m_freq;
+ float m_levela, m_levelb, m_levelc, m_leveld;
+ float m_phase;
+ float m_smpdur;
+
+ bool m_ar;
+
+ FLEXT_CALLBACK_I(m_seed);
+ FLEXT_CALLBACK_F(m_set);
+};
+
+FLEXT_LIB_DSP_V("LFDNoise2~",LFDNoise2_ar);
+
+LFDNoise2_ar::LFDNoise2_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD_(0,"seed",m_seed);
+ FLEXT_ADDMETHOD_(0,"set",m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_freq = sc_getfloatarg(Args,0);
+
+ rgen.init(timeseed());
+
+ RGET;
+
+ m_phase=0.f;
+ m_levela = frand2(s1, s2, s3) * 0.8f;// limits max interpol. overshoot to 1.
+ m_levelb = frand2(s1, s2, s3) * 0.8f;
+ m_levelc = frand2(s1, s2, s3) * 0.8f;
+ m_leveld = frand2(s1, s2, s3) * 0.8f;
+
+ RPUT;
+
+ m_ar = sc_ar(Args);
+
+ if (m_ar)
+ AddInSignal("freqency");
+ else
+ AddInSignal("\"set\" frequency");
+ AddOutSignal();
+}
+
+void LFDNoise2_ar::m_dsp(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ m_smpdur = sc_sampledur();
+}
+
+
+void LFDNoise2_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nout = *out;
+
+ float a = m_levela;
+ float b = m_levelb;
+ float c = m_levelc;
+ float d = m_leveld;
+
+ float phase = m_phase;
+
+ RGET;
+
+ if (m_ar)
+ {
+ t_sample *nin = *in;
+ float smpdur = m_smpdur;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= ZXP(nin) * smpdur;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ a = b;
+ b = c;
+ c = d;
+ d = frand2(s1,s2,s3) * 0.8f; // limits max interpol. overshoot to 1.
+
+ }
+ ZXP(nout) = cubicinterp(1.f - phase, a, b, c, d);
+ }
+ }
+ else
+ {
+ float dphase = m_smpdur * m_freq;
+ for (int i = 0; i!= n; ++i)
+ {
+ phase -= dphase;
+ if (phase <= 0)
+ {
+ phase = sc_wrap(phase, 0.f, 1.f);
+ a = b;
+ b = c;
+ c = d;
+ d = frand2(s1,s2,s3) * 0.8f; // limits max interpol. overshoot to 1.
+ }
+ ZXP(nout) = cubicinterp(1.f - phase, a, b, c, d);
+ }
+ }
+
+
+ m_phase = phase;
+
+ m_levela = a;
+ m_levelb = b;
+ m_levelc = c;
+ m_leveld = d;
+
+ RPUT;
+}
+
+
diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp
index 8216421..13fbc90 100644
--- a/sc4pd/source/main.cpp
+++ b/sc4pd/source/main.cpp
@@ -66,8 +66,9 @@ void sc4pd_library_setup()
"TwoPole~, \n"
" TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, "
"BRF~,\n"
- " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~)"
- "\n"
+ " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~), "
+ "LFDNoise0~,\n"
+ " LFDNoise1~, LFDNoise2~, sc+~, sc-~, sc*~, sc/~\n"
);
//initialize objects
@@ -281,6 +282,20 @@ void sc4pd_library_setup()
FLEXT_DSP_SETUP(BPZ2_ar);
FLEXT_SETUP(BPZ2_kr);
+
+ FLEXT_DSP_SETUP(LFDNoise0_ar);
+
+ FLEXT_DSP_SETUP(LFDNoise1_ar);
+
+ FLEXT_DSP_SETUP(LFDNoise2_ar);
+
+ FLEXT_DSP_SETUP(scadd_ar);
+
+ FLEXT_DSP_SETUP(scsub_ar);
+
+ FLEXT_DSP_SETUP(scmul_ar);
+
+ FLEXT_DSP_SETUP(scdiv_ar);
}
FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup);
diff --git a/sc4pd/source/sc*.cpp b/sc4pd/source/sc*.cpp
new file mode 100644
index 0000000..55ac074
--- /dev/null
+++ b/sc4pd/source/sc*.cpp
@@ -0,0 +1,113 @@
+/* sc4pd
+ sc*~
+
+ 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: Phil Minton & Veryan Weston: Ways
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ sc*~ -------------------------------*/
+
+class scmul_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(scmul_ar,sc4pd_dsp);
+
+public:
+ scmul_ar(int argc, t_atom *argv);
+
+protected:
+ virtual void m_signal(int n, t_sample *const *in, t_sample *const *out);
+
+ void m_set(float f)
+ {
+ m_nextfactor = f;
+ changed = true;
+ }
+
+ float m_nextfactor, m_factor;
+ bool changed;
+
+private:
+ FLEXT_CALLBACK_1(m_set,float);
+};
+
+FLEXT_LIB_DSP_V("sc*~",scmul_ar);
+
+scmul_ar::scmul_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD(1,m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_factor = sc_getfloatarg(Args,0);
+
+ AddInSignal("signal");
+ AddInFloat("scalar");
+ AddOutSignal();
+
+ changed = false;
+}
+
+void scmul_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nin = *in;
+ t_sample *nout = *out;
+
+ if (changed)
+ {
+ float xb = m_nextfactor;
+ float slope = CALCSLOPE(xb, m_factor);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) * xb;
+ xb += slope;
+ }
+ m_factor = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_factor;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) * xb;
+ }
+ }
+}
+
+
diff --git a/sc4pd/source/sc+.cpp b/sc4pd/source/sc+.cpp
new file mode 100644
index 0000000..e1a7e26
--- /dev/null
+++ b/sc4pd/source/sc+.cpp
@@ -0,0 +1,113 @@
+/* sc4pd
+ sc+~
+
+ 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: Phil Minton & Veryan Weston: Ways Past
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ sc+~ -------------------------------*/
+
+class scadd_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(scadd_ar,sc4pd_dsp);
+
+public:
+ scadd_ar(int argc, t_atom *argv);
+
+protected:
+ virtual void m_signal(int n, t_sample *const *in, t_sample *const *out);
+
+ void m_set(float f)
+ {
+ m_nextsummand = f;
+ changed = true;
+ }
+
+ float m_nextsummand, m_summand;
+ bool changed;
+
+private:
+ FLEXT_CALLBACK_1(m_set,float);
+};
+
+FLEXT_LIB_DSP_V("sc+~",scadd_ar);
+
+scadd_ar::scadd_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD(1,m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_summand = sc_getfloatarg(Args,0);
+
+ AddInSignal("signal");
+ AddInFloat("scalar");
+ AddOutSignal();
+
+ changed = false;
+}
+
+void scadd_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nin = *in;
+ t_sample *nout = *out;
+
+ if (changed)
+ {
+ float xb = m_nextsummand;
+ float slope = CALCSLOPE(xb, m_summand);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) + xb;
+ xb += slope;
+ }
+ m_summand = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_summand;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) + xb;
+ }
+ }
+}
+
+
diff --git a/sc4pd/source/sc-.cpp b/sc4pd/source/sc-.cpp
new file mode 100644
index 0000000..0dfd2ce
--- /dev/null
+++ b/sc4pd/source/sc-.cpp
@@ -0,0 +1,142 @@
+/* sc4pd
+ sc-~
+
+ 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: Phil Minton & Veryan Weston: Ways
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ sc-~ -------------------------------*/
+
+class scsub_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(scsub_ar,sc4pd_dsp);
+
+public:
+ scsub_ar(int argc, t_atom *argv);
+
+protected:
+ virtual void m_signal(int n, t_sample *const *in, t_sample *const *out);
+
+ void m_set(float f)
+ {
+ m_nextsubtrahend = f;
+ changed = true;
+ }
+
+ float m_nextsubtrahend, m_subtrahend;
+ bool changed;
+ bool invert;
+
+private:
+ FLEXT_CALLBACK_1(m_set,float);
+};
+
+FLEXT_LIB_DSP_V("sc-~",scsub_ar);
+
+scsub_ar::scsub_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD(1,m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_subtrahend = sc_getfloatarg(Args,0);
+
+ invert = sc_inv(Args);
+
+ AddInSignal("signal");
+ AddInFloat("scalar");
+ AddOutSignal();
+
+ changed = false;
+}
+
+void scsub_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nin = *in;
+ t_sample *nout = *out;
+
+ if (invert)
+ {
+ if (changed)
+ {
+ float xb = m_nextsubtrahend;
+ float slope = CALCSLOPE(xb, m_subtrahend);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = xb - ZXP(nin);
+ xb += slope;
+ }
+ m_subtrahend = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_subtrahend;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = xb - ZXP(nin);
+ }
+ }
+ }
+ else
+ {
+ if (changed)
+ {
+ float xb = m_nextsubtrahend;
+ float slope = CALCSLOPE(xb, m_subtrahend);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) - xb;
+ xb += slope;
+ }
+ m_subtrahend = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_subtrahend;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) - xb;
+ }
+ }
+ }
+}
+
diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp
index f80b177..13d82c0 100644
--- a/sc4pd/source/sc4pd.hpp
+++ b/sc4pd/source/sc4pd.hpp
@@ -124,5 +124,5 @@ class sc4pd_dsp
};
-#define _SC$PD_HPP
+#define _SC4PD_HPP
#endif
diff --git a/sc4pd/source/scdiv.cpp b/sc4pd/source/scdiv.cpp
new file mode 100644
index 0000000..045d1b4
--- /dev/null
+++ b/sc4pd/source/scdiv.cpp
@@ -0,0 +1,142 @@
+/* sc4pd
+ sc/~
+
+ 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: Phil Minton & Veryan Weston: Ways
+
+*/
+
+#include "sc4pd.hpp"
+
+
+/* ------------------------ sc/~ -------------------------------*/
+
+class scdiv_ar:
+ public sc4pd_dsp
+{
+ FLEXT_HEADER(scdiv_ar,sc4pd_dsp);
+
+public:
+ scdiv_ar(int argc, t_atom *argv);
+
+protected:
+ virtual void m_signal(int n, t_sample *const *in, t_sample *const *out);
+
+ void m_set(float f)
+ {
+ m_nextdivisor = f;
+ changed = true;
+ }
+
+ float m_nextdivisor, m_divisor;
+ bool changed;
+ bool invert;
+
+private:
+ FLEXT_CALLBACK_1(m_set,float);
+};
+
+FLEXT_LIB_DSP_V("sc/~",scdiv_ar);
+
+scdiv_ar::scdiv_ar(int argc, t_atom *argv)
+{
+ FLEXT_ADDMETHOD(1,m_set);
+
+ //parse arguments
+ AtomList Args(argc,argv);
+
+ m_divisor = sc_getfloatarg(Args,0);
+
+ invert = sc_inv(Args);
+
+ AddInSignal("signal");
+ AddInFloat("scalar");
+ AddOutSignal();
+
+ changed = false;
+}
+
+void scdiv_ar::m_signal(int n, t_sample *const *in,
+ t_sample *const *out)
+{
+ t_sample *nin = *in;
+ t_sample *nout = *out;
+
+ if (invert)
+ {
+ if (changed)
+ {
+ float xb = m_nextdivisor;
+ float slope = CALCSLOPE(xb, m_divisor);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = xb / ZXP(nin);
+ xb += slope;
+ }
+ m_divisor = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_divisor;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = xb / ZXP(nin);
+ }
+ }
+ }
+ else
+ {
+ if (changed)
+ {
+ float xb = m_nextdivisor;
+ float slope = CALCSLOPE(xb, m_divisor);
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) / xb;
+ xb += slope;
+ }
+ m_divisor = xb;
+ changed = false;
+ }
+ else
+ {
+ float xb = m_divisor;
+
+ for (int i = 0; i!=n; ++i)
+ {
+ ZXP(nout) = ZXP(nin) / xb;
+ }
+ }
+ }
+}
+
diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp
index fd87c86..077ea45 100644
--- a/sc4pd/source/support.cpp
+++ b/sc4pd/source/support.cpp
@@ -77,16 +77,20 @@ bool sc_ar(flext::AtomList a)
return false;
}
-// macros to put rgen state in registers
-#define RGET \
- uint32 s1 = rgen.s1; \
- uint32 s2 = rgen.s2; \
- uint32 s3 = rgen.s3;
-
-#define RPUT \
- rgen.s1 = s1; \
- rgen.s2 = s2; \
- rgen.s3 = s3;
+bool sc_inv(flext::AtomList a)
+{
+ for (int i = 0; i!=a.Count();++i)
+ {
+ if ( flext::IsSymbol(a[i]) )
+ {
+ const char * teststring;
+ teststring = flext::GetString(a[i]);
+ if((strcmp(teststring,"inv"))==0)
+ return true;
+ }
+ }
+ return false;
+}
int32 timeseed()
{
diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp
index 3972c83..a9258e8 100644
--- a/sc4pd/source/support.hpp
+++ b/sc4pd/source/support.hpp
@@ -50,6 +50,7 @@
bool sc_add (flext::AtomList a);
float sc_getfloatarg (flext::AtomList a,int i);
bool sc_ar(flext::AtomList a);
+bool sc_inv(flext::AtomList a);
/* for rngs */
@@ -94,7 +95,7 @@ inline float CalcFeedback(float delaytime, float decaytime)
}
-/* this is copied from thomas grill's xsample:
+/* this is adapted from thomas grill's xsample:
xsample - extended sample objects for Max/MSP and pd (pure data)
Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net)
@@ -102,34 +103,17 @@ For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
-#define F float
-#define D double
-#define I int
-#define L long
-#define C char
-#define V void
-#define BL bool
-#define S t_sample
-
#define SETSIGFUN(VAR,FUN) v_##VAR = FUN
-#define DEFSIGFUN(NAME) V NAME(I n,S *const *in,S *const *out)
+#define DEFSIGFUN(NAME) void NAME(int n,t_sample *const *in,t_sample *const *out)
#define DEFSIGCALL(NAME) \
- inline V NAME(I n,S *const *in,S *const *out) \
+ inline void NAME(int n,t_sample *const *in,t_sample *const *out) \
{ (this->*v_##NAME)(n,in,out); } \
- V (thisType::*v_##NAME)(I n,S *const *invecs,S *const *outvecs)
+ void (thisType::*v_##NAME)(int n,t_sample *const *invecs,t_sample *const *outvecs)
#define SIGFUN(FUN) &thisType::FUN
-#undef F
-#undef D
-#undef I
-#undef L
-#undef C
-#undef V
-#undef BL
-#undef S
#endif