From 9b76d2cfe25558b3f1951fcf8ee26982beca1e48 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 23 Jul 2004 10:01:56 +0000 Subject: added LinCong ugen svn path=/trunk/externals/tb/; revision=1887 --- sc4pd/config-pd-linux.txt | 6 +- sc4pd/make-files.txt | 2 +- sc4pd/pd/lincong.pd | 17 ++++ sc4pd/source/Latoocarfian.cpp | 4 +- sc4pd/source/LinCong.cpp | 218 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 5 +- 6 files changed, 244 insertions(+), 8 deletions(-) create mode 100644 sc4pd/pd/lincong.pd create mode 100644 sc4pd/source/LinCong.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 7aac9a8..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? @@ -28,8 +28,8 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -UFLAGS=-xN -tpp7 -ip -ipo_obj # icc -#UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 +#UFLAGS=-xN -tpp7 -ip -ipo_obj # icc +UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index df0e4a6..b662391 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -6,4 +6,4 @@ SRCS= \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ - Logistic.cpp Latoocarfian.cpp \ No newline at end of file + Logistic.cpp Latoocarfian.cpp LinCong.cpp \ No newline at end of file diff --git a/sc4pd/pd/lincong.pd b/sc4pd/pd/lincong.pd new file mode 100644 index 0000000..c777695 --- /dev/null +++ b/sc4pd/pd/lincong.pd @@ -0,0 +1,17 @@ +#N canvas 257 167 708 300 10; +#X obj 132 247 dac~; +#X obj 228 253 print~; +#X obj 309 229 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 286 73 LinCong 100 103 140 120002; +#X obj 267 32 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 295 110 10 0 0 0 - - -; +#X obj 577 226 block~ 64; +#X obj 22 142 LinCong~ 13437 1433.34 1.34233e+06 4.33243e+09; +#X connect 2 0 1 0; +#X connect 3 0 5 0; +#X connect 4 0 3 0; +#X connect 7 0 0 0; +#X connect 7 0 0 1; +#X connect 7 0 1 0; diff --git a/sc4pd/source/Latoocarfian.cpp b/sc4pd/source/Latoocarfian.cpp index f831c27..c509711 100644 --- a/sc4pd/source/Latoocarfian.cpp +++ b/sc4pd/source/Latoocarfian.cpp @@ -91,7 +91,7 @@ private: FLEXT_LIB_DSP_V("Latoocarfian~",Latoocarfian_ar); Latoocarfian_ar::Latoocarfian_ar(int argc, t_atom *argv) - :m_x(0.4),m_y(1) + :m_x(4),m_y(1) { FLEXT_ADDMETHOD_(0,"a",m_set_a); FLEXT_ADDMETHOD_(0,"b",m_set_b); @@ -100,12 +100,10 @@ Latoocarfian_ar::Latoocarfian_ar(int argc, t_atom *argv) //parse arguments AtomList Args(argc,argv); - if (Args.Count()!=4) { post("4 arguments needed"); } - m_a = sc_getfloatarg(Args,0); m_b = sc_getfloatarg(Args,1); m_c = sc_getfloatarg(Args,2); diff --git a/sc4pd/source/LinCong.cpp b/sc4pd/source/LinCong.cpp new file mode 100644 index 0000000..0da0df7 --- /dev/null +++ b/sc4pd/source/LinCong.cpp @@ -0,0 +1,218 @@ +/* sc4pd + LinCong, LinCong~ + + 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: Keith Rowe & John Tilbury: Duos For Doris + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LinCong~ -------------------------------*/ + +class LinCong_ar: + public flext_dsp +{ + FLEXT_HEADER(LinCong_ar,flext_dsp); + +public: + LinCong_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set_seed(float f) + { + m_seed = (int)f; + } + + void m_set_mul(float f) + { + m_mul = (int)f; + } + + void m_set_add(float f) + { + m_add = (int)f; + } + + void m_set_mod(float f) + { + m_mod = (int)f; + m_scale = 2/f; //output between -1 and 1 + } + +private: + unsigned int m_seed; //seed + unsigned int m_mul, m_add, m_mod; //parameters + + float m_scale; + + FLEXT_CALLBACK_F(m_set_seed); + FLEXT_CALLBACK_F(m_set_mul); + FLEXT_CALLBACK_F(m_set_add); + FLEXT_CALLBACK_F(m_set_mod); +}; + +FLEXT_LIB_DSP_V("LinCong~",LinCong_ar); + +LinCong_ar::LinCong_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_set_seed); + FLEXT_ADDMETHOD_(0,"mul",m_set_mul); + FLEXT_ADDMETHOD_(0,"add",m_set_add); + FLEXT_ADDMETHOD_(0,"mod",m_set_mod); + + //parse arguments + AtomList Args(argc,argv); + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + m_seed = sc_getfloatarg(Args,0); + m_mul = sc_getfloatarg(Args,1); + m_add = sc_getfloatarg(Args,2); + m_set_mod(sc_getfloatarg(Args,3)); + + AddOutSignal(); +} + + +void LinCong_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + + + unsigned int seed = m_seed; + unsigned int mul = m_mul; + unsigned int add = m_add; + unsigned int mod = m_mod; + + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + seed=(seed * mul + add) % mod; + (*(xout)++)=float(seed)*scale - 1; + } + + m_seed = seed; +} + + + +/* ------------------------ LinCong ---------------------------------*/ + +class LinCong_kr: + public flext_base +{ + FLEXT_HEADER(LinCong_kr,flext_base); + +public: + LinCong_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_set_seed(float f) + { + m_seed = (int)f; + } + + void m_set_mul(float f) + { + m_mul = (int)f; + } + + void m_set_add(float f) + { + m_add = (int)f; + } + + void m_set_mod(float f) + { + m_mod = (int)f; + m_scale = 2/f; //output between -1 and 1 + } + +private: + unsigned int m_seed; //seed + unsigned int m_mul, m_add, m_mod; //parameters + + float m_scale; + + FLEXT_CALLBACK_F(m_set_seed); + FLEXT_CALLBACK_F(m_set_mul); + FLEXT_CALLBACK_F(m_set_add); + FLEXT_CALLBACK_F(m_set_mod); + FLEXT_CALLBACK(m_perform); +}; + + +FLEXT_LIB_V("LinCong",LinCong_kr); + +LinCong_kr::LinCong_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_set_seed); + FLEXT_ADDMETHOD_(0,"mul",m_set_mul); + FLEXT_ADDMETHOD_(0,"add",m_set_add); + FLEXT_ADDMETHOD_(0,"mod",m_set_mod); + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + m_seed = sc_getfloatarg(Args,0); + m_mul = sc_getfloatarg(Args,1); + m_add = sc_getfloatarg(Args,2); + m_set_mod(sc_getfloatarg(Args,3)); + + AddOutFloat(); +} + +void LinCong_kr::m_perform() +{ + m_seed=(m_seed * m_mul + m_add) % m_mod; + ToOutFloat(0,float(m_seed) * m_scale - 1); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 668c300..9f2287a 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,7 @@ void sc4pd_library_setup() "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~), " - "Latoocarfian(~)\n"); + "Latoocarfian(~), LinCong(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -137,6 +137,9 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Latoocarfian_ar); FLEXT_SETUP(Latoocarfian_kr); + + FLEXT_DSP_SETUP(LinCong_ar); + FLEXT_SETUP(LinCong_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1