From ff876f5c6016f7e7670360c083370bcf199971fe Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Thu, 9 Apr 2020 21:07:24 +0200 Subject: [PATCH 1/9] Apply supecollider clangformat to BhobUGens --- source/BhobUGens/BhobChaos.cpp | 3235 ++++++++++--------- source/BhobUGens/BhobFFT.cpp | 561 ++-- source/BhobUGens/BhobFilt.cpp | 5315 ++++++++++++++------------------ source/BhobUGens/BhobGrain.cpp | 1069 +++---- source/BhobUGens/BhobNoise.cpp | 1433 +++++---- 5 files changed, 5448 insertions(+), 6165 deletions(-) diff --git a/source/BhobUGens/BhobChaos.cpp b/source/BhobUGens/BhobChaos.cpp index 96f45a019b..2cadd4912b 100644 --- a/source/BhobUGens/BhobChaos.cpp +++ b/source/BhobUGens/BhobChaos.cpp @@ -5,7 +5,7 @@ FitzHughNagumo ugen SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com + 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 @@ -29,1827 +29,1792 @@ SuperCollider real time audio synthesis system #define RECTWOPI 0.1591549430918953 #define ONESIXTH 0.1666666666666667 -static InterfaceTable *ft; +static InterfaceTable* ft; -struct Henon2DN : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, myclip, mxscale, myscale, mphase, mspeed; +struct Henon2DN : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, myclip, mxscale, myscale, mphase, mspeed; }; -struct Henon2DL : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mynm1, myclip, mxscale, myscale, mphase, mspeed; +struct Henon2DL : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mynm1, myclip, mxscale, myscale, mphase, mspeed; }; -struct Henon2DC : public Unit -{ - double mx0, my0, mxn, myn, myclip, mlevel, mxscale, myscale, mslope, mcurve; - int32 mphase; +struct Henon2DC : public Unit { + double mx0, my0, mxn, myn, myclip, mlevel, mxscale, myscale, mslope, mcurve; + int32 mphase; }; -struct HenonTrig : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mxscale, myscale, mphase, mspeed; +struct HenonTrig : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mxscale, myscale, mphase, mspeed; }; -struct Latoocarfian2DN : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, myclip, mxscale, mphase, mspeed; +struct Latoocarfian2DN : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, myclip, mxscale, mphase, mspeed; }; -struct Latoocarfian2DL : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mynm1, myclip, mxscale, mphase, mspeed; +struct Latoocarfian2DL : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mynm1, myclip, mxscale, mphase, mspeed; }; -struct Latoocarfian2DC : public Unit -{ - double mx0, my0, mxn, myn, myclip, mlevel, mxscale, mslope, mcurve; - int32 mphase; +struct Latoocarfian2DC : public Unit { + double mx0, my0, mxn, myn, myclip, mlevel, mxscale, mslope, mcurve; + int32 mphase; }; -struct LatoocarfianTrig : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mxscale, mphase, mspeed; +struct LatoocarfianTrig : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mxscale, mphase, mspeed; }; -struct Lorenz2DN : public Unit -{ - float mfreqMul; - double mx0, my0, mz0, mxn, myn, mzn, myclip, mxscale, myscale, mphase, mspeed; +struct Lorenz2DN : public Unit { + float mfreqMul; + double mx0, my0, mz0, mxn, myn, mzn, myclip, mxscale, myscale, mphase, mspeed; }; -struct Lorenz2DL : public Unit -{ - float mfreqMul; - double mx0, my0, mz0, mxn, myn, mzn, mynm1, myclip, mxscale, myscale, mphase, mspeed; +struct Lorenz2DL : public Unit { + float mfreqMul; + double mx0, my0, mz0, mxn, myn, mzn, mynm1, myclip, mxscale, myscale, mphase, mspeed; }; -struct Lorenz2DC : public Unit -{ - int32 mphase; - double mx0, my0, mz0, mxn, myn, mzn, myclip, mxscale, myscale, mlevel, mslope, mcurve; +struct Lorenz2DC : public Unit { + int32 mphase; + double mx0, my0, mz0, mxn, myn, mzn, myclip, mxscale, myscale, mlevel, mslope, mcurve; }; -struct LorenzTrig : public Unit -{ - float mfreqMul; - double mx0, my0, mz0, mxn, myn, mzn, mxscale, myscale, mphase, mspeed; +struct LorenzTrig : public Unit { + float mfreqMul; + double mx0, my0, mz0, mxn, myn, mzn, mxscale, myscale, mphase, mspeed; }; -struct Standard2DN : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, myclip, mscale, mphase, mspeed; +struct Standard2DN : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, myclip, mscale, mphase, mspeed; }; -struct Standard2DL : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mynm1, myclip, mscale, mphase, mspeed; +struct Standard2DL : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mynm1, myclip, mscale, mphase, mspeed; }; -struct Standard2DC : public Unit -{ - int32 mphase; - double mx0, my0, mxn, myn, myclip, mscale, mlevel, mslope, mcurve; +struct Standard2DC : public Unit { + int32 mphase; + double mx0, my0, mxn, myn, myclip, mscale, mlevel, mslope, mcurve; }; -struct StandardTrig : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mscale, mphase, mspeed; +struct StandardTrig : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mscale, mphase, mspeed; }; -struct Gbman2DN : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, myclip, mscale, mphase, mspeed; +struct Gbman2DN : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, myclip, mscale, mphase, mspeed; }; -struct Gbman2DL : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mynm1, myclip, mscale, mphase, mspeed; +struct Gbman2DL : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mynm1, myclip, mscale, mphase, mspeed; }; -struct Gbman2DC : public Unit -{ - int32 mphase; - double mx0, my0, mxn, myn, myclip, mscale, mslope, mcurve, mlevel; +struct Gbman2DC : public Unit { + int32 mphase; + double mx0, my0, mxn, myn, myclip, mscale, mslope, mcurve, mlevel; }; -struct GbmanTrig : public Unit -{ - float mfreqMul; - double mx0, my0, mxn, myn, mscale, mphase, mspeed; +struct GbmanTrig : public Unit { + float mfreqMul; + double mx0, my0, mxn, myn, mscale, mphase, mspeed; }; -struct Fhn2DN : public Unit -{ - float mfreqMul; - double mu0, mw0, mun, mwn, muclip, mphase, mspeed; +struct Fhn2DN : public Unit { + float mfreqMul; + double mu0, mw0, mun, mwn, muclip, mphase, mspeed; }; -struct Fhn2DL : public Unit -{ - float mfreqMul; - double mu0, mw0, mun, mwn, muclip, um1, mphase, mspeed; +struct Fhn2DL : public Unit { + float mfreqMul; + double mu0, mw0, mun, mwn, muclip, um1, mphase, mspeed; }; -struct Fhn2DC : public Unit -{ - int32 mphase; - double mu0, mw0, mun, mwn, muclip, um1, mslope, mcurve, mlevel; +struct Fhn2DC : public Unit { + int32 mphase; + double mu0, mw0, mun, mwn, muclip, um1, mslope, mcurve, mlevel; }; -struct FhnTrig : public Unit -{ - float mfreqMul; - double mu0, mw0, mun, mwn, mphase, mspeed; +struct FhnTrig : public Unit { + float mfreqMul; + double mu0, mw0, mun, mwn, mphase, mspeed; }; -extern "C" -{ - void Henon2DN_Ctor(Henon2DN* unit); - void Henon2DN_next(Henon2DN *unit, int inNumSamples); +extern "C" { +void Henon2DN_Ctor(Henon2DN* unit); +void Henon2DN_next(Henon2DN* unit, int inNumSamples); - void Henon2DL_Ctor(Henon2DL* unit); - void Henon2DL_next(Henon2DL *unit, int inNumSamples); +void Henon2DL_Ctor(Henon2DL* unit); +void Henon2DL_next(Henon2DL* unit, int inNumSamples); - void Henon2DC_Ctor(Henon2DC* unit); - void Henon2DC_next(Henon2DC *unit, int inNumSamples); +void Henon2DC_Ctor(Henon2DC* unit); +void Henon2DC_next(Henon2DC* unit, int inNumSamples); - void HenonTrig_Ctor(HenonTrig* unit); - void HenonTrig_next(HenonTrig *unit, int inNumSamples); +void HenonTrig_Ctor(HenonTrig* unit); +void HenonTrig_next(HenonTrig* unit, int inNumSamples); - void Latoocarfian2DN_Ctor(Latoocarfian2DN* unit); - void Latoocarfian2DN_next(Latoocarfian2DN *unit, int inNumSamples); +void Latoocarfian2DN_Ctor(Latoocarfian2DN* unit); +void Latoocarfian2DN_next(Latoocarfian2DN* unit, int inNumSamples); - void Latoocarfian2DL_Ctor(Latoocarfian2DL* unit); - void Latoocarfian2DL_next(Latoocarfian2DL *unit, int inNumSamples); +void Latoocarfian2DL_Ctor(Latoocarfian2DL* unit); +void Latoocarfian2DL_next(Latoocarfian2DL* unit, int inNumSamples); - void Latoocarfian2DC_Ctor(Latoocarfian2DC* unit); - void Latoocarfian2DC_next(Latoocarfian2DC *unit, int inNumSamples); +void Latoocarfian2DC_Ctor(Latoocarfian2DC* unit); +void Latoocarfian2DC_next(Latoocarfian2DC* unit, int inNumSamples); - void LatoocarfianTrig_Ctor(LatoocarfianTrig* unit); - void LatoocarfianTrig_next(LatoocarfianTrig *unit, int inNumSamples); +void LatoocarfianTrig_Ctor(LatoocarfianTrig* unit); +void LatoocarfianTrig_next(LatoocarfianTrig* unit, int inNumSamples); - void Lorenz2DN_Ctor(Lorenz2DN* unit); - void Lorenz2DN_next(Lorenz2DN *unit, int inNumSamples); +void Lorenz2DN_Ctor(Lorenz2DN* unit); +void Lorenz2DN_next(Lorenz2DN* unit, int inNumSamples); - void Lorenz2DL_Ctor(Lorenz2DL* unit); - void Lorenz2DL_next(Lorenz2DL *unit, int inNumSamples); +void Lorenz2DL_Ctor(Lorenz2DL* unit); +void Lorenz2DL_next(Lorenz2DL* unit, int inNumSamples); - void Lorenz2DC_Ctor(Lorenz2DC* unit); - void Lorenz2DC_next(Lorenz2DC *unit, int inNumSamples); +void Lorenz2DC_Ctor(Lorenz2DC* unit); +void Lorenz2DC_next(Lorenz2DC* unit, int inNumSamples); - void LorenzTrig_Ctor(LorenzTrig* unit); - void LorenzTrig_next(LorenzTrig *unit, int inNumSamples); +void LorenzTrig_Ctor(LorenzTrig* unit); +void LorenzTrig_next(LorenzTrig* unit, int inNumSamples); - void Standard2DN_Ctor(Standard2DN* unit); - void Standard2DN_next(Standard2DN *unit, int inNumSamples); +void Standard2DN_Ctor(Standard2DN* unit); +void Standard2DN_next(Standard2DN* unit, int inNumSamples); - void Standard2DL_Ctor(Standard2DL* unit); - void Standard2DL_next(Standard2DL *unit, int inNumSamples); +void Standard2DL_Ctor(Standard2DL* unit); +void Standard2DL_next(Standard2DL* unit, int inNumSamples); - void Standard2DC_Ctor(Standard2DC* unit); - void Standard2DC_next(Standard2DC *unit, int inNumSamples); +void Standard2DC_Ctor(Standard2DC* unit); +void Standard2DC_next(Standard2DC* unit, int inNumSamples); - void StandardTrig_Ctor(StandardTrig* unit); - void StandardTrig_next(StandardTrig *unit, int inNumSamples); +void StandardTrig_Ctor(StandardTrig* unit); +void StandardTrig_next(StandardTrig* unit, int inNumSamples); - void Gbman2DN_Ctor(Gbman2DN* unit); - void Gbman2DN_next(Gbman2DN *unit, int inNumSamples); +void Gbman2DN_Ctor(Gbman2DN* unit); +void Gbman2DN_next(Gbman2DN* unit, int inNumSamples); - void Gbman2DL_Ctor(Gbman2DL* unit); - void Gbman2DL_next(Gbman2DL *unit, int inNumSamples); +void Gbman2DL_Ctor(Gbman2DL* unit); +void Gbman2DL_next(Gbman2DL* unit, int inNumSamples); - void Gbman2DC_Ctor(Gbman2DC* unit); - void Gbman2DC_next(Gbman2DC *unit, int inNumSamples); +void Gbman2DC_Ctor(Gbman2DC* unit); +void Gbman2DC_next(Gbman2DC* unit, int inNumSamples); - void GbmanTrig_Ctor(GbmanTrig* unit); - void GbmanTrig_next(GbmanTrig *unit, int inNumSamples); +void GbmanTrig_Ctor(GbmanTrig* unit); +void GbmanTrig_next(GbmanTrig* unit, int inNumSamples); - void Fhn2DN_Ctor(Fhn2DN* unit); - void Fhn2DN_next(Fhn2DN *unit, int inNumSamples); +void Fhn2DN_Ctor(Fhn2DN* unit); +void Fhn2DN_next(Fhn2DN* unit, int inNumSamples); - void Fhn2DL_Ctor(Fhn2DL* unit); - void Fhn2DL_next(Fhn2DL *unit, int inNumSamples); +void Fhn2DL_Ctor(Fhn2DL* unit); +void Fhn2DL_next(Fhn2DL* unit, int inNumSamples); - void Fhn2DC_Ctor(Fhn2DC* unit); - void Fhn2DC_next(Fhn2DC *unit, int inNumSamples); +void Fhn2DC_Ctor(Fhn2DC* unit); +void Fhn2DC_next(Fhn2DC* unit, int inNumSamples); - void FhnTrig_Ctor(FhnTrig* unit); - void FhnTrig_next(FhnTrig *unit, int inNumSamples); +void FhnTrig_Ctor(FhnTrig* unit); +void FhnTrig_next(FhnTrig* unit, int inNumSamples); }; inline double mod2pi(double in) { - const double lo = (double)0.; - const double hi = TWOPI; - - if (in >= hi) { - in -= hi; - if (in < hi) return in; - } else if (in < lo) { - in += hi; - if (in >= lo) return in; - } else return in; - - return in - hi * (double)((int)(in * RECTWOPI)); + const double lo = (double)0.; + const double hi = TWOPI; + + if (in >= hi) { + in -= hi; + if (in < hi) + return in; + } else if (in < lo) { + in += hi; + if (in >= lo) + return in; + } else + return in; + + return in - hi * (double)((int)(in * RECTWOPI)); } -float Mirroring (float lower, float upper, float in); +float Mirroring(float lower, float upper, float in); /* float Mirroring (float lower, float upper, float in) { - if(in>upper || inupper || inupper || in upper || in < lower) { + if (in < lower) { + float diff = lower - in; + in = sc_min(upper, lower + diff); + } else { + float diff = in - upper; + in = sc_max(lower, upper - diff); + } + } + return in; } -void Henon2DN_Ctor(Henon2DN *unit) -{ - unit->mx0=ZIN0(4); - unit->my0=ZIN0(5); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.77850360953955; - unit->myscale=2.594; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Henon2DN_next); - ZOUT0(0) = 0.f; +void Henon2DN_Ctor(Henon2DN* unit) { + unit->mx0 = ZIN0(4); + unit->my0 = ZIN0(5); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.77850360953955; + unit->myscale = 2.594; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Henon2DN_next); + ZOUT0(0) = 0.f; } -void Henon2DN_next(Henon2DN *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double x0=ZIN0(4); - double y0=ZIN0(5); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - double newx = yn + 1 - a * xn * xn; - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn=b * xn; - yclip=yn * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - } - - ZXP(out) = yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->myclip=yclip; +void Henon2DN_next(Henon2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double x0 = ZIN0(4); + double y0 = ZIN0(5); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + double newx = yn + 1 - a * xn * xn; + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = b * xn; + yclip = yn * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + } + + ZXP(out) = yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->myclip = yclip; } -void Henon2DL_Ctor(Henon2DL *unit) -{ - unit->mx0=ZIN0(4); - unit->my0=ZIN0(5); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.77850360953955; - unit->myscale=2.594; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Henon2DL_next); - ZOUT0(0) = 0.f; +void Henon2DL_Ctor(Henon2DL* unit) { + unit->mx0 = ZIN0(4); + unit->my0 = ZIN0(5); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.77850360953955; + unit->myscale = 2.594; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Henon2DL_next); + ZOUT0(0) = 0.f; } -void Henon2DL_next(Henon2DL *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double x0=ZIN0(4); - double y0=ZIN0(5); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double ynm1=unit->mynm1; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - double newx = yn + 1 - a * xn * xn; - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - ynm1=yclip; - yn=b * xn; - yclip=yn * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - } - - ZXP(out) = (1-phase) * ynm1 + phase * yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mynm1=ynm1; - unit->myclip=yclip; +void Henon2DL_next(Henon2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double x0 = ZIN0(4); + double y0 = ZIN0(5); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double ynm1 = unit->mynm1; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + double newx = yn + 1 - a * xn * xn; + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + ynm1 = yclip; + yn = b * xn; + yclip = yn * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + } + + ZXP(out) = (1 - phase) * ynm1 + phase * yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mynm1 = ynm1; + unit->myclip = yclip; } -void Henon2DC_Ctor(Henon2DC *unit) -{ - unit->mx0=ZIN0(4); - unit->my0=ZIN0(5); - unit->mphase=0; - unit->mslope=0.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.77850360953955; - unit->myscale=2.594; - unit->mlevel=unit->my0 * unit->myscale; - SETCALC(Henon2DC_next); - ZOUT0(0) = 0.f; +void Henon2DC_Ctor(Henon2DC* unit) { + unit->mx0 = ZIN0(4); + unit->my0 = ZIN0(5); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.77850360953955; + unit->myscale = 2.594; + unit->mlevel = unit->my0 * unit->myscale; + SETCALC(Henon2DC_next); + ZOUT0(0) = 0.f; } -void Henon2DC_next(Henon2DC *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double x0=ZIN0(4); - double y0=ZIN0(5); - double xn=unit->mxn; - double yn=unit->myn; - double yscale=unit->myscale; - int32 phase=unit->mphase; - double level=unit->mlevel; - double slope=unit->mslope; - double curve=unit->mcurve; - - int remain=inNumSamples; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - do { - if (phase <= 0) { - double newx = yn + 1 - a * xn * xn; - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - float fphase = (minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate/sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - double ynm1=unit->myclip; - yn=b * xn; - double yclip=yn * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - double midpnt=(ynm1 + yclip) * 0.5; - unit->myclip=yclip; - curve=2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - xn=newx; - } - int nsmps = sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out) = level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mphase=phase; - unit->mlevel=level; - unit->mslope=slope; - unit->mcurve=curve; - unit->mxn=xn; - unit->myn=yn; +void Henon2DC_next(Henon2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double x0 = ZIN0(4); + double y0 = ZIN0(5); + double xn = unit->mxn; + double yn = unit->myn; + double yscale = unit->myscale; + int32 phase = unit->mphase; + double level = unit->mlevel; + double slope = unit->mslope; + double curve = unit->mcurve; + + int remain = inNumSamples; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + do { + if (phase <= 0) { + double newx = yn + 1 - a * xn * xn; + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + double ynm1 = unit->myclip; + yn = b * xn; + double yclip = yn * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + double midpnt = (ynm1 + yclip) * 0.5; + unit->myclip = yclip; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + xn = newx; + } + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mphase = phase; + unit->mlevel = level; + unit->mslope = slope; + unit->mcurve = curve; + unit->mxn = xn; + unit->myn = yn; } -void HenonTrig_Ctor(HenonTrig *unit) -{ - unit->mx0=ZIN0(4); - unit->my0=ZIN0(5); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.77850360953955; - unit->myscale=2.594; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(HenonTrig_next); - ZOUT0(0) = 0.f; +void HenonTrig_Ctor(HenonTrig* unit) { + unit->mx0 = ZIN0(4); + unit->my0 = ZIN0(5); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.77850360953955; + unit->myscale = 2.594; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(HenonTrig_next); + ZOUT0(0) = 0.f; } -void HenonTrig_next(HenonTrig *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double x0=ZIN0(4); - double y0=ZIN0(5); - double xn=unit->mxn; - double yn=unit->myn; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - double newx = yn + 1 - a * xn * xn; - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn=b * xn; - float yclip=(yn * yscale + 1) * 0.5; - yclip=Mirroring(0.0, 1.0, yclip); - xn=newx; - ZXP(out) = yclip; - } else ZXP(out) = 0.f; - - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; +void HenonTrig_next(HenonTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double x0 = ZIN0(4); + double y0 = ZIN0(5); + double xn = unit->mxn; + double yn = unit->myn; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + double newx = yn + 1 - a * xn * xn; + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = b * xn; + float yclip = (yn * yscale + 1) * 0.5; + yclip = Mirroring(0.0, 1.0, yclip); + xn = newx; + ZXP(out) = yclip; + } else ZXP(out) = 0.f; + + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; } -void Latoocarfian2DN_Ctor(Latoocarfian2DN *unit) -{ - unit->mx0=ZIN0(6); - unit->my0=ZIN0(7); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.70390617562334; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Latoocarfian2DN_next); - ZOUT0(0) = 0.f; +void Latoocarfian2DN_Ctor(Latoocarfian2DN* unit) { + unit->mx0 = ZIN0(6); + unit->my0 = ZIN0(7); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.70390617562334; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Latoocarfian2DN_next); + ZOUT0(0) = 0.f; } -void Latoocarfian2DN_next(Latoocarfian2DN *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double c=ZIN0(4); - double d=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = sin(b * yn) + c*sin(b * xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn = sin(a * xn) + d*sin(a * yn); - yclip=yn * 0.72074001609432; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - } - - ZXP(out) = yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->myclip=yclip; +void Latoocarfian2DN_next(Latoocarfian2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double c = ZIN0(4); + double d = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = sin(b * yn) + c * sin(b * xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = sin(a * xn) + d * sin(a * yn); + yclip = yn * 0.72074001609432; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + } + + ZXP(out) = yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->myclip = yclip; } -void Latoocarfian2DL_Ctor(Latoocarfian2DL *unit) -{ - unit->mx0=ZIN0(6); - unit->my0=ZIN0(7); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.70390617562334; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Latoocarfian2DL_next); - ZOUT0(0) = 0.f; +void Latoocarfian2DL_Ctor(Latoocarfian2DL* unit) { + unit->mx0 = ZIN0(6); + unit->my0 = ZIN0(7); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.70390617562334; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Latoocarfian2DL_next); + ZOUT0(0) = 0.f; } -void Latoocarfian2DL_next(Latoocarfian2DL *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double c=ZIN0(4); - double d=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double xn=unit->mxn; - double yn=unit->myn; - double ynm1=unit->mynm1; - double yclip=unit->myclip; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = sin(b * yn) + c*sin(b * xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - ynm1=yclip; - yn = sin(a * xn) + d*sin(a * yn); - yclip=yn * 0.72074001609432; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - } - - ZXP(out) = (1-phase) * ynm1 + phase * yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mynm1=ynm1; - unit->myclip=yclip; +void Latoocarfian2DL_next(Latoocarfian2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double c = ZIN0(4); + double d = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double xn = unit->mxn; + double yn = unit->myn; + double ynm1 = unit->mynm1; + double yclip = unit->myclip; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = sin(b * yn) + c * sin(b * xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + ynm1 = yclip; + yn = sin(a * xn) + d * sin(a * yn); + yclip = yn * 0.72074001609432; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + } + + ZXP(out) = (1 - phase) * ynm1 + phase * yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mynm1 = ynm1; + unit->myclip = yclip; } -void Latoocarfian2DC_Ctor(Latoocarfian2DC *unit) -{ - unit->mx0=ZIN0(6); - unit->my0=ZIN0(7); - unit->mphase=0; - unit->mslope=0.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.70390617562334; - unit->mlevel=unit->myn; - SETCALC(Latoocarfian2DC_next); - ZOUT0(0) = 0.f; +void Latoocarfian2DC_Ctor(Latoocarfian2DC* unit) { + unit->mx0 = ZIN0(6); + unit->my0 = ZIN0(7); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.70390617562334; + unit->mlevel = unit->myn; + SETCALC(Latoocarfian2DC_next); + ZOUT0(0) = 0.f; } -void Latoocarfian2DC_next(Latoocarfian2DC *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double c=ZIN0(4); - double d=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double xn=unit->mxn; - double yn=unit->myn; - double level=unit->mlevel; - double slope=unit->mslope; - double curve=unit->mcurve; - int32 phase=unit->mphase; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - - int remain = inNumSamples; - do { - if (phase <= 0) { - float newx = sin(b * yn) + c*sin(b * xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - float fphase = (minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate/sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - double ynm1=unit->myclip; - yn = sin(a * xn) + d*sin(a * yn); - double yclip=yn * 0.72074001609432; - yclip=Mirroring(-1.0, 1.0, yclip); - double midpnt=(ynm1 + yclip) * 0.5; - unit->myclip=yclip; - curve=2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - xn=newx; - } - - int nsmps = sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out)=level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mphase=phase; - unit->mslope=slope; - unit->mcurve=curve; - unit->mlevel=level; - unit->mxn=xn; - unit->myn=yn; +void Latoocarfian2DC_next(Latoocarfian2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double c = ZIN0(4); + double d = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double xn = unit->mxn; + double yn = unit->myn; + double level = unit->mlevel; + double slope = unit->mslope; + double curve = unit->mcurve; + int32 phase = unit->mphase; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + + int remain = inNumSamples; + do { + if (phase <= 0) { + float newx = sin(b * yn) + c * sin(b * xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + double ynm1 = unit->myclip; + yn = sin(a * xn) + d * sin(a * yn); + double yclip = yn * 0.72074001609432; + yclip = Mirroring(-1.0, 1.0, yclip); + double midpnt = (ynm1 + yclip) * 0.5; + unit->myclip = yclip; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + xn = newx; + } + + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mphase = phase; + unit->mslope = slope; + unit->mcurve = curve; + unit->mlevel = level; + unit->mxn = xn; + unit->myn = yn; } -void LatoocarfianTrig_Ctor(LatoocarfianTrig *unit) -{ - unit->mx0=ZIN0(6); - unit->my0=ZIN0(7); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mxscale=0.70390617562334; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(LatoocarfianTrig_next); - ZOUT0(0) = 0.f; +void LatoocarfianTrig_Ctor(LatoocarfianTrig* unit) { + unit->mx0 = ZIN0(6); + unit->my0 = ZIN0(7); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mxscale = 0.70390617562334; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(LatoocarfianTrig_next); + ZOUT0(0) = 0.f; } -void LatoocarfianTrig_next(LatoocarfianTrig *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double a=ZIN0(2); - double b=ZIN0(3); - double c=ZIN0(4); - double d=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double xn=unit->mxn; - double yn=unit->myn; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = sin(b * yn) + c*sin(b * xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn = sin(a * xn) + d*sin(a * yn); - float yclip=(yn * 0.72074001609432 + 1) * 0.5; - yclip=Mirroring(0.0, 1.0, yclip); - xn=newx; - ZXP(out) = yclip; - } else ZXP(out) = 0.f; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; +void LatoocarfianTrig_next(LatoocarfianTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double a = ZIN0(2); + double b = ZIN0(3); + double c = ZIN0(4); + double d = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double xn = unit->mxn; + double yn = unit->myn; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = sin(b * yn) + c * sin(b * xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = sin(a * xn) + d * sin(a * yn); + float yclip = (yn * 0.72074001609432 + 1) * 0.5; + yclip = Mirroring(0.0, 1.0, yclip); + xn = newx; + ZXP(out) = yclip; + } else ZXP(out) = 0.f; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; } -void Lorenz2DN_Ctor(Lorenz2DN *unit) -{ - unit->mx0=unit->mxn=ZIN0(6); - unit->my0=unit->myn=ZIN0(7); - unit->mz0=unit->mzn=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxscale=0.048269545768799; - unit->myscale=0.035757929840258; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Lorenz2DN_next); - ZOUT0(0) = 0.f; +void Lorenz2DN_Ctor(Lorenz2DN* unit) { + unit->mx0 = unit->mxn = ZIN0(6); + unit->my0 = unit->myn = ZIN0(7); + unit->mz0 = unit->mzn = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxscale = 0.048269545768799; + unit->myscale = 0.035757929840258; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Lorenz2DN_next); + ZOUT0(0) = 0.f; } -void Lorenz2DN_next(Lorenz2DN *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double s=ZIN0(2); - double r=ZIN0(3); - double b=ZIN0(4); - double h=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double z0=ZIN0(8); - double xn=unit->mxn; - double yn=unit->myn; - double zn=unit->mzn; - double yclip=unit->myclip; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - if (z0 != unit->mz0) unit->mz0=zn=z0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = xn + h * s * (yn - xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - float newy = yn + h * (-xn * zn + r * xn - yn); - zn = zn + h * (xn * yn - b * zn); - - yclip=newy * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - yn=newy; - } - - ZXP(out) = yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mzn=zn; - unit->myclip=yclip; +void Lorenz2DN_next(Lorenz2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double s = ZIN0(2); + double r = ZIN0(3); + double b = ZIN0(4); + double h = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double z0 = ZIN0(8); + double xn = unit->mxn; + double yn = unit->myn; + double zn = unit->mzn; + double yclip = unit->myclip; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + if (z0 != unit->mz0) + unit->mz0 = zn = z0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = xn + h * s * (yn - xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + float newy = yn + h * (-xn * zn + r * xn - yn); + zn = zn + h * (xn * yn - b * zn); + + yclip = newy * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + yn = newy; + } + + ZXP(out) = yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mzn = zn; + unit->myclip = yclip; } -void Lorenz2DL_Ctor(Lorenz2DL *unit) -{ - unit->mx0=unit->mxn=ZIN0(6); - unit->my0=unit->myn=ZIN0(7); - unit->mz0=unit->mzn=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxscale=0.048269545768799; - unit->myscale=0.035757929840258; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Lorenz2DL_next); - ZOUT0(0) = 0.f; +void Lorenz2DL_Ctor(Lorenz2DL* unit) { + unit->mx0 = unit->mxn = ZIN0(6); + unit->my0 = unit->myn = ZIN0(7); + unit->mz0 = unit->mzn = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxscale = 0.048269545768799; + unit->myscale = 0.035757929840258; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Lorenz2DL_next); + ZOUT0(0) = 0.f; } -void Lorenz2DL_next(Lorenz2DL *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double s=ZIN0(2); - double r=ZIN0(3); - double b=ZIN0(4); - double h=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double z0=ZIN0(8); - double xn=unit->mxn; - double yn=unit->myn; - double zn=unit->mzn; - double ynm1=unit->mynm1; - double yclip=unit->myclip; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - if (z0 != unit->mz0) unit->mz0=zn=z0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = xn + h * s * (yn - xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - float newy = yn + h * (-xn * zn + r * xn - yn); - zn = zn + h * (xn * yn - b * zn); - - ynm1=yclip; - yclip=newy * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - xn=newx; - yn=newy; - } - - ZXP(out) = (1-phase) * ynm1 + phase * yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mzn=zn; - unit->myclip=yclip; - unit->mynm1=ynm1; +void Lorenz2DL_next(Lorenz2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double s = ZIN0(2); + double r = ZIN0(3); + double b = ZIN0(4); + double h = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double z0 = ZIN0(8); + double xn = unit->mxn; + double yn = unit->myn; + double zn = unit->mzn; + double ynm1 = unit->mynm1; + double yclip = unit->myclip; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + if (z0 != unit->mz0) + unit->mz0 = zn = z0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = xn + h * s * (yn - xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + float newy = yn + h * (-xn * zn + r * xn - yn); + zn = zn + h * (xn * yn - b * zn); + + ynm1 = yclip; + yclip = newy * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + xn = newx; + yn = newy; + } + + ZXP(out) = (1 - phase) * ynm1 + phase * yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mzn = zn; + unit->myclip = yclip; + unit->mynm1 = ynm1; } -void Lorenz2DC_Ctor(Lorenz2DC *unit) -{ - unit->mx0=unit->mxn=ZIN0(6); - unit->my0=unit->myn=ZIN0(7); - unit->mz0=unit->mzn=ZIN0(8); - unit->mphase=0; - unit->mslope=0.f; - unit->mxscale=0.048269545768799; - unit->myscale=0.035757929840258; - unit->mlevel=unit->my0 * unit->myscale; - SETCALC(Lorenz2DC_next); - ZOUT0(0) = 0.f; +void Lorenz2DC_Ctor(Lorenz2DC* unit) { + unit->mx0 = unit->mxn = ZIN0(6); + unit->my0 = unit->myn = ZIN0(7); + unit->mz0 = unit->mzn = ZIN0(8); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mxscale = 0.048269545768799; + unit->myscale = 0.035757929840258; + unit->mlevel = unit->my0 * unit->myscale; + SETCALC(Lorenz2DC_next); + ZOUT0(0) = 0.f; } -void Lorenz2DC_next(Lorenz2DC *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double s=ZIN0(2); - double r=ZIN0(3); - double b=ZIN0(4); - double h=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double z0=ZIN0(8); - double xn=unit->mxn; - double yn=unit->myn; - double zn=unit->mzn; - double yscale=unit->myscale; - int32 phase=unit->mphase; - double slope=unit->mslope; - double level=unit->mlevel; - double curve=unit->mcurve; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - if (z0 != unit->mz0) unit->mz0=zn=z0; - - int remain=inNumSamples; - do { - if (phase <= 0) { - float newx = xn + h * s * (yn - xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - float fphase = (minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - float newy = yn + h * (-xn * zn + r * xn - yn); - zn = zn + h * (xn * yn - b * zn); - - double ynm1=unit->myclip; - double yclip=newy * yscale; - yclip=Mirroring(-1.0, 1.0, yclip); - double midpnt=(ynm1 + yclip) * 0.5; - unit->myclip=yclip; - curve=2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - xn=newx; - yn=newy; - } - - int nsmps=sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out)=level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mphase=phase; - unit->mslope=slope; - unit->mcurve=curve; - unit->mlevel=level; - unit->mxn=xn; - unit->myn=yn; - unit->mzn=zn; +void Lorenz2DC_next(Lorenz2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double s = ZIN0(2); + double r = ZIN0(3); + double b = ZIN0(4); + double h = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double z0 = ZIN0(8); + double xn = unit->mxn; + double yn = unit->myn; + double zn = unit->mzn; + double yscale = unit->myscale; + int32 phase = unit->mphase; + double slope = unit->mslope; + double level = unit->mlevel; + double curve = unit->mcurve; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + if (z0 != unit->mz0) + unit->mz0 = zn = z0; + + int remain = inNumSamples; + do { + if (phase <= 0) { + float newx = xn + h * s * (yn - xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + float newy = yn + h * (-xn * zn + r * xn - yn); + zn = zn + h * (xn * yn - b * zn); + + double ynm1 = unit->myclip; + double yclip = newy * yscale; + yclip = Mirroring(-1.0, 1.0, yclip); + double midpnt = (ynm1 + yclip) * 0.5; + unit->myclip = yclip; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + xn = newx; + yn = newy; + } + + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mphase = phase; + unit->mslope = slope; + unit->mcurve = curve; + unit->mlevel = level; + unit->mxn = xn; + unit->myn = yn; + unit->mzn = zn; } -void LorenzTrig_Ctor(LorenzTrig *unit) -{ - unit->mx0=unit->mxn=ZIN0(6); - unit->my0=unit->myn=ZIN0(7); - unit->mz0=unit->mzn=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxscale=0.048269545768799; - unit->myscale=0.035757929840258; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(LorenzTrig_next); - ZOUT0(0) = 0.f; +void LorenzTrig_Ctor(LorenzTrig* unit) { + unit->mx0 = unit->mxn = ZIN0(6); + unit->my0 = unit->myn = ZIN0(7); + unit->mz0 = unit->mzn = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxscale = 0.048269545768799; + unit->myscale = 0.035757929840258; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(LorenzTrig_next); + ZOUT0(0) = 0.f; } -void LorenzTrig_next(LorenzTrig *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double s=ZIN0(2); - double r=ZIN0(3); - double b=ZIN0(4); - double h=ZIN0(5); - double x0=ZIN0(6); - double y0=ZIN0(7); - double z0=ZIN0(8); - double xn=unit->mxn; - double yn=unit->myn; - double zn=unit->mzn; - double yscale=unit->myscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - if (z0 != unit->mz0) unit->mz0=zn=z0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float newx = xn + h * s * (yn - xn); - double rate = (newx * unit->mxscale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - float newy = yn + h * (-xn * zn + r * xn - yn); - zn = zn + h * (xn * yn - b * zn); - - float yclip=(newy * yscale + 1) * 0.5; - yclip=Mirroring(0.0, 1.0, yclip); - xn=newx; - yn=newy; - ZXP(out) = yclip; - } else ZXP(out) = 0.f; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mzn=zn; +void LorenzTrig_next(LorenzTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double s = ZIN0(2); + double r = ZIN0(3); + double b = ZIN0(4); + double h = ZIN0(5); + double x0 = ZIN0(6); + double y0 = ZIN0(7); + double z0 = ZIN0(8); + double xn = unit->mxn; + double yn = unit->myn; + double zn = unit->mzn; + double yscale = unit->myscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + if (z0 != unit->mz0) + unit->mz0 = zn = z0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float newx = xn + h * s * (yn - xn); + double rate = (newx * unit->mxscale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + float newy = yn + h * (-xn * zn + r * xn - yn); + zn = zn + h * (xn * yn - b * zn); + + float yclip = (newy * yscale + 1) * 0.5; + yclip = Mirroring(0.0, 1.0, yclip); + xn = newx; + yn = newy; + ZXP(out) = yclip; + } else ZXP(out) = 0.f; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mzn = zn; } -void Standard2DN_Ctor(Standard2DN *unit) -{ - unit->mx0=ZIN0(3); - unit->my0=ZIN0(4); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.1591549430919; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Standard2DN_next); - ZOUT0(0) = 0.f; +void Standard2DN_Ctor(Standard2DN* unit) { + unit->mx0 = ZIN0(3); + unit->my0 = ZIN0(4); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.1591549430919; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Standard2DN_next); + ZOUT0(0) = 0.f; } -void Standard2DN_next(Standard2DN *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double k=ZIN0(2); - double x0=ZIN0(3); - double y0=ZIN0(4); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - yn = (yn + k * sin(xn)); - yn = mod2pi(yn); - xn = (xn + yn); - xn = mod2pi(xn); - double rate = xn * scale; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yclip=yn * scale * 2.0 - 1.0; - yclip=Mirroring(-1.0, 1.0, yclip); - } - - ZXP(out) = yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->myclip=yclip; +void Standard2DN_next(Standard2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double k = ZIN0(2); + double x0 = ZIN0(3); + double y0 = ZIN0(4); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + yn = (yn + k * sin(xn)); + yn = mod2pi(yn); + xn = (xn + yn); + xn = mod2pi(xn); + double rate = xn * scale; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yclip = yn * scale * 2.0 - 1.0; + yclip = Mirroring(-1.0, 1.0, yclip); + } + + ZXP(out) = yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->myclip = yclip; } -void Standard2DL_Ctor(Standard2DL *unit) -{ - unit->mx0=ZIN0(3); - unit->my0=ZIN0(4); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.1591549430919; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Standard2DL_next); - ZOUT0(0) = 0.f; +void Standard2DL_Ctor(Standard2DL* unit) { + unit->mx0 = ZIN0(3); + unit->my0 = ZIN0(4); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.1591549430919; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Standard2DL_next); + ZOUT0(0) = 0.f; } -void Standard2DL_next(Standard2DL *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double k=ZIN0(2); - double x0=ZIN0(3); - double y0=ZIN0(4); - double xn=unit->mxn; - double yn=unit->myn; - double ynm1=unit->mynm1; - double yclip=unit->myclip; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - yn = (yn + k * sin(xn)); - yn = mod2pi(yn); - xn = (xn + yn); - xn = mod2pi(xn); - double rate = xn * scale; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - ynm1=yclip; - yclip=yn * scale * 2.0 - 1.0; - yclip=Mirroring(-1.0, 1.0, yclip); - } - - ZXP(out) = (1-phase) * ynm1 + phase * yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mynm1=ynm1; - unit->myclip=yclip; +void Standard2DL_next(Standard2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double k = ZIN0(2); + double x0 = ZIN0(3); + double y0 = ZIN0(4); + double xn = unit->mxn; + double yn = unit->myn; + double ynm1 = unit->mynm1; + double yclip = unit->myclip; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + yn = (yn + k * sin(xn)); + yn = mod2pi(yn); + xn = (xn + yn); + xn = mod2pi(xn); + double rate = xn * scale; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + ynm1 = yclip; + yclip = yn * scale * 2.0 - 1.0; + yclip = Mirroring(-1.0, 1.0, yclip); + } + + ZXP(out) = (1 - phase) * ynm1 + phase * yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mynm1 = ynm1; + unit->myclip = yclip; } -void Standard2DC_Ctor(Standard2DC *unit) -{ - unit->mx0=ZIN0(3); - unit->my0=ZIN0(4); - unit->mphase=0; - unit->mslope=0.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.1591549430919; - unit->mlevel=unit->my0 * unit->mscale; - SETCALC(Standard2DC_next); - ZOUT0(0) = 0.f; +void Standard2DC_Ctor(Standard2DC* unit) { + unit->mx0 = ZIN0(3); + unit->my0 = ZIN0(4); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.1591549430919; + unit->mlevel = unit->my0 * unit->mscale; + SETCALC(Standard2DC_next); + ZOUT0(0) = 0.f; } -void Standard2DC_next(Standard2DC *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double k=ZIN0(2); - double x0=ZIN0(3); - double y0=ZIN0(4); - double xn=unit->mxn; - double yn=unit->myn; - double scale=unit->mscale; - int32 phase=unit->mphase; - double level=unit->mlevel; - double slope=unit->mslope; - double curve=unit->mcurve; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - - int remain=inNumSamples; - do { - if (phase <= 0) { - yn = (yn + k * sin(xn)); - yn = mod2pi(yn); - xn = (xn + yn); - xn = mod2pi(xn); - double rate = xn * scale; - rate=Mirroring(0.0, 1.0, rate); - float fphase = (minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate/sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - double ynm1=unit->myclip; - double yclip=yn * scale * 2.0 - 1.0; - yclip=Mirroring(-1.0, 1.0, yclip); - unit->myclip=yclip; - double midpnt = (ynm1 + yclip) * 0.5; - curve=2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - } - - int nsmps = sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out)=level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mphase=phase; - unit->mslope=slope; - unit->mcurve=curve; - unit->mlevel=level; - unit->mxn=xn; - unit->myn=yn; +void Standard2DC_next(Standard2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double k = ZIN0(2); + double x0 = ZIN0(3); + double y0 = ZIN0(4); + double xn = unit->mxn; + double yn = unit->myn; + double scale = unit->mscale; + int32 phase = unit->mphase; + double level = unit->mlevel; + double slope = unit->mslope; + double curve = unit->mcurve; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + + int remain = inNumSamples; + do { + if (phase <= 0) { + yn = (yn + k * sin(xn)); + yn = mod2pi(yn); + xn = (xn + yn); + xn = mod2pi(xn); + double rate = xn * scale; + rate = Mirroring(0.0, 1.0, rate); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + double ynm1 = unit->myclip; + double yclip = yn * scale * 2.0 - 1.0; + yclip = Mirroring(-1.0, 1.0, yclip); + unit->myclip = yclip; + double midpnt = (ynm1 + yclip) * 0.5; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + } + + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mphase = phase; + unit->mslope = slope; + unit->mcurve = curve; + unit->mlevel = level; + unit->mxn = xn; + unit->myn = yn; } -void StandardTrig_Ctor(StandardTrig *unit) -{ - unit->mx0=ZIN0(3); - unit->my0=ZIN0(4); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.1591549430919; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(StandardTrig_next); - ZOUT0(0) = 0.f; +void StandardTrig_Ctor(StandardTrig* unit) { + unit->mx0 = ZIN0(3); + unit->my0 = ZIN0(4); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.1591549430919; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(StandardTrig_next); + ZOUT0(0) = 0.f; } -void StandardTrig_next(StandardTrig *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double k=ZIN0(2); - double x0=ZIN0(3); - double y0=ZIN0(4); - double xn=unit->mxn; - double yn=unit->myn; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - yn = (yn + k * sin(xn)); - yn = mod2pi(yn); - xn = (xn + yn); - xn = mod2pi(xn); - double rate = xn * scale; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - float yclip=yn * scale; - yclip=Mirroring(0.0, 1.0, yclip); - ZXP(out) = yclip; - } else ZXP(out) = 0.f; - - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; +void StandardTrig_next(StandardTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double k = ZIN0(2); + double x0 = ZIN0(3); + double y0 = ZIN0(4); + double xn = unit->mxn; + double yn = unit->myn; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + yn = (yn + k * sin(xn)); + yn = mod2pi(yn); + xn = (xn + yn); + xn = mod2pi(xn); + double rate = xn * scale; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + float yclip = yn * scale; + yclip = Mirroring(0.0, 1.0, yclip); + ZXP(out) = yclip; + } else ZXP(out) = 0.f; + + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; } -void Gbman2DN_Ctor(Gbman2DN *unit) -{ - unit->mx0=ZIN0(2); - unit->my0=ZIN0(3); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.125; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Gbman2DN_next); - ZOUT0(0) = 0.f; +void Gbman2DN_Ctor(Gbman2DN* unit) { + unit->mx0 = ZIN0(2); + unit->my0 = ZIN0(3); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.125; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Gbman2DN_next); + ZOUT0(0) = 0.f; } -void Gbman2DN_next(Gbman2DN *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double x0=ZIN0(2); - double y0=ZIN0(3); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float last_x=xn; - if (last_x < 0.f) xn = 1 - yn - last_x; - else xn = 1 - yn + last_x; - double rate = (xn * scale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn=last_x; - yclip=yn * scale; - yclip=Mirroring(-1.0, 1.0, yclip); - } - - ZXP(out) = yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->myclip=yclip; +void Gbman2DN_next(Gbman2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double x0 = ZIN0(2); + double y0 = ZIN0(3); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float last_x = xn; + if (last_x < 0.f) + xn = 1 - yn - last_x; + else + xn = 1 - yn + last_x; + double rate = (xn * scale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = last_x; + yclip = yn * scale; + yclip = Mirroring(-1.0, 1.0, yclip); + } + + ZXP(out) = yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->myclip = yclip; } -void Gbman2DL_Ctor(Gbman2DL *unit) -{ - unit->mx0=ZIN0(2); - unit->my0=ZIN0(3); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.125; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(Gbman2DL_next); - ZOUT0(0) = 0.f; +void Gbman2DL_Ctor(Gbman2DL* unit) { + unit->mx0 = ZIN0(2); + unit->my0 = ZIN0(3); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.125; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(Gbman2DL_next); + ZOUT0(0) = 0.f; } -void Gbman2DL_next(Gbman2DL *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double x0=ZIN0(2); - double y0=ZIN0(3); - double xn=unit->mxn; - double yn=unit->myn; - double yclip=unit->myclip; - double ynm1=unit->mynm1; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float last_x=xn; - if (last_x < 0.f) xn = 1 - yn - last_x; - else xn = 1 - yn + last_x; - double rate = (xn * scale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - ynm1=yclip; - yn=last_x; - yclip=yn * scale; - yclip=Mirroring(-1.0, 1.0, yclip); - } - - ZXP(out) = (1-phase) * ynm1 + phase * yclip; - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; - unit->mynm1=ynm1; - unit->myclip=yclip; +void Gbman2DL_next(Gbman2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double x0 = ZIN0(2); + double y0 = ZIN0(3); + double xn = unit->mxn; + double yn = unit->myn; + double yclip = unit->myclip; + double ynm1 = unit->mynm1; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float last_x = xn; + if (last_x < 0.f) + xn = 1 - yn - last_x; + else + xn = 1 - yn + last_x; + double rate = (xn * scale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + ynm1 = yclip; + yn = last_x; + yclip = yn * scale; + yclip = Mirroring(-1.0, 1.0, yclip); + } + + ZXP(out) = (1 - phase) * ynm1 + phase * yclip; + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; + unit->mynm1 = ynm1; + unit->myclip = yclip; } -void Gbman2DC_Ctor(Gbman2DC *unit) -{ - unit->mx0=ZIN0(2); - unit->my0=ZIN0(3); - unit->mphase=0; - unit->mslope=0.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.125; - unit->mlevel=unit->my0 * unit->mscale; - SETCALC(Gbman2DC_next); - ZOUT0(0) = 0.f; +void Gbman2DC_Ctor(Gbman2DC* unit) { + unit->mx0 = ZIN0(2); + unit->my0 = ZIN0(3); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.125; + unit->mlevel = unit->my0 * unit->mscale; + SETCALC(Gbman2DC_next); + ZOUT0(0) = 0.f; } -void Gbman2DC_next(Gbman2DC *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double x0=ZIN0(2); - double y0=ZIN0(3); - double xn=unit->mxn; - double yn=unit->myn; - double scale=unit->mscale; - int32 phase=unit->mphase; - double slope=unit->mslope; - double curve=unit->mcurve; - double level=unit->mlevel; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - - int remain=inNumSamples; - do { - if (phase <= 0) { - float last_x=xn; - if (last_x < 0.f) xn = 1 - yn - last_x; - else xn = 1 - yn + last_x; - double rate = (xn * scale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - float fphase = (minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate/sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - double ynm1=unit->myclip; - yn=last_x; - double yclip=yn * scale; - yclip=Mirroring(-1.0, 1.0, yclip); - unit->myclip=yclip; - double midpnt = (ynm1 + yclip) * 0.5; - curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - } - - int nsmps = sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out)=level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mphase=phase; - unit->mslope=slope; - unit->mcurve=curve; - unit->mlevel=level; - unit->mxn=xn; - unit->myn=yn; +void Gbman2DC_next(Gbman2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double x0 = ZIN0(2); + double y0 = ZIN0(3); + double xn = unit->mxn; + double yn = unit->myn; + double scale = unit->mscale; + int32 phase = unit->mphase; + double slope = unit->mslope; + double curve = unit->mcurve; + double level = unit->mlevel; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + + int remain = inNumSamples; + do { + if (phase <= 0) { + float last_x = xn; + if (last_x < 0.f) + xn = 1 - yn - last_x; + else + xn = 1 - yn + last_x; + double rate = (xn * scale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + double ynm1 = unit->myclip; + yn = last_x; + double yclip = yn * scale; + yclip = Mirroring(-1.0, 1.0, yclip); + unit->myclip = yclip; + double midpnt = (ynm1 + yclip) * 0.5; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + } + + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mphase = phase; + unit->mslope = slope; + unit->mcurve = curve; + unit->mlevel = level; + unit->mxn = xn; + unit->myn = yn; } -void GbmanTrig_Ctor(GbmanTrig *unit) -{ - unit->mx0=ZIN0(2); - unit->my0=ZIN0(3); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mxn=unit->mx0; - unit->myn=unit->my0; - unit->mscale=0.125; - unit->mfreqMul=unit->mRate->mSampleDur; - SETCALC(GbmanTrig_next); - ZOUT0(0) = 0.f; +void GbmanTrig_Ctor(GbmanTrig* unit) { + unit->mx0 = ZIN0(2); + unit->my0 = ZIN0(3); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mxn = unit->mx0; + unit->myn = unit->my0; + unit->mscale = 0.125; + unit->mfreqMul = unit->mRate->mSampleDur; + SETCALC(GbmanTrig_next); + ZOUT0(0) = 0.f; } -void GbmanTrig_next(GbmanTrig *unit, int inNumSamples) -{ - float *out=ZOUT(0); - float minf=ZIN0(0); - float maxf=ZIN0(1); - double x0=ZIN0(2); - double y0=ZIN0(3); - double xn=unit->mxn; - double yn=unit->myn; - double scale=unit->mscale; - double phase=unit->mphase; - double speed=unit->mspeed; - - if (x0 != unit->mx0) unit->mx0=xn=x0; - if (y0 != unit->my0) unit->my0=yn=y0; - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - float last_x=xn; - if (last_x < 0.f) xn = 1 - yn - last_x; - else xn = 1 - yn + last_x; - double rate = (xn * scale + 1) * 0.5; - rate=Mirroring(0.0, 1.0, rate); - speed = (minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - yn=last_x; - float yclip=(yn * scale + 1) * 0.5; - yclip=Mirroring(0.0, 1.0, yclip); - ZXP(out) = yclip; - } else ZXP(out) = 0.f; - - phase += speed; - ); - - unit->mphase=phase; - unit->mspeed=speed; - unit->mxn=xn; - unit->myn=yn; +void GbmanTrig_next(GbmanTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float minf = ZIN0(0); + float maxf = ZIN0(1); + double x0 = ZIN0(2); + double y0 = ZIN0(3); + double xn = unit->mxn; + double yn = unit->myn; + double scale = unit->mscale; + double phase = unit->mphase; + double speed = unit->mspeed; + + if (x0 != unit->mx0) + unit->mx0 = xn = x0; + if (y0 != unit->my0) + unit->my0 = yn = y0; + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + float last_x = xn; + if (last_x < 0.f) + xn = 1 - yn - last_x; + else + xn = 1 - yn + last_x; + double rate = (xn * scale + 1) * 0.5; + rate = Mirroring(0.0, 1.0, rate); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + yn = last_x; + float yclip = (yn * scale + 1) * 0.5; + yclip = Mirroring(0.0, 1.0, yclip); + ZXP(out) = yclip; + } else ZXP(out) = 0.f; + + phase += speed;); + + unit->mphase = phase; + unit->mspeed = speed; + unit->mxn = xn; + unit->myn = yn; } void Fhn2DN_Ctor(Fhn2DN* unit) { - - unit->mun=unit->mu0=ZIN0(7); - unit->mwn=unit->mw0=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mfreqMul=unit->mRate->mSampleDur; - - SETCALC(Fhn2DN_next); - ZOUT0(0) = 0.f; + unit->mun = unit->mu0 = ZIN0(7); + unit->mwn = unit->mw0 = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mfreqMul = unit->mRate->mSampleDur; + + SETCALC(Fhn2DN_next); + ZOUT0(0) = 0.f; } -void Fhn2DN_next(Fhn2DN *unit, int inNumSamples) { - - float *out = ZOUT(0); - - double phase=unit->mphase; - double speed=unit->mspeed; - - double u=unit->mun; - double w=unit->mwn; - double uclip=unit->muclip; - double u0=ZIN0(7); - double w0=ZIN0(8); - - if (u0 != unit->mu0) u=u0; - if (w0 != unit->mw0) w=w0; - - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - - double minf=ZIN0(0); - double maxf=ZIN0(1); - double urate=ZIN0(2); - double wrate=ZIN0(3); - double b0=ZIN0(4); - double b1=ZIN0(5); - double i=ZIN0(6); - double dudt=urate*(u-(0.33333*u*u*u)-w+i); - double dwdt=wrate*(b0+b1*u-w); - - u+=dudt; - w+=dwdt; - - double rate=(w * 0.5 + 1) * 0.5; - rate=sc_max(rate, 0.0); - speed=(minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - if ((u>1.0) || (u<-1.0)) u=fabs(fmod((u-1.0),4.0)-2.0)-1.0; - uclip=u * 0.3; - unit->muclip=uclip; - } - - ZXP(out) = uclip; - phase += speed; - ); - - unit->mun=u; - unit->mwn=w; - unit->mphase=phase; - unit->mspeed=speed; +void Fhn2DN_next(Fhn2DN* unit, int inNumSamples) { + float* out = ZOUT(0); + + double phase = unit->mphase; + double speed = unit->mspeed; + + double u = unit->mun; + double w = unit->mwn; + double uclip = unit->muclip; + double u0 = ZIN0(7); + double w0 = ZIN0(8); + + if (u0 != unit->mu0) + u = u0; + if (w0 != unit->mw0) + w = w0; + + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + + double minf = ZIN0(0); + double maxf = ZIN0(1); + double urate = ZIN0(2); + double wrate = ZIN0(3); + double b0 = ZIN0(4); + double b1 = ZIN0(5); + double i = ZIN0(6); + double dudt = urate * (u - (0.33333 * u * u * u) - w + i); + double dwdt = wrate * (b0 + b1 * u - w); + + u += dudt; + w += dwdt; + + double rate = (w * 0.5 + 1) * 0.5; + rate = sc_max(rate, 0.0); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + if ((u > 1.0) || (u < -1.0)) + u = fabs(fmod((u - 1.0), 4.0) - 2.0) - 1.0; + uclip = u * 0.3; + unit->muclip = uclip; + } + + ZXP(out) = uclip; + phase += speed;); + + unit->mun = u; + unit->mwn = w; + unit->mphase = phase; + unit->mspeed = speed; } void Fhn2DL_Ctor(Fhn2DL* unit) { - - unit->mun=unit->mu0=ZIN0(7); - unit->mwn=unit->mw0=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mfreqMul=unit->mRate->mSampleDur; - - SETCALC(Fhn2DL_next); - ZOUT0(0) = 0.f; + unit->mun = unit->mu0 = ZIN0(7); + unit->mwn = unit->mw0 = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mfreqMul = unit->mRate->mSampleDur; + + SETCALC(Fhn2DL_next); + ZOUT0(0) = 0.f; } -void Fhn2DL_next(Fhn2DL *unit, int inNumSamples) { - - float *out = ZOUT(0); - - double phase=unit->mphase; - double speed=unit->mspeed; - - double u=unit->mun; - double uclip=unit->muclip; - double um1=unit->um1; - double w=unit->mwn; - double u0=ZIN0(7); - double w0=ZIN0(8); - - if (u0 != unit->mu0) u=u0; - if (w0 != unit->mw0) w=w0; - - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - - double minf=ZIN0(0); - double maxf=ZIN0(1); - double urate=ZIN0(2); - double wrate=ZIN0(3); - double b0=ZIN0(4); - double b1=ZIN0(5); - double i=ZIN0(6); - double dudt=urate*(u-(0.33333*u*u*u)-w+i); - double dwdt=wrate*(b0+b1*u-w); - - um1=uclip; - u+=dudt; - w+=dwdt; - - double rate=(w * 0.5 + 1) * 0.5; - rate=sc_max(rate, 0.0); - speed=(minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - if ((u>1.0) || (u<-1.0)) u=fabs(fmod((u-1.0),4.0)-2.0)-1.0; - uclip=u * 0.3; - unit->muclip=uclip; - } - - ZXP(out) = (1-phase) * um1 + phase * uclip; - phase += speed; - ); - - unit->mun=u; - unit->um1=um1; - unit->mwn=w; - unit->mphase=phase; - unit->mspeed=speed; +void Fhn2DL_next(Fhn2DL* unit, int inNumSamples) { + float* out = ZOUT(0); + + double phase = unit->mphase; + double speed = unit->mspeed; + + double u = unit->mun; + double uclip = unit->muclip; + double um1 = unit->um1; + double w = unit->mwn; + double u0 = ZIN0(7); + double w0 = ZIN0(8); + + if (u0 != unit->mu0) + u = u0; + if (w0 != unit->mw0) + w = w0; + + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + + double minf = ZIN0(0); + double maxf = ZIN0(1); + double urate = ZIN0(2); + double wrate = ZIN0(3); + double b0 = ZIN0(4); + double b1 = ZIN0(5); + double i = ZIN0(6); + double dudt = urate * (u - (0.33333 * u * u * u) - w + i); + double dwdt = wrate * (b0 + b1 * u - w); + + um1 = uclip; + u += dudt; + w += dwdt; + + double rate = (w * 0.5 + 1) * 0.5; + rate = sc_max(rate, 0.0); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + if ((u > 1.0) || (u < -1.0)) + u = fabs(fmod((u - 1.0), 4.0) - 2.0) - 1.0; + uclip = u * 0.3; + unit->muclip = uclip; + } + + ZXP(out) = (1 - phase) * um1 + phase * uclip; + phase += speed;); + + unit->mun = u; + unit->um1 = um1; + unit->mwn = w; + unit->mphase = phase; + unit->mspeed = speed; } void Fhn2DC_Ctor(Fhn2DC* unit) { - - unit->mun=unit->mu0=ZIN0(7); - unit->mwn=unit->mw0=ZIN0(8); - unit->mphase=0; - unit->mslope=0.f; - unit->mlevel=unit->mw0; - - SETCALC(Fhn2DC_next); - ZOUT0(0) = 0.f; + unit->mun = unit->mu0 = ZIN0(7); + unit->mwn = unit->mw0 = ZIN0(8); + unit->mphase = 0; + unit->mslope = 0.f; + unit->mlevel = unit->mw0; + + SETCALC(Fhn2DC_next); + ZOUT0(0) = 0.f; } -void Fhn2DC_next(Fhn2DC *unit, int inNumSamples) { - - float *out = ZOUT(0); - - int32 phase=unit->mphase; - - double u=unit->mun; - double um1=unit->um1; - double w=unit->mwn; - double u0=ZIN0(7); - double w0=ZIN0(8); - double level=unit->mlevel; - double slope=unit->mslope; - double curve=unit->mcurve; - - if (u0 != unit->mu0) u=u0; - if (w0 != unit->mw0) w=w0; - int remain=inNumSamples; - do { - if (phase <= 0) { - double minf=ZIN0(0); - double maxf=ZIN0(1); - double urate=ZIN0(2); - double wrate=ZIN0(3); - double b0=ZIN0(4); - double b1=ZIN0(5); - double i=ZIN0(6); - double dudt=urate*(u-(0.33333*u*u*u)-w+i); - double dwdt=wrate*(b0+b1*u-w); - - um1=unit->muclip; - u+=dudt; - w+=dwdt; - - double rate=(w * 0.5 + 1) * 0.5; - rate=sc_max(rate, 0.); - float fphase=(minf + ((maxf-minf)*rate)); - phase = (int32)(unit->mRate->mSampleRate/sc_max(fphase, 0.001f)); - phase = sc_max(2, phase); - - if ((u>1.0) || (u<-1.0)) u=fabs(fmod((u-1.0),4.0)-2.0)-1.0; - unit->muclip=u * 0.3; - double midpnt=(um1 + unit->muclip) * 0.5; - curve=2.f * (midpnt - level - phase * slope) / (phase * phase + phase); - } - - int nsmps=sc_min(phase, remain); - phase -= nsmps; - remain -= nsmps; - LOOP(nsmps, - ZXP(out)=level; - slope += curve; - level += slope; - ); - } while (remain); - - unit->mun=u; - unit->mwn=w; - unit->mphase=phase; - unit->mslope=slope; - unit->mcurve=curve; - unit->mlevel=level; +void Fhn2DC_next(Fhn2DC* unit, int inNumSamples) { + float* out = ZOUT(0); + + int32 phase = unit->mphase; + + double u = unit->mun; + double um1 = unit->um1; + double w = unit->mwn; + double u0 = ZIN0(7); + double w0 = ZIN0(8); + double level = unit->mlevel; + double slope = unit->mslope; + double curve = unit->mcurve; + + if (u0 != unit->mu0) + u = u0; + if (w0 != unit->mw0) + w = w0; + int remain = inNumSamples; + do { + if (phase <= 0) { + double minf = ZIN0(0); + double maxf = ZIN0(1); + double urate = ZIN0(2); + double wrate = ZIN0(3); + double b0 = ZIN0(4); + double b1 = ZIN0(5); + double i = ZIN0(6); + double dudt = urate * (u - (0.33333 * u * u * u) - w + i); + double dwdt = wrate * (b0 + b1 * u - w); + + um1 = unit->muclip; + u += dudt; + w += dwdt; + + double rate = (w * 0.5 + 1) * 0.5; + rate = sc_max(rate, 0.); + float fphase = (minf + ((maxf - minf) * rate)); + phase = (int32)(unit->mRate->mSampleRate / sc_max(fphase, 0.001f)); + phase = sc_max(2, phase); + + if ((u > 1.0) || (u < -1.0)) + u = fabs(fmod((u - 1.0), 4.0) - 2.0) - 1.0; + unit->muclip = u * 0.3; + double midpnt = (um1 + unit->muclip) * 0.5; + curve = 2.f * (midpnt - level - phase * slope) / (phase * phase + phase); + } + + int nsmps = sc_min(phase, remain); + phase -= nsmps; + remain -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + + unit->mun = u; + unit->mwn = w; + unit->mphase = phase; + unit->mslope = slope; + unit->mcurve = curve; + unit->mlevel = level; } void FhnTrig_Ctor(FhnTrig* unit) { - - unit->mun=unit->mu0=ZIN0(7); - unit->mwn=unit->mw0=ZIN0(8); - unit->mphase=1.f; - unit->mspeed=100.f; - unit->mfreqMul=unit->mRate->mSampleDur; - - SETCALC(FhnTrig_next); - ZOUT0(0) = 0.f; + unit->mun = unit->mu0 = ZIN0(7); + unit->mwn = unit->mw0 = ZIN0(8); + unit->mphase = 1.f; + unit->mspeed = 100.f; + unit->mfreqMul = unit->mRate->mSampleDur; + + SETCALC(FhnTrig_next); + ZOUT0(0) = 0.f; } -void FhnTrig_next(FhnTrig *unit, int inNumSamples) { - - float *out = ZOUT(0); - - double phase=unit->mphase; - double speed=unit->mspeed; - - double u=unit->mun; - double w=unit->mwn; - double u0=ZIN0(7); - double w0=ZIN0(8); - - if (u0 != unit->mu0) u=u0; - if (w0 != unit->mw0) w=w0; - - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - - double minf=ZIN0(0); - double maxf=ZIN0(1); - double urate=ZIN0(2); - double wrate=ZIN0(3); - double b0=ZIN0(4); - double b1=ZIN0(5); - double i=ZIN0(6); - double dudt=urate*(u-(0.33333*u*u*u)-w+i); - double dwdt=wrate*(b0+b1*u-w); - - u+=dudt; - w+=dwdt; - - double rate=(w * 0.5 + 1) * 0.5; - rate=sc_max(rate, 0.0); - speed=(minf + ((maxf-minf)*rate)) * unit->mfreqMul; - - if ((u>1.0) || (u<-1.0)) u=fabs(fmod((u-1.0),4.0)-2.0)-1.0; - ZXP(out) = (u * 0.3 + 1) * 0.5; - } else { - ZXP(out) = 0.f; - } - phase += speed; - ); - - unit->mun=u; - unit->mwn=w; - unit->mphase=phase; - unit->mspeed=speed; +void FhnTrig_next(FhnTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + + double phase = unit->mphase; + double speed = unit->mspeed; + + double u = unit->mun; + double w = unit->mwn; + double u0 = ZIN0(7); + double w0 = ZIN0(8); + + if (u0 != unit->mu0) + u = u0; + if (w0 != unit->mw0) + w = w0; + + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + + double minf = ZIN0(0); + double maxf = ZIN0(1); + double urate = ZIN0(2); + double wrate = ZIN0(3); + double b0 = ZIN0(4); + double b1 = ZIN0(5); + double i = ZIN0(6); + double dudt = urate * (u - (0.33333 * u * u * u) - w + i); + double dwdt = wrate * (b0 + b1 * u - w); + + u += dudt; + w += dwdt; + + double rate = (w * 0.5 + 1) * 0.5; + rate = sc_max(rate, 0.0); + speed = (minf + ((maxf - minf) * rate)) * unit->mfreqMul; + + if ((u > 1.0) || (u < -1.0)) + u = fabs(fmod((u - 1.0), 4.0) - 2.0) - 1.0; + ZXP(out) = (u * 0.3 + 1) * 0.5; + } else { ZXP(out) = 0.f; } phase += speed;); + + unit->mun = u; + unit->mwn = w; + unit->mphase = phase; + unit->mspeed = speed; } -PluginLoad(BhobChaos) -{ - ft = inTable; - - DefineSimpleUnit(Henon2DN); - DefineSimpleUnit(Henon2DL); - DefineSimpleUnit(Henon2DC); - DefineSimpleUnit(HenonTrig); - DefineSimpleUnit(Latoocarfian2DN); - DefineSimpleUnit(Latoocarfian2DL); - DefineSimpleUnit(Latoocarfian2DC); - DefineSimpleUnit(LatoocarfianTrig); - DefineSimpleUnit(Lorenz2DN); - DefineSimpleUnit(Lorenz2DL); - DefineSimpleUnit(Lorenz2DC); - DefineSimpleUnit(LorenzTrig); - DefineSimpleUnit(Standard2DN); - DefineSimpleUnit(Standard2DL); - DefineSimpleUnit(Standard2DC); - DefineSimpleUnit(StandardTrig); - DefineSimpleUnit(Gbman2DN); - DefineSimpleUnit(Gbman2DL); - DefineSimpleUnit(Gbman2DC); - DefineSimpleUnit(GbmanTrig); - DefineSimpleUnit(Fhn2DN); - DefineSimpleUnit(Fhn2DL); - DefineSimpleUnit(Fhn2DC); - DefineSimpleUnit(FhnTrig); +PluginLoad(BhobChaos) { + ft = inTable; + + DefineSimpleUnit(Henon2DN); + DefineSimpleUnit(Henon2DL); + DefineSimpleUnit(Henon2DC); + DefineSimpleUnit(HenonTrig); + DefineSimpleUnit(Latoocarfian2DN); + DefineSimpleUnit(Latoocarfian2DL); + DefineSimpleUnit(Latoocarfian2DC); + DefineSimpleUnit(LatoocarfianTrig); + DefineSimpleUnit(Lorenz2DN); + DefineSimpleUnit(Lorenz2DL); + DefineSimpleUnit(Lorenz2DC); + DefineSimpleUnit(LorenzTrig); + DefineSimpleUnit(Standard2DN); + DefineSimpleUnit(Standard2DL); + DefineSimpleUnit(Standard2DC); + DefineSimpleUnit(StandardTrig); + DefineSimpleUnit(Gbman2DN); + DefineSimpleUnit(Gbman2DL); + DefineSimpleUnit(Gbman2DC); + DefineSimpleUnit(GbmanTrig); + DefineSimpleUnit(Fhn2DN); + DefineSimpleUnit(Fhn2DL); + DefineSimpleUnit(Fhn2DC); + DefineSimpleUnit(FhnTrig); } diff --git a/source/BhobUGens/BhobFFT.cpp b/source/BhobUGens/BhobFFT.cpp index 424f04f6f4..766ee9ee9d 100644 --- a/source/BhobUGens/BhobFFT.cpp +++ b/source/BhobUGens/BhobFFT.cpp @@ -1,7 +1,7 @@ /* various FFT manipulations by bhob rainey http://www.bhobrainey.net SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com + 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 @@ -21,373 +21,350 @@ SuperCollider real time audio synthesis system #include "SC_fftlib.h" #include "FFT_UGens.h" -struct PV_MagScale : public PV_Unit -{ - uint32 m_scalebufnum; - SndBuf *m_scalebuf; +struct PV_MagScale : public PV_Unit { + uint32 m_scalebufnum; + SndBuf* m_scalebuf; }; -#define MAKE_TEMP_BUF2 \ - if (!unit->m_tempbuf) { \ - unit->m_tempbuf = (float*)RTAlloc(unit->mWorld, buf1->samples * sizeof(float)); \ - unit->m_numbins = numbins; \ - } else if (numbins != unit->m_numbins) return; +#define MAKE_TEMP_BUF2 \ + if (!unit->m_tempbuf) { \ + unit->m_tempbuf = (float*)RTAlloc(unit->mWorld, buf1->samples * sizeof(float)); \ + unit->m_numbins = numbins; \ + } else if (numbins != unit->m_numbins) \ + return; -extern "C" -{ - void PV_CommonMag_Ctor(PV_Unit *unit); - void PV_CommonMag_next(PV_Unit *unit, int inNumSamples); +extern "C" { +void PV_CommonMag_Ctor(PV_Unit* unit); +void PV_CommonMag_next(PV_Unit* unit, int inNumSamples); - void PV_CommonMul_Ctor(PV_Unit *unit); - void PV_CommonMul_next(PV_Unit *unit, int inNumSamples); +void PV_CommonMul_Ctor(PV_Unit* unit); +void PV_CommonMul_next(PV_Unit* unit, int inNumSamples); - void PV_MagMinus_Ctor(PV_Unit *unit); - void PV_MagMinus_next(PV_Unit *unit, int inNumSamples); +void PV_MagMinus_Ctor(PV_Unit* unit); +void PV_MagMinus_next(PV_Unit* unit, int inNumSamples); - void PV_MagGate_Ctor(PV_Unit *unit); - void PV_MagGate_next(PV_Unit *unit, int inNumSamples); +void PV_MagGate_Ctor(PV_Unit* unit); +void PV_MagGate_next(PV_Unit* unit, int inNumSamples); - void PV_Compander_Ctor(PV_Unit *unit); - void PV_Compander_next(PV_Unit *unit, int inNumSamples); +void PV_Compander_Ctor(PV_Unit* unit); +void PV_Compander_next(PV_Unit* unit, int inNumSamples); - void PV_MagScale_Ctor(PV_MagScale *unit); - void PV_MagScale_next(PV_MagScale* unit, int inNumSamples); +void PV_MagScale_Ctor(PV_MagScale* unit); +void PV_MagScale_next(PV_MagScale* unit, int inNumSamples); - void PV_Morph_Ctor(PV_Unit *unit); - void PV_Morph_next(PV_Unit *unit, int inNumSamples); +void PV_Morph_Ctor(PV_Unit* unit); +void PV_Morph_next(PV_Unit* unit, int inNumSamples); - void PV_XFade_Ctor(PV_Unit *unit); - void PV_XFade_next(PV_Unit *unit, int inNumSamples); +void PV_XFade_Ctor(PV_Unit* unit); +void PV_XFade_next(PV_Unit* unit, int inNumSamples); - void PV_SoftWipe_Ctor(PV_Unit *unit); - void PV_SoftWipe_next(PV_Unit *unit, int inNumSamples); +void PV_SoftWipe_Ctor(PV_Unit* unit); +void PV_SoftWipe_next(PV_Unit* unit, int inNumSamples); - void PV_Cutoff_Ctor(PV_Unit *unit); - void PV_Cutoff_next(PV_Unit *unit, int inNumSamples); +void PV_Cutoff_Ctor(PV_Unit* unit); +void PV_Cutoff_next(PV_Unit* unit, int inNumSamples); } // these are already defined in PV_ThrirdParty.cpp. so build doest work on pbuilder - br #if gccversion >= 4 -SCPolarBuf* ToPolarApx(SndBuf *buf) -{ - if (buf->coord == coord_Complex) { - SCComplexBuf* p = (SCComplexBuf*)buf->data; - int numbins = buf->samples - 2 >> 1; - for (int i=0; ibin[i].ToPolarApxInPlace(); - } - buf->coord = coord_Polar; - } - return (SCPolarBuf*)buf->data; +SCPolarBuf* ToPolarApx(SndBuf* buf) { + if (buf->coord == coord_Complex) { + SCComplexBuf* p = (SCComplexBuf*)buf->data; + int numbins = buf->samples - 2 >> 1; + for (int i = 0; i < numbins; ++i) { + p->bin[i].ToPolarApxInPlace(); + } + buf->coord = coord_Polar; + } + return (SCPolarBuf*)buf->data; } -SCComplexBuf* ToComplexApx(SndBuf *buf) -{ - if (buf->coord == coord_Polar) { - SCPolarBuf* p = (SCPolarBuf*)buf->data; - int numbins = buf->samples - 2 >> 1; - for (int i=0; ibin[i].ToComplexApxInPlace(); - } - buf->coord = coord_Complex; - } - return (SCComplexBuf*)buf->data; +SCComplexBuf* ToComplexApx(SndBuf* buf) { + if (buf->coord == coord_Polar) { + SCPolarBuf* p = (SCPolarBuf*)buf->data; + int numbins = buf->samples - 2 >> 1; + for (int i = 0; i < numbins; ++i) { + p->bin[i].ToComplexApxInPlace(); + } + buf->coord = coord_Complex; + } + return (SCComplexBuf*)buf->data; } #endif // gccversion >= 4 -void PV_CommonMag_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 +void PV_CommonMag_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 - SCPolarBuf *p = ToPolarApx(buf1); - SCPolarBuf *q = ToPolarApx(buf2); - float tolerance=ZIN0(2); - float remove=ZIN0(3); + SCPolarBuf* p = ToPolarApx(buf1); + SCPolarBuf* q = ToPolarApx(buf2); + float tolerance = ZIN0(2); + float remove = ZIN0(3); - p->dc = q->dc; - p->nyq = q->nyq; - for (int i=0; ibin[i].mag; - float mag2 = q->bin[i].mag; - if (((mag2 - tolerance) >= mag1) || ((mag2 + tolerance) <= mag1)) p->bin[i].mag = mag1 * remove; - } + p->dc = q->dc; + p->nyq = q->nyq; + for (int i = 0; i < numbins; ++i) { + float mag1 = p->bin[i].mag; + float mag2 = q->bin[i].mag; + if (((mag2 - tolerance) >= mag1) || ((mag2 + tolerance) <= mag1)) + p->bin[i].mag = mag1 * remove; + } } -void PV_CommonMag_Ctor(PV_Unit *unit) -{ - SETCALC(PV_CommonMag_next); - ZOUT0(0) = ZIN0(0); +void PV_CommonMag_Ctor(PV_Unit* unit) { + SETCALC(PV_CommonMag_next); + ZOUT0(0) = ZIN0(0); } -void PV_CommonMul_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 - - SCPolarBuf *p = ToPolarApx(buf1); - SCPolarBuf *q = ToPolarApx(buf2); - float tolerance=ZIN0(2); - float remove=ZIN0(3); - - p->dc *= q->dc; - p->nyq *= q->nyq; - for (int i=0; ibin[i].mag; - float mag2 = q->bin[i].mag; - if (((mag2 - tolerance) >= mag1) || ((mag2 + tolerance) <= mag1)) { - p->bin[i].mag = mag1 * remove; - } else { - p->bin[i].mag *= mag2; - } - } +void PV_CommonMul_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 + + SCPolarBuf* p = ToPolarApx(buf1); + SCPolarBuf* q = ToPolarApx(buf2); + float tolerance = ZIN0(2); + float remove = ZIN0(3); + + p->dc *= q->dc; + p->nyq *= q->nyq; + for (int i = 0; i < numbins; ++i) { + float mag1 = p->bin[i].mag; + float mag2 = q->bin[i].mag; + if (((mag2 - tolerance) >= mag1) || ((mag2 + tolerance) <= mag1)) { + p->bin[i].mag = mag1 * remove; + } else { + p->bin[i].mag *= mag2; + } + } } -void PV_CommonMul_Ctor(PV_Unit *unit) -{ - SETCALC(PV_CommonMul_next); - ZOUT0(0) = ZIN0(0); +void PV_CommonMul_Ctor(PV_Unit* unit) { + SETCALC(PV_CommonMul_next); + ZOUT0(0) = ZIN0(0); } -void PV_MagMinus_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 +void PV_MagMinus_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 - SCPolarBuf *p = ToPolarApx(buf1); - SCPolarBuf *q = ToPolarApx(buf2); - float remove=ZIN0(2); + SCPolarBuf* p = ToPolarApx(buf1); + SCPolarBuf* q = ToPolarApx(buf2); + float remove = ZIN0(2); - for (int i=0; ibin[i].mag = sc_max(p->bin[i].mag - q->bin[i].mag*remove, 0.f); - } + for (int i = 0; i < numbins; ++i) { + p->bin[i].mag = sc_max(p->bin[i].mag - q->bin[i].mag * remove, 0.f); + } } -void PV_MagMinus_Ctor(PV_Unit *unit) -{ - SETCALC(PV_MagMinus_next); - ZOUT0(0) = ZIN0(0); +void PV_MagMinus_Ctor(PV_Unit* unit) { + SETCALC(PV_MagMinus_next); + ZOUT0(0) = ZIN0(0); } -void PV_MagGate_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF - - SCPolarBuf *p = ToPolarApx(buf); - float thresh=ZIN0(1); - float reduce=ZIN0(2); - - for (int i=0; ibin[i].mag; - if (thresh < 0.f) { - if (mag > fabs(thresh)) p->bin[i].mag=mag * reduce; - } else if (mag < thresh) p->bin[i].mag=mag * reduce; - } +void PV_MagGate_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF + + SCPolarBuf* p = ToPolarApx(buf); + float thresh = ZIN0(1); + float reduce = ZIN0(2); + + for (int i = 0; i < numbins; ++i) { + float mag = p->bin[i].mag; + if (thresh < 0.f) { + if (mag > fabs(thresh)) + p->bin[i].mag = mag * reduce; + } else if (mag < thresh) + p->bin[i].mag = mag * reduce; + } } -void PV_MagGate_Ctor(PV_Unit *unit) -{ - SETCALC(PV_MagGate_next); - ZOUT0(0) = ZIN0(0); +void PV_MagGate_Ctor(PV_Unit* unit) { + SETCALC(PV_MagGate_next); + ZOUT0(0) = ZIN0(0); } -void PV_Compander_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF - - SCPolarBuf *p = ToPolarApx(buf); - float thresh=ZIN0(1); - float slope_below=ZIN0(2); - float slope_above=ZIN0(3); - - for (int i=0; ibin[i].mag; - if (mag < thresh) { - if (slope_below != 1.f) { - float gain = pow(mag / thresh, slope_below - 1.f); - float32 absx = fabs(gain); - gain = (absx > (float32)1e-15 && absx < (float32)1e15) ? gain : (float32)1.; - p->bin[i].mag=mag * gain; - } - } else { - if (slope_above != 1.f) { - p->bin[i].mag=mag * (pow(mag / thresh, slope_above - 1.f)); - } - } - } +void PV_Compander_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF + + SCPolarBuf* p = ToPolarApx(buf); + float thresh = ZIN0(1); + float slope_below = ZIN0(2); + float slope_above = ZIN0(3); + + for (int i = 0; i < numbins; ++i) { + float mag = p->bin[i].mag; + if (mag < thresh) { + if (slope_below != 1.f) { + float gain = pow(mag / thresh, slope_below - 1.f); + float32 absx = fabs(gain); + gain = (absx > (float32)1e-15 && absx < (float32)1e15) ? gain : (float32)1.; + p->bin[i].mag = mag * gain; + } + } else { + if (slope_above != 1.f) { + p->bin[i].mag = mag * (pow(mag / thresh, slope_above - 1.f)); + } + } + } } -void PV_Compander_Ctor(PV_Unit *unit) -{ - SETCALC(PV_Compander_next); - ZOUT0(0) = ZIN0(0); +void PV_Compander_Ctor(PV_Unit* unit) { + SETCALC(PV_Compander_next); + ZOUT0(0) = ZIN0(0); } -void PV_MagScale_next(PV_MagScale *unit, int inNumSamples) -{ - PV_GET_BUF - float bufin = ZIN0(1); - uint32 scalebuf = (uint32)bufin; - if (scalebuf != unit->m_scalebufnum) { - if (scalebuf + 1 >= world->mNumSndBufs) scalebuf = 0; - unit->m_scalebufnum = scalebuf; - } - SndBuf *scales = world->mSndBufs + scalebuf; - float frac = bufin - (int)bufin; - if (frac == 0.f) { - float *scaleData1 = scales[0].data; - SCPolarBuf *p = ToPolarApx(buf); - for (int i=0; ibin[i].mag = p->bin[i].mag * scaleData1[i]; - } - } else { - float *scaleData1 = scales[0].data; - float *scaleData2 = scales[1].data; - SCPolarBuf *p = ToPolarApx(buf); - for (int i=0; ibin[i].mag = p->bin[i].mag * (scaleData1[i] * (1-frac) + scaleData2[i] * frac); - } - } +void PV_MagScale_next(PV_MagScale* unit, int inNumSamples) { + PV_GET_BUF + float bufin = ZIN0(1); + uint32 scalebuf = (uint32)bufin; + if (scalebuf != unit->m_scalebufnum) { + if (scalebuf + 1 >= world->mNumSndBufs) + scalebuf = 0; + unit->m_scalebufnum = scalebuf; + } + SndBuf* scales = world->mSndBufs + scalebuf; + float frac = bufin - (int)bufin; + if (frac == 0.f) { + float* scaleData1 = scales[0].data; + SCPolarBuf* p = ToPolarApx(buf); + for (int i = 0; i < numbins; ++i) { + p->bin[i].mag = p->bin[i].mag * scaleData1[i]; + } + } else { + float* scaleData1 = scales[0].data; + float* scaleData2 = scales[1].data; + SCPolarBuf* p = ToPolarApx(buf); + for (int i = 0; i < numbins; ++i) { + p->bin[i].mag = p->bin[i].mag * (scaleData1[i] * (1 - frac) + scaleData2[i] * frac); + } + } } -void PV_MagScale_Ctor(PV_MagScale *unit) -{ - SETCALC(PV_MagScale_next); - ZOUT0(0) = ZIN0(0); +void PV_MagScale_Ctor(PV_MagScale* unit) { + SETCALC(PV_MagScale_next); + ZOUT0(0) = ZIN0(0); } -void PV_XFade_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 - float fade=ZIN0(2); +void PV_XFade_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 + float fade = ZIN0(2); - SCComplexBuf *p = ToComplexApx(buf1); - SCComplexBuf *q = ToComplexApx(buf2); + SCComplexBuf* p = ToComplexApx(buf1); + SCComplexBuf* q = ToComplexApx(buf2); - p->dc = q->dc; - p->nyq = q->nyq; + p->dc = q->dc; + p->nyq = q->nyq; - for (int i=0; ibin[i].real=(1-fade) * p->bin[i].real + fade * q->bin[i].real; - p->bin[i].imag=(1-fade) * p->bin[i].imag + fade * q->bin[i].imag; - } + for (int i = 0; i < numbins; ++i) { + p->bin[i].real = (1 - fade) * p->bin[i].real + fade * q->bin[i].real; + p->bin[i].imag = (1 - fade) * p->bin[i].imag + fade * q->bin[i].imag; + } } -void PV_XFade_Ctor(PV_Unit *unit) -{ - SETCALC(PV_XFade_next); - ZOUT0(0) = ZIN0(0); +void PV_XFade_Ctor(PV_Unit* unit) { + SETCALC(PV_XFade_next); + ZOUT0(0) = ZIN0(0); } -void PV_Morph_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 - float morph=ZIN0(2); +void PV_Morph_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 + float morph = ZIN0(2); - SCPolarBuf *p = ToPolarApx(buf1); - SCPolarBuf *q = ToPolarApx(buf2); + SCPolarBuf* p = ToPolarApx(buf1); + SCPolarBuf* q = ToPolarApx(buf2); - p->dc = q->dc; - p->nyq = q->nyq; + p->dc = q->dc; + p->nyq = q->nyq; - for (int i=0; ibin[i].mag=(1-morph) * p->bin[i].mag + morph * q->bin[i].mag; - p->bin[i].phase=(1-morph) * p->bin[i].phase + morph * q->bin[i].phase; - } + for (int i = 0; i < numbins; ++i) { + p->bin[i].mag = (1 - morph) * p->bin[i].mag + morph * q->bin[i].mag; + p->bin[i].phase = (1 - morph) * p->bin[i].phase + morph * q->bin[i].phase; + } } -void PV_Morph_Ctor(PV_Unit *unit) -{ - SETCALC(PV_Morph_next); - ZOUT0(0) = ZIN0(0); +void PV_Morph_Ctor(PV_Unit* unit) { + SETCALC(PV_Morph_next); + ZOUT0(0) = ZIN0(0); } -void PV_SoftWipe_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF2 - - SCComplexBuf *p = (SCComplexBuf*)buf1->data; - SCComplexBuf *q = (SCComplexBuf*)buf2->data; - - float wipe = ZIN0(2) * numbins; - int iwipe = (int)wipe; - float frac = fabs(wipe - iwipe); - if (iwipe > 0) { - iwipe = sc_min(iwipe, numbins); - for (int i=0; i < iwipe-1; ++i) { - p->bin[i]=q->bin[i]; - } - p->bin[iwipe]=(1-frac) * p->bin[iwipe] + frac * q->bin[iwipe]; - } else if (iwipe < 0) { - iwipe = sc_max(iwipe, -numbins); - int lastbin=numbins+iwipe; - for (int i=lastbin+1; i < numbins; ++i) { - p->bin[i]=q->bin[i]; - } - p->bin[lastbin]=(1-frac) * p->bin[lastbin] + frac * q->bin[lastbin]; - } +void PV_SoftWipe_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF2 + + SCComplexBuf* p = (SCComplexBuf*)buf1->data; + SCComplexBuf* q = (SCComplexBuf*)buf2->data; + + float wipe = ZIN0(2) * numbins; + int iwipe = (int)wipe; + float frac = fabs(wipe - iwipe); + if (iwipe > 0) { + iwipe = sc_min(iwipe, numbins); + for (int i = 0; i < iwipe - 1; ++i) { + p->bin[i] = q->bin[i]; + } + p->bin[iwipe] = (1 - frac) * p->bin[iwipe] + frac * q->bin[iwipe]; + } else if (iwipe < 0) { + iwipe = sc_max(iwipe, -numbins); + int lastbin = numbins + iwipe; + for (int i = lastbin + 1; i < numbins; ++i) { + p->bin[i] = q->bin[i]; + } + p->bin[lastbin] = (1 - frac) * p->bin[lastbin] + frac * q->bin[lastbin]; + } } -void PV_SoftWipe_Ctor(PV_Unit *unit) -{ - SETCALC(PV_SoftWipe_next); - ZOUT0(0) = ZIN0(0); +void PV_SoftWipe_Ctor(PV_Unit* unit) { + SETCALC(PV_SoftWipe_next); + ZOUT0(0) = ZIN0(0); } -void PV_Cutoff_next(PV_Unit *unit, int inNumSamples) -{ - PV_GET_BUF - - SCComplexBuf *p = (SCComplexBuf*)buf->data; - - float wipe = ZIN0(1) * numbins; - int iwipe = (int)wipe; - float frac = fabs(wipe - iwipe); - if (iwipe > 0) { - iwipe = sc_min(iwipe, numbins); - for (int i=0; i < iwipe-1; ++i) { - p->bin[i] = 0.; - } - p->bin[iwipe]=(1-frac) * p->bin[iwipe]; - } else if (wipe < 0) { - iwipe = sc_max(iwipe, -numbins); - int lastbin=numbins+iwipe; - for (int i=lastbin+1; i < numbins; ++i) { - p->bin[i] = 0.; - } - p->bin[lastbin]=(1-frac) * p->bin[lastbin]; - } +void PV_Cutoff_next(PV_Unit* unit, int inNumSamples) { + PV_GET_BUF + + SCComplexBuf* p = (SCComplexBuf*)buf->data; + + float wipe = ZIN0(1) * numbins; + int iwipe = (int)wipe; + float frac = fabs(wipe - iwipe); + if (iwipe > 0) { + iwipe = sc_min(iwipe, numbins); + for (int i = 0; i < iwipe - 1; ++i) { + p->bin[i] = 0.; + } + p->bin[iwipe] = (1 - frac) * p->bin[iwipe]; + } else if (wipe < 0) { + iwipe = sc_max(iwipe, -numbins); + int lastbin = numbins + iwipe; + for (int i = lastbin + 1; i < numbins; ++i) { + p->bin[i] = 0.; + } + p->bin[lastbin] = (1 - frac) * p->bin[lastbin]; + } } -void PV_Cutoff_Ctor(PV_Unit *unit) -{ - SETCALC(PV_Cutoff_next); - ZOUT0(0) = ZIN0(0); +void PV_Cutoff_Ctor(PV_Unit* unit) { + SETCALC(PV_Cutoff_next); + ZOUT0(0) = ZIN0(0); } -#define DefinePVUnit(name) \ - (*ft->fDefineUnit)(#name, sizeof(PV_Unit), (UnitCtorFunc)&name##_Ctor, 0, 0); +#define DefinePVUnit(name) (*ft->fDefineUnit)(#name, sizeof(PV_Unit), (UnitCtorFunc)&name##_Ctor, 0, 0); -extern "C" -{ -} +extern "C" { } + +InterfaceTable* ft; + +PluginLoad(BhobPV) { + ft = inTable; -InterfaceTable *ft; - -PluginLoad(BhobPV) -{ - ft = inTable; - - DefinePVUnit(PV_MagMinus); - DefinePVUnit(PV_CommonMag); - DefinePVUnit(PV_CommonMul); - DefinePVUnit(PV_MagGate); - DefinePVUnit(PV_MagScale); - DefinePVUnit(PV_Morph); - DefinePVUnit(PV_XFade); - DefinePVUnit(PV_SoftWipe); - DefinePVUnit(PV_Cutoff); - DefinePVUnit(PV_Compander); + DefinePVUnit(PV_MagMinus); + DefinePVUnit(PV_CommonMag); + DefinePVUnit(PV_CommonMul); + DefinePVUnit(PV_MagGate); + DefinePVUnit(PV_MagScale); + DefinePVUnit(PV_Morph); + DefinePVUnit(PV_XFade); + DefinePVUnit(PV_SoftWipe); + DefinePVUnit(PV_Cutoff); + DefinePVUnit(PV_Compander); } diff --git a/source/BhobUGens/BhobFilt.cpp b/source/BhobUGens/BhobFilt.cpp index 872c0c04ac..ac3aed0efc 100644 --- a/source/BhobUGens/BhobFilt.cpp +++ b/source/BhobUGens/BhobFilt.cpp @@ -7,7 +7,7 @@ NLFilt is an implementation of a formula by Dobson and Fitch SuperCollider real time aud synthesis system Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audsynth.com + http://www.audsynth.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 @@ -26,1043 +26,827 @@ SuperCollider real time aud synthesis system #include "SC_PlugIn.h" -static InterfaceTable *ft; +static InterfaceTable* ft; -struct MoogLadder : public Unit -{ - float m_fco, m_k2v; - float m_res; - float m_xnm1, m_y1nm1, m_y2nm1, m_y3nm1, m_y4nm1; - float m_y1n, m_y2n, m_y3n, m_y4n, m_y1n1; +struct MoogLadder : public Unit { + float m_fco, m_k2v; + float m_res; + float m_xnm1, m_y1nm1, m_y2nm1, m_y3nm1, m_y4nm1; + float m_y1n, m_y2n, m_y3n, m_y4n, m_y1n1; }; -struct RLPFD : public Unit -{ - float m_fco, m_res, m_ap, m_scl; - float m_x1, m_y1, m_y2, m_y3; - float m_x1nm1, m_y1nm1, m_y2nm1; +struct RLPFD : public Unit { + float m_fco, m_res, m_ap, m_scl; + float m_x1, m_y1, m_y2, m_y3; + float m_x1nm1, m_y1nm1, m_y2nm1; }; -struct MultiFilt : public Unit -{ - float m_hp, m_lp, m_bp, m_halfsamp; - float m_cf, m_f, m_rq; +struct MultiFilt : public Unit { + float m_hp, m_lp, m_bp, m_halfsamp; + float m_cf, m_f, m_rq; }; -struct FilterDelayUnit : public Unit -{ - float *m_dlybuf; +struct FilterDelayUnit : public Unit { + float* m_dlybuf; - float m_dsamp, m_fdelaylen; - float m_delaytime, m_maxdelaytime; - long m_iwrphase, m_idelaylen, m_mask; - long m_numoutput; + float m_dsamp, m_fdelaylen; + float m_delaytime, m_maxdelaytime; + long m_iwrphase, m_idelaylen, m_mask; + long m_numoutput; }; -struct Streson : public FilterDelayUnit -{ - float m_lp, m_ap, m_a; +struct Streson : public FilterDelayUnit { + float m_lp, m_ap, m_a; }; -struct NLFiltN : public FilterDelayUnit -{ - float m_a, m_b, m_d, m_c, m_l; +struct NLFiltN : public FilterDelayUnit { + float m_a, m_b, m_d, m_c, m_l; }; -struct NLFiltL : public FilterDelayUnit -{ - float m_a, m_b, m_d, m_c, m_l; +struct NLFiltL : public FilterDelayUnit { + float m_a, m_b, m_d, m_c, m_l; }; -struct NLFiltC : public FilterDelayUnit -{ - float m_a, m_b, m_d, m_c, m_l; +struct NLFiltC : public FilterDelayUnit { + float m_a, m_b, m_d, m_c, m_l; }; -struct NestedAllpassN : public Unit -{ - float m_dt1, m_dt2; - float *m_buf1, *m_buf2; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput, m_dsamp1, m_dsamp2; +struct NestedAllpassN : public Unit { + float m_dt1, m_dt2; + float *m_buf1, *m_buf2; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput, m_dsamp1, m_dsamp2; }; -struct NestedAllpassL : public Unit -{ - float m_dt1, m_dt2, m_dsamp1, m_dsamp2; - float *m_buf1, *m_buf2; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput; +struct NestedAllpassL : public Unit { + float m_dt1, m_dt2, m_dsamp1, m_dsamp2; + float *m_buf1, *m_buf2; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput; }; -struct NestedAllpassC : public Unit -{ - float m_dt1, m_dt2, m_dsamp1, m_dsamp2; - float *m_buf1, *m_buf2; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput; +struct NestedAllpassC : public Unit { + float m_dt1, m_dt2, m_dsamp1, m_dsamp2; + float *m_buf1, *m_buf2; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel, m_numoutput; }; -struct DoubleNestedAllpassN : public Unit -{ - float m_dt1, m_dt2, m_dt3; - float *m_buf1, *m_buf2, *m_buf3; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_dsamp1, m_dsamp2, m_dsamp3, m_maxdel, m_numoutput; +struct DoubleNestedAllpassN : public Unit { + float m_dt1, m_dt2, m_dt3; + float *m_buf1, *m_buf2, *m_buf3; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_dsamp1, m_dsamp2, m_dsamp3, m_maxdel, m_numoutput; }; -struct DoubleNestedAllpassL : public Unit -{ - float m_dt1, m_dt2, m_dt3, m_dsamp1, m_dsamp2, m_dsamp3; - float *m_buf1, *m_buf2, *m_buf3; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_maxdel, m_numoutput; +struct DoubleNestedAllpassL : public Unit { + float m_dt1, m_dt2, m_dt3, m_dsamp1, m_dsamp2, m_dsamp3; + float *m_buf1, *m_buf2, *m_buf3; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_maxdel, m_numoutput; }; -struct DoubleNestedAllpassC : public Unit -{ - float m_dt1, m_dt2, m_dt3, m_dsamp1, m_dsamp2, m_dsamp3; - float *m_buf1, *m_buf2, *m_buf3; - long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_maxdel, m_numoutput; +struct DoubleNestedAllpassC : public Unit { + float m_dt1, m_dt2, m_dt3, m_dsamp1, m_dsamp2, m_dsamp3; + float *m_buf1, *m_buf2, *m_buf3; + long m_phase, m_maxdel1, m_maxdel2, m_maxdel3, m_maxdel, m_numoutput; }; // declare unit generator functions -extern "C" -{ - void MoogLadder_Ctor(MoogLadder* unit); - void MoogLadder_next_kk(MoogLadder *unit, int inNumSamples); - void MoogLadder_next_ka(MoogLadder *unit, int inNumSamples); - void MoogLadder_next_ak(MoogLadder *unit, int inNumSamples); - void MoogLadder_next_aa(MoogLadder *unit, int inNumSamples); - - void RLPFD_Ctor(RLPFD* unit); - void RLPFD_next_kk(RLPFD *unit, int inNumSamples); - void RLPFD_next_ka(RLPFD *unit, int inNumSamples); - void RLPFD_next_ak(RLPFD *unit, int inNumSamples); - void RLPFD_next_aa(RLPFD *unit, int inNumSamples); - - void MultiFilt_Ctor(MultiFilt* unit); - void MultiFilt_next_kk(MultiFilt *unit, int inNumSamples); - void MultiFilt_next_ak(MultiFilt *unit, int inNumSamples); - void MultiFilt_next_ka(MultiFilt *unit, int inNumSamples); - void MultiFilt_next_aa(MultiFilt *unit, int inNumSamples); - - void FiltDelay_Reset(FilterDelayUnit *unit); - void FilterDelay_Dtor(FilterDelayUnit *unit); - void FilterDelay_AllocDelayLine(FilterDelayUnit *unit); - - void Streson_Ctor(Streson* unit); - void Streson_next_a(Streson *unit, int inNumSamples); - void Streson_next_k(Streson *unit, int inNumSamples); - void Streson_next_a_z(Streson *unit, int inNumSamples); - void Streson_next_k_z(Streson *unit, int inNumSamples); - - void NLFiltN_Ctor(NLFiltN* unit); - void NLFiltN_next(NLFiltN *unit, int inNumSamples); - void NLFiltN_next_z(NLFiltN *unit, int inNumSamples); - - void NLFiltL_Ctor(NLFiltL* unit); - void NLFiltL_next(NLFiltL *unit, int inNumSamples); - void NLFiltL_next_z(NLFiltL *unit, int inNumSamples); - - void NLFiltC_Ctor(NLFiltC* unit); - void NLFiltC_next(NLFiltC *unit, int inNumSamples); - void NLFiltC_next_z(NLFiltC *unit, int inNumSamples); - - void NestedAllpassN_Ctor(NestedAllpassN* unit); - void NestedAllpassN_Dtor(NestedAllpassN *unit); - void NestedAllpassN_next(NestedAllpassN *unit, int inNumSamples); - void NestedAllpassN_next_z(NestedAllpassN *unit, int inNumSamples); - - void NestedAllpassL_Ctor(NestedAllpassL* unit); - void NestedAllpassL_Dtor(NestedAllpassL *unit); - void NestedAllpassL_next(NestedAllpassL *unit, int inNumSamples); - void NestedAllpassL_next_z(NestedAllpassL *unit, int inNumSamples); - - void NestedAllpassC_Ctor(NestedAllpassC* unit); - void NestedAllpassC_Dtor(NestedAllpassC *unit); - void NestedAllpassC_next(NestedAllpassC *unit, int inNumSamples); - void NestedAllpassC_next_z(NestedAllpassC *unit, int inNumSamples); - - void DoubleNestedAllpassN_Ctor(DoubleNestedAllpassN* unit); - void DoubleNestedAllpassN_Dtor(DoubleNestedAllpassN *unit); - void DoubleNestedAllpassN_next(DoubleNestedAllpassN *unit, int inNumSamples); - void DoubleNestedAllpassN_next_z(DoubleNestedAllpassN *unit, int inNumSamples); - - void DoubleNestedAllpassL_Ctor(DoubleNestedAllpassL* unit); - void DoubleNestedAllpassL_Dtor(DoubleNestedAllpassL *unit); - void DoubleNestedAllpassL_next(DoubleNestedAllpassL *unit, int inNumSamples); - void DoubleNestedAllpassL_next_z(DoubleNestedAllpassL *unit, int inNumSamples); - - void DoubleNestedAllpassC_Ctor(DoubleNestedAllpassC* unit); - void DoubleNestedAllpassC_Dtor(DoubleNestedAllpassC *unit); - void DoubleNestedAllpassC_next(DoubleNestedAllpassC *unit, int inNumSamples); - void DoubleNestedAllpassC_next_z(DoubleNestedAllpassC *unit, int inNumSamples); +extern "C" { +void MoogLadder_Ctor(MoogLadder* unit); +void MoogLadder_next_kk(MoogLadder* unit, int inNumSamples); +void MoogLadder_next_ka(MoogLadder* unit, int inNumSamples); +void MoogLadder_next_ak(MoogLadder* unit, int inNumSamples); +void MoogLadder_next_aa(MoogLadder* unit, int inNumSamples); + +void RLPFD_Ctor(RLPFD* unit); +void RLPFD_next_kk(RLPFD* unit, int inNumSamples); +void RLPFD_next_ka(RLPFD* unit, int inNumSamples); +void RLPFD_next_ak(RLPFD* unit, int inNumSamples); +void RLPFD_next_aa(RLPFD* unit, int inNumSamples); + +void MultiFilt_Ctor(MultiFilt* unit); +void MultiFilt_next_kk(MultiFilt* unit, int inNumSamples); +void MultiFilt_next_ak(MultiFilt* unit, int inNumSamples); +void MultiFilt_next_ka(MultiFilt* unit, int inNumSamples); +void MultiFilt_next_aa(MultiFilt* unit, int inNumSamples); + +void FiltDelay_Reset(FilterDelayUnit* unit); +void FilterDelay_Dtor(FilterDelayUnit* unit); +void FilterDelay_AllocDelayLine(FilterDelayUnit* unit); + +void Streson_Ctor(Streson* unit); +void Streson_next_a(Streson* unit, int inNumSamples); +void Streson_next_k(Streson* unit, int inNumSamples); +void Streson_next_a_z(Streson* unit, int inNumSamples); +void Streson_next_k_z(Streson* unit, int inNumSamples); + +void NLFiltN_Ctor(NLFiltN* unit); +void NLFiltN_next(NLFiltN* unit, int inNumSamples); +void NLFiltN_next_z(NLFiltN* unit, int inNumSamples); + +void NLFiltL_Ctor(NLFiltL* unit); +void NLFiltL_next(NLFiltL* unit, int inNumSamples); +void NLFiltL_next_z(NLFiltL* unit, int inNumSamples); + +void NLFiltC_Ctor(NLFiltC* unit); +void NLFiltC_next(NLFiltC* unit, int inNumSamples); +void NLFiltC_next_z(NLFiltC* unit, int inNumSamples); + +void NestedAllpassN_Ctor(NestedAllpassN* unit); +void NestedAllpassN_Dtor(NestedAllpassN* unit); +void NestedAllpassN_next(NestedAllpassN* unit, int inNumSamples); +void NestedAllpassN_next_z(NestedAllpassN* unit, int inNumSamples); + +void NestedAllpassL_Ctor(NestedAllpassL* unit); +void NestedAllpassL_Dtor(NestedAllpassL* unit); +void NestedAllpassL_next(NestedAllpassL* unit, int inNumSamples); +void NestedAllpassL_next_z(NestedAllpassL* unit, int inNumSamples); + +void NestedAllpassC_Ctor(NestedAllpassC* unit); +void NestedAllpassC_Dtor(NestedAllpassC* unit); +void NestedAllpassC_next(NestedAllpassC* unit, int inNumSamples); +void NestedAllpassC_next_z(NestedAllpassC* unit, int inNumSamples); + +void DoubleNestedAllpassN_Ctor(DoubleNestedAllpassN* unit); +void DoubleNestedAllpassN_Dtor(DoubleNestedAllpassN* unit); +void DoubleNestedAllpassN_next(DoubleNestedAllpassN* unit, int inNumSamples); +void DoubleNestedAllpassN_next_z(DoubleNestedAllpassN* unit, int inNumSamples); + +void DoubleNestedAllpassL_Ctor(DoubleNestedAllpassL* unit); +void DoubleNestedAllpassL_Dtor(DoubleNestedAllpassL* unit); +void DoubleNestedAllpassL_next(DoubleNestedAllpassL* unit, int inNumSamples); +void DoubleNestedAllpassL_next_z(DoubleNestedAllpassL* unit, int inNumSamples); + +void DoubleNestedAllpassC_Ctor(DoubleNestedAllpassC* unit); +void DoubleNestedAllpassC_Dtor(DoubleNestedAllpassC* unit); +void DoubleNestedAllpassC_next(DoubleNestedAllpassC* unit, int inNumSamples); +void DoubleNestedAllpassC_next_z(DoubleNestedAllpassC* unit, int inNumSamples); }; -#define SET2BUF \ - long bufsize1=(long)ceil(ZIN0(1) * unit->mRate->mSampleRate + 1.f); \ - long bufsize2=(long)ceil(ZIN0(4) * unit->mRate->mSampleRate + 1.f); \ - long maxdelay1=bufsize1 + BUFLENGTH; \ - maxdelay1 = NEXTPOWEROFTWO(maxdelay1); \ - long maxdelay2=bufsize2 + BUFLENGTH; \ - maxdelay2 = NEXTPOWEROFTWO(maxdelay2); \ - unit->m_buf1=0; \ - unit->m_buf2=0; \ - RTFree(unit->mWorld, unit->m_buf1); \ - unit->m_buf1=(float*)RTAlloc(unit->mWorld, maxdelay1 * sizeof(float)); \ - RTFree(unit->mWorld, unit->m_buf2); \ - unit->m_buf2=(float*)RTAlloc(unit->mWorld, maxdelay2 * sizeof(float)); \ - unit->m_maxdel1=maxdelay1-1; \ - unit->m_maxdel2=maxdelay2-1; \ - unit->m_maxdel=sc_max(unit->m_maxdel1, unit->m_maxdel2); \ - unit->m_numoutput=0; \ - unit->m_dt1=ZIN0(2); \ - unit->m_dt2=ZIN0(5); \ - -#define SET3BUF \ - long bufsize1=(long)ceil(ZIN0(1) * unit->mRate->mSampleRate + 1.f); \ - long bufsize2=(long)ceil(ZIN0(4) * unit->mRate->mSampleRate + 1.f); \ - long bufsize3=(long)ceil(ZIN0(7) * unit->mRate->mSampleRate + 1.f); \ - long maxdelay1=bufsize1 + BUFLENGTH; \ - maxdelay1 = NEXTPOWEROFTWO(maxdelay1); \ - long maxdelay2=bufsize2 + BUFLENGTH; \ - maxdelay2 = NEXTPOWEROFTWO(maxdelay2); \ - long maxdelay3=bufsize3 + BUFLENGTH; \ - maxdelay3 = NEXTPOWEROFTWO(maxdelay3); \ - unit->m_buf1=0; \ - unit->m_buf2=0; \ - unit->m_buf3=0; \ - RTFree(unit->mWorld, unit->m_buf1); \ - unit->m_buf1=(float*)RTAlloc(unit->mWorld, maxdelay1 * sizeof(float)); \ - RTFree(unit->mWorld, unit->m_buf2); \ - unit->m_buf2=(float*)RTAlloc(unit->mWorld, maxdelay2 * sizeof(float)); \ - RTFree(unit->mWorld, unit->m_buf3); \ - unit->m_buf3=(float*)RTAlloc(unit->mWorld, maxdelay3 * sizeof(float)); \ - unit->m_maxdel1=maxdelay1-1; \ - unit->m_maxdel2=maxdelay2-1; \ - unit->m_maxdel3=maxdelay3-1; \ - unit->m_maxdel=sc_max(unit->m_maxdel1, unit->m_maxdel2); \ - unit->m_maxdel=sc_max(unit->m_maxdel, unit->m_maxdel3); \ - unit->m_numoutput=0; \ - unit->m_dt1=ZIN0(2); \ - unit->m_dt2=ZIN0(5); \ - unit->m_dt3=ZIN0(8); \ -/* -static float cubicinterp(float x, float y0, float y1, float y2, float y3) -{ - float c0 = y1; - float c1 = 0.5f * (y2 - y0); - float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3; - float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2); - - return ((c3 * x + c2) * x + c1) * x + c0; -} +#define SET2BUF \ + long bufsize1 = (long)ceil(ZIN0(1) * unit->mRate->mSampleRate + 1.f); \ + long bufsize2 = (long)ceil(ZIN0(4) * unit->mRate->mSampleRate + 1.f); \ + long maxdelay1 = bufsize1 + BUFLENGTH; \ + maxdelay1 = NEXTPOWEROFTWO(maxdelay1); \ + long maxdelay2 = bufsize2 + BUFLENGTH; \ + maxdelay2 = NEXTPOWEROFTWO(maxdelay2); \ + unit->m_buf1 = 0; \ + unit->m_buf2 = 0; \ + RTFree(unit->mWorld, unit->m_buf1); \ + unit->m_buf1 = (float*)RTAlloc(unit->mWorld, maxdelay1 * sizeof(float)); \ + RTFree(unit->mWorld, unit->m_buf2); \ + unit->m_buf2 = (float*)RTAlloc(unit->mWorld, maxdelay2 * sizeof(float)); \ + unit->m_maxdel1 = maxdelay1 - 1; \ + unit->m_maxdel2 = maxdelay2 - 1; \ + unit->m_maxdel = sc_max(unit->m_maxdel1, unit->m_maxdel2); \ + unit->m_numoutput = 0; \ + unit->m_dt1 = ZIN0(2); \ + unit->m_dt2 = ZIN0(5); + +#define SET3BUF \ + long bufsize1 = (long)ceil(ZIN0(1) * unit->mRate->mSampleRate + 1.f); \ + long bufsize2 = (long)ceil(ZIN0(4) * unit->mRate->mSampleRate + 1.f); \ + long bufsize3 = (long)ceil(ZIN0(7) * unit->mRate->mSampleRate + 1.f); \ + long maxdelay1 = bufsize1 + BUFLENGTH; \ + maxdelay1 = NEXTPOWEROFTWO(maxdelay1); \ + long maxdelay2 = bufsize2 + BUFLENGTH; \ + maxdelay2 = NEXTPOWEROFTWO(maxdelay2); \ + long maxdelay3 = bufsize3 + BUFLENGTH; \ + maxdelay3 = NEXTPOWEROFTWO(maxdelay3); \ + unit->m_buf1 = 0; \ + unit->m_buf2 = 0; \ + unit->m_buf3 = 0; \ + RTFree(unit->mWorld, unit->m_buf1); \ + unit->m_buf1 = (float*)RTAlloc(unit->mWorld, maxdelay1 * sizeof(float)); \ + RTFree(unit->mWorld, unit->m_buf2); \ + unit->m_buf2 = (float*)RTAlloc(unit->mWorld, maxdelay2 * sizeof(float)); \ + RTFree(unit->mWorld, unit->m_buf3); \ + unit->m_buf3 = (float*)RTAlloc(unit->mWorld, maxdelay3 * sizeof(float)); \ + unit->m_maxdel1 = maxdelay1 - 1; \ + unit->m_maxdel2 = maxdelay2 - 1; \ + unit->m_maxdel3 = maxdelay3 - 1; \ + unit->m_maxdel = sc_max(unit->m_maxdel1, unit->m_maxdel2); \ + unit->m_maxdel = sc_max(unit->m_maxdel, unit->m_maxdel3); \ + unit->m_numoutput = 0; \ + unit->m_dt1 = ZIN0(2); \ + unit->m_dt2 = ZIN0(5); \ + unit->m_dt3 = ZIN0(8); \ +/* \ +static float cubicinterp(float x, float y0, float y1, float y2, float y3) \ +{ \ + float c0 = y1; \ + float c1 = 0.5f * (y2 - y0); \ + float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3; \ + float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2); \ + \ + return ((c3 * x + c2) * x + c1) * x + c0; \ +} \ */ -float CalcDelay(FilterDelayUnit *unit, float delaytime); -float CalcDelay(FilterDelayUnit *unit, float delaytime) -{ - float next_dsamp = delaytime * SAMPLERATE; - return sc_clip(next_dsamp, 1.f, unit->m_fdelaylen); +float CalcDelay(FilterDelayUnit* unit, float delaytime); +float CalcDelay(FilterDelayUnit* unit, float delaytime) { + float next_dsamp = delaytime * SAMPLERATE; + return sc_clip(next_dsamp, 1.f, unit->m_fdelaylen); } -void FilterDelay_AllocDelayLine(FilterDelayUnit *unit) -{ - long delaybufsize = (long)ceil(unit->m_maxdelaytime * SAMPLERATE + 1.f); - delaybufsize = delaybufsize + BUFLENGTH; - delaybufsize = NEXTPOWEROFTWO(delaybufsize); - unit->m_fdelaylen = unit->m_idelaylen = delaybufsize; - - RTFree(unit->mWorld, unit->m_dlybuf); - int size = delaybufsize * sizeof(float); - unit->m_dlybuf = (float*)RTAlloc(unit->mWorld, size); - unit->m_mask = delaybufsize - 1; +void FilterDelay_AllocDelayLine(FilterDelayUnit* unit) { + long delaybufsize = (long)ceil(unit->m_maxdelaytime * SAMPLERATE + 1.f); + delaybufsize = delaybufsize + BUFLENGTH; + delaybufsize = NEXTPOWEROFTWO(delaybufsize); + unit->m_fdelaylen = unit->m_idelaylen = delaybufsize; + + RTFree(unit->mWorld, unit->m_dlybuf); + int size = delaybufsize * sizeof(float); + unit->m_dlybuf = (float*)RTAlloc(unit->mWorld, size); + unit->m_mask = delaybufsize - 1; } -void FilterDelay_Reset(FilterDelayUnit *unit) -{ - unit->m_dlybuf = 0; +void FilterDelay_Reset(FilterDelayUnit* unit) { + unit->m_dlybuf = 0; - FilterDelay_AllocDelayLine(unit); + FilterDelay_AllocDelayLine(unit); - unit->m_dsamp = CalcDelay(unit, unit->m_delaytime); + unit->m_dsamp = CalcDelay(unit, unit->m_delaytime); - unit->m_numoutput = 0; - unit->m_iwrphase = 0; + unit->m_numoutput = 0; + unit->m_iwrphase = 0; } -void FilterDelay_Dtor(FilterDelayUnit *unit) -{ - RTFree(unit->mWorld, unit->m_dlybuf); -} +void FilterDelay_Dtor(FilterDelayUnit* unit) { RTFree(unit->mWorld, unit->m_dlybuf); } -float Mirroring (float lower, float upper, float in); -float Mirroring (float lower, float upper, float in) -{ - if(in > upper || in < lower) { - float infrac=fabs(in-(long)in); - if (in upper || in < lower) { + float infrac = fabs(in - (long)in); + if (in < lower) + in = lower + infrac; + else + in = upper - infrac; + } + return in; } -void NLFiltN_Ctor(NLFiltN *unit) -{ - unit->m_maxdelaytime=0.05; - FilterDelay_Reset(unit); - SETCALC(NLFiltN_next_z); - unit->m_a=ZIN0(1); - unit->m_b=ZIN0(2); - unit->m_d=ZIN0(3); - unit->m_c=ZIN0(4); - unit->m_l=ZIN0(5); - ZOUT0(0) = 0.f; +void NLFiltN_Ctor(NLFiltN* unit) { + unit->m_maxdelaytime = 0.05; + FilterDelay_Reset(unit); + SETCALC(NLFiltN_next_z); + unit->m_a = ZIN0(1); + unit->m_b = ZIN0(2); + unit->m_d = ZIN0(3); + unit->m_c = ZIN0(4); + unit->m_l = ZIN0(5); + ZOUT0(0) = 0.f; } -void NLFiltN_next(NLFiltN *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - a += aslope; - b += bslope; - d += dslope; - c += cslope; - l += lslope; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - float delayL = dlybuf[(iwrphase - (long)l) & mask]; - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ); - } else { - LOOP(inNumSamples, - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - float delayL = dlybuf[(iwrphase - (long)l) & mask]; - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ); - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; +void NLFiltN_next(NLFiltN* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP(inNumSamples, a += aslope; b += bslope; d += dslope; c += cslope; l += lslope; + float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + float delayL = dlybuf[(iwrphase - (long)l) & mask]; + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;); + } else { + LOOP(inNumSamples, float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + float delayL = dlybuf[(iwrphase - (long)l) & mask]; + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;); + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; } -void NLFiltN_next_z(NLFiltN *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - a += aslope; - b += bslope; - d += dslope; - c += cslope; - l += lslope; - long irphase = iwrphase - (long)l; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - float delayL = dlybuf[irphase & mask]; - - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if (irphase < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ); - } else { - LOOP(inNumSamples, - long irphase = iwrphase - (long)l; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - float delayL = dlybuf[irphase & mask]; - - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if (irphase < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ); - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_idelaylen) { - SETCALC(NLFiltN_next); - } +void NLFiltN_next_z(NLFiltN* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP( + inNumSamples, a += aslope; b += bslope; d += dslope; c += cslope; l += lslope; + long irphase = iwrphase - (long)l; float delay1 = dlybuf[(iwrphase - 1) & mask]; + float delay2 = dlybuf[(iwrphase - 2) & mask]; float delayL = dlybuf[irphase & mask]; + + float input = ZXP(in); float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if (irphase < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;); + } else { + LOOP( + inNumSamples, long irphase = iwrphase - (long)l; float delay1 = dlybuf[(iwrphase - 1) & mask]; + float delay2 = dlybuf[(iwrphase - 2) & mask]; float delayL = dlybuf[irphase & mask]; + + float input = ZXP(in); float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if (irphase < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;); + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_idelaylen) { + SETCALC(NLFiltN_next); + } } -void NLFiltL_Ctor(NLFiltL *unit) -{ - unit->m_maxdelaytime=0.05; - FilterDelay_Reset(unit); - SETCALC(NLFiltL_next_z); - unit->m_a=ZIN0(1); - unit->m_b=ZIN0(2); - unit->m_d=ZIN0(3); - unit->m_c=ZIN0(4); - unit->m_l=ZIN0(5); - ZOUT0(0) = 0.f; +void NLFiltL_Ctor(NLFiltL* unit) { + unit->m_maxdelaytime = 0.05; + FilterDelay_Reset(unit); + SETCALC(NLFiltL_next_z); + unit->m_a = ZIN0(1); + unit->m_b = ZIN0(2); + unit->m_d = ZIN0(3); + unit->m_c = ZIN0(4); + unit->m_l = ZIN0(5); + ZOUT0(0) = 0.f; } -void NLFiltL_next(NLFiltL *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - l += lslope; - a += aslope; - b += bslope; - d += dslope; - c += cslope; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - float delayL1 = dlybuf[(iwrphase - l1) & mask]; - float delayL2 = dlybuf[(iwrphase - l1 - 1) & mask]; - float delayL = lininterp(frac, delayL1, delayL2); - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ) - } else { - LOOP(inNumSamples, - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - float delayL = dlybuf[(iwrphase - (long)l) & mask]; - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ) - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; +void NLFiltL_next(NLFiltL* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP(inNumSamples, l += lslope; a += aslope; b += bslope; d += dslope; c += cslope; + float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; float delayL1 = dlybuf[(iwrphase - l1) & mask]; + float delayL2 = dlybuf[(iwrphase - l1 - 1) & mask]; float delayL = lininterp(frac, delayL1, delayL2); + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;) + } else { + LOOP(inNumSamples, float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + float delayL = dlybuf[(iwrphase - (long)l) & mask]; + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;) + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; } -void NLFiltL_next_z(NLFiltL *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - l += lslope; - a += aslope; - b += bslope; - d += dslope; - c += cslope; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - long irphase = iwrphase-l1; - float delayL1 = dlybuf[irphase & mask]; - float delayL2 = dlybuf[(irphase - 1) & mask]; - float delayL = lininterp(frac, delayL1, delayL2); - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if ((irphase-1) < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ) - } else { - LOOP(inNumSamples, - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1=(long)l; - float frac=l-l1; - long irphase = iwrphase-l1; - float delayL1 = dlybuf[irphase & mask]; - float delayL2 = dlybuf[(irphase - 1) & mask]; - float delayL = lininterp(frac, delayL1, delayL2); - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if ((irphase-1) < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ) - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_idelaylen) { - SETCALC(NLFiltL_next); - } +void NLFiltL_next_z(NLFiltL* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP( + inNumSamples, l += lslope; a += aslope; b += bslope; d += dslope; c += cslope; + float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irphase = iwrphase - l1; + float delayL1 = dlybuf[irphase & mask]; float delayL2 = dlybuf[(irphase - 1) & mask]; + float delayL = lininterp(frac, delayL1, delayL2); float input = ZXP(in); + float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if ((irphase - 1) < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;) + } else { + LOOP( + inNumSamples, float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irphase = iwrphase - l1; + float delayL1 = dlybuf[irphase & mask]; float delayL2 = dlybuf[(irphase - 1) & mask]; + float delayL = lininterp(frac, delayL1, delayL2); float input = ZXP(in); + float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if ((irphase - 1) < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;) + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_idelaylen) { + SETCALC(NLFiltL_next); + } } -void NLFiltC_Ctor(NLFiltC *unit) -{ - unit->m_maxdelaytime=0.05; - FilterDelay_Reset(unit); - SETCALC(NLFiltC_next_z); - unit->m_a=ZIN0(1); - unit->m_b=ZIN0(2); - unit->m_d=ZIN0(3); - unit->m_c=ZIN0(4); - unit->m_l=ZIN0(5); - ZOUT0(0) = 0.f; +void NLFiltC_Ctor(NLFiltC* unit) { + unit->m_maxdelaytime = 0.05; + FilterDelay_Reset(unit); + SETCALC(NLFiltC_next_z); + unit->m_a = ZIN0(1); + unit->m_b = ZIN0(2); + unit->m_d = ZIN0(3); + unit->m_c = ZIN0(4); + unit->m_l = ZIN0(5); + ZOUT0(0) = 0.f; } -void NLFiltC_next(NLFiltC *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - l += lslope; - a += aslope; - b += bslope; - d += dslope; - c += cslope; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - long irdphase1 = iwrphase - l1; - long irdphase2 = irdphase1 - 1; - long irdphase3 = irdphase1 - 2; - long irdphase0 = irdphase1 + 1; - float d0 = dlybuf[irdphase0 & mask]; - float d1 = dlybuf[irdphase1 & mask]; - float d2 = dlybuf[irdphase2 & mask]; - float d3 = dlybuf[irdphase3 & mask]; - float delayL = cubicinterp(frac, d0, d1, d2, d3); - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ) - } else { - LOOP(inNumSamples, - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - long irdphase1 = iwrphase - l1; - long irdphase2 = irdphase1 - 1; - long irdphase3 = irdphase1 - 2; - long irdphase0 = irdphase1 + 1; - float d0 = dlybuf[irdphase0 & mask]; - float d1 = dlybuf[irdphase1 & mask]; - float d2 = dlybuf[irdphase2 & mask]; - float d3 = dlybuf[irdphase3 & mask]; - float delayL = cubicinterp(frac, d0, d1, d2, d3); - - float output = ZXP(in) + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - ZXP(out) = dlybuf[iwrphase & mask] = output; - iwrphase++; - ) - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; +void NLFiltC_next(NLFiltC* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP(inNumSamples, l += lslope; a += aslope; b += bslope; d += dslope; c += cslope; + float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irdphase1 = iwrphase - l1; long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; long irdphase0 = irdphase1 + 1; float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; float delayL = cubicinterp(frac, d0, d1, d2, d3); + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;) + } else { + LOOP(inNumSamples, float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irdphase1 = iwrphase - l1; long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; long irdphase0 = irdphase1 + 1; float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; float delayL = cubicinterp(frac, d0, d1, d2, d3); + + float output = ZXP(in) + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + ZXP(out) = dlybuf[iwrphase & mask] = output; iwrphase++;) + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; } -void NLFiltC_next_z(NLFiltC *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float next_a = ZIN0(1); - float next_b = ZIN0(2); - float next_d = ZIN0(3); - float next_c = ZIN0(4); - float next_l = ZIN0(5); - float a = unit->m_a; - float b = unit->m_b; - float d = unit->m_d; - float c = unit->m_c; - float l = unit->m_l; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - - if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { - float lslope=CALCSLOPE(next_l, l); - float aslope=CALCSLOPE(next_a, a); - float bslope=CALCSLOPE(next_b, b); - float dslope=CALCSLOPE(next_d, d); - float cslope=CALCSLOPE(next_c, c); - LOOP(inNumSamples, - l += lslope; - a += aslope; - b += bslope; - d += dslope; - c += cslope; - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - long irdphase1 = iwrphase - l1; - long irdphase2 = irdphase1 - 1; - long irdphase3 = irdphase1 - 2; - long irdphase0 = irdphase1 + 1; - float d0 = dlybuf[irdphase0 & mask]; - float d1 = dlybuf[irdphase1 & mask]; - float d2 = dlybuf[irdphase2 & mask]; - float d3 = dlybuf[irdphase3 & mask]; - float delayL = cubicinterp(frac, d0, d1, d2, d3); - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if (irdphase3 < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ) - } else { - LOOP(inNumSamples, - float delay1 = dlybuf[(iwrphase - 1) & mask]; - float delay2 = dlybuf[(iwrphase - 2) & mask]; - long l1 = (long)l; - float frac = l-l1; - long irdphase1 = iwrphase - l1; - long irdphase2 = irdphase1 - 1; - long irdphase3 = irdphase1 - 2; - long irdphase0 = irdphase1 + 1; - float d0 = dlybuf[irdphase0 & mask]; - float d1 = dlybuf[irdphase1 & mask]; - float d2 = dlybuf[irdphase2 & mask]; - float d3 = dlybuf[irdphase3 & mask]; - float delayL = cubicinterp(frac, d0, d1, d2, d3); - float input = ZXP(in); - float output = input + a*delay1 + b*delay2 + d*delayL*delayL - c; - output = output - (output * output * output * 0.166666667); - output = Mirroring(-1.0, 1.0, output); - if (irdphase3 < 0) { - dlybuf[iwrphase & mask] = input; - ZXP(out)=0.f; - } else { - ZXP(out) = dlybuf[iwrphase & mask] = output; - } - iwrphase++; - ) - } - - unit->m_iwrphase=iwrphase; - unit->m_a = a; - unit->m_b = b; - unit->m_d = d; - unit->m_c = c; - unit->m_l = l; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput > unit->m_idelaylen) { - SETCALC(NLFiltC_next); - } +void NLFiltC_next_z(NLFiltC* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float next_a = ZIN0(1); + float next_b = ZIN0(2); + float next_d = ZIN0(3); + float next_c = ZIN0(4); + float next_l = ZIN0(5); + float a = unit->m_a; + float b = unit->m_b; + float d = unit->m_d; + float c = unit->m_c; + float l = unit->m_l; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + + if (next_a != a || next_b != b || next_d != d || next_c != c || next_l != l) { + float lslope = CALCSLOPE(next_l, l); + float aslope = CALCSLOPE(next_a, a); + float bslope = CALCSLOPE(next_b, b); + float dslope = CALCSLOPE(next_d, d); + float cslope = CALCSLOPE(next_c, c); + LOOP( + inNumSamples, l += lslope; a += aslope; b += bslope; d += dslope; c += cslope; + float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irdphase1 = iwrphase - l1; long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; long irdphase0 = irdphase1 + 1; float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; float delayL = cubicinterp(frac, d0, d1, d2, d3); + float input = ZXP(in); float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if (irdphase3 < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;) + } else { + LOOP( + inNumSamples, float delay1 = dlybuf[(iwrphase - 1) & mask]; float delay2 = dlybuf[(iwrphase - 2) & mask]; + long l1 = (long)l; float frac = l - l1; long irdphase1 = iwrphase - l1; long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; long irdphase0 = irdphase1 + 1; float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; float delayL = cubicinterp(frac, d0, d1, d2, d3); + float input = ZXP(in); float output = input + a * delay1 + b * delay2 + d * delayL * delayL - c; + output = output - (output * output * output * 0.166666667); output = Mirroring(-1.0, 1.0, output); + if (irdphase3 < 0) { + dlybuf[iwrphase & mask] = input; + ZXP(out) = 0.f; + } else { ZXP(out) = dlybuf[iwrphase & mask] = output; } iwrphase++;) + } + + unit->m_iwrphase = iwrphase; + unit->m_a = a; + unit->m_b = b; + unit->m_d = d; + unit->m_c = c; + unit->m_l = l; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput > unit->m_idelaylen) { + SETCALC(NLFiltC_next); + } } -void Streson_Ctor(Streson *unit) -{ - unit->m_maxdelaytime=0.05; - FilterDelay_Reset(unit); - float delaytime = ZIN0(1); - float tdelay = delaytime * SAMPLERATE; - unit->m_dsamp = (long)(tdelay - 0.5); - float fracdelay = tdelay - (unit->m_dsamp + 0.5); - unit->m_a = (1-fracdelay)/(1+fracdelay); - unit->m_lp=unit->m_ap=0.f; - unit->m_delaytime = delaytime; - if (INRATE(1) == calc_FullRate) SETCALC(Streson_next_a_z); - else SETCALC(Streson_next_k_z); - ZOUT0(0) = 0.f; +void Streson_Ctor(Streson* unit) { + unit->m_maxdelaytime = 0.05; + FilterDelay_Reset(unit); + float delaytime = ZIN0(1); + float tdelay = delaytime * SAMPLERATE; + unit->m_dsamp = (long)(tdelay - 0.5); + float fracdelay = tdelay - (unit->m_dsamp + 0.5); + unit->m_a = (1 - fracdelay) / (1 + fracdelay); + unit->m_lp = unit->m_ap = 0.f; + unit->m_delaytime = delaytime; + if (INRATE(1) == calc_FullRate) + SETCALC(Streson_next_a_z); + else + SETCALC(Streson_next_k_z); + ZOUT0(0) = 0.f; } -void Streson_next_k(Streson *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float delaytime = unit->m_delaytime; - float next_delaytime = ZIN0(1); - float dsamp = unit->m_dsamp; - float a = unit->m_a; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - float ap = unit->m_ap; - float lp = unit->m_lp; - - if (next_delaytime != delaytime) { - float tdelay = next_delaytime * SAMPLERATE; - float dsamp = (long)(tdelay - 0.5); - float fracdelay = tdelay - (dsamp + 0.5); - float a = (1-fracdelay)/(1+fracdelay); - LOOP(inNumSamples, - long irdphase = iwrphase - (long)dsamp; - float input = ZXP(in) + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ZXP(out) = sample; - ap = s - (sample * a); - dlybuf[iwrphase & mask] = sample * ZIN0(2); - ++iwrphase; - ); - } else { - LOOP(inNumSamples, - long irdphase = iwrphase - (long)dsamp; - float input = ZXP(in) + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ZXP(out) = sample; - ap = s - (sample * a); - dlybuf[iwrphase & mask] = sample * ZIN0(2); - ++iwrphase; - ); - } - - unit->m_iwrphase = iwrphase; - unit->m_ap = zapgremlins(ap); - unit->m_lp = zapgremlins(lp); - unit->m_dsamp = dsamp; - unit->m_a = a; +void Streson_next_k(Streson* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float delaytime = unit->m_delaytime; + float next_delaytime = ZIN0(1); + float dsamp = unit->m_dsamp; + float a = unit->m_a; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + float ap = unit->m_ap; + float lp = unit->m_lp; + + if (next_delaytime != delaytime) { + float tdelay = next_delaytime * SAMPLERATE; + float dsamp = (long)(tdelay - 0.5); + float fracdelay = tdelay - (dsamp + 0.5); + float a = (1 - fracdelay) / (1 + fracdelay); + LOOP(inNumSamples, long irdphase = iwrphase - (long)dsamp; float input = ZXP(in) + dlybuf[irdphase & mask]; + float s = lp * 0.5 + input * 0.5; lp = input; float sample = ap + s * a; ZXP(out) = sample; + ap = s - (sample * a); dlybuf[iwrphase & mask] = sample * ZIN0(2); ++iwrphase;); + } else { + LOOP(inNumSamples, long irdphase = iwrphase - (long)dsamp; float input = ZXP(in) + dlybuf[irdphase & mask]; + float s = lp * 0.5 + input * 0.5; lp = input; float sample = ap + s * a; ZXP(out) = sample; + ap = s - (sample * a); dlybuf[iwrphase & mask] = sample * ZIN0(2); ++iwrphase;); + } + + unit->m_iwrphase = iwrphase; + unit->m_ap = zapgremlins(ap); + unit->m_lp = zapgremlins(lp); + unit->m_dsamp = dsamp; + unit->m_a = a; } -void Streson_next_k_z(Streson *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float delaytime = unit->m_delaytime; - float next_delaytime = ZIN0(1); - float dsamp = unit->m_dsamp; - float a = unit->m_a; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - float ap = unit->m_ap; - float lp = unit->m_lp; - - if (next_delaytime != delaytime) { - float tdelay = next_delaytime * SAMPLERATE; - float dsamp = (long)(tdelay - 0.5); - float fracdelay = tdelay - (dsamp + 0.5); - float a = (1-fracdelay)/(1+fracdelay); - LOOP(inNumSamples, - long irdphase = iwrphase - (long)dsamp; - float aud = ZXP(in); - float input = aud + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ap = s - (sample * a); - if (irdphase < 0) { - dlybuf[iwrphase & mask] = aud; - ZXP(out) = 0.f; - } else { - ZXP(out) = sample; - dlybuf[iwrphase & mask] = sample * ZIN0(2); - } - ++iwrphase; - ); - } else { - LOOP(inNumSamples, - long irdphase = iwrphase - (long)dsamp; - float aud = ZXP(in); - float input = aud + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ap = s - (sample * a); - if (irdphase < 0) { - dlybuf[iwrphase & mask] = aud; - ZXP(out) = 0.f; - } else { - ZXP(out) = sample; - dlybuf[iwrphase & mask] = sample * ZIN0(2); - } - ++iwrphase; - ); - } - - unit->m_iwrphase = iwrphase; - unit->m_ap = zapgremlins(ap); - unit->m_lp = zapgremlins(lp); - unit->m_dsamp = dsamp; - unit->m_a = a; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_idelaylen) { - SETCALC(Streson_next_k); - } +void Streson_next_k_z(Streson* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float delaytime = unit->m_delaytime; + float next_delaytime = ZIN0(1); + float dsamp = unit->m_dsamp; + float a = unit->m_a; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + float ap = unit->m_ap; + float lp = unit->m_lp; + + if (next_delaytime != delaytime) { + float tdelay = next_delaytime * SAMPLERATE; + float dsamp = (long)(tdelay - 0.5); + float fracdelay = tdelay - (dsamp + 0.5); + float a = (1 - fracdelay) / (1 + fracdelay); + LOOP( + inNumSamples, long irdphase = iwrphase - (long)dsamp; float aud = ZXP(in); + float input = aud + dlybuf[irdphase & mask]; float s = lp * 0.5 + input * 0.5; lp = input; + float sample = ap + s * a; ap = s - (sample * a); if (irdphase < 0) { + dlybuf[iwrphase & mask] = aud; + ZXP(out) = 0.f; + } else { + ZXP(out) = sample; + dlybuf[iwrphase & mask] = sample * ZIN0(2); + } ++iwrphase;); + } else { + LOOP( + inNumSamples, long irdphase = iwrphase - (long)dsamp; float aud = ZXP(in); + float input = aud + dlybuf[irdphase & mask]; float s = lp * 0.5 + input * 0.5; lp = input; + float sample = ap + s * a; ap = s - (sample * a); if (irdphase < 0) { + dlybuf[iwrphase & mask] = aud; + ZXP(out) = 0.f; + } else { + ZXP(out) = sample; + dlybuf[iwrphase & mask] = sample * ZIN0(2); + } ++iwrphase;); + } + + unit->m_iwrphase = iwrphase; + unit->m_ap = zapgremlins(ap); + unit->m_lp = zapgremlins(lp); + unit->m_dsamp = dsamp; + unit->m_a = a; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_idelaylen) { + SETCALC(Streson_next_k); + } } -void Streson_next_a(Streson *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float *delaytime = ZIN(1); - float dsamp = unit->m_dsamp; - float a = unit->m_a; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - float ap = unit->m_ap; - float lp = unit->m_lp; - - LOOP(inNumSamples, - float tdelay = ZXP(delaytime) * SAMPLERATE; - float dsamp = (long)(tdelay - 0.5); - float fracdelay = tdelay - (dsamp + 0.5); - float a = (1-fracdelay)/(1+fracdelay); - long irdphase = iwrphase - (long)dsamp; - float input = ZXP(in) + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ZXP(out) = sample; - ap = s - (sample * a); - dlybuf[iwrphase & mask] = sample * ZIN0(2); - ++iwrphase; - ); - - unit->m_iwrphase = iwrphase; - unit->m_ap = zapgremlins(ap); - unit->m_lp = zapgremlins(lp); - unit->m_dsamp = dsamp; - unit->m_a = a; +void Streson_next_a(Streson* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float* delaytime = ZIN(1); + float dsamp = unit->m_dsamp; + float a = unit->m_a; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + float ap = unit->m_ap; + float lp = unit->m_lp; + + LOOP(inNumSamples, float tdelay = ZXP(delaytime) * SAMPLERATE; float dsamp = (long)(tdelay - 0.5); + float fracdelay = tdelay - (dsamp + 0.5); float a = (1 - fracdelay) / (1 + fracdelay); + long irdphase = iwrphase - (long)dsamp; float input = ZXP(in) + dlybuf[irdphase & mask]; + float s = lp * 0.5 + input * 0.5; lp = input; float sample = ap + s * a; ZXP(out) = sample; + ap = s - (sample * a); dlybuf[iwrphase & mask] = sample * ZIN0(2); ++iwrphase;); + + unit->m_iwrphase = iwrphase; + unit->m_ap = zapgremlins(ap); + unit->m_lp = zapgremlins(lp); + unit->m_dsamp = dsamp; + unit->m_a = a; } -void Streson_next_a_z(Streson *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float *in = ZIN(0); - float *delaytime = ZIN(1); - float dsamp = unit->m_dsamp; - float a = unit->m_a; - float *dlybuf = unit->m_dlybuf; - long iwrphase = unit->m_iwrphase; - long mask = unit->m_mask; - float ap = unit->m_ap; - float lp = unit->m_lp; - - LOOP(inNumSamples, - float tdelay = ZXP(delaytime) * SAMPLERATE; - float dsamp = (long)(tdelay - 0.5); - float fracdelay = tdelay - (dsamp + 0.5); - float a = (1-fracdelay)/(1+fracdelay); - long irdphase = iwrphase - (long)dsamp; - float aud = ZXP(in); - float input = aud + dlybuf[irdphase & mask]; - float s = lp * 0.5 + input * 0.5; - lp = input; - float sample = ap + s*a; - ap = s - (sample * a); - if (irdphase < 0) { - dlybuf[iwrphase & mask] = aud; - ZXP(out) = 0.f; - } else { - ZXP(out) = sample; - dlybuf[iwrphase & mask] = sample * ZIN0(2); - } - ++iwrphase; - ); - - unit->m_iwrphase = iwrphase; - unit->m_ap = zapgremlins(ap); - unit->m_lp = zapgremlins(lp); - unit->m_dsamp = dsamp; - unit->m_a = a; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_idelaylen) { - SETCALC(Streson_next_a); - } +void Streson_next_a_z(Streson* unit, int inNumSamples) { + float* out = ZOUT(0); + float* in = ZIN(0); + float* delaytime = ZIN(1); + float dsamp = unit->m_dsamp; + float a = unit->m_a; + float* dlybuf = unit->m_dlybuf; + long iwrphase = unit->m_iwrphase; + long mask = unit->m_mask; + float ap = unit->m_ap; + float lp = unit->m_lp; + + LOOP( + inNumSamples, float tdelay = ZXP(delaytime) * SAMPLERATE; float dsamp = (long)(tdelay - 0.5); + float fracdelay = tdelay - (dsamp + 0.5); float a = (1 - fracdelay) / (1 + fracdelay); + long irdphase = iwrphase - (long)dsamp; float aud = ZXP(in); float input = aud + dlybuf[irdphase & mask]; + float s = lp * 0.5 + input * 0.5; lp = input; float sample = ap + s * a; ap = s - (sample * a); + if (irdphase < 0) { + dlybuf[iwrphase & mask] = aud; + ZXP(out) = 0.f; + } else { + ZXP(out) = sample; + dlybuf[iwrphase & mask] = sample * ZIN0(2); + } ++iwrphase;); + + unit->m_iwrphase = iwrphase; + unit->m_ap = zapgremlins(ap); + unit->m_lp = zapgremlins(lp); + unit->m_dsamp = dsamp; + unit->m_a = a; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_idelaylen) { + SETCALC(Streson_next_a); + } } void MoogLadder_Ctor(MoogLadder* unit) { if (INRATE(1) == calc_FullRate) { - if (INRATE(2) == calc_FullRate) { - SETCALC(MoogLadder_next_aa); - } else { - SETCALC(MoogLadder_next_ak); - } - } else { - if (INRATE(2) == calc_FullRate) { - SETCALC(MoogLadder_next_ka); - } else { - SETCALC(MoogLadder_next_kk); - } - } - unit->m_fco = IN0(1); - float fc = unit->m_fco * SAMPLEDUR; - float f = unit->m_fco * SAMPLEDUR * 0.5; - float fcr = 1.8730*fc*fc*fc + 0.4955*fc*fc - 0.6490*fc + 0.9988; - unit->m_k2v = 1.25*(1-exp(-twopi*fcr*f)); - unit->m_res = IN0(2); - unit->m_xnm1 = unit->m_y1nm1 = unit->m_y2nm1 = unit->m_y3nm1 = unit->m_y4nm1 = 0.0f; - unit->m_y1n = unit->m_y2n = unit->m_y3n = unit->m_y4n = unit->m_y1n1 = 0.0f; - ClearUnitOutputs(unit, 1); + if (INRATE(2) == calc_FullRate) { + SETCALC(MoogLadder_next_aa); + } else { + SETCALC(MoogLadder_next_ak); + } + } else { + if (INRATE(2) == calc_FullRate) { + SETCALC(MoogLadder_next_ka); + } else { + SETCALC(MoogLadder_next_kk); + } + } + unit->m_fco = IN0(1); + float fc = unit->m_fco * SAMPLEDUR; + float f = unit->m_fco * SAMPLEDUR * 0.5; + float fcr = 1.8730 * fc * fc * fc + 0.4955 * fc * fc - 0.6490 * fc + 0.9988; + unit->m_k2v = 1.25 * (1 - exp(-twopi * fcr * f)); + unit->m_res = IN0(2); + unit->m_xnm1 = unit->m_y1nm1 = unit->m_y2nm1 = unit->m_y3nm1 = unit->m_y4nm1 = 0.0f; + unit->m_y1n = unit->m_y2n = unit->m_y3n = unit->m_y4n = unit->m_y1n1 = 0.0f; + ClearUnitOutputs(unit, 1); } -void MoogLadder_next_kk(MoogLadder *unit, int inNumSamples){ +void MoogLadder_next_kk(MoogLadder* unit, int inNumSamples) { float* in = ZIN(0); float* out = ZOUT(0); float nextfco = IN0(1); @@ -1074,101 +858,103 @@ void MoogLadder_next_kk(MoogLadder *unit, int inNumSamples){ float y1nm1 = unit->m_y1nm1; float y2nm1 = unit->m_y2nm1; float y3nm1 = unit->m_y3nm1; - float y4nm1 = unit->m_y4nm1; - float y1n1 = unit->m_y1n1; - float y2n1, y3n1; - float k2v = unit->m_k2v; + float y4nm1 = unit->m_y4nm1; + float y1n1 = unit->m_y1n1; + float y2n1, y3n1; + float k2v = unit->m_k2v; float y1n = unit->m_y1n; float y2n = unit->m_y2n; float y3n = unit->m_y3n; float y4n = unit->m_y4n; - // float i2v = 0.6103515625; - float i2v = 0.70466; + // float i2v = 0.6103515625; + float i2v = 0.70466; float fc, f, fcr, xn; - float k2vslope=0; - float resslope=0; - - if (nextfco != fco) { - fc = nextfco * SAMPLEDUR; - f = nextfco * SAMPLEDUR * 0.5; - fcr = 1.8730*((fc * fc * fc) + 0.4955*(fc * fc)) - 0.6490*fc + 0.9988; - float nextk2v = 1.25 * (1-exp(-twopi*fcr*f)); - k2vslope=CALCSLOPE(nextk2v, k2v); - } - - if (nextres != res) { - resslope=CALCSLOPE(nextres, res); - }; - - for (int i = 0; i < inNumSamples; i++) { - float input = ZXP(in); - xn = input - 8*res*y4n; - float xn1 = xn * i2v; - - float y2nm11 = y2nm1 * i2v; - float y3nm11 = y3nm1 * i2v; - float y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - xn = input - 8*res*y4n; - - xn1 = xn * i2v; - y2nm11 = y2nm1 * i2v; - y3nm11 = y3nm1 * i2v; - y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - if (k2vslope != 0) k2v += k2vslope; - if (resslope != 0) res += resslope; - ZXP(out) = y4n; + float k2vslope = 0; + float resslope = 0; + + if (nextfco != fco) { + fc = nextfco * SAMPLEDUR; + f = nextfco * SAMPLEDUR * 0.5; + fcr = 1.8730 * ((fc * fc * fc) + 0.4955 * (fc * fc)) - 0.6490 * fc + 0.9988; + float nextk2v = 1.25 * (1 - exp(-twopi * fcr * f)); + k2vslope = CALCSLOPE(nextk2v, k2v); + } + + if (nextres != res) { + resslope = CALCSLOPE(nextres, res); + }; + + for (int i = 0; i < inNumSamples; i++) { + float input = ZXP(in); + xn = input - 8 * res * y4n; + float xn1 = xn * i2v; + + float y2nm11 = y2nm1 * i2v; + float y3nm11 = y3nm1 * i2v; + float y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + xn = input - 8 * res * y4n; + + xn1 = xn * i2v; + y2nm11 = y2nm1 * i2v; + y3nm11 = y3nm1 * i2v; + y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + if (k2vslope != 0) + k2v += k2vslope; + if (resslope != 0) + res += resslope; + ZXP(out) = y4n; } unit->m_fco = nextfco; unit->m_res = res; - unit->m_k2v = k2v; + unit->m_k2v = k2v; unit->m_xnm1 = zapgremlins(xnm1); unit->m_y1nm1 = zapgremlins(y1nm1); unit->m_y2nm1 = zapgremlins(y2nm1); unit->m_y3nm1 = zapgremlins(y3nm1); - unit->m_y4nm1 = zapgremlins(y4nm1); - unit->m_y1n1 = zapgremlins(y1n1); + unit->m_y4nm1 = zapgremlins(y4nm1); + unit->m_y1n1 = zapgremlins(y1n1); unit->m_y1n = zapgremlins(y1n); unit->m_y2n = zapgremlins(y2n); unit->m_y3n = zapgremlins(y3n); unit->m_y4n = zapgremlins(y4n); } -void MoogLadder_next_ka(MoogLadder *unit, int inNumSamples){ - float* in = ZIN(0); +void MoogLadder_next_ka(MoogLadder* unit, int inNumSamples) { + float* in = ZIN(0); float* out = ZOUT(0); float nextfco = IN0(1); float fco = unit->m_fco; @@ -1178,93 +964,94 @@ void MoogLadder_next_ka(MoogLadder *unit, int inNumSamples){ float y1nm1 = unit->m_y1nm1; float y2nm1 = unit->m_y2nm1; float y3nm1 = unit->m_y3nm1; - float y4nm1 = unit->m_y4nm1; - float y1n1 = unit->m_y1n1; - float y2n1, y3n1; - float k2v = unit->m_k2v; + float y4nm1 = unit->m_y4nm1; + float y1n1 = unit->m_y1n1; + float y2n1, y3n1; + float k2v = unit->m_k2v; float y1n = unit->m_y1n; float y2n = unit->m_y2n; float y3n = unit->m_y3n; float y4n = unit->m_y4n; - float i2v = 0.70466; + float i2v = 0.70466; float fc, f, fcr, xn; - float k2vslope=0; - - if (nextfco != fco) { - fc = nextfco * SAMPLEDUR; - f = nextfco * SAMPLEDUR * 0.5; - fcr = 1.8730*((fc * fc * fc) + 0.4955*(fc * fc)) - 0.6490*fc + 0.9988; - float nextk2v = 1.25*(1-exp(-twopi*fcr*f)); - k2vslope=CALCSLOPE(nextk2v, k2v); - } + float k2vslope = 0; + + if (nextfco != fco) { + fc = nextfco * SAMPLEDUR; + f = nextfco * SAMPLEDUR * 0.5; + fcr = 1.8730 * ((fc * fc * fc) + 0.4955 * (fc * fc)) - 0.6490 * fc + 0.9988; + float nextk2v = 1.25 * (1 - exp(-twopi * fcr * f)); + k2vslope = CALCSLOPE(nextk2v, k2v); + } for (int i = 0; i < inNumSamples; i++) { - float input = ZXP(in); - xn = input - 8*res[i]*y4n; - float xn1 = xn * i2v; - - float y2nm11 = y2nm1 * i2v; - float y3nm11 = y3nm1 * i2v; - float y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - xn = input - 8*res[i]*y4n; - - xn1 = xn * i2v; - y2nm11 = y2nm1 * i2v; - y3nm11 = y3nm1 * i2v; - y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - if (k2vslope != 0) k2v += k2vslope; - ZXP(out) = y4n; + float input = ZXP(in); + xn = input - 8 * res[i] * y4n; + float xn1 = xn * i2v; + + float y2nm11 = y2nm1 * i2v; + float y3nm11 = y3nm1 * i2v; + float y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + xn = input - 8 * res[i] * y4n; + + xn1 = xn * i2v; + y2nm11 = y2nm1 * i2v; + y3nm11 = y3nm1 * i2v; + y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + if (k2vslope != 0) + k2v += k2vslope; + ZXP(out) = y4n; } unit->m_fco = nextfco; - unit->m_k2v = k2v; + unit->m_k2v = k2v; unit->m_xnm1 = zapgremlins(xnm1); unit->m_y1nm1 = zapgremlins(y1nm1); unit->m_y2nm1 = zapgremlins(y2nm1); unit->m_y3nm1 = zapgremlins(y3nm1); - unit->m_y4nm1 = zapgremlins(y4nm1); - unit->m_y1n1 = zapgremlins(y1n1); + unit->m_y4nm1 = zapgremlins(y4nm1); + unit->m_y1n1 = zapgremlins(y1n1); unit->m_y1n = zapgremlins(y1n); unit->m_y2n = zapgremlins(y2n); unit->m_y3n = zapgremlins(y3n); unit->m_y4n = zapgremlins(y4n); } -void MoogLadder_next_ak(MoogLadder *unit, int inNumSamples){ - float* in = ZIN(0); +void MoogLadder_next_ak(MoogLadder* unit, int inNumSamples) { + float* in = ZIN(0); float* out = ZOUT(0); float* nextfco = IN(1); float nextres = IN0(2); @@ -1275,96 +1062,97 @@ void MoogLadder_next_ak(MoogLadder *unit, int inNumSamples){ float y1nm1 = unit->m_y1nm1; float y2nm1 = unit->m_y2nm1; float y3nm1 = unit->m_y3nm1; - float y4nm1 = unit->m_y4nm1; - float y1n1 = unit->m_y1n1; - float y2n1, y3n1; - float k2v = unit->m_k2v; + float y4nm1 = unit->m_y4nm1; + float y1n1 = unit->m_y1n1; + float y2n1, y3n1; + float k2v = unit->m_k2v; float y1n = unit->m_y1n; float y2n = unit->m_y2n; float y3n = unit->m_y3n; float y4n = unit->m_y4n; - float i2v = 0.70466; + float i2v = 0.70466; float fc, f, fcr, xn; - float resslope=0; + float resslope = 0; - if (nextres != res) { - resslope=CALCSLOPE(nextres, res); - } + if (nextres != res) { + resslope = CALCSLOPE(nextres, res); + } for (int i = 0; i < inNumSamples; i++) { - if (nextfco[i] != fco) { - fc = nextfco[i] * SAMPLEDUR; - f = nextfco[i] * SAMPLEDUR * 0.5; - fcr = 1.8730*((fc * fc * fc) + 0.4955*(fc * fc)) - 0.6490*fc + 0.9988; - k2v = 1.25*(1-exp(-twopi*fcr*f)); - fco=nextfco[i]; - } - float input = ZXP(in); - xn = input - 8*res*y4n; - float xn1 = xn * i2v; - - float y2nm11 = y2nm1 * i2v; - float y3nm11 = y3nm1 * i2v; - float y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - xn = input - 8*res*y4n; - - xn1 = xn * i2v; - y2nm11 = y2nm1 * i2v; - y3nm11 = y3nm1 * i2v; - y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - if (resslope != 0) res += resslope; - ZXP(out) = y4n; + if (nextfco[i] != fco) { + fc = nextfco[i] * SAMPLEDUR; + f = nextfco[i] * SAMPLEDUR * 0.5; + fcr = 1.8730 * ((fc * fc * fc) + 0.4955 * (fc * fc)) - 0.6490 * fc + 0.9988; + k2v = 1.25 * (1 - exp(-twopi * fcr * f)); + fco = nextfco[i]; + } + float input = ZXP(in); + xn = input - 8 * res * y4n; + float xn1 = xn * i2v; + + float y2nm11 = y2nm1 * i2v; + float y3nm11 = y3nm1 * i2v; + float y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + xn = input - 8 * res * y4n; + + xn1 = xn * i2v; + y2nm11 = y2nm1 * i2v; + y3nm11 = y3nm1 * i2v; + y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + if (resslope != 0) + res += resslope; + ZXP(out) = y4n; } unit->m_fco = fco; unit->m_res = res; - unit->m_k2v = k2v; + unit->m_k2v = k2v; unit->m_xnm1 = zapgremlins(xnm1); unit->m_y1nm1 = zapgremlins(y1nm1); unit->m_y2nm1 = zapgremlins(y2nm1); unit->m_y3nm1 = zapgremlins(y3nm1); - unit->m_y4nm1 = zapgremlins(y4nm1); - unit->m_y1n1 = zapgremlins(y1n1); + unit->m_y4nm1 = zapgremlins(y4nm1); + unit->m_y1n1 = zapgremlins(y1n1); unit->m_y1n = zapgremlins(y1n); unit->m_y2n = zapgremlins(y2n); unit->m_y3n = zapgremlins(y3n); unit->m_y4n = zapgremlins(y4n); } -void MoogLadder_next_aa(MoogLadder *unit, int inNumSamples){ +void MoogLadder_next_aa(MoogLadder* unit, int inNumSamples) { float* in = ZIN(0); float* out = ZOUT(0); float* nextfco = IN(1); @@ -1375,73 +1163,73 @@ void MoogLadder_next_aa(MoogLadder *unit, int inNumSamples){ float y1nm1 = unit->m_y1nm1; float y2nm1 = unit->m_y2nm1; float y3nm1 = unit->m_y3nm1; - float y4nm1 = unit->m_y4nm1; - float y1n1 = unit->m_y1n1; - float y2n1, y3n1; - float k2v = unit->m_k2v; + float y4nm1 = unit->m_y4nm1; + float y1n1 = unit->m_y1n1; + float y2n1, y3n1; + float k2v = unit->m_k2v; float y1n = unit->m_y1n; float y2n = unit->m_y2n; float y3n = unit->m_y3n; float y4n = unit->m_y4n; - float i2v = 0.70466; + float i2v = 0.70466; float fc, f, fcr, xn; for (int i = 0; i < inNumSamples; i++) { - if (nextfco[i] != fco) { - fc = nextfco[i] * SAMPLEDUR; - f = nextfco[i] * SAMPLEDUR * 0.5; - fcr = 1.8730*((fc * fc * fc) + 0.4955*(fc * fc)) - 0.6490*fc + 0.9988; - k2v = 1.220703125*(1-exp(-twopi*fcr*f)); - fco=nextfco[i]; - } - - float input = ZXP(in); - xn = input - 8*res[i]*y4n; - float xn1 = xn * i2v; - - float y2nm11 = y2nm1 * i2v; - float y3nm11 = y3nm1 * i2v; - float y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - xn = input - 8*res[i]*y4n; - - xn1 = xn * i2v; - y2nm11 = y2nm1 * i2v; - y3nm11 = y3nm1 * i2v; - y4nm11 = y4nm1 * i2v; - - y1n = xnm1 + k2v * (xn1/(1 + fabs(xn1)) - y1n1/(1 + fabs(y1n1))); - y1n1 = y1n * i2v; - y2n = y2nm1 + k2v * (y1n1/(1 + fabs(y1n1)) - y2nm11/(1 + fabs(y2nm11))); - y2n1 = y2n * i2v; - y3n = y3nm1 + k2v * (y2n1/(1 + fabs(y2n1)) - y3nm11/(1 + fabs(y3nm11))); - y3n1 = y3n * i2v; - y4n = y4nm1 + k2v * (y3n1/(1 + fabs(y3n1)) - y4nm11/(1 + fabs(y4nm11))); - y4n = (y4n+y4nm1) * 0.5; - - xnm1 = xn; - y1nm1 = y1n; - y2nm1 = y2n; - y3nm1 = y3n; - y4nm1 = y4n; - - ZXP(out) = y4n; + if (nextfco[i] != fco) { + fc = nextfco[i] * SAMPLEDUR; + f = nextfco[i] * SAMPLEDUR * 0.5; + fcr = 1.8730 * ((fc * fc * fc) + 0.4955 * (fc * fc)) - 0.6490 * fc + 0.9988; + k2v = 1.220703125 * (1 - exp(-twopi * fcr * f)); + fco = nextfco[i]; + } + + float input = ZXP(in); + xn = input - 8 * res[i] * y4n; + float xn1 = xn * i2v; + + float y2nm11 = y2nm1 * i2v; + float y3nm11 = y3nm1 * i2v; + float y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + xn = input - 8 * res[i] * y4n; + + xn1 = xn * i2v; + y2nm11 = y2nm1 * i2v; + y3nm11 = y3nm1 * i2v; + y4nm11 = y4nm1 * i2v; + + y1n = xnm1 + k2v * (xn1 / (1 + fabs(xn1)) - y1n1 / (1 + fabs(y1n1))); + y1n1 = y1n * i2v; + y2n = y2nm1 + k2v * (y1n1 / (1 + fabs(y1n1)) - y2nm11 / (1 + fabs(y2nm11))); + y2n1 = y2n * i2v; + y3n = y3nm1 + k2v * (y2n1 / (1 + fabs(y2n1)) - y3nm11 / (1 + fabs(y3nm11))); + y3n1 = y3n * i2v; + y4n = y4nm1 + k2v * (y3n1 / (1 + fabs(y3n1)) - y4nm11 / (1 + fabs(y4nm11))); + y4n = (y4n + y4nm1) * 0.5; + + xnm1 = xn; + y1nm1 = y1n; + y2nm1 = y2n; + y3nm1 = y3n; + y4nm1 = y4n; + + ZXP(out) = y4n; } unit->m_k2v = k2v; @@ -1449,8 +1237,8 @@ void MoogLadder_next_aa(MoogLadder *unit, int inNumSamples){ unit->m_y1nm1 = zapgremlins(y1nm1); unit->m_y2nm1 = zapgremlins(y2nm1); unit->m_y3nm1 = zapgremlins(y3nm1); - unit->m_y4nm1 = zapgremlins(y4nm1); - unit->m_y1n1 = zapgremlins(y1n1); + unit->m_y4nm1 = zapgremlins(y4nm1); + unit->m_y1n1 = zapgremlins(y1n1); unit->m_y1n = zapgremlins(y1n); unit->m_y2n = zapgremlins(y2n); unit->m_y3n = zapgremlins(y3n); @@ -1458,1878 +1246,1475 @@ void MoogLadder_next_aa(MoogLadder *unit, int inNumSamples){ } void MultiFilt_Ctor(MultiFilt* unit) { - if (INRATE(1) == calc_FullRate) { - if (INRATE(2) == calc_FullRate) { - SETCALC(MultiFilt_next_aa); - } else { - SETCALC(MultiFilt_next_ak); - } - } else { - if (INRATE(2) == calc_FullRate) { - SETCALC(MultiFilt_next_ka); - } else { - SETCALC(MultiFilt_next_kk); - } - } - float cf = ZIN0(1); - unit->m_cf = cf; - unit->m_rq = ZIN0(2); - unit->m_f = 2.f*sin(pi*cf*SAMPLEDUR*0.25); - unit->m_hp = unit->m_lp = unit->m_bp = 0.0f; - unit->m_halfsamp = 20000; - ClearUnitOutputs(unit, 1); + if (INRATE(1) == calc_FullRate) { + if (INRATE(2) == calc_FullRate) { + SETCALC(MultiFilt_next_aa); + } else { + SETCALC(MultiFilt_next_ak); + } + } else { + if (INRATE(2) == calc_FullRate) { + SETCALC(MultiFilt_next_ka); + } else { + SETCALC(MultiFilt_next_kk); + } + } + float cf = ZIN0(1); + unit->m_cf = cf; + unit->m_rq = ZIN0(2); + unit->m_f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); + unit->m_hp = unit->m_lp = unit->m_bp = 0.0f; + unit->m_halfsamp = 20000; + ClearUnitOutputs(unit, 1); } -void MultiFilt_next_kk(MultiFilt *unit, int inNumSamples) { - float* in = ZIN(0); +void MultiFilt_next_kk(MultiFilt* unit, int inNumSamples) { + float* in = ZIN(0); float* out[3]; - out[0] = ZOUT(0); - out[1] = ZOUT(1); - out[2] = ZOUT(2); + out[0] = ZOUT(0); + out[1] = ZOUT(1); + out[2] = ZOUT(2); float nextcf = ZIN0(1); float nextrq = ZIN0(2); - float rq = unit->m_rq; - float f = unit->m_f; - float hp = unit->m_hp; - float lp = unit->m_lp; - float bp = unit->m_bp; - - if (nextcf != unit->m_cf) { - float nextf = 2.f * sin(pi * nextcf * SAMPLEDUR * 0.25); - float fslope = CALCSLOPE(nextf, f); - - if (nextrq != rq) { - if (nextrq * unit->m_halfsamp < nextcf) nextrq = nextcf/unit->m_halfsamp; - float rqslope = CALCSLOPE(nextrq, rq); - LOOP(inNumSamples, - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - f += fslope; - rq += rqslope; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } else { - if (rq * unit->m_halfsamp < nextcf) rq = nextcf/unit->m_halfsamp; - LOOP(inNumSamples, - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - f += fslope; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } - } else { - if (nextrq != rq) { - if (nextrq * unit->m_halfsamp < nextcf) nextrq = nextcf/unit->m_halfsamp; - float rqslope = CALCSLOPE(nextrq, rq); - LOOP(inNumSamples, - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - rq += rqslope; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } else { - if (rq * unit->m_halfsamp < nextcf) rq = nextcf/unit->m_halfsamp; - LOOP(inNumSamples, - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } - } - - unit->m_hp=zapgremlins(hp); - unit->m_lp=zapgremlins(lp); - unit->m_bp=zapgremlins(bp); - unit->m_f=f; - unit->m_cf=nextcf; - unit->m_rq=nextrq; + float rq = unit->m_rq; + float f = unit->m_f; + float hp = unit->m_hp; + float lp = unit->m_lp; + float bp = unit->m_bp; + + if (nextcf != unit->m_cf) { + float nextf = 2.f * sin(pi * nextcf * SAMPLEDUR * 0.25); + float fslope = CALCSLOPE(nextf, f); + + if (nextrq != rq) { + if (nextrq * unit->m_halfsamp < nextcf) + nextrq = nextcf / unit->m_halfsamp; + float rqslope = CALCSLOPE(nextrq, rq); + LOOP(inNumSamples, float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + f += fslope; rq += rqslope; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } else { + if (rq * unit->m_halfsamp < nextcf) + rq = nextcf / unit->m_halfsamp; + LOOP(inNumSamples, float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + f += fslope; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } + } else { + if (nextrq != rq) { + if (nextrq * unit->m_halfsamp < nextcf) + nextrq = nextcf / unit->m_halfsamp; + float rqslope = CALCSLOPE(nextrq, rq); + LOOP(inNumSamples, float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + rq += rqslope; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } else { + if (rq * unit->m_halfsamp < nextcf) + rq = nextcf / unit->m_halfsamp; + LOOP(inNumSamples, float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } + } + + unit->m_hp = zapgremlins(hp); + unit->m_lp = zapgremlins(lp); + unit->m_bp = zapgremlins(bp); + unit->m_f = f; + unit->m_cf = nextcf; + unit->m_rq = nextrq; } -void MultiFilt_next_ak(MultiFilt *unit, int inNumSamples) { - float* in = ZIN(0); +void MultiFilt_next_ak(MultiFilt* unit, int inNumSamples) { + float* in = ZIN(0); float* out[3]; - out[0] = ZOUT(0); - out[1] = ZOUT(1); - out[2] = ZOUT(2); + out[0] = ZOUT(0); + out[1] = ZOUT(1); + out[2] = ZOUT(2); float* nextcf = ZIN(1); float nextrq = ZIN0(2); - float rq = unit->m_rq; - float f = unit->m_f; - float hp = unit->m_hp; - float lp = unit->m_lp; - float bp = unit->m_bp; - float lastcf = unit->m_cf; - float cf; - - if (nextrq != rq) { - float rqslope = CALCSLOPE(nextrq, rq); - LOOP(inNumSamples, - cf = ZXP(nextcf); - if (cf != lastcf) { - f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); - lastcf = cf; - } - - if (rq * unit->m_halfsamp < cf) rq = cf/unit->m_halfsamp; - - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - rq += rqslope; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } else { - LOOP(inNumSamples, - cf = ZXP(nextcf); - if (cf != lastcf) { - f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); - lastcf = cf; - } - - if (rq * unit->m_halfsamp < cf) rq = cf/unit->m_halfsamp; - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } - - unit->m_hp=zapgremlins(hp); - unit->m_lp=zapgremlins(lp); - unit->m_bp=zapgremlins(bp); - unit->m_f=f; - unit->m_cf=cf; - unit->m_rq=nextrq; + float rq = unit->m_rq; + float f = unit->m_f; + float hp = unit->m_hp; + float lp = unit->m_lp; + float bp = unit->m_bp; + float lastcf = unit->m_cf; + float cf; + + if (nextrq != rq) { + float rqslope = CALCSLOPE(nextrq, rq); + LOOP( + inNumSamples, cf = ZXP(nextcf); if (cf != lastcf) { + f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); + lastcf = cf; + } + + if (rq * unit->m_halfsamp < cf) rq = cf / unit->m_halfsamp; + + float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + rq += rqslope; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } else { + LOOP( + inNumSamples, cf = ZXP(nextcf); if (cf != lastcf) { + f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); + lastcf = cf; + } + + if (rq * unit->m_halfsamp < cf) rq = cf / unit->m_halfsamp; + float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } + + unit->m_hp = zapgremlins(hp); + unit->m_lp = zapgremlins(lp); + unit->m_bp = zapgremlins(bp); + unit->m_f = f; + unit->m_cf = cf; + unit->m_rq = nextrq; } -void MultiFilt_next_ka(MultiFilt *unit, int inNumSamples) { - float* in = ZIN(0); +void MultiFilt_next_ka(MultiFilt* unit, int inNumSamples) { + float* in = ZIN(0); float* out[3]; - out[0] = ZOUT(0); - out[1] = ZOUT(1); - out[2] = ZOUT(2); + out[0] = ZOUT(0); + out[1] = ZOUT(1); + out[2] = ZOUT(2); float nextcf = ZIN0(1); float* nextrq = ZIN(2); - float rq; - float f = unit->m_f; - float hp = unit->m_hp; - float lp = unit->m_lp; - float bp = unit->m_bp; - - if (nextcf != unit->m_cf) { - float nextf = 2.f * sin(pi * nextcf * SAMPLEDUR * 0.25); - float fslope = CALCSLOPE(nextf, f); - - LOOP(inNumSamples, - rq = ZXP(nextrq); - if (rq * unit->m_halfsamp < nextcf) rq = nextcf/unit->m_halfsamp; - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - f += fslope; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } else { - LOOP(inNumSamples, - rq = ZXP(nextrq); - if (rq * unit->m_halfsamp < nextcf) rq = nextcf/unit->m_halfsamp; - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - } - - unit->m_hp=zapgremlins(hp); - unit->m_lp=zapgremlins(lp); - unit->m_bp=zapgremlins(bp); - unit->m_f=f; - unit->m_cf=nextcf; - unit->m_rq=rq; + float rq; + float f = unit->m_f; + float hp = unit->m_hp; + float lp = unit->m_lp; + float bp = unit->m_bp; + + if (nextcf != unit->m_cf) { + float nextf = 2.f * sin(pi * nextcf * SAMPLEDUR * 0.25); + float fslope = CALCSLOPE(nextf, f); + + LOOP(inNumSamples, rq = ZXP(nextrq); if (rq * unit->m_halfsamp < nextcf) rq = nextcf / unit->m_halfsamp; + float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + f += fslope; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } else { + LOOP(inNumSamples, rq = ZXP(nextrq); if (rq * unit->m_halfsamp < nextcf) rq = nextcf / unit->m_halfsamp; + float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + } + + unit->m_hp = zapgremlins(hp); + unit->m_lp = zapgremlins(lp); + unit->m_bp = zapgremlins(bp); + unit->m_f = f; + unit->m_cf = nextcf; + unit->m_rq = rq; } -void MultiFilt_next_aa(MultiFilt *unit, int inNumSamples) { - float* in = ZIN(0); +void MultiFilt_next_aa(MultiFilt* unit, int inNumSamples) { + float* in = ZIN(0); float* out[3]; - out[0] = ZOUT(0); - out[1] = ZOUT(1); - out[2] = ZOUT(2); + out[0] = ZOUT(0); + out[1] = ZOUT(1); + out[2] = ZOUT(2); float* nextcf = ZIN(1); - float* nextrq = ZIN(2); - float f = unit->m_f; - float hp = unit->m_hp; - float lp = unit->m_lp; - float bp = unit->m_bp; - float lastcf = unit->m_cf; - float cf, rq; - - LOOP(inNumSamples, - cf = ZXP(nextcf); - rq = ZXP(nextrq); - if (cf != lastcf) { - f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); - lastcf = cf; - } - - if (rq * unit->m_halfsamp < cf) rq = cf/unit->m_halfsamp; - - float sig = ZXP(in); - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - hp=sig - rq * bp - lp; - lp=bp * f + lp; - bp=hp * f + bp; - - ZXP(out[0]) = lp; - ZXP(out[1]) = hp; - ZXP(out[2]) = bp; - ); - - unit->m_hp=zapgremlins(hp); - unit->m_lp=zapgremlins(lp); - unit->m_bp=zapgremlins(bp); - unit->m_f=f; - unit->m_cf=cf; - unit->m_rq=rq; + float* nextrq = ZIN(2); + float f = unit->m_f; + float hp = unit->m_hp; + float lp = unit->m_lp; + float bp = unit->m_bp; + float lastcf = unit->m_cf; + float cf, rq; + + LOOP( + inNumSamples, cf = ZXP(nextcf); rq = ZXP(nextrq); if (cf != lastcf) { + f = 2.f * sin(pi * cf * SAMPLEDUR * 0.25); + lastcf = cf; + } + + if (rq * unit->m_halfsamp < cf) rq = cf / unit->m_halfsamp; + + float sig = ZXP(in); hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + hp = sig - rq * bp - lp; lp = bp * f + lp; bp = hp * f + bp; + + ZXP(out[0]) = lp; ZXP(out[1]) = hp; ZXP(out[2]) = bp;); + + unit->m_hp = zapgremlins(hp); + unit->m_lp = zapgremlins(lp); + unit->m_bp = zapgremlins(bp); + unit->m_f = f; + unit->m_cf = cf; + unit->m_rq = rq; } void RLPFD_Ctor(RLPFD* unit) { if (INRATE(1) == calc_FullRate) { - if (INRATE(2) == calc_FullRate) { - SETCALC(RLPFD_next_aa); // a-rate fco and res - } else { - SETCALC(RLPFD_next_ak); // a-rate fco, k-rate res - } - } else { - if (INRATE(2) == calc_FullRate) { - SETCALC(RLPFD_next_ka); // k-rate fco, a-rate res - } else { - SETCALC(RLPFD_next_kk); - } // k-rate fco and res - } - float fco = IN0(1); - float fcn = 2.f * fco * SAMPLEDUR; - unit->m_ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; - float ap1 = unit->m_ap + 1; - unit->m_scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; - unit->m_fco = fco; - unit->m_res = IN0(2); - unit->m_x1 = unit->m_y1 = unit->m_y2 = unit->m_y3 = 0.0f; - unit->m_x1nm1 = unit->m_y1nm1 = unit->m_y2nm1 = 0.0f; - ClearUnitOutputs(unit, 1); + if (INRATE(2) == calc_FullRate) { + SETCALC(RLPFD_next_aa); // a-rate fco and res + } else { + SETCALC(RLPFD_next_ak); // a-rate fco, k-rate res + } + } else { + if (INRATE(2) == calc_FullRate) { + SETCALC(RLPFD_next_ka); // k-rate fco, a-rate res + } else { + SETCALC(RLPFD_next_kk); + } // k-rate fco and res + } + float fco = IN0(1); + float fcn = 2.f * fco * SAMPLEDUR; + unit->m_ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; + float ap1 = unit->m_ap + 1; + unit->m_scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; + unit->m_fco = fco; + unit->m_res = IN0(2); + unit->m_x1 = unit->m_y1 = unit->m_y2 = unit->m_y3 = 0.0f; + unit->m_x1nm1 = unit->m_y1nm1 = unit->m_y2nm1 = 0.0f; + ClearUnitOutputs(unit, 1); } -void RLPFD_next_kk(RLPFD *unit, int inNumSamples){ +void RLPFD_next_kk(RLPFD* unit, int inNumSamples) { float* in = IN(0); float* out = OUT(0); float nextfco = IN0(1); float nextres = IN0(2); - float dist = IN0(3) * 0.001; + float dist = IN0(3) * 0.001; float fco = unit->m_fco; float res = unit->m_res; - float fcn = 2.f * nextfco * SAMPLEDUR; + float fcn = 2.f * nextfco * SAMPLEDUR; float x1nm1 = unit->m_x1nm1; float y1nm1 = unit->m_y1nm1; - float y2nm1 = unit->m_y2nm1; - float ap = unit->m_ap; - float ap1 = ap + 1.f; - float scl = unit->m_scl; + float y2nm1 = unit->m_y2nm1; + float ap = unit->m_ap; + float ap1 = ap + 1.f; + float scl = unit->m_scl; float y1 = unit->m_y1; float y2 = unit->m_y2; float y3 = unit->m_y3; float x1 = unit->m_x1; - float apslope=0; - float resslope=0; - float sclslope=0; - - if (nextfco != fco) { - float nextap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; - ap1 = nextap + 1; - float nextscl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; - apslope=CALCSLOPE(nextap, ap); - sclslope=CALCSLOPE(nextscl, scl); - } - - if (nextres != res) { - resslope=CALCSLOPE(nextres, res); - } - - for (int i = 0; i < inNumSamples; i++) { - float kres = res * scl; - ap1 = ap + 1.f; - x1 = in[i] - kres * y3/sqrt(1 + y3 * y3); - y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; - y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; - y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; - if (dist > 0.f) y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); - y3 = y3/sqrt(1 + y3 * y3); - - x1nm1 = x1; - y1nm1 = y1; - y2nm1 = y2; - - out[i] = y3; - - if (apslope != 0.f) { - ap += apslope; - scl += sclslope; - } - if (resslope != 0.f) res += resslope; - } - - unit->m_ap=ap; - unit->m_scl=scl; - unit->m_fco=nextfco; - unit->m_res=res; - unit->m_x1=zapgremlins(x1); - unit->m_y1=zapgremlins(y1); - unit->m_y2=zapgremlins(y2); - unit->m_y3=zapgremlins(y3); - unit->m_x1nm1=zapgremlins(x1nm1); - unit->m_y1nm1=zapgremlins(y1nm1); - unit->m_y2nm1=zapgremlins(y2nm1); + float apslope = 0; + float resslope = 0; + float sclslope = 0; + + if (nextfco != fco) { + float nextap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; + ap1 = nextap + 1; + float nextscl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; + apslope = CALCSLOPE(nextap, ap); + sclslope = CALCSLOPE(nextscl, scl); + } + + if (nextres != res) { + resslope = CALCSLOPE(nextres, res); + } + + for (int i = 0; i < inNumSamples; i++) { + float kres = res * scl; + ap1 = ap + 1.f; + x1 = in[i] - kres * y3 / sqrt(1 + y3 * y3); + y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; + y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; + y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; + if (dist > 0.f) + y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); + y3 = y3 / sqrt(1 + y3 * y3); + + x1nm1 = x1; + y1nm1 = y1; + y2nm1 = y2; + + out[i] = y3; + + if (apslope != 0.f) { + ap += apslope; + scl += sclslope; + } + if (resslope != 0.f) + res += resslope; + } + + unit->m_ap = ap; + unit->m_scl = scl; + unit->m_fco = nextfco; + unit->m_res = res; + unit->m_x1 = zapgremlins(x1); + unit->m_y1 = zapgremlins(y1); + unit->m_y2 = zapgremlins(y2); + unit->m_y3 = zapgremlins(y3); + unit->m_x1nm1 = zapgremlins(x1nm1); + unit->m_y1nm1 = zapgremlins(y1nm1); + unit->m_y2nm1 = zapgremlins(y2nm1); } -void RLPFD_next_ka(RLPFD *unit, int inNumSamples){ - float* in = IN(0); +void RLPFD_next_ka(RLPFD* unit, int inNumSamples) { + float* in = IN(0); float* out = OUT(0); float nextfco = IN0(1); - float dist = IN0(3) * 0.001; + float dist = IN0(3) * 0.001; float fco = unit->m_fco; float* res = IN(2); - float fcn = 2.f * nextfco * SAMPLEDUR; + float fcn = 2.f * nextfco * SAMPLEDUR; float x1nm1 = unit->m_x1nm1; float y1nm1 = unit->m_y1nm1; - float y2nm1 = unit->m_y2nm1; - float ap = unit->m_ap; - float ap1 = ap + 1.f; - float scl = unit->m_scl; + float y2nm1 = unit->m_y2nm1; + float ap = unit->m_ap; + float ap1 = ap + 1.f; + float scl = unit->m_scl; float y1 = unit->m_y1; float y2 = unit->m_y2; float y3 = unit->m_y3; float x1 = unit->m_x1; - float apslope=0; - float sclslope=0; - - if (nextfco != fco) { - float nextap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; - ap1 = nextap + 1; - float nextscl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; - apslope=CALCSLOPE(nextap, ap); - sclslope=CALCSLOPE(nextscl, scl); - } - - for (int i = 0; i < inNumSamples; i++) { - float kres = res[i] * scl; - ap1 = ap + 1.f; - x1 = in[i] - kres * y3/sqrt(1 + y3 * y3); - y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; - y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; - y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; - if (dist > 0.f) y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); - y3 = y3/sqrt(1 + y3 * y3); - - x1nm1 = x1; - y1nm1 = y1; - y2nm1 = y2; - - out[i] = y3; - - if (apslope != 0.f) { - ap += apslope; - scl += sclslope; - } - } - - unit->m_ap=ap; - unit->m_scl=scl; - unit->m_fco=nextfco; - unit->m_x1=zapgremlins(x1); - unit->m_y1=zapgremlins(y1); - unit->m_y2=zapgremlins(y2); - unit->m_y3=zapgremlins(y3); - unit->m_x1nm1=zapgremlins(x1nm1); - unit->m_y1nm1=zapgremlins(y1nm1); - unit->m_y2nm1=zapgremlins(y2nm1); + float apslope = 0; + float sclslope = 0; + + if (nextfco != fco) { + float nextap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; + ap1 = nextap + 1; + float nextscl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; + apslope = CALCSLOPE(nextap, ap); + sclslope = CALCSLOPE(nextscl, scl); + } + + for (int i = 0; i < inNumSamples; i++) { + float kres = res[i] * scl; + ap1 = ap + 1.f; + x1 = in[i] - kres * y3 / sqrt(1 + y3 * y3); + y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; + y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; + y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; + if (dist > 0.f) + y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); + y3 = y3 / sqrt(1 + y3 * y3); + + x1nm1 = x1; + y1nm1 = y1; + y2nm1 = y2; + + out[i] = y3; + + if (apslope != 0.f) { + ap += apslope; + scl += sclslope; + } + } + unit->m_ap = ap; + unit->m_scl = scl; + unit->m_fco = nextfco; + unit->m_x1 = zapgremlins(x1); + unit->m_y1 = zapgremlins(y1); + unit->m_y2 = zapgremlins(y2); + unit->m_y3 = zapgremlins(y3); + unit->m_x1nm1 = zapgremlins(x1nm1); + unit->m_y1nm1 = zapgremlins(y1nm1); + unit->m_y2nm1 = zapgremlins(y2nm1); } -void RLPFD_next_ak(RLPFD *unit, int inNumSamples){ +void RLPFD_next_ak(RLPFD* unit, int inNumSamples) { float* in = IN(0); float* out = OUT(0); float nextres = IN0(2); - float dist = IN0(3) * 0.001; + float dist = IN0(3) * 0.001; float* nextfco = IN(1); - float fco = unit->m_fco; + float fco = unit->m_fco; float res = unit->m_res; float x1nm1 = unit->m_x1nm1; float y1nm1 = unit->m_y1nm1; - float y2nm1 = unit->m_y2nm1; - float ap = unit->m_ap; - float ap1 = ap + 1.f; - float scl = unit->m_scl; + float y2nm1 = unit->m_y2nm1; + float ap = unit->m_ap; + float ap1 = ap + 1.f; + float scl = unit->m_scl; float y1 = unit->m_y1; float y2 = unit->m_y2; float y3 = unit->m_y3; float x1 = unit->m_x1; - float resslope=0; - - if (nextres != res) { - resslope=CALCSLOPE(nextres, res); - } - - for (int i = 0; i < inNumSamples; i++) { - float fcn = 2.f * nextfco[i] * SAMPLEDUR; - if (nextfco[i] != fco) { - ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; - ap1 = ap + 1; - scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; - fco=nextfco[i]; - } - float kres = res * scl; - x1 = in[i] - kres * y3/sqrt(1 + y3 * y3); - y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; - y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; - y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; - if (dist > 0.f) y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); - y3 = y3/sqrt(1 + y3 * y3); - - x1nm1 = x1; - y1nm1 = y1; - y2nm1 = y2; - - out[i] = y3; - if (resslope != 0.f) res += resslope; - } - - unit->m_res=res; - unit->m_fco=fco; - unit->m_ap=ap; - unit->m_scl=scl; - unit->m_x1=zapgremlins(x1); - unit->m_y1=zapgremlins(y1); - unit->m_y2=zapgremlins(y2); - unit->m_y3=zapgremlins(y3); - unit->m_x1nm1=zapgremlins(x1nm1); - unit->m_y1nm1=zapgremlins(y1nm1); - unit->m_y2nm1=zapgremlins(y2nm1); + float resslope = 0; + + if (nextres != res) { + resslope = CALCSLOPE(nextres, res); + } + + for (int i = 0; i < inNumSamples; i++) { + float fcn = 2.f * nextfco[i] * SAMPLEDUR; + if (nextfco[i] != fco) { + ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; + ap1 = ap + 1; + scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; + fco = nextfco[i]; + } + float kres = res * scl; + x1 = in[i] - kres * y3 / sqrt(1 + y3 * y3); + y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; + y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; + y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; + if (dist > 0.f) + y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); + y3 = y3 / sqrt(1 + y3 * y3); + + x1nm1 = x1; + y1nm1 = y1; + y2nm1 = y2; + + out[i] = y3; + if (resslope != 0.f) + res += resslope; + } + + unit->m_res = res; + unit->m_fco = fco; + unit->m_ap = ap; + unit->m_scl = scl; + unit->m_x1 = zapgremlins(x1); + unit->m_y1 = zapgremlins(y1); + unit->m_y2 = zapgremlins(y2); + unit->m_y3 = zapgremlins(y3); + unit->m_x1nm1 = zapgremlins(x1nm1); + unit->m_y1nm1 = zapgremlins(y1nm1); + unit->m_y2nm1 = zapgremlins(y2nm1); } -void RLPFD_next_aa(RLPFD *unit, int inNumSamples){ - float* in = IN(0); +void RLPFD_next_aa(RLPFD* unit, int inNumSamples) { + float* in = IN(0); float* out = OUT(0); - float dist = IN0(3) * 0.001; + float dist = IN0(3) * 0.001; float* nextfco = IN(1); - float fco = unit->m_fco; + float fco = unit->m_fco; float* res = IN(2); float x1nm1 = unit->m_x1nm1; float y1nm1 = unit->m_y1nm1; - float y2nm1 = unit->m_y2nm1; - float ap = unit->m_ap; - float ap1 = ap + 1.f; - float scl = unit->m_scl; + float y2nm1 = unit->m_y2nm1; + float ap = unit->m_ap; + float ap1 = ap + 1.f; + float scl = unit->m_scl; float y1 = unit->m_y1; float y2 = unit->m_y2; float y3 = unit->m_y3; float x1 = unit->m_x1; - for (int i = 0; i < inNumSamples; i++) { - float fcn = 2.f * nextfco[i] * SAMPLEDUR; - if (nextfco[i] != fco) { - ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; - ap1 = ap + 1; - scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; - fco=nextfco[i]; - } - float kres = res[i] * scl; - x1 = in[i] - kres * y3/sqrt(1 + y3 * y3); - y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; - y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; - y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; - if (dist > 0.f) y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); - y3 = y3/sqrt(1 + y3 * y3); - - x1nm1 = x1; - y1nm1 = y1; - y2nm1 = y2; - - out[i] = y3; - } - - unit->m_fco=fco; - unit->m_ap=ap; - unit->m_scl=scl; - unit->m_x1=zapgremlins(x1); - unit->m_y1=zapgremlins(y1); - unit->m_y2=zapgremlins(y2); - unit->m_y3=zapgremlins(y3); - unit->m_x1nm1=zapgremlins(x1nm1); - unit->m_y1nm1=zapgremlins(y1nm1); - unit->m_y2nm1=zapgremlins(y2nm1); + for (int i = 0; i < inNumSamples; i++) { + float fcn = 2.f * nextfco[i] * SAMPLEDUR; + if (nextfco[i] != fco) { + ap = ((-2.7441 * fcn + 3.1433) * fcn + 1.74) * fcn - 0.9984; + ap1 = ap + 1; + scl = ((2.7079 * ap1 + 10.963) * ap1 - 14.934) * ap1 + 8.4974; + fco = nextfco[i]; + } + float kres = res[i] * scl; + x1 = in[i] - kres * y3 / sqrt(1 + y3 * y3); + y1 = ((x1 + x1nm1) * ap1) * 0.5 - ap * y1; + y2 = ((y1 + y1nm1) * ap1) * 0.5 - ap * y2; + y3 = ((y2 + y2nm1) * ap1) * 0.5 - ap * y3; + if (dist > 0.f) + y3 = y3 * (1.f + (dist * (1.5 + 2.f * kres * (1.f - fcn)))); + y3 = y3 / sqrt(1 + y3 * y3); + + x1nm1 = x1; + y1nm1 = y1; + y2nm1 = y2; + + out[i] = y3; + } + + unit->m_fco = fco; + unit->m_ap = ap; + unit->m_scl = scl; + unit->m_x1 = zapgremlins(x1); + unit->m_y1 = zapgremlins(y1); + unit->m_y2 = zapgremlins(y2); + unit->m_y3 = zapgremlins(y3); + unit->m_x1nm1 = zapgremlins(x1nm1); + unit->m_y1nm1 = zapgremlins(y1nm1); + unit->m_y2nm1 = zapgremlins(y2nm1); } -void NestedAllpassN_Ctor(NestedAllpassN* unit ) { - SET2BUF - unit->m_phase=0; - unit->m_dsamp1= -(long)(unit->m_dt1 * unit->mRate->mSampleRate); - unit->m_dsamp2= -(long)(unit->m_dt2 * unit->mRate->mSampleRate); - SETCALC(NestedAllpassN_next_z); - ZOUT0(0)=0.f; +void NestedAllpassN_Ctor(NestedAllpassN* unit) { + SET2BUF + unit->m_phase = 0; + unit->m_dsamp1 = -(long)(unit->m_dt1 * unit->mRate->mSampleRate); + unit->m_dsamp2 = -(long)(unit->m_dt2 * unit->mRate->mSampleRate); + SETCALC(NestedAllpassN_next_z); + ZOUT0(0) = 0.f; } -void NestedAllpassN_Dtor(NestedAllpassN *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); +void NestedAllpassN_Dtor(NestedAllpassN* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); } -void NestedAllpassN_next_z(NestedAllpassN *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - long dsamp1=unit->m_dsamp1; - long dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - samp=ZXP(in); - if (dsamp1 < 0 || dsamp2 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - del1=buf1[dsamp1 & mask1]; - sum=buf2[dsamp2 & mask2]-gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - }; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - samp=ZXP(in); - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - if (dsamp1 < 0 || dsamp2 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - del1=buf1[dsamp1 & mask1]; - sum=buf2[dsamp2 & mask2]-gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - }; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(NestedAllpassN_next); - } +void NestedAllpassN_next_z(NestedAllpassN* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + long dsamp1 = unit->m_dsamp1; + long dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; samp = ZXP(in); if (dsamp1 < 0 || dsamp2 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + del1 = buf1[dsamp1 & mask1]; + sum = buf2[dsamp2 & mask2] - gain2 * del1; + output = sum - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + };); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); samp = ZXP(in); + buf1[phase & mask1] = samp + gain1 * output; buf2[phase & mask2] = del1 + gain2 * sum; + if (dsamp1 < 0 || dsamp2 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + del1 = buf1[dsamp1 & mask1]; + sum = buf2[dsamp2 & mask2] - gain2 * del1; + output = sum - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + };); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(NestedAllpassN_next); + } } -void NestedAllpassN_next(NestedAllpassN *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - long dsamp1=unit->m_dsamp1; - long dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum=buf2[dsamp2 & mask2]-gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum=buf2[dsamp2 & mask2]-gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; +void NestedAllpassN_next(NestedAllpassN* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + long dsamp1 = unit->m_dsamp1; + long dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum = buf2[dsamp2 & mask2] - gain2 * del1; output = sum - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum = buf2[dsamp2 & mask2] - gain2 * del1; output = sum - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; } -void NestedAllpassL_Ctor(NestedAllpassL* unit ) { - SET2BUF - unit->m_phase=0; - unit->m_dsamp1= -(unit->m_dt1 * unit->mRate->mSampleRate); - unit->m_dsamp2= -(unit->m_dt2 * unit->mRate->mSampleRate); - SETCALC(NestedAllpassL_next_z); - ZOUT0(0)=0.f; +void NestedAllpassL_Ctor(NestedAllpassL* unit) { + SET2BUF + unit->m_phase = 0; + unit->m_dsamp1 = -(unit->m_dt1 * unit->mRate->mSampleRate); + unit->m_dsamp2 = -(unit->m_dt2 * unit->mRate->mSampleRate); + SETCALC(NestedAllpassL_next_z); + ZOUT0(0) = 0.f; } -void NestedAllpassL_Dtor(NestedAllpassL *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); +void NestedAllpassL_Dtor(NestedAllpassL* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); } -void NestedAllpassL_next(NestedAllpassL *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output, frac1, frac2, del11, del21; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - int idsamp1; - int idsamp2; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - idsamp1=(int)dsamp1; - idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - del11=buf1[idsamp1 & mask1]; - del21=buf2[idsamp2 & mask2]; - float del12=buf1[(idsamp1-1) & mask1]; - float del22=buf2[(idsamp2-1) & mask2]; - del1=lininterp(frac1, del11, del12); - sum=lininterp(frac2, del21, del22) - gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-dt1 * unit->mRate->mSampleRate; - dsamp2=phase-dt2 * unit->mRate->mSampleRate; - int idsamp1=(int)dsamp1; - int idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - del1=lininterp(frac1, buf1[idsamp1 & mask1], buf1[(idsamp1-1) & mask1]); - sum=lininterp(frac2, buf2[idsamp2 & mask2], buf2[(idsamp2-1) & mask2]) - gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; +void NestedAllpassL_next(NestedAllpassL* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output, frac1, frac2, del11, del21; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + int idsamp1; + int idsamp2; + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; idsamp1 = (int)dsamp1; idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); del11 = buf1[idsamp1 & mask1]; + del21 = buf2[idsamp2 & mask2]; float del12 = buf1[(idsamp1 - 1) & mask1]; + float del22 = buf2[(idsamp2 - 1) & mask2]; del1 = lininterp(frac1, del11, del12); + sum = lininterp(frac2, del21, del22) - gain2 * del1; output = sum - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dsamp1 = phase - dt1 * unit->mRate->mSampleRate; + dsamp2 = phase - dt2 * unit->mRate->mSampleRate; int idsamp1 = (int)dsamp1; int idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); + del1 = lininterp(frac1, buf1[idsamp1 & mask1], buf1[(idsamp1 - 1) & mask1]); + sum = lininterp(frac2, buf2[idsamp2 & mask2], buf2[(idsamp2 - 1) & mask2]) - gain2 * del1; + output = sum - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; } -void NestedAllpassL_next_z(NestedAllpassL *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output, frac1, frac2, del11, del21; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - int idsamp1; - int idsamp2; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - idsamp1=(int)dsamp1; - idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - del11=buf1[idsamp1 & mask1]; - del21=buf2[idsamp2 & mask2]; - float del12=buf1[(idsamp1-1) & mask1]; - float del22=buf2[(idsamp2-1) & mask2]; - del1=lininterp(frac1, del11, del12); - sum=lininterp(frac2, del21, del22) - gain2*del1; - output=sum-gain1*samp; - if ((idsamp1-1) < 0 || (idsamp2-1) < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - } - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-dt1 * unit->mRate->mSampleRate; - dsamp2=phase-dt2 * unit->mRate->mSampleRate; - int idsamp1=(int)dsamp1; - int idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - del11=buf1[idsamp1 & mask1]; - del21=buf2[idsamp2 & mask2]; - del1=lininterp(frac1, del11, buf1[(idsamp1-1) & mask1]); - sum=lininterp(frac2, del21, buf2[(idsamp2-1) & mask2]) - gain2*del1; - output=sum-gain1*samp; - if ((idsamp1-1) < 0 || (idsamp2-1) < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - } - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(NestedAllpassL_next); - } +void NestedAllpassL_next_z(NestedAllpassL* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output, frac1, frac2, del11, del21; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + int idsamp1; + int idsamp2; + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; idsamp1 = (int)dsamp1; idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); del11 = buf1[idsamp1 & mask1]; + del21 = buf2[idsamp2 & mask2]; float del12 = buf1[(idsamp1 - 1) & mask1]; + float del22 = buf2[(idsamp2 - 1) & mask2]; del1 = lininterp(frac1, del11, del12); + sum = lininterp(frac2, del21, del22) - gain2 * del1; output = sum - gain1 * samp; + if ((idsamp1 - 1) < 0 || (idsamp2 - 1) < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + }); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dsamp1 = phase - dt1 * unit->mRate->mSampleRate; + dsamp2 = phase - dt2 * unit->mRate->mSampleRate; int idsamp1 = (int)dsamp1; int idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); del11 = buf1[idsamp1 & mask1]; + del21 = buf2[idsamp2 & mask2]; del1 = lininterp(frac1, del11, buf1[(idsamp1 - 1) & mask1]); + sum = lininterp(frac2, del21, buf2[(idsamp2 - 1) & mask2]) - gain2 * del1; output = sum - gain1 * samp; + if ((idsamp1 - 1) < 0 || (idsamp2 - 1) < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + }); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(NestedAllpassL_next); + } } -void NestedAllpassC_Ctor(NestedAllpassC* unit ) { - SET2BUF - unit->m_phase=0; - unit->m_dsamp1= -(unit->m_dt1 * unit->mRate->mSampleRate); - unit->m_dsamp2= -(unit->m_dt2 * unit->mRate->mSampleRate); - SETCALC(NestedAllpassC_next_z); - ZOUT0(0)=0.f; +void NestedAllpassC_Ctor(NestedAllpassC* unit) { + SET2BUF + unit->m_phase = 0; + unit->m_dsamp1 = -(unit->m_dt1 * unit->mRate->mSampleRate); + unit->m_dsamp2 = -(unit->m_dt2 * unit->mRate->mSampleRate); + SETCALC(NestedAllpassC_next_z); + ZOUT0(0) = 0.f; } -void NestedAllpassC_Dtor(NestedAllpassC *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); +void NestedAllpassC_Dtor(NestedAllpassC* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); } -void NestedAllpassC_next(NestedAllpassC *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1, del2; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output, frac1, frac2; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - int idsamp1; - int idsamp2; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - idsamp1=(int)dsamp1; - idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - float del10=buf1[(idsamp1 + 1) & mask1]; - float del11=buf1[idsamp1 & mask1]; - float del12=buf1[(idsamp1 - 1) & mask1]; - float del13=buf1[(idsamp1 - 2) & mask1]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - float del20=buf2[(idsamp2 + 1) & mask2]; - float del21=buf2[idsamp2 & mask2]; - float del22=buf2[(idsamp2 - 1) & mask2]; - float del23=buf2[(idsamp2 - 2) & mask2]; - del2=cubicinterp(frac1, del20, del21, del22, del23); - sum=del2 - gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-dt1 * unit->mRate->mSampleRate; - dsamp2=phase-dt2 * unit->mRate->mSampleRate; - int idsamp1=(int)dsamp1; - int idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - float del11=buf1[idsamp1 & mask1]; - float del12=buf1[(idsamp1-1) & mask1]; - float del13=buf1[(idsamp1-2) & mask1]; - float del10=buf1[(idsamp1 + 1) & mask1]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - float del21=buf2[idsamp2 & mask2]; - float del22=buf2[(idsamp2-1) & mask2]; - float del23=buf2[(idsamp2-2) & mask2]; - float del20=buf2[(idsamp2 + 1) & mask2]; - del2=cubicinterp(frac1, del20, del21, del22, del23); - sum=del2 - gain2*del1; - output=sum-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; +void NestedAllpassC_next(NestedAllpassC* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1, del2; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output, frac1, frac2; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + int idsamp1; + int idsamp2; + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; idsamp1 = (int)dsamp1; idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); + float del10 = buf1[(idsamp1 + 1) & mask1]; float del11 = buf1[idsamp1 & mask1]; + float del12 = buf1[(idsamp1 - 1) & mask1]; float del13 = buf1[(idsamp1 - 2) & mask1]; + del1 = cubicinterp(frac1, del10, del11, del12, del13); float del20 = buf2[(idsamp2 + 1) & mask2]; + float del21 = buf2[idsamp2 & mask2]; float del22 = buf2[(idsamp2 - 1) & mask2]; + float del23 = buf2[(idsamp2 - 2) & mask2]; del2 = cubicinterp(frac1, del20, del21, del22, del23); + sum = del2 - gain2 * del1; output = sum - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dsamp1 = phase - dt1 * unit->mRate->mSampleRate; + dsamp2 = phase - dt2 * unit->mRate->mSampleRate; int idsamp1 = (int)dsamp1; int idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); float del11 = buf1[idsamp1 & mask1]; + float del12 = buf1[(idsamp1 - 1) & mask1]; float del13 = buf1[(idsamp1 - 2) & mask1]; + float del10 = buf1[(idsamp1 + 1) & mask1]; del1 = cubicinterp(frac1, del10, del11, del12, del13); + float del21 = buf2[idsamp2 & mask2]; float del22 = buf2[(idsamp2 - 1) & mask2]; + float del23 = buf2[(idsamp2 - 2) & mask2]; float del20 = buf2[(idsamp2 + 1) & mask2]; + del2 = cubicinterp(frac1, del20, del21, del22, del23); sum = del2 - gain2 * del1; + output = sum - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; } -void NestedAllpassC_next_z(NestedAllpassC *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float del1, del2; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - float samp, sum, output, frac1, frac2; - - if (next_dt1 == dt1 && next_dt2 == dt2) { - int idsamp1; - int idsamp2; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - idsamp1=(int)dsamp1; - idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - float del10=buf1[(idsamp1 + 1) & mask1]; - float del11=buf1[idsamp1 & mask1]; - float del12=buf1[(idsamp1 - 1) & mask1]; - float del13=buf1[(idsamp1 - 2) & mask1]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - float del20=buf2[(idsamp2 + 1) & mask2]; - float del21=buf2[idsamp2 & mask2]; - float del22=buf2[(idsamp2 - 1) & mask2]; - float del23=buf2[(idsamp2 - 2) & mask2]; - del2=cubicinterp(frac1, del20, del21, del22, del23); - sum=del2 - gain2*del1; - output=sum-gain1*samp; - if (idsamp1 < 0 || idsamp2 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - } - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dsamp1=phase-dt1 * unit->mRate->mSampleRate; - dsamp2=phase-dt2 * unit->mRate->mSampleRate; - int idsamp1=(int)dsamp1; - int idsamp2=(int)dsamp2; - frac1=dsamp1-idsamp1; - frac2=dsamp2-idsamp2; - samp=ZXP(in); - float del11=buf1[idsamp1 & mask1]; - float del12=buf1[(idsamp1-1) & mask1]; - float del13=buf1[(idsamp1-2) & mask1]; - float del10=buf1[(idsamp1 + 1) & mask1]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - float del21=buf2[idsamp2 & mask2]; - float del22=buf2[(idsamp2-1) & mask2]; - float del23=buf2[(idsamp2-2) & mask2]; - float del20=buf2[(idsamp2 + 1) & mask2]; - del2=cubicinterp(frac1, del20, del21, del22, del23); - sum=del2 - gain2*del1; - output=sum-gain1*samp; - if (idsamp1 < 0 || idsamp2 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum; - ZXP(out)=output; - } - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(NestedAllpassC_next); - } +void NestedAllpassC_next_z(NestedAllpassC* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float del1, del2; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + float samp, sum, output, frac1, frac2; + + if (next_dt1 == dt1 && next_dt2 == dt2) { + int idsamp1; + int idsamp2; + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; idsamp1 = (int)dsamp1; idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); + float del10 = buf1[(idsamp1 + 1) & mask1]; float del11 = buf1[idsamp1 & mask1]; + float del12 = buf1[(idsamp1 - 1) & mask1]; float del13 = buf1[(idsamp1 - 2) & mask1]; + del1 = cubicinterp(frac1, del10, del11, del12, del13); float del20 = buf2[(idsamp2 + 1) & mask2]; + float del21 = buf2[idsamp2 & mask2]; float del22 = buf2[(idsamp2 - 1) & mask2]; + float del23 = buf2[(idsamp2 - 2) & mask2]; del2 = cubicinterp(frac1, del20, del21, del22, del23); + sum = del2 - gain2 * del1; output = sum - gain1 * samp; if (idsamp1 < 0 || idsamp2 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + }); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dsamp1 = phase - dt1 * unit->mRate->mSampleRate; + dsamp2 = phase - dt2 * unit->mRate->mSampleRate; int idsamp1 = (int)dsamp1; int idsamp2 = (int)dsamp2; + frac1 = dsamp1 - idsamp1; frac2 = dsamp2 - idsamp2; samp = ZXP(in); float del11 = buf1[idsamp1 & mask1]; + float del12 = buf1[(idsamp1 - 1) & mask1]; float del13 = buf1[(idsamp1 - 2) & mask1]; + float del10 = buf1[(idsamp1 + 1) & mask1]; del1 = cubicinterp(frac1, del10, del11, del12, del13); + float del21 = buf2[idsamp2 & mask2]; float del22 = buf2[(idsamp2 - 1) & mask2]; + float del23 = buf2[(idsamp2 - 2) & mask2]; float del20 = buf2[(idsamp2 + 1) & mask2]; + del2 = cubicinterp(frac1, del20, del21, del22, del23); sum = del2 - gain2 * del1; + output = sum - gain1 * samp; if (idsamp1 < 0 || idsamp2 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum; + ZXP(out) = output; + }); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(NestedAllpassC_next); + } } -void DoubleNestedAllpassN_Ctor(DoubleNestedAllpassN* unit ) { - SET3BUF - unit->m_phase=0; - unit->m_dsamp1= -(long)(unit->m_dt1 * unit->mRate->mSampleRate); - unit->m_dsamp2= -(long)(unit->m_dt2 * unit->mRate->mSampleRate); - unit->m_dsamp3= -(long)(unit->m_dt3 * unit->mRate->mSampleRate); - SETCALC(DoubleNestedAllpassN_next_z); - ZOUT0(0)=0.f; +void DoubleNestedAllpassN_Ctor(DoubleNestedAllpassN* unit) { + SET3BUF + unit->m_phase = 0; + unit->m_dsamp1 = -(long)(unit->m_dt1 * unit->mRate->mSampleRate); + unit->m_dsamp2 = -(long)(unit->m_dt2 * unit->mRate->mSampleRate); + unit->m_dsamp3 = -(long)(unit->m_dt3 * unit->mRate->mSampleRate); + SETCALC(DoubleNestedAllpassN_next_z); + ZOUT0(0) = 0.f; } -void DoubleNestedAllpassN_Dtor(DoubleNestedAllpassN *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); - RTFree(unit->mWorld, unit->m_buf3); +void DoubleNestedAllpassN_Dtor(DoubleNestedAllpassN* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); + RTFree(unit->mWorld, unit->m_buf3); } -void DoubleNestedAllpassN_next(DoubleNestedAllpassN *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - long dsamp1=unit->m_dsamp1; - long dsamp2=unit->m_dsamp2; - long dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum1=buf2[dsamp2 & mask2]-gain2*del1; - sum2=buf3[dsamp3 & mask3]-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum1=buf2[dsamp2 & mask2]-gain2*del1; - sum2=buf3[dsamp3 & mask3]-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; +void DoubleNestedAllpassN_next(DoubleNestedAllpassN* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + long dsamp1 = unit->m_dsamp1; + long dsamp2 = unit->m_dsamp2; + long dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum1 = buf2[dsamp2 & mask2] - gain2 * del1; sum2 = buf3[dsamp3 & mask3] - gain3 * sum1; + output = sum2 - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum1 = buf2[dsamp2 & mask2] - gain2 * del1; sum2 = buf3[dsamp3 & mask3] - gain3 * sum1; + output = sum2 - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; } -void DoubleNestedAllpassN_next_z(DoubleNestedAllpassN *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - long dsamp1=unit->m_dsamp1; - long dsamp2=unit->m_dsamp2; - long dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum1=buf2[dsamp2 & mask2]-gain2*del1; - sum2=buf3[dsamp3 & mask3]-gain3*sum1; - output=sum2-gain1*samp; - if (dsamp1 < 0 || dsamp2 < 0 || dsamp3 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - samp=ZXP(in); - del1=buf1[dsamp1 & mask1]; - sum1=buf2[dsamp2 & mask2]-gain2*del1; - sum2=buf3[dsamp3 & mask3]-gain3*sum1; - output=sum2-gain1*samp; - if (dsamp1 < 0 || dsamp2 < 0 || dsamp3 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(DoubleNestedAllpassN_next); - } +void DoubleNestedAllpassN_next_z(DoubleNestedAllpassN* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + long dsamp1 = unit->m_dsamp1; + long dsamp2 = unit->m_dsamp2; + long dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum1 = buf2[dsamp2 & mask2] - gain2 * del1; sum2 = buf3[dsamp3 & mask3] - gain3 * sum1; + output = sum2 - gain1 * samp; if (dsamp1 < 0 || dsamp2 < 0 || dsamp3 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); samp = ZXP(in); del1 = buf1[dsamp1 & mask1]; + sum1 = buf2[dsamp2 & mask2] - gain2 * del1; sum2 = buf3[dsamp3 & mask3] - gain3 * sum1; + output = sum2 - gain1 * samp; if (dsamp1 < 0 || dsamp2 < 0 || dsamp3 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(DoubleNestedAllpassN_next); + } } -void DoubleNestedAllpassL_Ctor(DoubleNestedAllpassL* unit ) { - SET3BUF - unit->m_phase=0; - unit->m_dsamp1= -unit->m_dt1 * unit->mRate->mSampleRate; - unit->m_dsamp2= -unit->m_dt2 * unit->mRate->mSampleRate; - unit->m_dsamp3= -unit->m_dt3 * unit->mRate->mSampleRate; - SETCALC(DoubleNestedAllpassL_next_z); - ZOUT0(0)=0.f; +void DoubleNestedAllpassL_Ctor(DoubleNestedAllpassL* unit) { + SET3BUF + unit->m_phase = 0; + unit->m_dsamp1 = -unit->m_dt1 * unit->mRate->mSampleRate; + unit->m_dsamp2 = -unit->m_dt2 * unit->mRate->mSampleRate; + unit->m_dsamp3 = -unit->m_dt3 * unit->mRate->mSampleRate; + SETCALC(DoubleNestedAllpassL_next_z); + ZOUT0(0) = 0.f; } -void DoubleNestedAllpassL_Dtor(DoubleNestedAllpassL *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); - RTFree(unit->mWorld, unit->m_buf3); +void DoubleNestedAllpassL_Dtor(DoubleNestedAllpassL* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); + RTFree(unit->mWorld, unit->m_buf3); } -void DoubleNestedAllpassL_next(DoubleNestedAllpassL *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - int idsamp1; - int idsamp2; - int idsamp3; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - samp=ZXP(in); - float del10=buf1[idsamp1 & mask1]; - float del20=buf2[idsamp2 & mask2]; - float del30=buf3[idsamp3 & mask3]; - float del11=buf1[(idsamp1-1) & mask1]; - float del21=buf2[(idsamp2-1) & mask2]; - float del31=buf3[(idsamp3-1) & mask3]; - del1=lininterp(frac1, del10, del11); - sum1=lininterp(frac2, del20, del21)-gain2*del1; - sum2=lininterp(frac3, del30, del31)-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - int idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - int idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - int idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - samp=ZXP(in); - del1=lininterp(frac1, buf1[idsamp1 & mask1], buf1[(idsamp1-1) & mask1]); - sum1=lininterp(frac2, buf2[idsamp2 & mask2], buf2[(idsamp2-1) & mask2])-gain2*del1; - sum2=lininterp(frac3, buf3[idsamp3 & mask3], buf3[(idsamp3-1) & mask3])-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; +void DoubleNestedAllpassL_next(DoubleNestedAllpassL* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + int idsamp1; + int idsamp2; + int idsamp3; + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; idsamp1 = (int)dsamp1; float frac1 = dsamp1 - idsamp1; + idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; idsamp3 = (int)dsamp3; + float frac3 = dsamp3 - idsamp3; samp = ZXP(in); float del10 = buf1[idsamp1 & mask1]; + float del20 = buf2[idsamp2 & mask2]; float del30 = buf3[idsamp3 & mask3]; + float del11 = buf1[(idsamp1 - 1) & mask1]; float del21 = buf2[(idsamp2 - 1) & mask2]; + float del31 = buf3[(idsamp3 - 1) & mask3]; del1 = lininterp(frac1, del10, del11); + sum1 = lininterp(frac2, del20, del21) - gain2 * del1; sum2 = lininterp(frac3, del30, del31) - gain3 * sum1; + output = sum2 - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); int idsamp1 = (int)dsamp1; + float frac1 = dsamp1 - idsamp1; int idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; + int idsamp3 = (int)dsamp3; float frac3 = dsamp3 - idsamp3; samp = ZXP(in); + del1 = lininterp(frac1, buf1[idsamp1 & mask1], buf1[(idsamp1 - 1) & mask1]); + sum1 = lininterp(frac2, buf2[idsamp2 & mask2], buf2[(idsamp2 - 1) & mask2]) - gain2 * del1; + sum2 = lininterp(frac3, buf3[idsamp3 & mask3], buf3[(idsamp3 - 1) & mask3]) - gain3 * sum1; + output = sum2 - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; } -void DoubleNestedAllpassL_next_z(DoubleNestedAllpassL *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - int idsamp1; - int idsamp2; - int idsamp3; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - int idsamp11=idsamp1-1; - int idsamp21=idsamp2-1; - int idsamp31=idsamp3-1; - samp=ZXP(in); - float del10=buf1[idsamp1 & mask1]; - float del20=buf2[idsamp2 & mask2]; - float del30=buf3[idsamp3 & mask3]; - float del11=buf1[idsamp11 & mask1]; - float del21=buf2[idsamp21 & mask2]; - float del31=buf3[idsamp31 & mask3]; - del1=lininterp(frac1, del10, del11); - sum1=lininterp(frac2, del20, del21)-gain2*del1; - sum2=lininterp(frac3, del30, del31)-gain3*sum1; - output=sum2-gain1*samp; - if (idsamp11 < 0 || idsamp21 < 0 || idsamp31 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - int idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - int idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - int idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - int idsamp11=idsamp1-1; - int idsamp21=idsamp2-1; - int idsamp31=idsamp3-1; - samp=ZXP(in); - del1=lininterp(frac1, buf1[idsamp1 & mask1], buf1[idsamp11 & mask1]); - sum1=lininterp(frac2, buf2[idsamp2 & mask2], buf2[idsamp21 & mask2])-gain2*del1; - sum2=lininterp(frac3, buf3[idsamp3 & mask3], buf3[idsamp31 & mask3])-gain3*sum1; - output=sum2-gain1*samp; - if (idsamp11 < 0 || idsamp21 < 0 || idsamp31 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(DoubleNestedAllpassL_next); - } +void DoubleNestedAllpassL_next_z(DoubleNestedAllpassL* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + int idsamp1; + int idsamp2; + int idsamp3; + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; idsamp1 = (int)dsamp1; float frac1 = dsamp1 - idsamp1; + idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; idsamp3 = (int)dsamp3; + float frac3 = dsamp3 - idsamp3; int idsamp11 = idsamp1 - 1; int idsamp21 = idsamp2 - 1; + int idsamp31 = idsamp3 - 1; samp = ZXP(in); float del10 = buf1[idsamp1 & mask1]; + float del20 = buf2[idsamp2 & mask2]; float del30 = buf3[idsamp3 & mask3]; + float del11 = buf1[idsamp11 & mask1]; float del21 = buf2[idsamp21 & mask2]; + float del31 = buf3[idsamp31 & mask3]; del1 = lininterp(frac1, del10, del11); + sum1 = lininterp(frac2, del20, del21) - gain2 * del1; sum2 = lininterp(frac3, del30, del31) - gain3 * sum1; + output = sum2 - gain1 * samp; if (idsamp11 < 0 || idsamp21 < 0 || idsamp31 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); int idsamp1 = (int)dsamp1; + float frac1 = dsamp1 - idsamp1; int idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; + int idsamp3 = (int)dsamp3; float frac3 = dsamp3 - idsamp3; int idsamp11 = idsamp1 - 1; + int idsamp21 = idsamp2 - 1; int idsamp31 = idsamp3 - 1; samp = ZXP(in); + del1 = lininterp(frac1, buf1[idsamp1 & mask1], buf1[idsamp11 & mask1]); + sum1 = lininterp(frac2, buf2[idsamp2 & mask2], buf2[idsamp21 & mask2]) - gain2 * del1; + sum2 = lininterp(frac3, buf3[idsamp3 & mask3], buf3[idsamp31 & mask3]) - gain3 * sum1; + output = sum2 - gain1 * samp; if (idsamp11 < 0 || idsamp21 < 0 || idsamp31 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(DoubleNestedAllpassL_next); + } } -void DoubleNestedAllpassC_Ctor(DoubleNestedAllpassC* unit ) { - SET3BUF - unit->m_phase=0; - unit->m_dsamp1= -unit->m_dt1 * unit->mRate->mSampleRate; - unit->m_dsamp2= -unit->m_dt2 * unit->mRate->mSampleRate; - unit->m_dsamp3= -unit->m_dt3 * unit->mRate->mSampleRate; - SETCALC(DoubleNestedAllpassC_next_z); - ZOUT0(0)=0.f; +void DoubleNestedAllpassC_Ctor(DoubleNestedAllpassC* unit) { + SET3BUF + unit->m_phase = 0; + unit->m_dsamp1 = -unit->m_dt1 * unit->mRate->mSampleRate; + unit->m_dsamp2 = -unit->m_dt2 * unit->mRate->mSampleRate; + unit->m_dsamp3 = -unit->m_dt3 * unit->mRate->mSampleRate; + SETCALC(DoubleNestedAllpassC_next_z); + ZOUT0(0) = 0.f; } -void DoubleNestedAllpassC_Dtor(DoubleNestedAllpassC *unit ) { - RTFree(unit->mWorld, unit->m_buf1); - RTFree(unit->mWorld, unit->m_buf2); - RTFree(unit->mWorld, unit->m_buf3); +void DoubleNestedAllpassC_Dtor(DoubleNestedAllpassC* unit) { + RTFree(unit->mWorld, unit->m_buf1); + RTFree(unit->mWorld, unit->m_buf2); + RTFree(unit->mWorld, unit->m_buf3); } -void DoubleNestedAllpassC_next(DoubleNestedAllpassC *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - int idsamp1; - int idsamp2; - int idsamp3; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - samp=ZXP(in); - float del10=buf1[(idsamp1+1) & mask1]; - float del20=buf2[(idsamp2+1) & mask2]; - float del30=buf3[(idsamp3+1) & mask3]; - float del11=buf1[(idsamp1) & mask1]; - float del21=buf2[(idsamp2) & mask2]; - float del31=buf3[(idsamp3) & mask3]; - float del12=buf1[(idsamp1-1) & mask1]; - float del22=buf2[(idsamp2-1) & mask2]; - float del32=buf3[(idsamp3-1) & mask3]; - float del13=buf1[(idsamp1-2) & mask1]; - float del23=buf2[(idsamp2-2) & mask2]; - float del33=buf3[(idsamp3-2) & mask3]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - sum1=cubicinterp(frac2, del20, del21, del22, del23)-gain2*del1; - sum2=cubicinterp(frac3, del30, del31, del32, del33)-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - int idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - int idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - int idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - samp=ZXP(in); - del1=cubicinterp(frac1, buf1[(idsamp1 + 1) & mask1], buf1[idsamp1 & mask1], buf1[(idsamp1-1) & mask1], buf1[(idsamp1-2) & mask1]); - sum1=cubicinterp(frac2, buf2[(idsamp2 + 1) & mask2], buf2[idsamp2 & mask2], buf2[(idsamp2-1) & mask2], buf2[(idsamp2-2) & mask2])-gain2*del1; - sum2=cubicinterp(frac3, buf3[(idsamp3 + 1) & mask3], buf3[idsamp3 & mask3], buf3[(idsamp3-1) & mask3], buf3[(idsamp3-2) & mask3])-gain3*sum1; - output=sum2-gain1*samp; - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; +void DoubleNestedAllpassC_next(DoubleNestedAllpassC* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + int idsamp1; + int idsamp2; + int idsamp3; + LOOP(inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; idsamp1 = (int)dsamp1; float frac1 = dsamp1 - idsamp1; + idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; idsamp3 = (int)dsamp3; + float frac3 = dsamp3 - idsamp3; samp = ZXP(in); float del10 = buf1[(idsamp1 + 1) & mask1]; + float del20 = buf2[(idsamp2 + 1) & mask2]; float del30 = buf3[(idsamp3 + 1) & mask3]; + float del11 = buf1[(idsamp1)&mask1]; float del21 = buf2[(idsamp2)&mask2]; + float del31 = buf3[(idsamp3)&mask3]; float del12 = buf1[(idsamp1 - 1) & mask1]; + float del22 = buf2[(idsamp2 - 1) & mask2]; float del32 = buf3[(idsamp3 - 1) & mask3]; + float del13 = buf1[(idsamp1 - 2) & mask1]; float del23 = buf2[(idsamp2 - 2) & mask2]; + float del33 = buf3[(idsamp3 - 2) & mask3]; del1 = cubicinterp(frac1, del10, del11, del12, del13); + sum1 = cubicinterp(frac2, del20, del21, del22, del23) - gain2 * del1; + sum2 = cubicinterp(frac3, del30, del31, del32, del33) - gain3 * sum1; output = sum2 - gain1 * samp; + buf1[phase & mask1] = samp + gain1 * output; buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP(inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); int idsamp1 = (int)dsamp1; + float frac1 = dsamp1 - idsamp1; int idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; + int idsamp3 = (int)dsamp3; float frac3 = dsamp3 - idsamp3; samp = ZXP(in); + del1 = cubicinterp(frac1, buf1[(idsamp1 + 1) & mask1], buf1[idsamp1 & mask1], buf1[(idsamp1 - 1) & mask1], + buf1[(idsamp1 - 2) & mask1]); + sum1 = cubicinterp(frac2, buf2[(idsamp2 + 1) & mask2], buf2[idsamp2 & mask2], buf2[(idsamp2 - 1) & mask2], + buf2[(idsamp2 - 2) & mask2]) + - gain2 * del1; + sum2 = cubicinterp(frac3, buf3[(idsamp3 + 1) & mask3], buf3[idsamp3 & mask3], buf3[(idsamp3 - 1) & mask3], + buf3[(idsamp3 - 2) & mask3]) + - gain3 * sum1; + output = sum2 - gain1 * samp; buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; buf3[phase & mask3] = sum1 + gain3 * sum2; ZXP(out) = output;); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; } -void DoubleNestedAllpassC_next_z(DoubleNestedAllpassC *unit, int inNumSamples) { - float *in=ZIN(0); - float *out=ZOUT(0); - float *buf1=unit->m_buf1; - float *buf2=unit->m_buf2; - float *buf3=unit->m_buf3; - float del1; - float dt1=unit->m_dt1; - float dt2=unit->m_dt2; - float dt3=unit->m_dt3; - float next_dt1=ZIN0(2); - float next_dt2=ZIN0(5); - float next_dt3=ZIN0(8); - float dsamp1=unit->m_dsamp1; - float dsamp2=unit->m_dsamp2; - float dsamp3=unit->m_dsamp3; - float gain1=ZIN0(3); - float gain2=ZIN0(6); - float gain3=ZIN0(9); - long phase=unit->m_phase; - long mask1=unit->m_maxdel1; - long mask2=unit->m_maxdel2; - long mask3=unit->m_maxdel3; - float samp, sum1, sum2, output; - - if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { - int idsamp1; - int idsamp2; - int idsamp3; - LOOP (inNumSamples, - phase++; - dsamp1++; - dsamp2++; - dsamp3++; - idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - int idsamp13=idsamp1-2; - int idsamp23=idsamp2-2; - int idsamp33=idsamp3-2; - samp=ZXP(in); - float del10=buf1[(idsamp1+1) & mask1]; - float del20=buf2[(idsamp2+1) & mask2]; - float del30=buf3[(idsamp3+1) & mask3]; - float del11=buf1[(idsamp1) & mask1]; - float del21=buf2[(idsamp2) & mask2]; - float del31=buf3[(idsamp3) & mask3]; - float del12=buf1[(idsamp1-1) & mask1]; - float del22=buf2[(idsamp2-1) & mask2]; - float del32=buf3[(idsamp3-1) & mask3]; - float del13=buf1[idsamp13 & mask1]; - float del23=buf2[idsamp23 & mask2]; - float del33=buf3[idsamp33 & mask3]; - del1=cubicinterp(frac1, del10, del11, del12, del13); - sum1=cubicinterp(frac2, del20, del21, del22, del23)-gain2*del1; - sum2=cubicinterp(frac3, del30, del31, del32, del33)-gain3*sum1; - output=sum2-gain1*samp; - if (idsamp13 < 0 || idsamp23 < 0 || idsamp33 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } else { - float dslope1=CALCSLOPE(next_dt1, dt1); - float dslope2=CALCSLOPE(next_dt2, dt2); - float dslope3=CALCSLOPE(next_dt3, dt3); - LOOP (inNumSamples, - phase++; - dt1 += dslope1; - dt2 += dslope2; - dt3 += dslope3; - dsamp1=phase-(long)(dt1 * unit->mRate->mSampleRate); - dsamp2=phase-(long)(dt2 * unit->mRate->mSampleRate); - dsamp3=phase-(long)(dt3 * unit->mRate->mSampleRate); - int idsamp1=(int)dsamp1; - float frac1=dsamp1-idsamp1; - int idsamp2=(int)dsamp2; - float frac2=dsamp2-idsamp2; - int idsamp3=(int)dsamp3; - float frac3=dsamp3-idsamp3; - int idsamp13=idsamp1-2; - int idsamp23=idsamp2-2; - int idsamp33=idsamp3-2; - samp=ZXP(in); - del1=cubicinterp(frac1, buf1[(idsamp1 + 1) & mask1], buf1[idsamp1 & mask1], buf1[(idsamp1-1) & mask1], buf1[idsamp13 & mask1]); - sum1=cubicinterp(frac2, buf2[(idsamp2 + 1) & mask2], buf2[idsamp2 & mask2], buf2[(idsamp2-1) & mask2], buf2[idsamp23 & mask2])-gain2*del1; - sum2=cubicinterp(frac3, buf3[(idsamp3 + 1) & mask3], buf3[idsamp3 & mask3], buf3[(idsamp3-1) & mask3], buf3[idsamp33 & mask3])-gain3*sum1; - output=sum2-gain1*samp; - if (idsamp13 < 0 || idsamp23 < 0 || idsamp33 < 0) { - buf1[phase & mask1]=samp; - buf2[phase & mask2]=samp; - buf3[phase & mask3]=samp; - ZXP(out)=0.f; - } else { - buf1[phase & mask1]=samp+gain1*output; - buf2[phase & mask2]=del1+gain2*sum1; - buf3[phase & mask3]=sum1+gain3*sum2; - ZXP(out)=output; - } - ); - } - - unit->m_phase=phase; - unit->m_dsamp1=dsamp1; - unit->m_dsamp2=dsamp2; - unit->m_dsamp3=dsamp3; - unit->m_dt1=dt1; - unit->m_dt2=dt2; - unit->m_dt3=dt3; - - unit->m_numoutput += inNumSamples; - if (unit->m_numoutput >= unit->m_maxdel) { - SETCALC(DoubleNestedAllpassC_next); - } +void DoubleNestedAllpassC_next_z(DoubleNestedAllpassC* unit, int inNumSamples) { + float* in = ZIN(0); + float* out = ZOUT(0); + float* buf1 = unit->m_buf1; + float* buf2 = unit->m_buf2; + float* buf3 = unit->m_buf3; + float del1; + float dt1 = unit->m_dt1; + float dt2 = unit->m_dt2; + float dt3 = unit->m_dt3; + float next_dt1 = ZIN0(2); + float next_dt2 = ZIN0(5); + float next_dt3 = ZIN0(8); + float dsamp1 = unit->m_dsamp1; + float dsamp2 = unit->m_dsamp2; + float dsamp3 = unit->m_dsamp3; + float gain1 = ZIN0(3); + float gain2 = ZIN0(6); + float gain3 = ZIN0(9); + long phase = unit->m_phase; + long mask1 = unit->m_maxdel1; + long mask2 = unit->m_maxdel2; + long mask3 = unit->m_maxdel3; + float samp, sum1, sum2, output; + + if (next_dt1 == dt1 && next_dt2 == dt2 && next_dt3 == dt3) { + int idsamp1; + int idsamp2; + int idsamp3; + LOOP( + inNumSamples, phase++; dsamp1++; dsamp2++; dsamp3++; idsamp1 = (int)dsamp1; float frac1 = dsamp1 - idsamp1; + idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; idsamp3 = (int)dsamp3; + float frac3 = dsamp3 - idsamp3; int idsamp13 = idsamp1 - 2; int idsamp23 = idsamp2 - 2; + int idsamp33 = idsamp3 - 2; samp = ZXP(in); float del10 = buf1[(idsamp1 + 1) & mask1]; + float del20 = buf2[(idsamp2 + 1) & mask2]; float del30 = buf3[(idsamp3 + 1) & mask3]; + float del11 = buf1[(idsamp1)&mask1]; float del21 = buf2[(idsamp2)&mask2]; + float del31 = buf3[(idsamp3)&mask3]; float del12 = buf1[(idsamp1 - 1) & mask1]; + float del22 = buf2[(idsamp2 - 1) & mask2]; float del32 = buf3[(idsamp3 - 1) & mask3]; + float del13 = buf1[idsamp13 & mask1]; float del23 = buf2[idsamp23 & mask2]; + float del33 = buf3[idsamp33 & mask3]; del1 = cubicinterp(frac1, del10, del11, del12, del13); + sum1 = cubicinterp(frac2, del20, del21, del22, del23) - gain2 * del1; + sum2 = cubicinterp(frac3, del30, del31, del32, del33) - gain3 * sum1; output = sum2 - gain1 * samp; + if (idsamp13 < 0 || idsamp23 < 0 || idsamp33 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } else { + float dslope1 = CALCSLOPE(next_dt1, dt1); + float dslope2 = CALCSLOPE(next_dt2, dt2); + float dslope3 = CALCSLOPE(next_dt3, dt3); + LOOP( + inNumSamples, phase++; dt1 += dslope1; dt2 += dslope2; dt3 += dslope3; + dsamp1 = phase - (long)(dt1 * unit->mRate->mSampleRate); + dsamp2 = phase - (long)(dt2 * unit->mRate->mSampleRate); + dsamp3 = phase - (long)(dt3 * unit->mRate->mSampleRate); int idsamp1 = (int)dsamp1; + float frac1 = dsamp1 - idsamp1; int idsamp2 = (int)dsamp2; float frac2 = dsamp2 - idsamp2; + int idsamp3 = (int)dsamp3; float frac3 = dsamp3 - idsamp3; int idsamp13 = idsamp1 - 2; + int idsamp23 = idsamp2 - 2; int idsamp33 = idsamp3 - 2; samp = ZXP(in); + del1 = cubicinterp(frac1, buf1[(idsamp1 + 1) & mask1], buf1[idsamp1 & mask1], buf1[(idsamp1 - 1) & mask1], + buf1[idsamp13 & mask1]); + sum1 = cubicinterp(frac2, buf2[(idsamp2 + 1) & mask2], buf2[idsamp2 & mask2], buf2[(idsamp2 - 1) & mask2], + buf2[idsamp23 & mask2]) + - gain2 * del1; + sum2 = cubicinterp(frac3, buf3[(idsamp3 + 1) & mask3], buf3[idsamp3 & mask3], buf3[(idsamp3 - 1) & mask3], + buf3[idsamp33 & mask3]) + - gain3 * sum1; + output = sum2 - gain1 * samp; if (idsamp13 < 0 || idsamp23 < 0 || idsamp33 < 0) { + buf1[phase & mask1] = samp; + buf2[phase & mask2] = samp; + buf3[phase & mask3] = samp; + ZXP(out) = 0.f; + } else { + buf1[phase & mask1] = samp + gain1 * output; + buf2[phase & mask2] = del1 + gain2 * sum1; + buf3[phase & mask3] = sum1 + gain3 * sum2; + ZXP(out) = output; + }); + } + + unit->m_phase = phase; + unit->m_dsamp1 = dsamp1; + unit->m_dsamp2 = dsamp2; + unit->m_dsamp3 = dsamp3; + unit->m_dt1 = dt1; + unit->m_dt2 = dt2; + unit->m_dt3 = dt3; + + unit->m_numoutput += inNumSamples; + if (unit->m_numoutput >= unit->m_maxdel) { + SETCALC(DoubleNestedAllpassC_next); + } } -#define DefineFilterDelay(name) \ - (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \ - (UnitDtorFunc)&FilterDelay_Dtor, 0); - -PluginLoad(BhobFilt) -{ - ft = inTable; - - DefineSimpleUnit(MoogLadder); - DefineSimpleUnit(RLPFD); - DefineSimpleUnit(MultiFilt); - DefineDtorUnit(NestedAllpassN); - DefineDtorUnit(NestedAllpassL); - DefineDtorUnit(NestedAllpassC); - DefineDtorUnit(DoubleNestedAllpassN); - DefineDtorUnit(DoubleNestedAllpassL); - DefineDtorUnit(DoubleNestedAllpassC); - DefineFilterDelay(Streson); - DefineFilterDelay(NLFiltN); - DefineFilterDelay(NLFiltL); - DefineFilterDelay(NLFiltC); +#define DefineFilterDelay(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, (UnitDtorFunc)&FilterDelay_Dtor, 0); + +PluginLoad(BhobFilt) { + ft = inTable; + + DefineSimpleUnit(MoogLadder); + DefineSimpleUnit(RLPFD); + DefineSimpleUnit(MultiFilt); + DefineDtorUnit(NestedAllpassN); + DefineDtorUnit(NestedAllpassL); + DefineDtorUnit(NestedAllpassC); + DefineDtorUnit(DoubleNestedAllpassN); + DefineDtorUnit(DoubleNestedAllpassL); + DefineDtorUnit(DoubleNestedAllpassC); + DefineFilterDelay(Streson); + DefineFilterDelay(NLFiltN); + DefineFilterDelay(NLFiltL); + DefineFilterDelay(NLFiltC); } //////////////////////////////////////////////////////////////////// diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index f933128da9..512d9db3c3 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -4,7 +4,7 @@ the user with more control over the grain shape SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com + 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 @@ -23,572 +23,579 @@ SuperCollider real time audio synthesis system #include "SC_PlugIn.h" -static InterfaceTable *ft; +static InterfaceTable* ft; -struct Grain2 -{ - double phase, rate, attPhase, decPhase; - double attIncr, decIncr; - float pan1, pan2; - int counter, decCount; - int bufnum; - int chan; - int interp; +struct Grain2 { + double phase, rate, attPhase, decPhase; + double attIncr, decIncr; + float pan1, pan2; + int counter, decCount; + int bufnum; + int chan; + int interp; }; const int kMaxGrains = 64; -struct TGrains2 : public Unit -{ - float mPrevTrig; - int mNumActive; - Grain2 mGrains[kMaxGrains]; +struct TGrains2 : public Unit { + float mPrevTrig; + int mNumActive; + Grain2 mGrains[kMaxGrains]; }; -struct TGrains3 : public Unit -{ - float mPrevTrig; - int mNumActive, mWindowSize; - float* mWindow; - Grain2 mGrains[kMaxGrains]; +struct TGrains3 : public Unit { + float mPrevTrig; + int mNumActive, mWindowSize; + float* mWindow; + Grain2 mGrains[kMaxGrains]; }; // declare unit generator functions -extern "C" -{ - void TGrains2_next(TGrains2 *unit, int inNumSamples); - void TGrains2_Ctor(TGrains2* unit); +extern "C" { +void TGrains2_next(TGrains2* unit, int inNumSamples); +void TGrains2_Ctor(TGrains2* unit); - void TGrains3_next(TGrains3 *unit, int inNumSamples); - void TGrains3_Ctor(TGrains3* unit); +void TGrains3_next(TGrains3* unit, int inNumSamples); +void TGrains3_Ctor(TGrains3* unit); }; /* static float cubicinterp(float x, float y0, float y1, float y2, float y3) { - float c0 = y1; - float c1 = 0.5f * (y2 - y0); - float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3; - float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2); + float c0 = y1; + float c1 = 0.5f * (y2 - y0); + float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3; + float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2); - return ((c3 * x + c2) * x + c1) * x + c0; + return ((c3 * x + c2) * x + c1) * x + c0; } */ -#define GRAIN_BUF \ - SndBuf *buf = bufs + bufnum; \ - float *bufData __attribute__((__unused__)) = buf->data; \ - uint32 bufChannels __attribute__((__unused__)) = buf->channels; \ - uint32 bufSamples __attribute__((__unused__)) = buf->samples; \ - uint32 bufFrames = buf->frames; \ - int guardFrame __attribute__((__unused__)) = bufFrames - 2; \ - - -inline float IN_AT(Unit* unit, int index, int offset) -{ - if (INRATE(index) == calc_FullRate) return IN(index)[offset]; - return ZIN0(index); +#define GRAIN_BUF \ + SndBuf* buf = bufs + bufnum; \ + float* bufData __attribute__((__unused__)) = buf->data; \ + uint32 bufChannels __attribute__((__unused__)) = buf->channels; \ + uint32 bufSamples __attribute__((__unused__)) = buf->samples; \ + uint32 bufFrames = buf->frames; \ + int guardFrame __attribute__((__unused__)) = bufFrames - 2; + + +inline float IN_AT(Unit* unit, int index, int offset) { + if (INRATE(index) == calc_FullRate) + return IN(index)[offset]; + return ZIN0(index); } -inline double sc_gloop(double in, double hi) -{ - // avoid the divide if possible - if (in >= hi) { - in -= hi; - if (in < hi) return in; - } else if (in < 0.) { - in += hi; - if (in >= 0.) return in; - } else return in; - - return in - hi * floor(in/hi); +inline double sc_gloop(double in, double hi) { + // avoid the divide if possible + if (in >= hi) { + in -= hi; + if (in < hi) + return in; + } else if (in < 0.) { + in += hi; + if (in >= 0.) + return in; + } else + return in; + + return in - hi * floor(in / hi); } -#define GRAIN_AMP_2 \ - double amp; \ - double attPhase = grain->attPhase; \ - double decPhase = grain->decPhase; \ - if (counter > grain->decCount) { \ - amp = attPhase; \ - if (attPhase < 1.f) { \ - grain->attPhase += grain->attIncr; \ - } \ - } else { \ - amp = decPhase; \ - grain->decPhase -= grain->decIncr; \ - } \ - -#define GRAIN2_LOOP_BODY_4 \ - phase = sc_gloop(phase, loopMax); \ - int32 iphase = (int32)phase; \ - float* table1 = bufData + iphase; \ - float* table0 = table1 - 1; \ - float* table2 = table1 + 1; \ - float* table3 = table1 + 2; \ - if (iphase == 0) { \ - table0 += bufSamples; \ - } else if (iphase >= guardFrame) { \ - if (iphase == guardFrame) { \ - table3 -= bufSamples; \ - } else { \ - table2 -= bufSamples; \ - table3 -= bufSamples; \ - } \ - } \ - float fracphase = phase - (double)iphase; \ - float a = table0[0]; \ - float b = table1[0]; \ - float c = table2[0]; \ - float d = table3[0]; \ - float outval = amp * cubicinterp(fracphase, a, b, c, d); \ - ZXP(out1) += outval * pan1; \ - ZXP(out2) += outval * pan2; \ - counter--; \ - -#define GRAIN2_LOOP_BODY_2 \ - phase = sc_gloop(phase, loopMax); \ - int32 iphase = (int32)phase; \ - float* table1 = bufData + iphase; \ - float* table2 = table1 + 1; \ - if (iphase > guardFrame) { \ - table2 -= bufSamples; \ - } \ - float fracphase = phase - (double)iphase; \ - float b = table1[0]; \ - float c = table2[0]; \ - float outval = amp * (b + fracphase * (c - b)); \ - ZXP(out1) += outval * pan1; \ - ZXP(out2) += outval * pan2; \ - counter--; \ - -#define GRAIN2_LOOP_BODY_1 \ - phase = sc_gloop(phase, loopMax); \ - int32 iphase = (int32)phase; \ - float outval = amp * bufData[iphase]; \ - ZXP(out1) += outval * pan1; \ - ZXP(out2) += outval * pan2; \ - counter--; \ - - -void TGrains2_next(TGrains2 *unit, int inNumSamples) -{ - float *trigin = IN(0); - float prevtrig = unit->mPrevTrig; - - uint32 numOutputs = unit->mNumOutputs; - ClearUnitOutputs(unit, inNumSamples); - float *out[16]; - for (uint32 i=0; imWorld; - SndBuf *bufs = world->mSndBufs; - uint32 numBufs = world->mNumSndBufs; - - for (int i=0; i < unit->mNumActive; ) { - Grain2 *grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; - - GRAIN_BUF - - if (bufChannels != 1) { - ++i; - continue; - } - - double loopMax = (double)bufFrames; - - float pan1 = grain->pan1; - float pan2 = grain->pan2; - double rate = grain->rate; - double phase = grain->phase; - int counter = grain->counter; - - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) chan2 = 0; - - float *out1 = out[chan1]; - float *out2 = out[chan2]; - - int nsmps = sc_min(grain->counter, inNumSamples); - if (grain->interp >= 4) { - for (int j=0; jinterp >= 2) { - for (int j=0; jphase = phase; - - grain->counter = counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } else ++i; - } - - int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; - - for (int i=0; i 0.f && prevtrig <= 0.f) { - // start a grain - if (unit->mNumActive+1 >= kMaxGrains) break; - uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) continue; - GRAIN_BUF - - if (bufChannels != 1) continue; - - float bufSampleRate = buf->samplerate; - float bufRateScale = bufSampleRate * SAMPLEDUR; - double loopMax = (double)bufFrames; - - Grain2 *grain = unit->mGrains + unit->mNumActive++; - grain->bufnum = bufnum; - - double dur = IN_AT(unit, 4, i); - double counter = floor(dur * SAMPLERATE); - counter = sc_max(4., counter); - - double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; - double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; - double phase = centerPhase - 0.5 * counter * rate; - - float pan = IN_AT(unit, 5, i); - float amp = IN_AT(unit, 6, i); - double att = sc_max((double)IN_AT(unit, 7, i), SAMPLEDUR); - double dec = IN_AT(unit, 8, i); - - if ((att + dec) > dur) { - double sum=att + dec; - double norm=dur/sum; - att *= norm; - dec *= norm; - } - - grain->interp = (int)IN_AT(unit, 9, i); - - float panangle; - float pan1, pan2; - if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); - float cpan = numOutputs * pan + 0.5f; - float ipan = floor(cpan); - float panfrac = cpan - ipan; - panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) - grain->chan -= numOutputs; - } else { - grain->chan = 0; - pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); - panangle = pan * pi2_f; - } - pan1 = grain->pan1 = cos(panangle); - pan2 = grain->pan2 = sin(panangle); - } else { - grain->chan = 0; - pan1 = grain->pan1 = 1.; - pan2 = grain->pan2 = 0.; - } - int attCount = sc_max((int)(SAMPLERATE * att), 2); - int decCount = sc_max((int)(SAMPLERATE * dec), 2); - grain->attIncr = 1.0/attCount; - grain->decIncr = 1.0/decCount; - grain->decCount = decCount; - grain->attPhase = 0.f; - grain->decPhase = 1.f; - - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) chan2 = 0; - - float *out1 = out[chan1] + i; - float *out2 = out[chan2] + i; - - int nsmps = sc_min(grain->counter, inNumSamples - i); - if (grain->interp >= 4) { - for (int j=0; jinterp >= 2) { - for (int j=0; jphase = phase; - - grain->counter = (int)counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } - } - prevtrig = trig; - } - - unit->mPrevTrig = prevtrig; +#define GRAIN_AMP_2 \ + double amp; \ + double attPhase = grain->attPhase; \ + double decPhase = grain->decPhase; \ + if (counter > grain->decCount) { \ + amp = attPhase; \ + if (attPhase < 1.f) { \ + grain->attPhase += grain->attIncr; \ + } \ + } else { \ + amp = decPhase; \ + grain->decPhase -= grain->decIncr; \ + } + +#define GRAIN2_LOOP_BODY_4 \ + phase = sc_gloop(phase, loopMax); \ + int32 iphase = (int32)phase; \ + float* table1 = bufData + iphase; \ + float* table0 = table1 - 1; \ + float* table2 = table1 + 1; \ + float* table3 = table1 + 2; \ + if (iphase == 0) { \ + table0 += bufSamples; \ + } else if (iphase >= guardFrame) { \ + if (iphase == guardFrame) { \ + table3 -= bufSamples; \ + } else { \ + table2 -= bufSamples; \ + table3 -= bufSamples; \ + } \ + } \ + float fracphase = phase - (double)iphase; \ + float a = table0[0]; \ + float b = table1[0]; \ + float c = table2[0]; \ + float d = table3[0]; \ + float outval = amp * cubicinterp(fracphase, a, b, c, d); \ + ZXP(out1) += outval * pan1; \ + ZXP(out2) += outval * pan2; \ + counter--; + +#define GRAIN2_LOOP_BODY_2 \ + phase = sc_gloop(phase, loopMax); \ + int32 iphase = (int32)phase; \ + float* table1 = bufData + iphase; \ + float* table2 = table1 + 1; \ + if (iphase > guardFrame) { \ + table2 -= bufSamples; \ + } \ + float fracphase = phase - (double)iphase; \ + float b = table1[0]; \ + float c = table2[0]; \ + float outval = amp * (b + fracphase * (c - b)); \ + ZXP(out1) += outval * pan1; \ + ZXP(out2) += outval * pan2; \ + counter--; + +#define GRAIN2_LOOP_BODY_1 \ + phase = sc_gloop(phase, loopMax); \ + int32 iphase = (int32)phase; \ + float outval = amp * bufData[iphase]; \ + ZXP(out1) += outval * pan1; \ + ZXP(out2) += outval * pan2; \ + counter--; + + +void TGrains2_next(TGrains2* unit, int inNumSamples) { + float* trigin = IN(0); + float prevtrig = unit->mPrevTrig; + + uint32 numOutputs = unit->mNumOutputs; + ClearUnitOutputs(unit, inNumSamples); + float* out[16]; + for (uint32 i = 0; i < numOutputs; ++i) + out[i] = ZOUT(i); + + World* world = unit->mWorld; + SndBuf* bufs = world->mSndBufs; + uint32 numBufs = world->mNumSndBufs; + + for (int i = 0; i < unit->mNumActive;) { + Grain2* grain = unit->mGrains + i; + uint32 bufnum = grain->bufnum; + + GRAIN_BUF + + if (bufChannels != 1) { + ++i; + continue; + } + + double loopMax = (double)bufFrames; + + float pan1 = grain->pan1; + float pan2 = grain->pan2; + double rate = grain->rate; + double phase = grain->phase; + int counter = grain->counter; + + uint32 chan1 = grain->chan; + uint32 chan2 = chan1 + 1; + if (chan2 >= numOutputs) + chan2 = 0; + + float* out1 = out[chan1]; + float* out2 = out[chan2]; + + int nsmps = sc_min(grain->counter, inNumSamples); + if (grain->interp >= 4) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_4; + phase += rate; + } + } else if (grain->interp >= 2) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_2; + phase += rate; + } + } else { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_1; + phase += rate; + } + } + + grain->phase = phase; + + grain->counter = counter; + if (grain->counter <= 0) { + // remove grain + *grain = unit->mGrains[--unit->mNumActive]; + } else + ++i; + } + + int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; + + for (int i = 0; i < trigSamples; ++i) { + float trig = trigin[i]; + + if (trig > 0.f && prevtrig <= 0.f) { + // start a grain + if (unit->mNumActive + 1 >= kMaxGrains) + break; + uint32 bufnum = (uint32)IN_AT(unit, 1, i); + if (bufnum >= numBufs) + continue; + GRAIN_BUF + + if (bufChannels != 1) + continue; + + float bufSampleRate = buf->samplerate; + float bufRateScale = bufSampleRate * SAMPLEDUR; + double loopMax = (double)bufFrames; + + Grain2* grain = unit->mGrains + unit->mNumActive++; + grain->bufnum = bufnum; + + double dur = IN_AT(unit, 4, i); + double counter = floor(dur * SAMPLERATE); + counter = sc_max(4., counter); + + double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; + double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; + double phase = centerPhase - 0.5 * counter * rate; + + float pan = IN_AT(unit, 5, i); + float amp = IN_AT(unit, 6, i); + double att = sc_max((double)IN_AT(unit, 7, i), SAMPLEDUR); + double dec = IN_AT(unit, 8, i); + + if ((att + dec) > dur) { + double sum = att + dec; + double norm = dur / sum; + att *= norm; + dec *= norm; + } + + grain->interp = (int)IN_AT(unit, 9, i); + + float panangle; + float pan1, pan2; + if (numOutputs > 1) { + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + float cpan = numOutputs * pan + 0.5f; + float ipan = floor(cpan); + float panfrac = cpan - ipan; + panangle = panfrac * pi2_f; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) + grain->chan -= numOutputs; + } else { + grain->chan = 0; + pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); + panangle = pan * pi2_f; + } + pan1 = grain->pan1 = cos(panangle); + pan2 = grain->pan2 = sin(panangle); + } else { + grain->chan = 0; + pan1 = grain->pan1 = 1.; + pan2 = grain->pan2 = 0.; + } + int attCount = sc_max((int)(SAMPLERATE * att), 2); + int decCount = sc_max((int)(SAMPLERATE * dec), 2); + grain->attIncr = 1.0 / attCount; + grain->decIncr = 1.0 / decCount; + grain->decCount = decCount; + grain->attPhase = 0.f; + grain->decPhase = 1.f; + + uint32 chan1 = grain->chan; + uint32 chan2 = chan1 + 1; + if (chan2 >= numOutputs) + chan2 = 0; + + float* out1 = out[chan1] + i; + float* out2 = out[chan2] + i; + + int nsmps = sc_min(grain->counter, inNumSamples - i); + if (grain->interp >= 4) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_4; + phase += rate; + } + } else if (grain->interp >= 2) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_2; + phase += rate; + } + } else { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_2; + GRAIN2_LOOP_BODY_1; + phase += rate; + } + } + + grain->phase = phase; + + grain->counter = (int)counter; + if (grain->counter <= 0) { + // remove grain + *grain = unit->mGrains[--unit->mNumActive]; + } + } + prevtrig = trig; + } + + unit->mPrevTrig = prevtrig; } -void TGrains2_Ctor(TGrains2 *unit) -{ - SETCALC(TGrains2_next); +void TGrains2_Ctor(TGrains2* unit) { + SETCALC(TGrains2_next); - unit->mNumActive = 0; - unit->mPrevTrig = 0.; + unit->mNumActive = 0; + unit->mPrevTrig = 0.; - ClearUnitOutputs(unit, 1); + ClearUnitOutputs(unit, 1); } -#define GRAIN_AMP_3 \ - float amp; \ - int i_attPhase = (int)grain->attPhase; \ - int i_decPhase = (int)grain->decPhase; \ - if (counter > grain->decCount) { \ - amp = window[sc_min(i_attPhase, windowSize)]; \ - if (i_attPhase < windowSize) { \ - grain->attPhase += grain->attIncr; \ - } \ - } else { \ - amp = window[sc_max(i_decPhase, 0)]; \ - grain->decPhase -= grain->decIncr; \ - } \ - -void TGrains3_next(TGrains3 *unit, int inNumSamples) -{ - float *trigin = IN(0); - float prevtrig = unit->mPrevTrig; - float* window = unit->mWindow; - int windowSize = unit->mWindowSize; - - uint32 numOutputs = unit->mNumOutputs; - ClearUnitOutputs(unit, inNumSamples); - float *out[16]; - for (uint32 i=0; imWorld; - SndBuf *bufs = world->mSndBufs; - uint32 numBufs = world->mNumSndBufs; - - for (int i=0; i < unit->mNumActive; ) { - Grain2 *grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; - - GRAIN_BUF - - if (bufChannels != 1) { - ++i; - continue; - } - - double loopMax = (double)bufFrames; - - float pan1 = grain->pan1; - float pan2 = grain->pan2; - double rate = grain->rate; - double phase = grain->phase; - int counter = grain->counter; - - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) chan2 = 0; - - float *out1 = out[chan1]; - float *out2 = out[chan2]; - //printf("B chan %d %d %08X %08X", chan1, chan2, out1, out2); - - int nsmps = sc_min(grain->counter, inNumSamples); - if (grain->interp >= 4) { - for (int j=0; jinterp >= 2) { - for (int j=0; jphase = phase; - - grain->counter = counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } else ++i; - } - - int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; - - for (int i=0; i 0.f && prevtrig <= 0.f) { - // start a grain - if (unit->mNumActive+1 >= kMaxGrains) break; - uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) continue; - GRAIN_BUF - - if (bufChannels != 1) continue; - - float bufSampleRate = buf->samplerate; - float bufRateScale = bufSampleRate * SAMPLEDUR; - double loopMax = (double)bufFrames; - - Grain2 *grain = unit->mGrains + unit->mNumActive++; - grain->bufnum = bufnum; - - double dur=IN_AT(unit, 4, i); - double counter = floor(dur * SAMPLERATE); - counter = sc_max(4., counter); - - double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; - double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; - double phase = centerPhase - 0.5 * counter * rate; - - float pan = IN_AT(unit, 5, i); - float amp = IN_AT(unit, 6, i); - double att = IN_AT(unit, 7, i); - double dec = IN_AT(unit, 8, i); - - if ((att + dec) > dur) { - double sum=att + dec; - double norm=dur/sum; - att *= norm; - dec *= norm; - } - - grain->interp = (int)IN_AT(unit, 10, i); - - float panangle; - float pan1, pan2; - if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); - float cpan = numOutputs * pan + 0.5f; - float ipan = floor(cpan); - float panfrac = cpan - ipan; - panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) - grain->chan -= numOutputs; - } else { - grain->chan = 0; - pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); - panangle = pan * pi2_f; - } - pan1 = grain->pan1 = cos(panangle); - pan2 = grain->pan2 = sin(panangle); - } else { - grain->chan = 0; - pan1 = grain->pan1 = 1.; - pan2 = grain->pan2 = 0.; - } - int attCount = sc_max((int)(SAMPLERATE * att), 2); - int decCount = sc_max((int)(SAMPLERATE * dec), 2); - grain->attIncr = (float)windowSize/attCount; - grain->decIncr = (float)windowSize/decCount; - grain->decCount = decCount; - grain->attPhase = 0.f; - grain->decPhase = (float)windowSize; - - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) chan2 = 0; - - float *out1 = out[chan1] + i; - float *out2 = out[chan2] + i; - - int nsmps = sc_min(grain->counter, inNumSamples - i); - if (grain->interp >= 4) { - for (int j=0; jinterp >= 2) { - for (int j=0; jphase = phase; - - grain->counter = (int)counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } - } - prevtrig = trig; - } - - unit->mPrevTrig = prevtrig; +#define GRAIN_AMP_3 \ + float amp; \ + int i_attPhase = (int)grain->attPhase; \ + int i_decPhase = (int)grain->decPhase; \ + if (counter > grain->decCount) { \ + amp = window[sc_min(i_attPhase, windowSize)]; \ + if (i_attPhase < windowSize) { \ + grain->attPhase += grain->attIncr; \ + } \ + } else { \ + amp = window[sc_max(i_decPhase, 0)]; \ + grain->decPhase -= grain->decIncr; \ + } + +void TGrains3_next(TGrains3* unit, int inNumSamples) { + float* trigin = IN(0); + float prevtrig = unit->mPrevTrig; + float* window = unit->mWindow; + int windowSize = unit->mWindowSize; + + uint32 numOutputs = unit->mNumOutputs; + ClearUnitOutputs(unit, inNumSamples); + float* out[16]; + for (uint32 i = 0; i < numOutputs; ++i) + out[i] = ZOUT(i); + + World* world = unit->mWorld; + SndBuf* bufs = world->mSndBufs; + uint32 numBufs = world->mNumSndBufs; + + for (int i = 0; i < unit->mNumActive;) { + Grain2* grain = unit->mGrains + i; + uint32 bufnum = grain->bufnum; + + GRAIN_BUF + + if (bufChannels != 1) { + ++i; + continue; + } + + double loopMax = (double)bufFrames; + + float pan1 = grain->pan1; + float pan2 = grain->pan2; + double rate = grain->rate; + double phase = grain->phase; + int counter = grain->counter; + + uint32 chan1 = grain->chan; + uint32 chan2 = chan1 + 1; + if (chan2 >= numOutputs) + chan2 = 0; + + float* out1 = out[chan1]; + float* out2 = out[chan2]; + // printf("B chan %d %d %08X %08X", chan1, chan2, out1, out2); + + int nsmps = sc_min(grain->counter, inNumSamples); + if (grain->interp >= 4) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_4; + phase += rate; + } + } else if (grain->interp >= 2) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_2; + phase += rate; + } + } else { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_1; + phase += rate; + } + } + + grain->phase = phase; + + grain->counter = counter; + if (grain->counter <= 0) { + // remove grain + *grain = unit->mGrains[--unit->mNumActive]; + } else + ++i; + } + + int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; + + for (int i = 0; i < trigSamples; ++i) { + float trig = trigin[i]; + + if (trig > 0.f && prevtrig <= 0.f) { + // start a grain + if (unit->mNumActive + 1 >= kMaxGrains) + break; + uint32 bufnum = (uint32)IN_AT(unit, 1, i); + if (bufnum >= numBufs) + continue; + GRAIN_BUF + + if (bufChannels != 1) + continue; + + float bufSampleRate = buf->samplerate; + float bufRateScale = bufSampleRate * SAMPLEDUR; + double loopMax = (double)bufFrames; + + Grain2* grain = unit->mGrains + unit->mNumActive++; + grain->bufnum = bufnum; + + double dur = IN_AT(unit, 4, i); + double counter = floor(dur * SAMPLERATE); + counter = sc_max(4., counter); + + double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; + double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; + double phase = centerPhase - 0.5 * counter * rate; + + float pan = IN_AT(unit, 5, i); + float amp = IN_AT(unit, 6, i); + double att = IN_AT(unit, 7, i); + double dec = IN_AT(unit, 8, i); + + if ((att + dec) > dur) { + double sum = att + dec; + double norm = dur / sum; + att *= norm; + dec *= norm; + } + + grain->interp = (int)IN_AT(unit, 10, i); + + float panangle; + float pan1, pan2; + if (numOutputs > 1) { + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + float cpan = numOutputs * pan + 0.5f; + float ipan = floor(cpan); + float panfrac = cpan - ipan; + panangle = panfrac * pi2_f; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) + grain->chan -= numOutputs; + } else { + grain->chan = 0; + pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); + panangle = pan * pi2_f; + } + pan1 = grain->pan1 = cos(panangle); + pan2 = grain->pan2 = sin(panangle); + } else { + grain->chan = 0; + pan1 = grain->pan1 = 1.; + pan2 = grain->pan2 = 0.; + } + int attCount = sc_max((int)(SAMPLERATE * att), 2); + int decCount = sc_max((int)(SAMPLERATE * dec), 2); + grain->attIncr = (float)windowSize / attCount; + grain->decIncr = (float)windowSize / decCount; + grain->decCount = decCount; + grain->attPhase = 0.f; + grain->decPhase = (float)windowSize; + + uint32 chan1 = grain->chan; + uint32 chan2 = chan1 + 1; + if (chan2 >= numOutputs) + chan2 = 0; + + float* out1 = out[chan1] + i; + float* out2 = out[chan2] + i; + + int nsmps = sc_min(grain->counter, inNumSamples - i); + if (grain->interp >= 4) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_4; + phase += rate; + } + } else if (grain->interp >= 2) { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_2; + phase += rate; + } + } else { + for (int j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_1; + phase += rate; + } + } + + grain->phase = phase; + + grain->counter = (int)counter; + if (grain->counter <= 0) { + // remove grain + *grain = unit->mGrains[--unit->mNumActive]; + } + } + prevtrig = trig; + } + + unit->mPrevTrig = prevtrig; } -void TGrains3_Ctor(TGrains3 *unit) -{ - SETCALC(TGrains3_next); +void TGrains3_Ctor(TGrains3* unit) { + SETCALC(TGrains3_next); - unit->mNumActive = 0; - unit->mPrevTrig = 0.; - SndBuf* window=unit->mWorld->mSndBufs + (int)IN0(9); - unit->mWindow=window->data; - unit->mWindowSize=window->samples - 1; + unit->mNumActive = 0; + unit->mPrevTrig = 0.; + SndBuf* window = unit->mWorld->mSndBufs + (int)IN0(9); + unit->mWindow = window->data; + unit->mWindowSize = window->samples - 1; - ClearUnitOutputs(unit, 1); + ClearUnitOutputs(unit, 1); } -PluginLoad(BhobGrains) -{ - ft = inTable; +PluginLoad(BhobGrains) { + ft = inTable; - DefineSimpleUnit(TGrains2); - DefineSimpleUnit(TGrains3); + DefineSimpleUnit(TGrains2); + DefineSimpleUnit(TGrains3); } //////////////////////////////////////////////////////////////////// diff --git a/source/BhobUGens/BhobNoise.cpp b/source/BhobUGens/BhobNoise.cpp index 08d636bc84..194756f4a8 100644 --- a/source/BhobUGens/BhobNoise.cpp +++ b/source/BhobUGens/BhobNoise.cpp @@ -4,7 +4,7 @@ interpolation. Gendy5 is the same, but with no interpolation. SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com + 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 @@ -23,882 +23,831 @@ SuperCollider real time audio synthesis system #include "SC_PlugIn.h" -static InterfaceTable *ft; +static InterfaceTable* ft; -struct LFBrownNoise0 : public Unit -{ - int32 mCounter; - float mLevel; +struct LFBrownNoise0 : public Unit { + int32 mCounter; + float mLevel; }; -struct LFBrownNoise1 : public Unit -{ - int32 mCounter; - float mSlope, mLevel; +struct LFBrownNoise1 : public Unit { + int32 mCounter; + float mSlope, mLevel; }; -struct LFBrownNoise2 : public Unit -{ - int32 mCounter; - float mSlope, mLevel, mCurve, m_nextvalue; +struct LFBrownNoise2 : public Unit { + int32 mCounter; + float mSlope, mLevel, mCurve, m_nextvalue; }; -struct Dbrown2 : public Unit -{ - int32 m_repeats, m_repeatCount; - int m_dist; - float m_lo, m_hi, m_step, m_val; +struct Dbrown2 : public Unit { + int32 m_repeats, m_repeatCount; + int m_dist; + float m_lo, m_hi, m_step, m_val; }; /* struct Dbeta : public Unit { - int32 m_repeats, m_repeatCount; - float m_lo, m_hi, m_prob1, m_prob2; + int32 m_repeats, m_repeatCount; + float m_lo, m_hi, m_prob1, m_prob2; }; */ -struct Dgauss : public Unit -{ - int32 m_repeats, m_repeatCount; - float m_lo, m_hi; +struct Dgauss : public Unit { + int32 m_repeats, m_repeatCount; + float m_lo, m_hi; }; -struct GaussTrig : public Unit -{ - int mCount; +struct GaussTrig : public Unit { + int mCount; }; -struct TBrownRand : public Unit -{ - float m_trig, m_value; +struct TBrownRand : public Unit { + float m_trig, m_value; }; -struct TGaussRand : public Unit -{ - float m_trig, m_value; +struct TGaussRand : public Unit { + float m_trig, m_value; }; -struct TBetaRand : public Unit -{ - float m_trig, m_value; +struct TBetaRand : public Unit { + float m_trig, m_value; }; -struct Gendy4 : public Unit -{ - int32 mPhase; - float mAmp, mNextAmp, mDur, mSlope, mMidpnt, mCurve; - int mMemorySize, mIndex; - float* mMemoryAmp; - float* mMemoryDur; +struct Gendy4 : public Unit { + int32 mPhase; + float mAmp, mNextAmp, mDur, mSlope, mMidpnt, mCurve; + int mMemorySize, mIndex; + float* mMemoryAmp; + float* mMemoryDur; }; -struct Gendy5 : public Unit -{ - double mPhase; - float mAmp, mDur, mSpeed; - int mMemorySize, mIndex; - float* mMemoryAmp; - float* mMemoryDur; +struct Gendy5 : public Unit { + double mPhase; + float mAmp, mDur, mSpeed; + int mMemorySize, mIndex; + float* mMemoryAmp; + float* mMemoryDur; }; // declare unit generator functions -extern "C" -{ - void TBrownRand_next_a(TBrownRand *unit, int inNumSamples); - void TBrownRand_next_k(TBrownRand *unit, int inNumSamples);; - void TBrownRand_Ctor(TBrownRand* unit); +extern "C" { +void TBrownRand_next_a(TBrownRand* unit, int inNumSamples); +void TBrownRand_next_k(TBrownRand* unit, int inNumSamples); +; +void TBrownRand_Ctor(TBrownRand* unit); - void Dbrown2_Ctor(Dbrown2 *unit); - void Dbrown2_next(Dbrown2 *unit, int inNumSamples); +void Dbrown2_Ctor(Dbrown2* unit); +void Dbrown2_next(Dbrown2* unit, int inNumSamples); - /* void Dbeta_Ctor(Dbeta *unit); - void Dbeta_next(Dbeta *unit, int inNumSamples); */ +/* void Dbeta_Ctor(Dbeta *unit); +void Dbeta_next(Dbeta *unit, int inNumSamples); */ - void Dgauss_Ctor(Dgauss *unit); - void Dgauss_next(Dgauss *unit, int inNumSamples); +void Dgauss_Ctor(Dgauss* unit); +void Dgauss_next(Dgauss* unit, int inNumSamples); - void TGaussRand_next_a(TGaussRand *unit, int inNumSamples); - void TGaussRand_next_k(TGaussRand *unit, int inNumSamples);; - void TGaussRand_Ctor(TGaussRand* unit); +void TGaussRand_next_a(TGaussRand* unit, int inNumSamples); +void TGaussRand_next_k(TGaussRand* unit, int inNumSamples); +; +void TGaussRand_Ctor(TGaussRand* unit); - void TBetaRand_next_a(TBetaRand *unit, int inNumSamples); - void TBetaRand_next_k(TBetaRand *unit, int inNumSamples);; - void TBetaRand_Ctor(TBetaRand* unit); +void TBetaRand_next_a(TBetaRand* unit, int inNumSamples); +void TBetaRand_next_k(TBetaRand* unit, int inNumSamples); +; +void TBetaRand_Ctor(TBetaRand* unit); - void GaussTrig_next(GaussTrig *unit, int inNumSamples); - void GaussTrig_Ctor(GaussTrig* unit); +void GaussTrig_next(GaussTrig* unit, int inNumSamples); +void GaussTrig_Ctor(GaussTrig* unit); - void LFBrownNoise0_next(LFBrownNoise0 *unit, int inNumSamples); - void LFBrownNoise0_Ctor(LFBrownNoise0* unit); +void LFBrownNoise0_next(LFBrownNoise0* unit, int inNumSamples); +void LFBrownNoise0_Ctor(LFBrownNoise0* unit); - void LFBrownNoise1_next(LFBrownNoise1 *unit, int inNumSamples); - void LFBrownNoise1_Ctor(LFBrownNoise1* unit); +void LFBrownNoise1_next(LFBrownNoise1* unit, int inNumSamples); +void LFBrownNoise1_Ctor(LFBrownNoise1* unit); - void LFBrownNoise2_next(LFBrownNoise2 *unit, int inNumSamples); - void LFBrownNoise2_Ctor(LFBrownNoise2* unit); +void LFBrownNoise2_next(LFBrownNoise2* unit, int inNumSamples); +void LFBrownNoise2_Ctor(LFBrownNoise2* unit); - void Gendy4_next_k(Gendy4 *unit, int inNumSamples); - void Gendy4_Ctor(Gendy4* unit); - void Gendy4_Dtor(Gendy4* unit); +void Gendy4_next_k(Gendy4* unit, int inNumSamples); +void Gendy4_Ctor(Gendy4* unit); +void Gendy4_Dtor(Gendy4* unit); - void Gendy5_next_k(Gendy5 *unit, int inNumSamples); - void Gendy5_Ctor(Gendy5* unit); - void Gendy5_Dtor(Gendy5* unit); +void Gendy5_next_k(Gendy5* unit, int inNumSamples); +void Gendy5_Ctor(Gendy5* unit); +void Gendy5_Dtor(Gendy5* unit); }; -#define RGET \ - RGen& rgen = *unit->mParent->mRGen; \ - uint32 s1 = rgen.s1; \ - uint32 s2 = rgen.s2; \ - uint32 s3 = rgen.s3; +#define RGET \ + RGen& rgen = *unit->mParent->mRGen; \ + uint32 s1 = rgen.s1; \ + uint32 s2 = rgen.s2; \ + uint32 s3 = rgen.s3; -#define RPUT \ - rgen.s1 = s1; \ - rgen.s2 = s2; \ - rgen.s3 = s3; +#define RPUT \ + rgen.s1 = s1; \ + rgen.s2 = s2; \ + rgen.s3 = s3; // this is Nick Collins's version of Gendyn distributions -static inline float Gendyn_distribution( int which, float a, float f) { - float temp, c; +static inline float Gendyn_distribution(int which, float a, float f) { + float temp, c; - if(a>1.0) a=1.0; - if(a<0.0001) a=0.0001; + if (a > 1.0) + a = 1.0; + if (a < 0.0001) + a = 0.0001; - switch (which) - { - case 0: //LINEAR - break; - case 1: //CAUCHY - c= atan(10*a); - temp= (1/a)*tan(c*(2*f - 1)); + switch (which) { + case 0: // LINEAR + break; + case 1: // CAUCHY + c = atan(10 * a); + temp = (1 / a) * tan(c * (2 * f - 1)); - return temp*0.1; + return temp * 0.1; - case 2: //LOGIST (ic) + case 2: // LOGIST (ic) - c=0.5+(0.499*a); - c= log((1-c)/c); - f= ((f-0.5)*0.998*a)+0.5; - temp= log((1-f)/f)/c; + c = 0.5 + (0.499 * a); + c = log((1 - c) / c); + f = ((f - 0.5) * 0.998 * a) + 0.5; + temp = log((1 - f) / f) / c; - return temp; + return temp; - case 3: //HYPERBCOS - c=tan(1.5692255*a); - temp= tan(1.5692255*a*f)/c; - temp= log(temp*0.999+0.001)*(-0.1447648); + case 3: // HYPERBCOS + c = tan(1.5692255 * a); + temp = tan(1.5692255 * a * f) / c; + temp = log(temp * 0.999 + 0.001) * (-0.1447648); - return 2*temp-1.0; + return 2 * temp - 1.0; - case 4: //ARCSINE - c= sin(1.5707963*a); - temp= sin(pi*(f-0.5)*a)/c; + case 4: // ARCSINE + c = sin(1.5707963 * a); + temp = sin(pi * (f - 0.5) * a) / c; - return temp; + return temp; - case 5: //EXPON - c= log(1.0-(0.999*a)); - temp= log(1.0-(f*0.999*a))/c; + case 5: // EXPON + c = log(1.0 - (0.999 * a)); + temp = log(1.0 - (f * 0.999 * a)) / c; - return 2*temp-1.0; + return 2 * temp - 1.0; - case 6: //SINUS - return 2*a-1.0; + case 6: // SINUS + return 2 * a - 1.0; - default: - break; - } + default: + break; + } - return 2*f-1.0; + return 2 * f - 1.0; } -static inline float Mirroring (float lower, float upper, float in) -{ - if(in>upper || in upper || in < lower) { + if (in < lower) { + float diff = lower - in; + in = sc_min(upper, lower + diff); + } else { + float diff = in - upper; + in = sc_max(lower, upper - diff); + } + } + return in; } -void GaussTrig_Ctor(GaussTrig* unit) -{ - RGET - int nextSamples=(int)(SAMPLERATE/sc_max(ZIN0(0), 0.001f)); - float nextcount=sqrt(-2*log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi); - nextcount=Mirroring(-1.f, 1.f, nextcount); - int count=(int)(nextSamples + nextcount * ZIN0(1) * nextSamples); - SETCALC(GaussTrig_next); - unit->mCount = count; - ZOUT0(0)=1.f; - RPUT +void GaussTrig_Ctor(GaussTrig* unit) { + RGET int nextSamples = (int)(SAMPLERATE / sc_max(ZIN0(0), 0.001f)); + float nextcount = sqrt(-2 * log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi); + nextcount = Mirroring(-1.f, 1.f, nextcount); + int count = (int)(nextSamples + nextcount * ZIN0(1) * nextSamples); + SETCALC(GaussTrig_next); + unit->mCount = count; + ZOUT0(0) = 1.f; + RPUT } -void GaussTrig_next(GaussTrig* unit, int inNumSamples) -{ - float *out=ZOUT(0); - float freq=ZIN0(0); - int count=unit->mCount; - - LOOP(inNumSamples, - if (count <= 0) { - RGET - int nextSamples=(int)(SAMPLERATE/sc_max(freq, 0.001f)); - float nextcount=sqrt(-2*log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi); - nextcount=Mirroring(-1.0, 1.0, nextcount); - count=(int)(nextSamples + nextcount * ZIN0(1) * nextSamples); - ZXP(out)=1.f; - RPUT - } else { - ZXP(out)=0.f; - } - count -= 1; - ); - - unit->mCount=count; +void GaussTrig_next(GaussTrig* unit, int inNumSamples) { + float* out = ZOUT(0); + float freq = ZIN0(0); + int count = unit->mCount; + + LOOP( + inNumSamples, + if (count <= 0) { + RGET int nextSamples = (int)(SAMPLERATE / sc_max(freq, 0.001f)); + float nextcount = sqrt(-2 * log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi); + nextcount = Mirroring(-1.0, 1.0, nextcount); + count = (int)(nextSamples + nextcount * ZIN0(1) * nextSamples); + ZXP(out) = 1.f; + RPUT + } else { ZXP(out) = 0.f; } count -= 1;); + + unit->mCount = count; } -void LFBrownNoise0_next(LFBrownNoise0 *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float freq = ZIN0(0); - float level = unit->mLevel; - int32 counter = unit->mCounter; - RGen& rgen = *unit->mParent->mRGen; - - int remain = inNumSamples; - do { - if (counter<=0) { - counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); - counter = sc_max(1, counter); - level = level + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); - level = Mirroring(-1.0, 1.0, level); - } - int nsmps = sc_min(remain, counter); - remain -= nsmps; - counter -= nsmps; - LOOP(nsmps, ZXP(out) = level;); - } while (remain); - unit->mLevel = level; - unit->mCounter = counter; - +void LFBrownNoise0_next(LFBrownNoise0* unit, int inNumSamples) { + float* out = ZOUT(0); + float freq = ZIN0(0); + float level = unit->mLevel; + int32 counter = unit->mCounter; + RGen& rgen = *unit->mParent->mRGen; + + int remain = inNumSamples; + do { + if (counter <= 0) { + counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); + counter = sc_max(1, counter); + level = level + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); + level = Mirroring(-1.0, 1.0, level); + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + LOOP(nsmps, ZXP(out) = level;); + } while (remain); + unit->mLevel = level; + unit->mCounter = counter; } -void LFBrownNoise0_Ctor(LFBrownNoise0* unit) -{ - SETCALC(LFBrownNoise0_next); +void LFBrownNoise0_Ctor(LFBrownNoise0* unit) { + SETCALC(LFBrownNoise0_next); - unit->mCounter = 0; - unit->mLevel = unit->mParent->mRGen->frand2(); + unit->mCounter = 0; + unit->mLevel = unit->mParent->mRGen->frand2(); - LFBrownNoise0_next(unit, 1); + LFBrownNoise0_next(unit, 1); } -void LFBrownNoise1_next(LFBrownNoise1 *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float freq = ZIN0(0); - float level = unit->mLevel; - float slope = unit->mSlope; - int32 counter = unit->mCounter; - RGen& rgen = *unit->mParent->mRGen; - - int remain = inNumSamples; - - do { - if (counter<=0) { - counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); - counter = sc_max(1, counter); - float nextlevel = level + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); - nextlevel = Mirroring(-1.0, 1.0, nextlevel); - slope = (nextlevel - level) / counter; - } - int nsmps = sc_min(remain, counter); - remain -= nsmps; - counter -= nsmps; - LOOP(nsmps, ZXP(out) = level; level += slope;); - } while (remain); - unit->mLevel = level; - unit->mSlope = slope; - unit->mCounter = counter; - +void LFBrownNoise1_next(LFBrownNoise1* unit, int inNumSamples) { + float* out = ZOUT(0); + float freq = ZIN0(0); + float level = unit->mLevel; + float slope = unit->mSlope; + int32 counter = unit->mCounter; + RGen& rgen = *unit->mParent->mRGen; + + int remain = inNumSamples; + + do { + if (counter <= 0) { + counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); + counter = sc_max(1, counter); + float nextlevel = level + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); + nextlevel = Mirroring(-1.0, 1.0, nextlevel); + slope = (nextlevel - level) / counter; + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + LOOP(nsmps, ZXP(out) = level; level += slope;); + } while (remain); + unit->mLevel = level; + unit->mSlope = slope; + unit->mCounter = counter; } -void LFBrownNoise1_Ctor(LFBrownNoise1* unit) -{ - SETCALC(LFBrownNoise1_next); +void LFBrownNoise1_Ctor(LFBrownNoise1* unit) { + SETCALC(LFBrownNoise1_next); - unit->mCounter = 0; - unit->mLevel = unit->mParent->mRGen->frand2(); - unit->mSlope = 0.f; + unit->mCounter = 0; + unit->mLevel = unit->mParent->mRGen->frand2(); + unit->mSlope = 0.f; - LFBrownNoise1_next(unit, 1); + LFBrownNoise1_next(unit, 1); } -void LFBrownNoise2_next(LFBrownNoise2 *unit, int inNumSamples) -{ - float *out = ZOUT(0); - float freq = ZIN0(0); - float level = unit->mLevel; - float slope = unit->mSlope; - float curve = unit->mCurve; - int32 counter = unit->mCounter; - RGen& rgen = *unit->mParent->mRGen; - - int remain = inNumSamples; - do { - if (counter<=0) { - float value = unit->m_nextvalue; - float nextlevel = value + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); - nextlevel = Mirroring(-1.0, 1.0, nextlevel); - unit->m_nextvalue=nextlevel; - float nextmidpt = (nextlevel + value) * 0.5; - - counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); - counter = sc_max(2, counter); - float fseglen = (float)counter; - curve = 2.f * (nextmidpt - level - fseglen * slope) / (fseglen * fseglen + fseglen); - } - int nsmps = sc_min(remain, counter); - remain -= nsmps; - counter -= nsmps; - LOOP(nsmps, - ZXP(out) = level; - slope += curve; - level += slope; - ); - } while (remain); - unit->mLevel = level; - unit->mSlope = slope; - unit->mCurve = curve; - unit->mCounter = counter; - +void LFBrownNoise2_next(LFBrownNoise2* unit, int inNumSamples) { + float* out = ZOUT(0); + float freq = ZIN0(0); + float level = unit->mLevel; + float slope = unit->mSlope; + float curve = unit->mCurve; + int32 counter = unit->mCounter; + RGen& rgen = *unit->mParent->mRGen; + + int remain = inNumSamples; + do { + if (counter <= 0) { + float value = unit->m_nextvalue; + float nextlevel = value + (ZIN0(1) * Gendyn_distribution((int)ZIN0(2), 1.0, rgen.frand())); + nextlevel = Mirroring(-1.0, 1.0, nextlevel); + unit->m_nextvalue = nextlevel; + float nextmidpt = (nextlevel + value) * 0.5; + + counter = (int32)(unit->mRate->mSampleRate / sc_max(freq, .001f)); + counter = sc_max(2, counter); + float fseglen = (float)counter; + curve = 2.f * (nextmidpt - level - fseglen * slope) / (fseglen * fseglen + fseglen); + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + LOOP(nsmps, ZXP(out) = level; slope += curve; level += slope;); + } while (remain); + unit->mLevel = level; + unit->mSlope = slope; + unit->mCurve = curve; + unit->mCounter = counter; } -void LFBrownNoise2_Ctor(LFBrownNoise2* unit) -{ - SETCALC(LFBrownNoise2_next); - - unit->mCounter = 0; - unit->mSlope = 0.f; - unit->mLevel = unit->mParent->mRGen->frand2(); - float nextvalue = unit->mLevel + unit->mParent->mRGen->frand2() * ZIN0(2); - nextvalue = Mirroring(-1.0, 1.0, nextvalue); - unit->m_nextvalue = nextvalue; - LFBrownNoise2_next(unit, 1); +void LFBrownNoise2_Ctor(LFBrownNoise2* unit) { + SETCALC(LFBrownNoise2_next); + + unit->mCounter = 0; + unit->mSlope = 0.f; + unit->mLevel = unit->mParent->mRGen->frand2(); + float nextvalue = unit->mLevel + unit->mParent->mRGen->frand2() * ZIN0(2); + nextvalue = Mirroring(-1.0, 1.0, nextvalue); + unit->m_nextvalue = nextvalue; + LFBrownNoise2_next(unit, 1); } -void Dbrown2_next(Dbrown2 *unit, int inNumSamples) -{ - if (inNumSamples) { - if (unit->m_repeats < 0) { - float x = DEMANDINPUT(0); - unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); - unit->m_lo = DEMANDINPUT(1); - unit->m_hi = DEMANDINPUT(2); - unit->m_step = DEMANDINPUT(3); - unit->m_dist = (int)DEMANDINPUT(4); - unit->m_val = unit->mParent->mRGen->frand() * (unit->m_hi - unit->m_lo) + unit->m_lo; - } - if (unit->m_repeatCount >= unit->m_repeats) { - OUT0(0) = NAN; - return; - } - unit->m_repeatCount++; - OUT0(0) = unit->m_val; - float x = unit->m_val + Gendyn_distribution(unit->m_dist, 1.0, unit->mParent->mRGen->frand()) * unit->m_step; - unit->m_val = sc_fold(x, unit->m_lo, unit->m_hi); - } else { - unit->m_repeats = -1; - unit->m_repeatCount = 0; - } +void Dbrown2_next(Dbrown2* unit, int inNumSamples) { + if (inNumSamples) { + if (unit->m_repeats < 0) { + float x = DEMANDINPUT(0); + unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); + unit->m_lo = DEMANDINPUT(1); + unit->m_hi = DEMANDINPUT(2); + unit->m_step = DEMANDINPUT(3); + unit->m_dist = (int)DEMANDINPUT(4); + unit->m_val = unit->mParent->mRGen->frand() * (unit->m_hi - unit->m_lo) + unit->m_lo; + } + if (unit->m_repeatCount >= unit->m_repeats) { + OUT0(0) = NAN; + return; + } + unit->m_repeatCount++; + OUT0(0) = unit->m_val; + float x = unit->m_val + Gendyn_distribution(unit->m_dist, 1.0, unit->mParent->mRGen->frand()) * unit->m_step; + unit->m_val = sc_fold(x, unit->m_lo, unit->m_hi); + } else { + unit->m_repeats = -1; + unit->m_repeatCount = 0; + } } -void Dbrown2_Ctor(Dbrown2 *unit) -{ - SETCALC(Dbrown2_next); - Dbrown2_next(unit, 0); - OUT0(0) = 0.f; +void Dbrown2_Ctor(Dbrown2* unit) { + SETCALC(Dbrown2_next); + Dbrown2_next(unit, 0); + OUT0(0) = 0.f; } /* void Dbeta_next(Dbeta *unit, int inNumSamples) { - float sum=2.f; - float value; - if (inNumSamples) { - if (unit->m_repeats < 0) { - float x = DEMANDINPUT(0); - unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); - unit->m_lo = DEMANDINPUT(1); - unit->m_hi = DEMANDINPUT(2); - unit->m_prob1 = DEMANDINPUT(3); - unit->m_prob2 = DEMANDINPUT(4); - } - if (unit->m_repeatCount >= unit->m_repeats) { - OUT0(0) = NAN; - return; - } - unit->m_repeatCount++; - while (sum > 1.f) { - value=pow(unit->mParent->mRGen->frand(), unit->m_prob1); - sum=value + pow(unit->mParent->mRGen->frand(), unit->m_prob2); - }; - OUT0(0) = (value/sum) * (unit->m_hi-unit->m_lo) + unit->m_lo; - } else { - unit->m_repeats = -1; - unit->m_repeatCount = 0; - } + float sum=2.f; + float value; + if (inNumSamples) { + if (unit->m_repeats < 0) { + float x = DEMANDINPUT(0); + unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); + unit->m_lo = DEMANDINPUT(1); + unit->m_hi = DEMANDINPUT(2); + unit->m_prob1 = DEMANDINPUT(3); + unit->m_prob2 = DEMANDINPUT(4); + } + if (unit->m_repeatCount >= unit->m_repeats) { + OUT0(0) = NAN; + return; + } + unit->m_repeatCount++; + while (sum > 1.f) { + value=pow(unit->mParent->mRGen->frand(), unit->m_prob1); + sum=value + pow(unit->mParent->mRGen->frand(), unit->m_prob2); + }; + OUT0(0) = (value/sum) * (unit->m_hi-unit->m_lo) + unit->m_lo; + } else { + unit->m_repeats = -1; + unit->m_repeatCount = 0; + } } void Dbeta_Ctor(Dbeta *unit) { - SETCALC(Dbeta_next); - Dbeta_next(unit, 0); - OUT0(0) = 0.f; + SETCALC(Dbeta_next); + Dbeta_next(unit, 0); + OUT0(0) = 0.f; } */ -void Dgauss_next(Dgauss *unit, int inNumSamples) -{ - if (inNumSamples) { - if (unit->m_repeats < 0) { - float x = DEMANDINPUT(0); - unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); - unit->m_lo = DEMANDINPUT(1); - unit->m_hi = DEMANDINPUT(2); - } - if (unit->m_repeatCount >= unit->m_repeats) { - OUT0(0) = NAN; - return; - } - unit->m_repeatCount++; - float range = (unit->m_hi - unit->m_lo); - float value = ((sqrt(-2*log(unit->mParent->mRGen->frand())) * sin(unit->mParent->mRGen->frand() * twopi)) + 1) * 0.5; - value=Mirroring(0.0, 1.0, value); - OUT0(0) = value * range + unit->m_lo; - } else { - unit->m_repeats = -1; - unit->m_repeatCount = 0; - } +void Dgauss_next(Dgauss* unit, int inNumSamples) { + if (inNumSamples) { + if (unit->m_repeats < 0) { + float x = DEMANDINPUT(0); + unit->m_repeats = sc_isnan(x) ? 0 : (int32)floor(x + 0.5f); + unit->m_lo = DEMANDINPUT(1); + unit->m_hi = DEMANDINPUT(2); + } + if (unit->m_repeatCount >= unit->m_repeats) { + OUT0(0) = NAN; + return; + } + unit->m_repeatCount++; + float range = (unit->m_hi - unit->m_lo); + float value = + ((sqrt(-2 * log(unit->mParent->mRGen->frand())) * sin(unit->mParent->mRGen->frand() * twopi)) + 1) * 0.5; + value = Mirroring(0.0, 1.0, value); + OUT0(0) = value * range + unit->m_lo; + } else { + unit->m_repeats = -1; + unit->m_repeatCount = 0; + } } -void Dgauss_Ctor(Dgauss *unit) -{ - SETCALC(Dgauss_next); - Dgauss_next(unit, 0); - OUT0(0) = 0.f; +void Dgauss_Ctor(Dgauss* unit) { + SETCALC(Dgauss_next); + Dgauss_next(unit, 0); + OUT0(0) = 0.f; } -void TBrownRand_next_k(TBrownRand* unit, int inNumSamples) -{ - float trig = ZIN0(4); - float lo = ZIN0(0); - float hi = ZIN0(1); - float range = (hi - lo) * 0.5; - RGen& rgen = *unit->mParent->mRGen; - - if (trig > 0.f && unit->m_trig <= 0.f) { - float value = unit->m_value + (ZIN0(2)*Gendyn_distribution((int)ZIN0(3), 1.0, rgen.frand())); - value = Mirroring(-1.0, 1.0, value); - ZOUT0(0) = value * range + range + lo; - unit->m_value=value; - } else { - ZOUT0(0) = unit->m_value * range + range + lo; - } - unit->m_trig = trig; +void TBrownRand_next_k(TBrownRand* unit, int inNumSamples) { + float trig = ZIN0(4); + float lo = ZIN0(0); + float hi = ZIN0(1); + float range = (hi - lo) * 0.5; + RGen& rgen = *unit->mParent->mRGen; + + if (trig > 0.f && unit->m_trig <= 0.f) { + float value = unit->m_value + (ZIN0(2) * Gendyn_distribution((int)ZIN0(3), 1.0, rgen.frand())); + value = Mirroring(-1.0, 1.0, value); + ZOUT0(0) = value * range + range + lo; + unit->m_value = value; + } else { + ZOUT0(0) = unit->m_value * range + range + lo; + } + unit->m_trig = trig; } -void TBrownRand_next_a(TBrownRand* unit, int inNumSamples) -{ - float *trig = ZIN(4); - float prev = unit->m_trig; - float *out = ZOUT(0); - float oldval = unit->m_value; - float next, range, value; - RGen& rgen = *unit->mParent->mRGen; - - LOOP(inNumSamples, - next = ZXP(trig); - if (next > 0.f && prev <= 0.f) { - float lo=ZIN0(0); - float hi=ZIN0(1); - range = (hi - lo) * 0.5; - value = oldval + (ZIN0(2)*Gendyn_distribution((int)ZIN0(3), 1.0, rgen.frand())); - value = Mirroring(-1.0, 1.0, value); - ZXP(out) = value * range + range + lo; - oldval=value; - prev=next; - } else { - range = (ZIN0(1) - ZIN0(0)) * 0.5; - ZXP(out) = oldval * range + range + ZIN0(0); - }; - prev = next; - ) - - unit->m_trig = next; - unit->m_value=oldval; +void TBrownRand_next_a(TBrownRand* unit, int inNumSamples) { + float* trig = ZIN(4); + float prev = unit->m_trig; + float* out = ZOUT(0); + float oldval = unit->m_value; + float next, range, value; + RGen& rgen = *unit->mParent->mRGen; + + LOOP( + inNumSamples, next = ZXP(trig); if (next > 0.f && prev <= 0.f) { + float lo = ZIN0(0); + float hi = ZIN0(1); + range = (hi - lo) * 0.5; + value = oldval + (ZIN0(2) * Gendyn_distribution((int)ZIN0(3), 1.0, rgen.frand())); + value = Mirroring(-1.0, 1.0, value); + ZXP(out) = value * range + range + lo; + oldval = value; + prev = next; + } else { + range = (ZIN0(1) - ZIN0(0)) * 0.5; + ZXP(out) = oldval * range + range + ZIN0(0); + }; + prev = next;) + + unit->m_trig = next; + unit->m_value = oldval; } -void TBrownRand_Ctor(TBrownRand* unit) -{ - float lo = ZIN0(0); - float hi = ZIN0(1); - float range = (hi - lo) * 0.5; - RGen& rgen = *unit->mParent->mRGen; - unit->m_value = rgen.frand2(); - ZOUT0(0) = unit->m_value * range + range + lo; - if(unit->mCalcRate == calc_FullRate){ SETCALC(TBrownRand_next_a); } else { SETCALC(TBrownRand_next_k); } - unit->m_trig = ZIN0(3); +void TBrownRand_Ctor(TBrownRand* unit) { + float lo = ZIN0(0); + float hi = ZIN0(1); + float range = (hi - lo) * 0.5; + RGen& rgen = *unit->mParent->mRGen; + unit->m_value = rgen.frand2(); + ZOUT0(0) = unit->m_value * range + range + lo; + if (unit->mCalcRate == calc_FullRate) { + SETCALC(TBrownRand_next_a); + } else { + SETCALC(TBrownRand_next_k); + } + unit->m_trig = ZIN0(3); } -void TGaussRand_next_k(TGaussRand* unit, int inNumSamples) -{ - float trig = ZIN0(2); - float lo = ZIN0(0); - float hi = ZIN0(1); - float range = (hi - lo); - - if (trig > 0.f && unit->m_trig <= 0.f) { - RGET - float value = ((sqrt(-2*log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi)) + 1) * 0.5; - value=Mirroring(0.0, 1.0, value); - ZOUT0(0) = value * range + lo; - unit->m_value=value; - RPUT - } else { - ZOUT0(0) = unit->m_value * range + lo; - } - unit->m_trig = trig; +void TGaussRand_next_k(TGaussRand* unit, int inNumSamples) { + float trig = ZIN0(2); + float lo = ZIN0(0); + float hi = ZIN0(1); + float range = (hi - lo); + + if (trig > 0.f && unit->m_trig <= 0.f) { + RGET float value = ((sqrt(-2 * log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi)) + 1) * 0.5; + value = Mirroring(0.0, 1.0, value); + ZOUT0(0) = value * range + lo; + unit->m_value = value; + RPUT + } else { + ZOUT0(0) = unit->m_value * range + lo; + } + unit->m_trig = trig; } -void TGaussRand_next_a(TGaussRand* unit, int inNumSamples) -{ - float *trig = ZIN(2); - float prev = unit->m_trig; - float *out = ZOUT(0); - float value = unit->m_value; - float range, next; - - LOOP(inNumSamples, - next = ZXP(trig); - if (next > 0.f && prev <= 0.f) { - RGET - float lo=ZIN0(0); - float hi=ZIN0(1); - range = (hi - lo); - value = ((sqrt(-2*log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi)) + 1) * 0.5; - value=Mirroring(0.0, 1.0, value); - ZXP(out) = value * range + lo; - prev=next; - RPUT - } else { - range = (ZIN0(1) - ZIN0(0)); - ZXP(out) = value * range + ZIN0(0); - }; - prev = next; - ) - - unit->m_trig = next; - unit->m_value=value; +void TGaussRand_next_a(TGaussRand* unit, int inNumSamples) { + float* trig = ZIN(2); + float prev = unit->m_trig; + float* out = ZOUT(0); + float value = unit->m_value; + float range, next; + + LOOP( + inNumSamples, next = ZXP(trig); if (next > 0.f && prev <= 0.f) { + RGET float lo = ZIN0(0); + float hi = ZIN0(1); + range = (hi - lo); + value = ((sqrt(-2 * log(frand(s1, s2, s3))) * sin(frand(s1, s2, s3) * twopi)) + 1) * 0.5; + value = Mirroring(0.0, 1.0, value); + ZXP(out) = value * range + lo; + prev = next; + RPUT + } else { + range = (ZIN0(1) - ZIN0(0)); + ZXP(out) = value * range + ZIN0(0); + }; + prev = next;) + + unit->m_trig = next; + unit->m_value = value; } -void TGaussRand_Ctor(TGaussRand* unit) -{ - float lo = ZIN0(0); - float hi = ZIN0(1); - float range = (hi - lo); - RGen& rgen = *unit->mParent->mRGen; - unit->m_value = rgen.frand(); - ZOUT0(0) = unit->m_value * range + lo; - if(unit->mCalcRate == calc_FullRate){ SETCALC(TGaussRand_next_a); } else { SETCALC(TGaussRand_next_k); } - unit->m_trig = ZIN0(2); +void TGaussRand_Ctor(TGaussRand* unit) { + float lo = ZIN0(0); + float hi = ZIN0(1); + float range = (hi - lo); + RGen& rgen = *unit->mParent->mRGen; + unit->m_value = rgen.frand(); + ZOUT0(0) = unit->m_value * range + lo; + if (unit->mCalcRate == calc_FullRate) { + SETCALC(TGaussRand_next_a); + } else { + SETCALC(TGaussRand_next_k); + } + unit->m_trig = ZIN0(2); } -void TBetaRand_next_k(TBetaRand* unit, int inNumSamples) -{ - float trig = ZIN0(4); - float lo = ZIN0(0); - float hi = ZIN0(1); - float prob1 = 1/ZIN0(2); - float prob2 = 1/ZIN0(3); - float sum = 2.f; - float value = unit->m_value; - - if (trig > 0.f && unit->m_trig <= 0.f) { - RGET - while (sum > 1.f) { - value=pow(frand(s1, s2, s3), prob1); - sum=value + pow(frand(s1, s2, s3), prob2); - }; - if (sum == 0.f) { - ZOUT0(0) = unit->m_value = 0.f; - } else { - ZOUT0(0) = unit->m_value = (value/sum) * (hi-lo) + lo; - } - RPUT - } else { - ZOUT0(0) = unit->m_value; - } - unit->m_trig = trig; +void TBetaRand_next_k(TBetaRand* unit, int inNumSamples) { + float trig = ZIN0(4); + float lo = ZIN0(0); + float hi = ZIN0(1); + float prob1 = 1 / ZIN0(2); + float prob2 = 1 / ZIN0(3); + float sum = 2.f; + float value = unit->m_value; + + if (trig > 0.f && unit->m_trig <= 0.f) { + RGET while (sum > 1.f) { + value = pow(frand(s1, s2, s3), prob1); + sum = value + pow(frand(s1, s2, s3), prob2); + }; + if (sum == 0.f) { + ZOUT0(0) = unit->m_value = 0.f; + } else { + ZOUT0(0) = unit->m_value = (value / sum) * (hi - lo) + lo; + } + RPUT + } else { + ZOUT0(0) = unit->m_value; + } + unit->m_trig = trig; } -void TBetaRand_next_a(TBetaRand* unit, int inNumSamples) -{ - float *trig = ZIN(4); - float *prob1 = ZIN(2); - float *prob2 = ZIN(3); - float prev = unit->m_trig; - float *out = ZOUT(0); - float value = unit->m_value; - float sum = 2.f; - float next; - - LOOP(inNumSamples, - float invProb1 = 1/ZXP(prob1); - float invProb2 = 1/ZXP(prob2); - next = ZXP(trig); - if (next > 0.f && prev <= 0.f) { - RGET - while (sum > 1.f) { - value=pow(frand(s1, s2, s3), invProb1); - sum=value + pow(frand(s1, s2, s3), invProb2); - }; - float lo=ZIN0(0); - float hi=ZIN0(1); - if (sum == 0.f) { - ZXP(out) = value = 0.f; - } else { - ZXP(out) = value = (value/sum) * (hi - lo) + lo; - } - prev=next; - RPUT - } else { - ZXP(out) = value; - prev = next; - }; - ); - - unit->m_trig = next; - unit->m_value=value; +void TBetaRand_next_a(TBetaRand* unit, int inNumSamples) { + float* trig = ZIN(4); + float* prob1 = ZIN(2); + float* prob2 = ZIN(3); + float prev = unit->m_trig; + float* out = ZOUT(0); + float value = unit->m_value; + float sum = 2.f; + float next; + + LOOP( + inNumSamples, float invProb1 = 1 / ZXP(prob1); float invProb2 = 1 / ZXP(prob2); next = ZXP(trig); + if (next > 0.f && prev <= 0.f) { + RGET while (sum > 1.f) { + value = pow(frand(s1, s2, s3), invProb1); + sum = value + pow(frand(s1, s2, s3), invProb2); + }; + float lo = ZIN0(0); + float hi = ZIN0(1); + if (sum == 0.f) { + ZXP(out) = value = 0.f; + } else { + ZXP(out) = value = (value / sum) * (hi - lo) + lo; + } + prev = next; + RPUT + } else { + ZXP(out) = value; + prev = next; + };); + + unit->m_trig = next; + unit->m_value = value; } -void TBetaRand_Ctor(TBetaRand* unit) -{ - float lo = ZIN0(0); - float hi = ZIN0(1); - float prob1 = 1/ZIN0(2); - float prob2 = 1/ZIN0(3); - float sum = 2.f; - float value; - RGET - while (sum > 1.f) { - value=pow(frand(s1, s2, s3), prob1); - sum=value + pow(frand(s1, s2, s3), prob2); - }; - ZOUT0(0) = unit->m_value = (value/sum) * (hi-lo) + lo; - RPUT - if(unit->mCalcRate == calc_FullRate){ SETCALC(TBetaRand_next_a); } else { SETCALC(TBetaRand_next_k); } - unit->m_trig = ZIN0(4); +void TBetaRand_Ctor(TBetaRand* unit) { + float lo = ZIN0(0); + float hi = ZIN0(1); + float prob1 = 1 / ZIN0(2); + float prob2 = 1 / ZIN0(3); + float sum = 2.f; + float value; + RGET while (sum > 1.f) { + value = pow(frand(s1, s2, s3), prob1); + sum = value + pow(frand(s1, s2, s3), prob2); + }; + ZOUT0(0) = unit->m_value = (value / sum) * (hi - lo) + lo; + RPUT if (unit->mCalcRate == calc_FullRate) { SETCALC(TBetaRand_next_a); } + else { + SETCALC(TBetaRand_next_k); + } + unit->m_trig = ZIN0(4); } -void Gendy4_Ctor( Gendy4* unit ) { - - SETCALC(Gendy4_next_k); - unit->mPhase = 0; - unit->mAmp = 0.0; - unit->mNextAmp = 0.0; - unit->mSlope = 0.f; - unit->mMidpnt = 0.f; - - unit->mMemorySize= (int) ZIN0(8); //default is 12 - if(unit->mMemorySize<1) unit->mMemorySize=1; - unit->mIndex=0; - unit->mMemoryAmp= (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); - unit->mMemoryDur= (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); - - - RGen& rgen = *unit->mParent->mRGen; - - int i=0; - for(i=0; imMemorySize;++i) { - unit->mMemoryAmp[i]=2*rgen.frand() - 1.0; - unit->mMemoryDur[i]=rgen.frand(); - } +void Gendy4_Ctor(Gendy4* unit) { + SETCALC(Gendy4_next_k); + unit->mPhase = 0; + unit->mAmp = 0.0; + unit->mNextAmp = 0.0; + unit->mSlope = 0.f; + unit->mMidpnt = 0.f; + + unit->mMemorySize = (int)ZIN0(8); // default is 12 + if (unit->mMemorySize < 1) + unit->mMemorySize = 1; + unit->mIndex = 0; + unit->mMemoryAmp = (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); + unit->mMemoryDur = (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); + + + RGen& rgen = *unit->mParent->mRGen; + + int i = 0; + for (i = 0; i < unit->mMemorySize; ++i) { + unit->mMemoryAmp[i] = 2 * rgen.frand() - 1.0; + unit->mMemoryDur[i] = rgen.frand(); + } } -void Gendy4_Dtor(Gendy4 *unit) -{ - RTFree(unit->mWorld, unit->mMemoryAmp); - RTFree(unit->mWorld, unit->mMemoryDur); +void Gendy4_Dtor(Gendy4* unit) { + RTFree(unit->mWorld, unit->mMemoryAmp); + RTFree(unit->mWorld, unit->mMemoryDur); } -void Gendy4_next_k(Gendy4 *unit, int inNumSamples) { - - float *out = ZOUT(0); - - int whichamp= (int)ZIN0(0); - int whichdur= (int)ZIN0(1); - float aamp = ZIN0(2); - float adur = ZIN0(3); - float minfreq = ZIN0(4); - float maxfreq = ZIN0(5); - float scaleamp = ZIN0(6); - float scaledur = ZIN0(7); - - float rate=unit->mDur; - float slope=unit->mSlope; - float midpnt=unit->mMidpnt; - float curve=unit->mCurve; - - int32 phase = unit->mPhase; - - float amp=unit->mAmp; - float nextamp=unit->mNextAmp; - RGen& rgen = *unit->mParent->mRGen; - - int remain = inNumSamples; - do { - if (phase <= 0) { - - int index= unit->mIndex; - int num= (int)(ZIN0(9)); - if((num>(unit->mMemorySize)) || (num<1)) num=unit->mMemorySize; - index=(index+1)%num; - amp=nextamp; - unit->mIndex=index; - nextamp=(unit->mMemoryAmp[index])+(scaleamp*Gendyn_distribution(whichamp, aamp, rgen.frand())); - nextamp=Mirroring(-1.f, 1.f, nextamp); - float next_midpnt = (amp + nextamp) * 0.5; - unit->mMemoryAmp[index] = nextamp; - - rate=(unit->mMemoryDur[index])+(scaledur*Gendyn_distribution(whichdur, adur, rgen.frand())); - rate=Mirroring(0.0, 1.0, rate); - unit->mMemoryDur[index]=rate; - float fphase=(minfreq+((maxfreq-minfreq)*rate)) * num; - fphase=sc_max(fphase, 0.001f); - phase=(int32)(unit->mRate->mSampleRate/fphase); - phase=sc_max(2, phase); - curve = 2.f * (next_midpnt - midpnt - phase * slope) / (phase * phase + phase); - } - - int nsmps = sc_min(remain, phase); - remain -= nsmps; - phase -= nsmps; - LOOP(nsmps, - ZXP(out) = midpnt; - slope += curve; - midpnt += slope; - ); - } while (remain); - - unit->mPhase = phase; - unit->mAmp = amp; - unit->mNextAmp = nextamp; - unit->mMidpnt = midpnt; - unit->mDur = rate; - unit->mSlope = slope; - unit->mCurve = curve; +void Gendy4_next_k(Gendy4* unit, int inNumSamples) { + float* out = ZOUT(0); + + int whichamp = (int)ZIN0(0); + int whichdur = (int)ZIN0(1); + float aamp = ZIN0(2); + float adur = ZIN0(3); + float minfreq = ZIN0(4); + float maxfreq = ZIN0(5); + float scaleamp = ZIN0(6); + float scaledur = ZIN0(7); + + float rate = unit->mDur; + float slope = unit->mSlope; + float midpnt = unit->mMidpnt; + float curve = unit->mCurve; + + int32 phase = unit->mPhase; + + float amp = unit->mAmp; + float nextamp = unit->mNextAmp; + RGen& rgen = *unit->mParent->mRGen; + + int remain = inNumSamples; + do { + if (phase <= 0) { + int index = unit->mIndex; + int num = (int)(ZIN0(9)); + if ((num > (unit->mMemorySize)) || (num < 1)) + num = unit->mMemorySize; + index = (index + 1) % num; + amp = nextamp; + unit->mIndex = index; + nextamp = (unit->mMemoryAmp[index]) + (scaleamp * Gendyn_distribution(whichamp, aamp, rgen.frand())); + nextamp = Mirroring(-1.f, 1.f, nextamp); + float next_midpnt = (amp + nextamp) * 0.5; + unit->mMemoryAmp[index] = nextamp; + + rate = (unit->mMemoryDur[index]) + (scaledur * Gendyn_distribution(whichdur, adur, rgen.frand())); + rate = Mirroring(0.0, 1.0, rate); + unit->mMemoryDur[index] = rate; + float fphase = (minfreq + ((maxfreq - minfreq) * rate)) * num; + fphase = sc_max(fphase, 0.001f); + phase = (int32)(unit->mRate->mSampleRate / fphase); + phase = sc_max(2, phase); + curve = 2.f * (next_midpnt - midpnt - phase * slope) / (phase * phase + phase); + } + + int nsmps = sc_min(remain, phase); + remain -= nsmps; + phase -= nsmps; + LOOP(nsmps, ZXP(out) = midpnt; slope += curve; midpnt += slope;); + } while (remain); + + unit->mPhase = phase; + unit->mAmp = amp; + unit->mNextAmp = nextamp; + unit->mMidpnt = midpnt; + unit->mDur = rate; + unit->mSlope = slope; + unit->mCurve = curve; } -void Gendy5_Ctor( Gendy5* unit ) { - - SETCALC(Gendy5_next_k); - unit->mPhase = 1.f; - unit->mAmp = 0.0; +void Gendy5_Ctor(Gendy5* unit) { + SETCALC(Gendy5_next_k); + unit->mPhase = 1.f; + unit->mAmp = 0.0; - unit->mMemorySize= (int) ZIN0(8); - if(unit->mMemorySize<1) unit->mMemorySize=1; - unit->mIndex=0; - unit->mMemoryAmp= (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); - unit->mMemoryDur= (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); + unit->mMemorySize = (int)ZIN0(8); + if (unit->mMemorySize < 1) + unit->mMemorySize = 1; + unit->mIndex = 0; + unit->mMemoryAmp = (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); + unit->mMemoryDur = (float*)RTAlloc(unit->mWorld, unit->mMemorySize * sizeof(float)); - RGen& rgen = *unit->mParent->mRGen; + RGen& rgen = *unit->mParent->mRGen; - int i=0; - for(i=0; imMemorySize;++i) { - unit->mMemoryAmp[i]=2*rgen.frand() - 1.0; - unit->mMemoryDur[i]=rgen.frand(); - } + int i = 0; + for (i = 0; i < unit->mMemorySize; ++i) { + unit->mMemoryAmp[i] = 2 * rgen.frand() - 1.0; + unit->mMemoryDur[i] = rgen.frand(); + } } -void Gendy5_Dtor(Gendy5 *unit) -{ - RTFree(unit->mWorld, unit->mMemoryAmp); - RTFree(unit->mWorld, unit->mMemoryDur); +void Gendy5_Dtor(Gendy5* unit) { + RTFree(unit->mWorld, unit->mMemoryAmp); + RTFree(unit->mWorld, unit->mMemoryDur); } -void Gendy5_next_k(Gendy5 *unit, int inNumSamples) { - - float *out = ZOUT(0); - - int whichamp = (int)ZIN0(0); - int whichdur = (int)ZIN0(1); - float aamp = ZIN0(2); - float adur = ZIN0(3); - float minfreq = ZIN0(4); - float maxfreq = ZIN0(5); - float scaleamp = ZIN0(6); - float scaledur = ZIN0(7); - - float rate=unit->mDur; - - double phase = unit->mPhase; - float speed = unit->mSpeed; - - float amp=unit->mAmp; - RGen& rgen = *unit->mParent->mRGen; - - LOOP(inNumSamples, - if (phase >= 1.f) { - phase -= 1.f; - - int index=unit->mIndex; - int num=(int)(ZIN0(9)); - if((num>(unit->mMemorySize)) || (num<1)) num=unit->mMemorySize; - index=(index+1)%num; - unit->mIndex=index; - amp=(unit->mMemoryAmp[index])+(scaleamp*Gendyn_distribution(whichamp, aamp, rgen.frand())); - amp=Mirroring(-1.f, 1.f, amp); - unit->mMemoryAmp[index]= amp; - - rate=(unit->mMemoryDur[index])+(scaledur*Gendyn_distribution(whichdur, adur, rgen.frand())); - rate=Mirroring(0.0, 1.f, rate); - unit->mMemoryDur[index]= rate; - speed=(minfreq+((maxfreq-minfreq)*rate))*SAMPLEDUR*num; - } - - phase += speed; - ZXP(out) = amp; - ); - - unit->mPhase = phase; - unit->mSpeed = speed; - unit->mAmp = amp; - unit->mDur = rate; +void Gendy5_next_k(Gendy5* unit, int inNumSamples) { + float* out = ZOUT(0); + + int whichamp = (int)ZIN0(0); + int whichdur = (int)ZIN0(1); + float aamp = ZIN0(2); + float adur = ZIN0(3); + float minfreq = ZIN0(4); + float maxfreq = ZIN0(5); + float scaleamp = ZIN0(6); + float scaledur = ZIN0(7); + + float rate = unit->mDur; + + double phase = unit->mPhase; + float speed = unit->mSpeed; + + float amp = unit->mAmp; + RGen& rgen = *unit->mParent->mRGen; + + LOOP( + inNumSamples, + if (phase >= 1.f) { + phase -= 1.f; + + int index = unit->mIndex; + int num = (int)(ZIN0(9)); + if ((num > (unit->mMemorySize)) || (num < 1)) + num = unit->mMemorySize; + index = (index + 1) % num; + unit->mIndex = index; + amp = (unit->mMemoryAmp[index]) + (scaleamp * Gendyn_distribution(whichamp, aamp, rgen.frand())); + amp = Mirroring(-1.f, 1.f, amp); + unit->mMemoryAmp[index] = amp; + + rate = (unit->mMemoryDur[index]) + (scaledur * Gendyn_distribution(whichdur, adur, rgen.frand())); + rate = Mirroring(0.0, 1.f, rate); + unit->mMemoryDur[index] = rate; + speed = (minfreq + ((maxfreq - minfreq) * rate)) * SAMPLEDUR * num; + } + + phase += speed; + ZXP(out) = amp;); + + unit->mPhase = phase; + unit->mSpeed = speed; + unit->mAmp = amp; + unit->mDur = rate; } -PluginLoad(BhobNoise) -{ - ft = inTable; - - DefineSimpleUnit(GaussTrig); - DefineSimpleUnit(LFBrownNoise0); - DefineSimpleUnit(LFBrownNoise1); - DefineSimpleUnit(LFBrownNoise2); - DefineSimpleUnit(TBrownRand); - DefineSimpleUnit(Dbrown2); - // DefineSimpleUnit(Dbeta); - DefineSimpleUnit(Dgauss); - DefineSimpleUnit(TGaussRand); - DefineSimpleUnit(TBetaRand); - DefineDtorUnit(Gendy4); - DefineDtorUnit(Gendy5); +PluginLoad(BhobNoise) { + ft = inTable; + + DefineSimpleUnit(GaussTrig); + DefineSimpleUnit(LFBrownNoise0); + DefineSimpleUnit(LFBrownNoise1); + DefineSimpleUnit(LFBrownNoise2); + DefineSimpleUnit(TBrownRand); + DefineSimpleUnit(Dbrown2); + // DefineSimpleUnit(Dbeta); + DefineSimpleUnit(Dgauss); + DefineSimpleUnit(TGaussRand); + DefineSimpleUnit(TBetaRand); + DefineDtorUnit(Gendy4); + DefineDtorUnit(Gendy5); } //////////////////////////////////////////////////////////////////// From 0af7775144dc54e5b4928bd9d926ebecaa58a0ed Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Tue, 7 Apr 2020 23:02:06 +0200 Subject: [PATCH 2/9] BhobGrain: Const correctness, bracket cleanup Fix some bracket-less conditionals. Make all obvious stack variable const - this should make logic flow at least a little clearer, in these huge functions where things are declared and then modified 100 lines later... No functonal change. # Conflicts: # source/BhobUGens/BhobGrain.cpp --- source/BhobUGens/BhobGrain.cpp | 249 +++++++++++++++++---------------- 1 file changed, 126 insertions(+), 123 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 512d9db3c3..4772cd6fae 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -89,22 +89,25 @@ inline double sc_gloop(double in, double hi) { // avoid the divide if possible if (in >= hi) { in -= hi; - if (in < hi) + if (in < hi) { return in; + } } else if (in < 0.) { in += hi; - if (in >= 0.) + if (in >= 0.) { return in; - } else + } + } else { return in; + } return in - hi * floor(in / hi); } #define GRAIN_AMP_2 \ - double amp; \ - double attPhase = grain->attPhase; \ - double decPhase = grain->decPhase; \ + double amp; \ + const auto attPhase = grain->attPhase; \ + const auto decPhase = grain->decPhase; \ if (counter > grain->decCount) { \ amp = attPhase; \ if (attPhase < 1.f) { \ @@ -132,12 +135,12 @@ inline double sc_gloop(double in, double hi) { table3 -= bufSamples; \ } \ } \ - float fracphase = phase - (double)iphase; \ - float a = table0[0]; \ - float b = table1[0]; \ - float c = table2[0]; \ - float d = table3[0]; \ - float outval = amp * cubicinterp(fracphase, a, b, c, d); \ + const float fracphase = phase - (double)iphase; \ + const float a = table0[0]; \ + const float b = table1[0]; \ + const float c = table2[0]; \ + const float d = table3[0]; \ + const float outval = amp * cubicinterp(fracphase, a, b, c, d); \ ZXP(out1) += outval * pan1; \ ZXP(out2) += outval * pan2; \ counter--; @@ -150,10 +153,10 @@ inline double sc_gloop(double in, double hi) { if (iphase > guardFrame) { \ table2 -= bufSamples; \ } \ - float fracphase = phase - (double)iphase; \ - float b = table1[0]; \ - float c = table2[0]; \ - float outval = amp * (b + fracphase * (c - b)); \ + const float fracphase = phase - (double)iphase; \ + const float b = table1[0]; \ + const float c = table2[0]; \ + const float outval = amp * (b + fracphase * (c - b)); \ ZXP(out1) += outval * pan1; \ ZXP(out2) += outval * pan2; \ counter--; @@ -167,23 +170,24 @@ inline double sc_gloop(double in, double hi) { counter--; -void TGrains2_next(TGrains2* unit, int inNumSamples) { - float* trigin = IN(0); +void TGrains2_next(TGrains2* unit, const int inNumSamples) { + const float* trigin = IN(0); float prevtrig = unit->mPrevTrig; - uint32 numOutputs = unit->mNumOutputs; + const uint32 numOutputs = unit->mNumOutputs; ClearUnitOutputs(unit, inNumSamples); float* out[16]; - for (uint32 i = 0; i < numOutputs; ++i) + for (auto i = 0; i < numOutputs; ++i) { out[i] = ZOUT(i); + } - World* world = unit->mWorld; + const World* world = unit->mWorld; SndBuf* bufs = world->mSndBufs; - uint32 numBufs = world->mNumSndBufs; + const uint32 numBufs = world->mNumSndBufs; - for (int i = 0; i < unit->mNumActive;) { + for (auto i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; + const uint32 bufnum = grain->bufnum; GRAIN_BUF @@ -192,37 +196,35 @@ void TGrains2_next(TGrains2* unit, int inNumSamples) { continue; } - double loopMax = (double)bufFrames; + const double loopMax = (double)bufFrames; - float pan1 = grain->pan1; - float pan2 = grain->pan2; - double rate = grain->rate; + const float pan1 = grain->pan1; + const float pan2 = grain->pan2; + const double rate = grain->rate; double phase = grain->phase; int counter = grain->counter; - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) - chan2 = 0; + const uint32 chan1 = grain->chan; + const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; float* out1 = out[chan1]; float* out2 = out[chan2]; - int nsmps = sc_min(grain->counter, inNumSamples); + const int nsmps = sc_min(grain->counter, inNumSamples); if (grain->interp >= 4) { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_2; GRAIN2_LOOP_BODY_4; phase += rate; } } else if (grain->interp >= 2) { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_2; GRAIN2_LOOP_BODY_2; phase += rate; } } else { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_2; GRAIN2_LOOP_BODY_1; phase += rate; @@ -235,50 +237,52 @@ void TGrains2_next(TGrains2* unit, int inNumSamples) { if (grain->counter <= 0) { // remove grain *grain = unit->mGrains[--unit->mNumActive]; - } else + } else { ++i; + } } - int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; + const int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; - for (int i = 0; i < trigSamples; ++i) { - float trig = trigin[i]; + for (auto i = 0; i < trigSamples; ++i) { + const float trig = trigin[i]; if (trig > 0.f && prevtrig <= 0.f) { // start a grain - if (unit->mNumActive + 1 >= kMaxGrains) + if (unit->mNumActive + 1 >= kMaxGrains) { break; - uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) + } + const uint32 bufnum = (uint32)IN_AT(unit, 1, i); + if (bufnum >= numBufs) { continue; + } GRAIN_BUF if (bufChannels != 1) continue; - float bufSampleRate = buf->samplerate; - float bufRateScale = bufSampleRate * SAMPLEDUR; - double loopMax = (double)bufFrames; + const float bufSampleRate = buf->samplerate; + const float bufRateScale = bufSampleRate * SAMPLEDUR; + const double loopMax = (double)bufFrames; Grain2* grain = unit->mGrains + unit->mNumActive++; grain->bufnum = bufnum; - double dur = IN_AT(unit, 4, i); - double counter = floor(dur * SAMPLERATE); - counter = sc_max(4., counter); + const double dur = IN_AT(unit, 4, i); + double counter = sc_max(4.0, floor(dur * SAMPLERATE)); - double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; - double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; + const double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; + const double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; double phase = centerPhase - 0.5 * counter * rate; float pan = IN_AT(unit, 5, i); - float amp = IN_AT(unit, 6, i); + const float amp = IN_AT(unit, 6, i); double att = sc_max((double)IN_AT(unit, 7, i), SAMPLEDUR); double dec = IN_AT(unit, 8, i); if ((att + dec) > dur) { - double sum = att + dec; - double norm = dur / sum; + const auto sum = att + dec; + const auto norm = dur / sum; att *= norm; dec *= norm; } @@ -288,17 +292,17 @@ void TGrains2_next(TGrains2* unit, int inNumSamples) { float panangle; float pan1, pan2; if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); float cpan = numOutputs * pan + 0.5f; - float ipan = floor(cpan); - float panfrac = cpan - ipan; + float ipan = floor(cpan); + float panfrac = cpan - ipan; panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) - grain->chan -= numOutputs; - } else { - grain->chan = 0; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) + grain->chan -= numOutputs; + } else { + grain->chan = 0; pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); panangle = pan * pi2_f; } @@ -309,23 +313,21 @@ void TGrains2_next(TGrains2* unit, int inNumSamples) { pan1 = grain->pan1 = 1.; pan2 = grain->pan2 = 0.; } - int attCount = sc_max((int)(SAMPLERATE * att), 2); - int decCount = sc_max((int)(SAMPLERATE * dec), 2); + const int attCount = sc_max((int)(SAMPLERATE * att), 2); + const int decCount = sc_max((int)(SAMPLERATE * dec), 2); grain->attIncr = 1.0 / attCount; grain->decIncr = 1.0 / decCount; grain->decCount = decCount; grain->attPhase = 0.f; grain->decPhase = 1.f; - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) - chan2 = 0; + const uint32 chan1 = grain->chan; + const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; float* out1 = out[chan1] + i; float* out2 = out[chan2] + i; - int nsmps = sc_min(grain->counter, inNumSamples - i); + const int nsmps = sc_min(grain->counter, inNumSamples - i); if (grain->interp >= 4) { for (int j = 0; j < nsmps; ++j) { GRAIN_AMP_2; @@ -371,8 +373,8 @@ void TGrains2_Ctor(TGrains2* unit) { #define GRAIN_AMP_3 \ float amp; \ - int i_attPhase = (int)grain->attPhase; \ - int i_decPhase = (int)grain->decPhase; \ + const int i_attPhase = (int)grain->attPhase; \ + const int i_decPhase = (int)grain->decPhase; \ if (counter > grain->decCount) { \ amp = window[sc_min(i_attPhase, windowSize)]; \ if (i_attPhase < windowSize) { \ @@ -387,21 +389,22 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { float* trigin = IN(0); float prevtrig = unit->mPrevTrig; float* window = unit->mWindow; - int windowSize = unit->mWindowSize; + const int windowSize = unit->mWindowSize; - uint32 numOutputs = unit->mNumOutputs; + const uint32 numOutputs = unit->mNumOutputs; ClearUnitOutputs(unit, inNumSamples); float* out[16]; - for (uint32 i = 0; i < numOutputs; ++i) + for (uint32 i = 0; i < numOutputs; ++i) { out[i] = ZOUT(i); + } - World* world = unit->mWorld; + const World* world = unit->mWorld; SndBuf* bufs = world->mSndBufs; - uint32 numBufs = world->mNumSndBufs; + const uint32 numBufs = world->mNumSndBufs; for (int i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; + const uint32 bufnum = grain->bufnum; GRAIN_BUF @@ -410,38 +413,36 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { continue; } - double loopMax = (double)bufFrames; + const double loopMax = (double)bufFrames; - float pan1 = grain->pan1; - float pan2 = grain->pan2; - double rate = grain->rate; + const float pan1 = grain->pan1; + const float pan2 = grain->pan2; + const double rate = grain->rate; double phase = grain->phase; int counter = grain->counter; - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) - chan2 = 0; + const uint32 chan1 = grain->chan; + const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; float* out1 = out[chan1]; float* out2 = out[chan2]; // printf("B chan %d %d %08X %08X", chan1, chan2, out1, out2); - int nsmps = sc_min(grain->counter, inNumSamples); + const int nsmps = sc_min(grain->counter, inNumSamples); if (grain->interp >= 4) { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_3; GRAIN2_LOOP_BODY_4; phase += rate; } } else if (grain->interp >= 2) { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_3; GRAIN2_LOOP_BODY_2; phase += rate; } } else { - for (int j = 0; j < nsmps; ++j) { + for (auto j = 0; j < nsmps; ++j) { GRAIN_AMP_3; GRAIN2_LOOP_BODY_1; phase += rate; @@ -458,46 +459,49 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { ++i; } - int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; + const int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; for (int i = 0; i < trigSamples; ++i) { - float trig = trigin[i]; + const float trig = trigin[i]; if (trig > 0.f && prevtrig <= 0.f) { // start a grain - if (unit->mNumActive + 1 >= kMaxGrains) + if (unit->mNumActive + 1 >= kMaxGrains) { break; + } uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) + if (bufnum >= numBufs) { continue; + } GRAIN_BUF - if (bufChannels != 1) + if (bufChannels != 1) { continue; + } - float bufSampleRate = buf->samplerate; - float bufRateScale = bufSampleRate * SAMPLEDUR; - double loopMax = (double)bufFrames; + const float bufSampleRate = buf->samplerate; + const float bufRateScale = bufSampleRate * SAMPLEDUR; + const double loopMax = (double)bufFrames; Grain2* grain = unit->mGrains + unit->mNumActive++; grain->bufnum = bufnum; - double dur = IN_AT(unit, 4, i); + const double dur = IN_AT(unit, 4, i); double counter = floor(dur * SAMPLERATE); counter = sc_max(4., counter); - double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; - double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; + const double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; + const double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; double phase = centerPhase - 0.5 * counter * rate; float pan = IN_AT(unit, 5, i); - float amp = IN_AT(unit, 6, i); + const float amp = IN_AT(unit, 6, i); double att = IN_AT(unit, 7, i); double dec = IN_AT(unit, 8, i); if ((att + dec) > dur) { - double sum = att + dec; - double norm = dur / sum; + const double sum = att + dec; + const double norm = dur / sum; att *= norm; dec *= norm; } @@ -507,17 +511,18 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { float panangle; float pan1, pan2; if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); - float cpan = numOutputs * pan + 0.5f; - float ipan = floor(cpan); - float panfrac = cpan - ipan; - panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) - grain->chan -= numOutputs; - } else { - grain->chan = 0; + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + const float cpan = numOutputs * pan + 0.5f; + const float ipan = floor(cpan); + const float panfrac = cpan - ipan; + panangle = panfrac * pi2_f; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) { + grain->chan -= numOutputs; + } + } else { + grain->chan = 0; pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); panangle = pan * pi2_f; } @@ -528,23 +533,21 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { pan1 = grain->pan1 = 1.; pan2 = grain->pan2 = 0.; } - int attCount = sc_max((int)(SAMPLERATE * att), 2); - int decCount = sc_max((int)(SAMPLERATE * dec), 2); + const int attCount = sc_max((int)(SAMPLERATE * att), 2); + const int decCount = sc_max((int)(SAMPLERATE * dec), 2); grain->attIncr = (float)windowSize / attCount; grain->decIncr = (float)windowSize / decCount; grain->decCount = decCount; grain->attPhase = 0.f; grain->decPhase = (float)windowSize; - uint32 chan1 = grain->chan; - uint32 chan2 = chan1 + 1; - if (chan2 >= numOutputs) - chan2 = 0; + const uint32 chan1 = grain->chan; + const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; float* out1 = out[chan1] + i; float* out2 = out[chan2] + i; - int nsmps = sc_min(grain->counter, inNumSamples - i); + const int nsmps = sc_min(grain->counter, inNumSamples - i); if (grain->interp >= 4) { for (int j = 0; j < nsmps; ++j) { GRAIN_AMP_3; @@ -584,7 +587,7 @@ void TGrains3_Ctor(TGrains3* unit) { unit->mNumActive = 0; unit->mPrevTrig = 0.; - SndBuf* window = unit->mWorld->mSndBufs + (int)IN0(9); + const SndBuf* window = unit->mWorld->mSndBufs + (int)IN0(9); unit->mWindow = window->data; unit->mWindowSize = window->samples - 1; From 13c5c57966a4c0b57ef228db2d491795abd88a3a Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Thu, 9 Apr 2020 18:58:13 +0200 Subject: [PATCH 3/9] Re-arrange _next calls for TGrains2/3 to properly support output aliasing TGrains* did not properly support audio rate triggers, because they are configured to support aliasing input and output buffers. HOWEVER: in the implementation, triggers were calculated AFTER audio was processed - this resulted in the audio actually overwriting the trigger input in alias cases. Aside from this, we had two separate inner-loop grain functions - one in the trigger code for "new" grain, and the other in the loop processing existing grains - the extra inner-loop is removed, and we simply process new grains with the rest, and offset their write position according to their start point as stored in grain->startDelay. --- source/BhobUGens/BhobGrain.cpp | 303 ++++++++++++++------------------- 1 file changed, 128 insertions(+), 175 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 4772cd6fae..16c57c9d97 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -29,7 +29,7 @@ struct Grain2 { double phase, rate, attPhase, decPhase; double attIncr, decIncr; float pan1, pan2; - int counter, decCount; + int startDelay, counter, decCount; int bufnum; int chan; int interp; @@ -173,75 +173,13 @@ inline double sc_gloop(double in, double hi) { void TGrains2_next(TGrains2* unit, const int inNumSamples) { const float* trigin = IN(0); float prevtrig = unit->mPrevTrig; - const uint32 numOutputs = unit->mNumOutputs; - ClearUnitOutputs(unit, inNumSamples); - float* out[16]; - for (auto i = 0; i < numOutputs; ++i) { - out[i] = ZOUT(i); - } const World* world = unit->mWorld; SndBuf* bufs = world->mSndBufs; const uint32 numBufs = world->mNumSndBufs; - for (auto i = 0; i < unit->mNumActive;) { - Grain2* grain = unit->mGrains + i; - const uint32 bufnum = grain->bufnum; - - GRAIN_BUF - - if (bufChannels != 1) { - ++i; - continue; - } - - const double loopMax = (double)bufFrames; - - const float pan1 = grain->pan1; - const float pan2 = grain->pan2; - const double rate = grain->rate; - double phase = grain->phase; - int counter = grain->counter; - - const uint32 chan1 = grain->chan; - const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; - - float* out1 = out[chan1]; - float* out2 = out[chan2]; - - const int nsmps = sc_min(grain->counter, inNumSamples); - if (grain->interp >= 4) { - for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_4; - phase += rate; - } - } else if (grain->interp >= 2) { - for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_2; - phase += rate; - } - } else { - for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_1; - phase += rate; - } - } - - grain->phase = phase; - - grain->counter = counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } else { - ++i; - } - } - + // PROCESS TRIGGERS const int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; for (auto i = 0; i < trigSamples; ++i) { @@ -270,7 +208,6 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { const double dur = IN_AT(unit, 4, i); double counter = sc_max(4.0, floor(dur * SAMPLERATE)); - const double rate = grain->rate = IN_AT(unit, 2, i) * bufRateScale; const double centerPhase = IN_AT(unit, 3, i) * bufSampleRate; double phase = centerPhase - 0.5 * counter * rate; @@ -320,89 +257,23 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { grain->decCount = decCount; grain->attPhase = 0.f; grain->decPhase = 1.f; - - const uint32 chan1 = grain->chan; - const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; - - float* out1 = out[chan1] + i; - float* out2 = out[chan2] + i; - - const int nsmps = sc_min(grain->counter, inNumSamples - i); - if (grain->interp >= 4) { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_4; - phase += rate; - } - } else if (grain->interp >= 2) { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_2; - phase += rate; - } - } else { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_2; - GRAIN2_LOOP_BODY_1; - phase += rate; - } - } - grain->phase = phase; - grain->counter = (int)counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; - } + grain->startDelay = i; } prevtrig = trig; } - unit->mPrevTrig = prevtrig; -} - -void TGrains2_Ctor(TGrains2* unit) { - SETCALC(TGrains2_next); - - unit->mNumActive = 0; - unit->mPrevTrig = 0.; - - ClearUnitOutputs(unit, 1); -} - -#define GRAIN_AMP_3 \ - float amp; \ - const int i_attPhase = (int)grain->attPhase; \ - const int i_decPhase = (int)grain->decPhase; \ - if (counter > grain->decCount) { \ - amp = window[sc_min(i_attPhase, windowSize)]; \ - if (i_attPhase < windowSize) { \ - grain->attPhase += grain->attIncr; \ - } \ - } else { \ - amp = window[sc_max(i_decPhase, 0)]; \ - grain->decPhase -= grain->decIncr; \ - } -void TGrains3_next(TGrains3* unit, int inNumSamples) { - float* trigin = IN(0); - float prevtrig = unit->mPrevTrig; - float* window = unit->mWindow; - const int windowSize = unit->mWindowSize; - - const uint32 numOutputs = unit->mNumOutputs; + // SETUP OUTPUTS ClearUnitOutputs(unit, inNumSamples); float* out[16]; - for (uint32 i = 0; i < numOutputs; ++i) { + for (auto i = 0; i < numOutputs; ++i) { out[i] = ZOUT(i); } - const World* world = unit->mWorld; - SndBuf* bufs = world->mSndBufs; - const uint32 numBufs = world->mNumSndBufs; - - for (int i = 0; i < unit->mNumActive;) { + // PROCESS GRAINS + for (auto i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; const uint32 bufnum = grain->bufnum; @@ -426,39 +297,81 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { float* out1 = out[chan1]; float* out2 = out[chan2]; - // printf("B chan %d %d %08X %08X", chan1, chan2, out1, out2); - const int nsmps = sc_min(grain->counter, inNumSamples); + int nsmps = sc_min(grain->counter, inNumSamples); + if (grain->startDelay > 0) { + nsmps -= grain->startDelay; + out1 += grain->startDelay; + out2 += grain->startDelay; + grain->startDelay = 0; + } + if (grain->interp >= 4) { for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; + GRAIN_AMP_2; GRAIN2_LOOP_BODY_4; phase += rate; } } else if (grain->interp >= 2) { for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; + GRAIN_AMP_2; GRAIN2_LOOP_BODY_2; phase += rate; } } else { for (auto j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; + GRAIN_AMP_2; GRAIN2_LOOP_BODY_1; phase += rate; } } grain->phase = phase; - grain->counter = counter; if (grain->counter <= 0) { // remove grain *grain = unit->mGrains[--unit->mNumActive]; - } else + } else { ++i; + } } +} + +void TGrains2_Ctor(TGrains2* unit) { + SETCALC(TGrains2_next); + + unit->mNumActive = 0; + unit->mPrevTrig = 0.; + + ClearUnitOutputs(unit, 1); +} +#define GRAIN_AMP_3 \ + float amp; \ + const int i_attPhase = (int)grain->attPhase; \ + const int i_decPhase = (int)grain->decPhase; \ + if (counter > grain->decCount) { \ + amp = window[sc_min(i_attPhase, windowSize)]; \ + if (i_attPhase < windowSize) { \ + grain->attPhase += grain->attIncr; \ + } \ + } else { \ + amp = window[sc_max(i_decPhase, 0)]; \ + grain->decPhase -= grain->decIncr; \ + } + +void TGrains3_next(TGrains3* unit, int inNumSamples) { + float* trigin = IN(0); + float prevtrig = unit->mPrevTrig; + float* window = unit->mWindow; + const int windowSize = unit->mWindowSize; + const uint32 numOutputs = unit->mNumOutputs; + + const World* world = unit->mWorld; + SndBuf* bufs = world->mSndBufs; + const uint32 numBufs = world->mNumSndBufs; + + // PROCESS TRIGGERS const int trigSamples = INRATE(0) == calc_FullRate ? inNumSamples : 1; for (int i = 0; i < trigSamples; ++i) { @@ -540,46 +453,86 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { grain->decCount = decCount; grain->attPhase = 0.f; grain->decPhase = (float)windowSize; + grain->phase = phase; + grain->counter = (int)counter; + grain->startDelay = i; + } + prevtrig = trig; + } + unit->mPrevTrig = prevtrig; - const uint32 chan1 = grain->chan; - const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; + // SETUP OUTPUTS + ClearUnitOutputs(unit, inNumSamples); + float* out[16]; + for (uint32 i = 0; i < numOutputs; ++i) { + out[i] = ZOUT(i); + } - float* out1 = out[chan1] + i; - float* out2 = out[chan2] + i; + // PROCESS GRAINS + for (int i = 0; i < unit->mNumActive;) { + Grain2* grain = unit->mGrains + i; + const uint32 bufnum = grain->bufnum; - const int nsmps = sc_min(grain->counter, inNumSamples - i); - if (grain->interp >= 4) { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; - GRAIN2_LOOP_BODY_4; - phase += rate; - } - } else if (grain->interp >= 2) { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; - GRAIN2_LOOP_BODY_2; - phase += rate; - } - } else { - for (int j = 0; j < nsmps; ++j) { - GRAIN_AMP_3; - GRAIN2_LOOP_BODY_1; - phase += rate; - } - } + GRAIN_BUF - grain->phase = phase; + if (bufChannels != 1) { + ++i; + continue; + } - grain->counter = (int)counter; - if (grain->counter <= 0) { - // remove grain - *grain = unit->mGrains[--unit->mNumActive]; + const double loopMax = (double)bufFrames; + + const float pan1 = grain->pan1; + const float pan2 = grain->pan2; + const double rate = grain->rate; + double phase = grain->phase; + int counter = grain->counter; + + const uint32 chan1 = grain->chan; + const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; + + float* out1 = out[chan1]; + float* out2 = out[chan2]; + // printf("B chan %d %d %08X %08X", chan1, chan2, out1, out2); + + int nsmps = sc_min(grain->counter, inNumSamples); + if (grain->startDelay > 0) { + nsmps -= grain->startDelay; + out1 += grain->startDelay; + out2 += grain->startDelay; + grain->startDelay = 0; + } + + if (grain->interp >= 4) { + for (auto j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_4; + phase += rate; + } + } else if (grain->interp >= 2) { + for (auto j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_2; + phase += rate; + } + } else { + for (auto j = 0; j < nsmps; ++j) { + GRAIN_AMP_3; + GRAIN2_LOOP_BODY_1; + phase += rate; } } - prevtrig = trig; - } - unit->mPrevTrig = prevtrig; + grain->phase = phase; + + grain->counter = counter; + if (grain->counter <= 0) { + // remove grain + *grain = unit->mGrains[--unit->mNumActive]; + } else { + ++i; + } + } } void TGrains3_Ctor(TGrains3* unit) { From 4910786501192950ac9ecf355cd998b044317d95 Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 15:27:57 +0200 Subject: [PATCH 4/9] Fix logic for second channel This should wrap channels - broke during refactor. --- source/BhobUGens/BhobGrain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 16c57c9d97..964316aabd 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -293,7 +293,7 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { int counter = grain->counter; const uint32 chan1 = grain->chan; - const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; + const uint32 chan2 = (chan1 + 1) % numOutputs; float* out1 = out[chan1]; float* out2 = out[chan2]; @@ -489,7 +489,7 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { int counter = grain->counter; const uint32 chan1 = grain->chan; - const uint32 chan2 = (chan2 >= numOutputs) ? 0 : chan1 + 1; + const uint32 chan2 = (chan1 + 1) % numOutputs; float* out1 = out[chan1]; float* out2 = out[chan2]; From dcc595e5a9a51e21ae76e67aaa40925bd701e025 Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 20:05:16 +0200 Subject: [PATCH 5/9] Const correctness for buffer read macros --- source/BhobUGens/BhobGrain.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 964316aabd..a4edb630f2 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -121,10 +121,10 @@ inline double sc_gloop(double in, double hi) { #define GRAIN2_LOOP_BODY_4 \ phase = sc_gloop(phase, loopMax); \ int32 iphase = (int32)phase; \ - float* table1 = bufData + iphase; \ - float* table0 = table1 - 1; \ - float* table2 = table1 + 1; \ - float* table3 = table1 + 2; \ + const float* table1 = bufData + iphase; \ + const float* table0 = table1 - 1; \ + const float* table2 = table1 + 1; \ + const float* table3 = table1 + 2; \ if (iphase == 0) { \ table0 += bufSamples; \ } else if (iphase >= guardFrame) { \ @@ -148,8 +148,8 @@ inline double sc_gloop(double in, double hi) { #define GRAIN2_LOOP_BODY_2 \ phase = sc_gloop(phase, loopMax); \ int32 iphase = (int32)phase; \ - float* table1 = bufData + iphase; \ - float* table2 = table1 + 1; \ + const float* table1 = bufData + iphase; \ +const float* table2 = table1 + 1; \ if (iphase > guardFrame) { \ table2 -= bufSamples; \ } \ From ee4ed565809a82e29a0435e1a63ef911cee51afb Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 20:06:44 +0200 Subject: [PATCH 6/9] Fix buffer lookup to include localbufs --- source/BhobUGens/BhobGrain.cpp | 64 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index a4edb630f2..1394babb69 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -169,6 +169,24 @@ const float* table2 = table1 + 1; ZXP(out2) += outval * pan2; \ counter--; +const SndBuf* findBuf(uint32_t& bufnum, const World* world, const Graph* parent) +{ + const SndBuf* buf; + + if (bufnum >= world->mNumSndBufs) { + int localBufNum = bufnum - world->mNumSndBufs; + if (localBufNum <= parent->localBufNum) { + buf = parent->mLocalSndBufs + localBufNum; + } else { + bufnum = 0; + buf = world->mSndBufs + bufnum; + } + } else { + buf = world->mSndBufs + bufnum; + } + + return buf; +}; void TGrains2_next(TGrains2* unit, const int inNumSamples) { const float* trigin = IN(0); @@ -190,11 +208,12 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { if (unit->mNumActive + 1 >= kMaxGrains) { break; } - const uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) { - continue; - } - GRAIN_BUF + uint32_t bufnum = (uint32_t )IN_AT(unit, 1, i); + const SndBuf* buf = findBuf(bufnum, world, unit->mParent); + const float* bufData = buf->data; + const uint32_t bufChannels = buf->channels; + const uint32_t bufSamples = buf->samples; + const uint32_t bufFrames = buf->frames; if (bufChannels != 1) continue; @@ -275,15 +294,21 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { // PROCESS GRAINS for (auto i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - const uint32 bufnum = grain->bufnum; - - GRAIN_BUF + uint32 bufnum = grain->bufnum; + const SndBuf* buf = findBuf(bufnum, world, unit->mParent); + const float* bufData = buf->data; + const uint32 bufChannels = buf->channels; + const uint32 bufSamples = buf->samples; + const uint32 bufFrames = buf->frames; + const int guardFrame = bufFrames - 2; if (bufChannels != 1) { ++i; continue; } + LOCK_SNDBUF_SHARED(buf); + const double loopMax = (double)bufFrames; const float pan1 = grain->pan1; @@ -382,11 +407,12 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { if (unit->mNumActive + 1 >= kMaxGrains) { break; } - uint32 bufnum = (uint32)IN_AT(unit, 1, i); - if (bufnum >= numBufs) { - continue; - } - GRAIN_BUF + uint32_t bufnum = (uint32_t )IN_AT(unit, 1, i); + const SndBuf* buf = findBuf(bufnum, world, unit->mParent); + const float* bufData = buf->data; + const uint32_t bufChannels = buf->channels; + const uint32_t bufSamples = buf->samples; + const uint32_t bufFrames = buf->frames; if (bufChannels != 1) { continue; @@ -471,15 +497,21 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { // PROCESS GRAINS for (int i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - const uint32 bufnum = grain->bufnum; - - GRAIN_BUF + uint32 bufnum = grain->bufnum; + const SndBuf* buf = findBuf(bufnum, world, unit->mParent); + const float* bufData = buf->data; + const uint32 bufChannels = buf->channels; + const uint32 bufSamples = buf->samples; + const uint32 bufFrames = buf->frames; + const int guardFrame = bufFrames - 2; if (bufChannels != 1) { ++i; continue; } + LOCK_SNDBUF_SHARED(buf); + const double loopMax = (double)bufFrames; const float pan1 = grain->pan1; From 8fe6d1d7134a07f8b4fbbfa219c65816bf1934cf Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 20:11:07 +0200 Subject: [PATCH 7/9] Formatting --- source/BhobUGens/BhobGrain.cpp | 67 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 1394babb69..2222af2aec 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -105,7 +105,7 @@ inline double sc_gloop(double in, double hi) { } #define GRAIN_AMP_2 \ - double amp; \ + double amp; \ const auto attPhase = grain->attPhase; \ const auto decPhase = grain->decPhase; \ if (counter > grain->decCount) { \ @@ -121,10 +121,10 @@ inline double sc_gloop(double in, double hi) { #define GRAIN2_LOOP_BODY_4 \ phase = sc_gloop(phase, loopMax); \ int32 iphase = (int32)phase; \ - const float* table1 = bufData + iphase; \ - const float* table0 = table1 - 1; \ - const float* table2 = table1 + 1; \ - const float* table3 = table1 + 2; \ + const float* table1 = bufData + iphase; \ + const float* table0 = table1 - 1; \ + const float* table2 = table1 + 1; \ + const float* table3 = table1 + 2; \ if (iphase == 0) { \ table0 += bufSamples; \ } else if (iphase >= guardFrame) { \ @@ -148,8 +148,8 @@ inline double sc_gloop(double in, double hi) { #define GRAIN2_LOOP_BODY_2 \ phase = sc_gloop(phase, loopMax); \ int32 iphase = (int32)phase; \ - const float* table1 = bufData + iphase; \ -const float* table2 = table1 + 1; \ + const float* table1 = bufData + iphase; \ + const float* table2 = table1 + 1; \ if (iphase > guardFrame) { \ table2 -= bufSamples; \ } \ @@ -169,8 +169,7 @@ const float* table2 = table1 + 1; ZXP(out2) += outval * pan2; \ counter--; -const SndBuf* findBuf(uint32_t& bufnum, const World* world, const Graph* parent) -{ +const SndBuf* findBuf(uint32_t& bufnum, const World* world, const Graph* parent) { const SndBuf* buf; if (bufnum >= world->mNumSndBufs) { @@ -208,7 +207,7 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { if (unit->mNumActive + 1 >= kMaxGrains) { break; } - uint32_t bufnum = (uint32_t )IN_AT(unit, 1, i); + uint32_t bufnum = (uint32_t)IN_AT(unit, 1, i); const SndBuf* buf = findBuf(bufnum, world, unit->mParent); const float* bufData = buf->data; const uint32_t bufChannels = buf->channels; @@ -248,17 +247,17 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { float panangle; float pan1, pan2; if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); float cpan = numOutputs * pan + 0.5f; - float ipan = floor(cpan); - float panfrac = cpan - ipan; + float ipan = floor(cpan); + float panfrac = cpan - ipan; panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) - grain->chan -= numOutputs; - } else { - grain->chan = 0; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) + grain->chan -= numOutputs; + } else { + grain->chan = 0; pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); panangle = pan * pi2_f; } @@ -373,8 +372,8 @@ void TGrains2_Ctor(TGrains2* unit) { #define GRAIN_AMP_3 \ float amp; \ - const int i_attPhase = (int)grain->attPhase; \ - const int i_decPhase = (int)grain->decPhase; \ + const int i_attPhase = (int)grain->attPhase; \ + const int i_decPhase = (int)grain->decPhase; \ if (counter > grain->decCount) { \ amp = window[sc_min(i_attPhase, windowSize)]; \ if (i_attPhase < windowSize) { \ @@ -407,7 +406,7 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { if (unit->mNumActive + 1 >= kMaxGrains) { break; } - uint32_t bufnum = (uint32_t )IN_AT(unit, 1, i); + uint32_t bufnum = (uint32_t)IN_AT(unit, 1, i); const SndBuf* buf = findBuf(bufnum, world, unit->mParent); const float* bufData = buf->data; const uint32_t bufChannels = buf->channels; @@ -450,18 +449,18 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { float panangle; float pan1, pan2; if (numOutputs > 1) { - if (numOutputs > 2) { - pan = sc_wrap(pan * 0.5f, 0.f, 1.f); - const float cpan = numOutputs * pan + 0.5f; - const float ipan = floor(cpan); - const float panfrac = cpan - ipan; - panangle = panfrac * pi2_f; - grain->chan = (int)ipan; - if (grain->chan >= (int)numOutputs) { - grain->chan -= numOutputs; - } - } else { - grain->chan = 0; + if (numOutputs > 2) { + pan = sc_wrap(pan * 0.5f, 0.f, 1.f); + const float cpan = numOutputs * pan + 0.5f; + const float ipan = floor(cpan); + const float panfrac = cpan - ipan; + panangle = panfrac * pi2_f; + grain->chan = (int)ipan; + if (grain->chan >= (int)numOutputs) { + grain->chan -= numOutputs; + } + } else { + grain->chan = 0; pan = sc_clip(pan * 0.5f + 0.5f, 0.f, 1.f); panangle = pan * pi2_f; } From 059e6c0232b86630bc7890e34785fa643bd72744 Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 20:24:17 +0200 Subject: [PATCH 8/9] Only perform buffer lookup if the buffer has changed since the last loop. --- source/BhobUGens/BhobGrain.cpp | 61 ++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 2222af2aec..345c1d5ecf 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -70,6 +70,9 @@ static float cubicinterp(float x, float y0, float y1, float y2, float y3) return ((c3 * x + c2) * x + c1) * x + c0; } */ + +constexpr auto NO_BUFFER = -1e9f; + #define GRAIN_BUF \ SndBuf* buf = bufs + bufnum; \ float* bufData __attribute__((__unused__)) = buf->data; \ @@ -291,17 +294,28 @@ void TGrains2_next(TGrains2* unit, const int inNumSamples) { } // PROCESS GRAINS + const SndBuf* buf = nullptr; + uint32 bufnum = NO_BUFFER; + const float* bufData; + uint32 bufChannels = 0; + uint32 bufSamples; + uint32 bufFrames; + int guardFrame; + for (auto i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; - const SndBuf* buf = findBuf(bufnum, world, unit->mParent); - const float* bufData = buf->data; - const uint32 bufChannels = buf->channels; - const uint32 bufSamples = buf->samples; - const uint32 bufFrames = buf->frames; - const int guardFrame = bufFrames - 2; - - if (bufChannels != 1) { + + if (bufnum != grain->bufnum) { + bufnum = grain->bufnum; + buf = findBuf(bufnum, world, unit->mParent); + bufData = buf->data; + bufChannels = buf->channels; + bufSamples = buf->samples; + bufFrames = buf->frames; + guardFrame = bufFrames - 2; + } + + if (bufChannels != 1 || !buf) { ++i; continue; } @@ -494,17 +508,28 @@ void TGrains3_next(TGrains3* unit, int inNumSamples) { } // PROCESS GRAINS + const SndBuf* buf = nullptr; + uint32 bufnum = NO_BUFFER; + const float* bufData; + uint32 bufChannels = 0; + uint32 bufSamples; + uint32 bufFrames; + int guardFrame; + for (int i = 0; i < unit->mNumActive;) { Grain2* grain = unit->mGrains + i; - uint32 bufnum = grain->bufnum; - const SndBuf* buf = findBuf(bufnum, world, unit->mParent); - const float* bufData = buf->data; - const uint32 bufChannels = buf->channels; - const uint32 bufSamples = buf->samples; - const uint32 bufFrames = buf->frames; - const int guardFrame = bufFrames - 2; - - if (bufChannels != 1) { + + if (bufnum != grain->bufnum) { + bufnum = grain->bufnum; + buf = findBuf(bufnum, world, unit->mParent); + bufData = buf->data; + bufChannels = buf->channels; + bufSamples = buf->samples; + bufFrames = buf->frames; + guardFrame = bufFrames - 2; + } + + if (bufChannels != 1 || !buf) { ++i; continue; } From 29360e0053a27f8c07b58f2dfe7be840b878debc Mon Sep 17 00:00:00 2001 From: Scott Carver Date: Fri, 10 Apr 2020 22:19:11 +0200 Subject: [PATCH 9/9] Explicitly inline findBuf. --- source/BhobUGens/BhobGrain.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/BhobUGens/BhobGrain.cpp b/source/BhobUGens/BhobGrain.cpp index 345c1d5ecf..c092e79c89 100644 --- a/source/BhobUGens/BhobGrain.cpp +++ b/source/BhobUGens/BhobGrain.cpp @@ -172,22 +172,18 @@ inline double sc_gloop(double in, double hi) { ZXP(out2) += outval * pan2; \ counter--; -const SndBuf* findBuf(uint32_t& bufnum, const World* world, const Graph* parent) { - const SndBuf* buf; - +inline const SndBuf* findBuf(uint32_t& bufnum, const World* world, const Graph* parent) { if (bufnum >= world->mNumSndBufs) { int localBufNum = bufnum - world->mNumSndBufs; if (localBufNum <= parent->localBufNum) { - buf = parent->mLocalSndBufs + localBufNum; + return parent->mLocalSndBufs + localBufNum; } else { bufnum = 0; - buf = world->mSndBufs + bufnum; + return world->mSndBufs + bufnum; } } else { - buf = world->mSndBufs + bufnum; + return world->mSndBufs + bufnum; } - - return buf; }; void TGrains2_next(TGrains2* unit, const int inNumSamples) {