[PD-cvs] externals/sc4pd/source LFDNoise0.cpp,NONE,1.1 LFDNoise1.cpp,NONE,1.1 LFDNoise2.cpp,NONE,1.1 sc*.cpp,NONE,1.1 sc+.cpp,NONE,1.1 sc-.cpp,NONE,1.1 scdiv.cpp,NONE,1.1 main.cpp,1.26,1.27 sc4pd.hpp,1.5,1.6 support.cpp,1.4,1.5 support.hpp,1.8,1.9
Tim Blechmann
timblech at users.sourceforge.net
Thu Sep 9 10:45:20 CEST 2004
Update of /cvsroot/pure-data/externals/sc4pd/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30080/source
Modified Files:
main.cpp sc4pd.hpp support.cpp support.hpp
Added Files:
LFDNoise0.cpp LFDNoise1.cpp LFDNoise2.cpp sc*.cpp sc+.cpp
sc-.cpp scdiv.cpp
Log Message:
lfdnoises and interpolating vector/scalar operations
Index: support.hpp
===================================================================
RCS file: /cvsroot/pure-data/externals/sc4pd/source/support.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** support.hpp 8 Aug 2004 11:10:30 -0000 1.8
--- support.hpp 9 Sep 2004 08:45:18 -0000 1.9
***************
*** 51,54 ****
--- 51,55 ----
float sc_getfloatarg (flext::AtomList a,int i);
bool sc_ar(flext::AtomList a);
+ bool sc_inv(flext::AtomList a);
***************
*** 95,99 ****
! /* this is copied from thomas grill's xsample:
xsample - extended sample objects for Max/MSP and pd (pure data)
--- 96,100 ----
! /* this is adapted from thomas grill's xsample:
xsample - extended sample objects for Max/MSP and pd (pure data)
***************
*** 103,134 ****
*/
- #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 DEFSIGCALL(NAME) \
! inline V NAME(I n,S *const *in,S *const *out) \
{ (this->*v_##NAME)(n,in,out); } \
! V (thisType::*v_##NAME)(I n,S *const *invecs,S *const *outvecs)
#define SIGFUN(FUN) &thisType::FUN
- #undef F
- #undef D
- #undef I
- #undef L
- #undef C
- #undef V
- #undef BL
- #undef S
--- 104,118 ----
*/
#define SETSIGFUN(VAR,FUN) v_##VAR = FUN
! #define DEFSIGFUN(NAME) void NAME(int n,t_sample *const *in,t_sample *const *out)
#define DEFSIGCALL(NAME) \
! inline void NAME(int n,t_sample *const *in,t_sample *const *out) \
{ (this->*v_##NAME)(n,in,out); } \
! void (thisType::*v_##NAME)(int n,t_sample *const *invecs,t_sample *const *outvecs)
#define SIGFUN(FUN) &thisType::FUN
--- NEW FILE: sc-.cpp ---
/* 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;
}
}
}
}
Index: main.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/sc4pd/source/main.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** main.cpp 8 Aug 2004 17:30:20 -0000 1.26
--- main.cpp 9 Sep 2004 08:45:18 -0000 1.27
***************
*** 67,72 ****
" TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, "
"BRF~,\n"
! " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~)"
! "\n"
);
--- 67,73 ----
" TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, "
"BRF~,\n"
! " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~), "
! "LFDNoise0~,\n"
! " LFDNoise1~, LFDNoise2~, sc+~, sc-~, sc*~, sc/~\n"
);
***************
*** 282,285 ****
--- 283,300 ----
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);
}
--- NEW FILE: sc+.cpp ---
/* 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;
}
}
}
--- NEW FILE: sc*.cpp ---
/* 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;
}
}
}
--- NEW FILE: LFDNoise0.cpp ---
/* 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;
}
--- NEW FILE: LFDNoise2.cpp ---
/* 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;
}
Index: support.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/sc4pd/source/support.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** support.cpp 2 Aug 2004 19:18:22 -0000 1.4
--- support.cpp 9 Sep 2004 08:45:18 -0000 1.5
***************
*** 78,91 ****
}
! // 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;
int32 timeseed()
--- 78,95 ----
}
! 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()
--- NEW FILE: LFDNoise1.cpp ---
/* 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;
}
Index: sc4pd.hpp
===================================================================
RCS file: /cvsroot/pure-data/externals/sc4pd/source/sc4pd.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** sc4pd.hpp 7 Aug 2004 20:43:57 -0000 1.5
--- sc4pd.hpp 9 Sep 2004 08:45:18 -0000 1.6
***************
*** 125,128 ****
! #define _SC$PD_HPP
#endif
--- 125,128 ----
! #define _SC4PD_HPP
#endif
--- NEW FILE: scdiv.cpp ---
/* 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;
}
}
}
}
More information about the Pd-cvs
mailing list