From ea10413727c241467ab729cee102dd68534f4db9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 22:57:36 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1915 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 2 +- sc4pd/makefile.pd-linux | 2 +- sc4pd/pd/fos.pd | 45 ++++++++ sc4pd/pd/sos.pd | 38 +++++++ sc4pd/pd/twozero.pd | 15 +++ sc4pd/source/DelayUnit.cpp | 2 +- sc4pd/source/DelayUnit.hpp | 2 +- sc4pd/source/FOS.cpp | 258 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/SOS.cpp | 258 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/TwoZero.cpp | 175 ++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 13 ++- 12 files changed, 804 insertions(+), 8 deletions(-) create mode 100644 sc4pd/pd/fos.pd create mode 100644 sc4pd/pd/sos.pd create mode 100644 sc4pd/pd/twozero.pd create mode 100644 sc4pd/source/FOS.cpp create mode 100644 sc4pd/source/SOS.cpp create mode 100644 sc4pd/source/TwoZero.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 1e95392..9b46ed4 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 a9b154f..d6e04d5 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -13,4 +13,4 @@ SRCS= \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ - TwoPole.cpp + TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux index 99d62ef..f1deedb 100644 --- a/sc4pd/makefile.pd-linux +++ b/sc4pd/makefile.pd-linux @@ -24,7 +24,7 @@ LIBS=m ifdef FLEXT_SHARED CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS LDFLAGS+=-Bdynamic -LINKFLEXT=-lflext +LINKFLEXT=-lflext_d else LINKFLEXT=$(FLEXTLIB) endif diff --git a/sc4pd/pd/fos.pd b/sc4pd/pd/fos.pd new file mode 100644 index 0000000..f03f45b --- /dev/null +++ b/sc4pd/pd/fos.pd @@ -0,0 +1,45 @@ +#N canvas 0 0 539 300 10; +#X obj 12 159 dac~; +#X floatatom 112 20 5 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 37 269 dac~; +#X obj 95 174 Dust~ 444; +#X obj 18 86 FOS~ 0.3 0.3 0.3; +#X msg 89 60 a0 \$1; +#X floatatom 161 20 5 0 0 0 - - -; +#X msg 138 60 a1 \$1; +#X floatatom 215 20 5 0 0 0 - - -; +#X msg 192 60 b1 \$1; +#X obj 46 229 FOS~ 0.3 0.3 0.3 ar; +#X floatatom 374 26 5 0 0 0 - - -; +#X msg 351 66 a0 \$1; +#X floatatom 423 26 5 0 0 0 - - -; +#X msg 400 66 a1 \$1; +#X floatatom 477 26 5 0 0 0 - - -; +#X msg 454 66 b1 \$1; +#X obj 280 92 FOS 0.3 0.3 0.3; +#X floatatom 282 129 5 0 0 0 - - -; +#X floatatom 283 36 5 0 0 0 - - -; +#X connect 1 0 6 0; +#X connect 2 0 5 0; +#X connect 4 0 11 1; +#X connect 4 0 11 0; +#X connect 4 0 11 2; +#X connect 4 0 11 3; +#X connect 5 0 0 0; +#X connect 5 0 0 1; +#X connect 6 0 5 0; +#X connect 7 0 8 0; +#X connect 8 0 5 0; +#X connect 9 0 10 0; +#X connect 10 0 5 0; +#X connect 11 0 3 0; +#X connect 11 0 3 1; +#X connect 12 0 13 0; +#X connect 13 0 18 0; +#X connect 14 0 15 0; +#X connect 15 0 18 0; +#X connect 16 0 17 0; +#X connect 17 0 18 0; +#X connect 18 0 19 0; +#X connect 20 0 18 0; diff --git a/sc4pd/pd/sos.pd b/sc4pd/pd/sos.pd new file mode 100644 index 0000000..b09be69 --- /dev/null +++ b/sc4pd/pd/sos.pd @@ -0,0 +1,38 @@ +#N canvas 0 0 539 300 10; +#X obj 12 159 dac~; +#X floatatom 112 20 5 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 90 262 dac~; +#X obj 206 145 Dust~ 444; +#X msg 89 60 a0 \$1; +#X floatatom 161 20 5 0 0 0 - - -; +#X msg 138 60 a1 \$1; +#X floatatom 262 20 5 0 0 0 - - -; +#X msg 239 60 b1 \$1; +#X obj 18 87 SOS~ 0.3 0.3 0.3 0.3 0.3; +#X floatatom 212 20 5 0 0 0 - - -; +#X floatatom 313 20 5 0 0 0 - - -; +#X msg 189 60 a2 \$1; +#X msg 290 60 b2 \$1; +#X obj 85 208 SOS~ 0.3 0.3 0.3 0.3 0.3 ar; +#X connect 1 0 5 0; +#X connect 2 0 10 0; +#X connect 4 0 15 0; +#X connect 4 0 15 1; +#X connect 4 0 15 2; +#X connect 4 0 15 3; +#X connect 4 0 15 4; +#X connect 4 0 15 5; +#X connect 5 0 10 0; +#X connect 6 0 7 0; +#X connect 7 0 10 0; +#X connect 8 0 9 0; +#X connect 9 0 10 0; +#X connect 10 0 0 0; +#X connect 10 0 0 1; +#X connect 11 0 13 0; +#X connect 12 0 14 0; +#X connect 13 0 10 0; +#X connect 14 0 10 0; +#X connect 15 0 3 1; +#X connect 15 0 3 0; diff --git a/sc4pd/pd/twozero.pd b/sc4pd/pd/twozero.pd new file mode 100644 index 0000000..3cd2c63 --- /dev/null +++ b/sc4pd/pd/twozero.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 kradius \$1; +#X obj 130 160 TwoZero~ 440 0.5; +#X connect 1 0 3 0; +#X connect 2 0 6 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp index bbd5a2d..bd57f7d 100644 --- a/sc4pd/source/DelayUnit.cpp +++ b/sc4pd/source/DelayUnit.cpp @@ -35,7 +35,7 @@ */ -// #include "sc4pd.hpp" +#include "sc4pd.hpp" #include "DelayUnit.hpp" void DelayUnit_ar::DelayUnit_AllocDelayLine() diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp index e9db066..a5951e5 100644 --- a/sc4pd/source/DelayUnit.hpp +++ b/sc4pd/source/DelayUnit.hpp @@ -35,7 +35,7 @@ */ -#include "sc4pd.hpp" +//#include "sc4pd.hpp" class DelayUnit_ar : public sc4pd_dsp diff --git a/sc4pd/source/FOS.cpp b/sc4pd/source/FOS.cpp new file mode 100644 index 0000000..6bd3c26 --- /dev/null +++ b/sc4pd/source/FOS.cpp @@ -0,0 +1,258 @@ +/* sc4pd + FOS, FOS~ + + 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: Susie Ibarra & Assif Tsahar: Home Cookin' + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ FOS~ -------------------------------*/ + +class FOS_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(FOS_ar,sc4pd_dsp); + +public: + FOS_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + void m_set_a0(float f) + { + next_a0=f; + } + + void m_set_a1(float f) + { + next_a1=f; + } + + void m_set_b1(float f) + { + next_b1=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + float next_a0, next_a1, next_b1; + float m_y1, m_a0, m_a1, m_b1; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("FOS~",FOS_ar); + +FOS_ar::FOS_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()<3) + { + post("needs at least 3 arguments"); + return; + } + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_b1 = sc_getfloatarg(Args,2); + + if(sc_ar(Args)) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + } + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_b1 = 0.f; +} + +void FOS_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + float *a0 = *(in+1); + float *a1 = *(in+2); + float *b1 = *(in+3); + + float y1 = m_y1; + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin) + ZXP(b1) * y1; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1; + y1 = y0; + } + m_y1 = zapgremlins(y1); +} + + +void FOS_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y1 = m_y1; + float a0 = m_a0; + float a1 = m_a1; + float b1 = m_b1; + float a0_slope = CALCSLOPE(next_a0, a0); + float a1_slope = CALCSLOPE(next_a1, a1); + float b1_slope = CALCSLOPE(next_b1, b1); + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin) + b1 * y1; + ZXP(nout) = a0 * y0 + a1 * y1; + y1 = y0; + + a0 += a0_slope; + a1 += a1_slope; + b1 += b1_slope; + } +} + +/* ------------------------ FOS ---------------------------------*/ + + +class FOS_kr: + public flext_base +{ + FLEXT_HEADER(FOS_kr,flext_base); + +public: + FOS_kr(int argc, t_atom *argv); + +protected: + void m_perform(float f); + + void m_set_a0(float f) + { + m_a0=f; + } + + void m_set_a1(float f) + { + m_a1=f; + } + + void m_set_b1(float f) + { + m_b1=f; + } + + +private: + float m_y1, m_a0, m_a1, m_b1; + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK_F(m_perform); +}; + + +FLEXT_LIB_V("FOS",FOS_kr); + +FOS_kr::FOS_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()!=3) + { + post("needs 3 arguments"); + return; + } + + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_b1 = sc_getfloatarg(Args,2); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_b1 = 0.f; +} + +void FOS_kr::m_perform(float f) +{ + m_y1 = m_a0 * (f + m_b1 * m_y1) + m_a1 * m_y1; + ToOutFloat(0,m_y1); +} diff --git a/sc4pd/source/SOS.cpp b/sc4pd/source/SOS.cpp new file mode 100644 index 0000000..996833a --- /dev/null +++ b/sc4pd/source/SOS.cpp @@ -0,0 +1,258 @@ +/* sc4pd + SOS~ + + 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: Susie Ibarra & Assif Tsahar: Home Cookin' + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ SOS~ -------------------------------*/ + +class SOS_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(SOS_ar,sc4pd_dsp); + +public: + SOS_ar(int argc, t_atom *argv); + +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) + { + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + mFilterSlope = sc_filterslope(); + } + + void m_set_a0(float f) + { + next_a0=f; + } + + void m_set_a1(float f) + { + next_a1=f; + } + + void m_set_a2(float f) + { + next_a2=f; + } + + void m_set_b1(float f) + { + next_b1=f; + } + + void m_set_b2(float f) + { + next_b2=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + float next_a0, next_a1, next_a2, next_b1, next_b2; + float m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2; + + float mFilterSlope; + int mFilterLoops, mFilterRemain; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_a2); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK_F(m_set_b2); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("SOS~",SOS_ar); + +SOS_ar::SOS_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"a2",m_set_a2); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + FLEXT_ADDMETHOD_(0,"b2",m_set_b2); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()<5) + { + post("needs at least 5 arguments"); + return; + } + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_a2 = sc_getfloatarg(Args,2); + m_b1 = sc_getfloatarg(Args,3); + m_b2 = sc_getfloatarg(Args,4); + + if(sc_ar(Args)) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + } + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_a2 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; +} + +void SOS_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + float *a0 = *(in+1); + float *a1 = *(in+2); + float *a2 = *(in+3); + float *b1 = *(in+4); + float *b2 = *(in+5); + + float y0; + float y1 = m_y1; + float y2 = m_y2; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + ZXP(b1) * y1 + ZXP(b2) * y2; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2; + + y2 = ZXP(nin) + ZXP(b1) * y0 + ZXP(b2) * y1; + ZXP(nout) = ZXP(a0) * y2 + ZXP(a1) * y0 + ZXP(a2) * y1; + + y1 = ZXP(nin) + ZXP(b1) * y2 + ZXP(b2) * y0; + ZXP(nout) = ZXP(a0) * y1 + ZXP(a1) * y2 + ZXP(a2) * y0; + } + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + ZXP(b1) * y1 + ZXP(b2) * y2; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2; + y2 = y1; + y1 = y0; + } + + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); + +} + + +void SOS_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float a1 = m_a1; + float a2 = m_a2; + float b1 = m_b1; + float b2 = m_b2; + float a0_slope = (next_a0 - a0) * mFilterSlope; + float a1_slope = (next_a1 - a1) * mFilterSlope; + float a2_slope = (next_a2 - a2) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * y0 + a1 * y1 + a2 * y2; + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * y2 + a1 * y0 + a2 * y1; + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * y1 + a1 * y2 + a2 * y0; + + a0 += a0_slope; + a1 += a1_slope; + a2 += a2_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * y0 + a1 * y1 + a2 * y2; + y2 = y1; + y1 = y0; + } + + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no kr SOS */ diff --git a/sc4pd/source/TwoZero.cpp b/sc4pd/source/TwoZero.cpp new file mode 100644 index 0000000..85a7633 --- /dev/null +++ b/sc4pd/source/TwoZero.cpp @@ -0,0 +1,175 @@ +/* sc4pd + TwoZero~ + + 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: Insight + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ TwoZero~ -------------------------------*/ + +class TwoZero_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(TwoZero_ar,sc4pd_dsp); + +public: + TwoZero_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) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_radius(float f) + { + m_reson=f; + changed = true; + } + + +private: + float m_b1, m_b2, m_x1, m_x2, m_freq, m_reson; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_radius); +}; + +FLEXT_LIB_DSP_V("TwoZero~",TwoZero_ar); + +TwoZero_ar::TwoZero_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"kradius",m_set_radius); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_reson = sc_getfloatarg(Args,1); + changed = false; + + AddOutSignal(); + + m_b1 = 0.f; + m_b2 = 0.f; + m_x1 = 0.f; + m_x2 = 0.f; +} + +void TwoZero_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + if (changed) + { + float b1 = m_b1; + float b2 = m_b2; + float b1_next = -2.f * m_reson * cos(m_freq * mRadiansPerSample); + float b2_next = (m_reson * m_reson); + float b1_slope = (b1_next - b1) * mFilterSlope; + float b2_slope = (b2_next - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = ZXP(nin); + ZXP(nout) = x2 + b1 * x0 + b2 * x1; + x1 = ZXP(nin); + ZXP(nout) = x1 + b1 * x2 + b2 * x0; + + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = x1; + x1 = x0; + } + + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + float b1 = m_b1; + float b2 = m_b2; + + for (int i = 0; i!= mFilterLoops;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = ZXP(nin); + ZXP(nout) = x2 + b1 * x0 + b2 * x1; + x1 = ZXP(nin); + ZXP(nout) = x1 + b1 * x2 + b2 * x0; + } + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = x1; + x1 = x0; + } + } + m_x1 = x1; + m_x2 = x2; +} + +/* no control rate twozero filter */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 2cac635..3430ee4 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,9 +62,9 @@ void sc4pd_library_setup() "DelayN~,\n" " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " "AllpassL~,\n" - " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~)" - "TwoPole~" - + " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~), " + "TwoPole~, \n" + " TwoZero~, FOS(~), SOS~" "\n" ); @@ -242,6 +242,13 @@ void sc4pd_library_setup() FLEXT_SETUP(OneZero_kr); FLEXT_DSP_SETUP(TwoPole_ar); + + FLEXT_DSP_SETUP(TwoZero_ar); + + FLEXT_DSP_SETUP(FOS_ar); + FLEXT_SETUP(FOS_kr); + + FLEXT_DSP_SETUP(SOS_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1