From 6acc2541dc63f382acb2d316c562982b82914b0c Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 9 Jan 2009 22:52:35 +0000 Subject: [PATCH] added XCut ugen --- RFWUGens.scx | Bin 19216 -> 19188 bytes classes/RFW-UGens.sc | 2 +- src/rfw-ugens.cpp | 67 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/RFWUGens.scx b/RFWUGens.scx index 15e2ac4c3038321bd7a601828bea23289f52aace..4718b74f493b219060450017233b80d16d0142ed 100755 GIT binary patch delta 2992 zcmai04^W&(72ogU!*Jy8zPp2iw$5p z#?<6z>?Pzh4Lap4S*nF1WvjfL3muBPWb*23yPp43=ReEuy4`wjbM*V@#9Y{HQO3TE z{XEAR;RlLeGDCm1Cwn)_;lXKThvJ(GsWGf1`2sPn660Kw&nIFzx)xh& z94>*E%`yAlwc5@Sa9cLXt`gX83CKkyaLD48-wMMC3zs1bf3$pFt_;H#Yn%1&Axw@E zw&KKdzY4+A*3I&<5KLM>Cbx&ctZtS)A*fgDs z%`5+A1Eg$E$wvdQ-yVu<^Et-C+mbvd87lq6eHZP+TuP?d-^8iqz%5=t#Aw47UL z(d5n?y|>Mb`DBTP>NQd=I*mkQ47&@_CQ7~DyC;B5TQW|AMlQbEm-+2Xysgc*{#QU4 zQ%i!sgr4fzXzVyo8S^(L_!|ajN^pwOAWaycI>9d+pfgd~A3|))iSBGGlOj z#;{isoQ+@L#%zBJOBj!lg4Kl$CHN~z{z?rWJG?K+=WvWHK9k8!E1z0Y?R*~1B7zT{ zM)=T73+Tw_m(<;a?0h-NmnqUXbyFieB_;VA365*Hb)FT?EV{9t?i4%xu+AsaIa>Dw zJKT}v6SreNd%Dyw4lSvF8Pa>l*E80omh*uwwTures;wDmQMG+)K<_<(R)nZ48(&mA z#^MOhEvoJ4Z0F}G#>-1;8zDQNx~^hiSgVWZL~EGR`CJ;aG*`pT>WQ(N=`@yEJ5-F&B9W390MiIyCSLN%KdauyrQ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Qyr`4z+xl$5}A^v_hR=bK>a;7t59 zbPIeNih_TDrzGY$bbci;{yn@pW3Ngq3Uf(f9e7M)QKTypCxEX>EQ&cPaT550d33E{?gZwx`GvOwmq{$D?4t4Y4LvGCYGRCqv1>nY3fKcILhX?FF5qs7zYF}R z#ChO;iMP8^cZoj%eoo?-aLoT!;*xaE~b4i(oW}DA+lPMGK5eENcJ0#G>e*NGw`YMf-}mqU|+_McW07xR(`cDtS@< tMqrrZ&e(d+=-qUma+4k~o<<^B@{!@c8*{wuq5TKC_a4d)Uu&!4{{n3Fxw-%V diff --git a/classes/RFW-UGens.sc b/classes/RFW-UGens.sc index 351885e..55bab9b 100644 --- a/classes/RFW-UGens.sc +++ b/classes/RFW-UGens.sc @@ -20,4 +20,4 @@ XCut : UGen { *ar { arg inArray, which=0.0, envLength=2000; ^this.multiNewList(['audio', which, envLength, inArray.size] ++ inArray.asArray); } -} \ No newline at end of file +} diff --git a/src/rfw-ugens.cpp b/src/rfw-ugens.cpp index afa827d..382a928 100644 --- a/src/rfw-ugens.cpp +++ b/src/rfw-ugens.cpp @@ -47,8 +47,10 @@ struct AverageOutput : public Unit { }; struct XCut : public Unit { - float prev_trig; - uint32 envlen; + float offset_start, offset_current; + int numInputs, envlen, current; + uint32 offset_timer; + char crossfading; }; extern "C" { @@ -65,9 +67,13 @@ extern "C" { } void XCut_Ctor(XCut *unit) { - printf("Hello world, num inputs is %d\n", (int)ZIN0(2)); - - //unit->envlen = (uint32)ZIN0(1); + unit->envlen = (int)ZIN0(1); + unit->offset_timer = unit->envlen; + unit->numInputs = (int)ZIN0(2); + unit->offset_start = 0.; + unit->offset_current = 0.; + unit->crossfading = 0; + unit->current = 0; SETCALC(XCut_next); } @@ -75,6 +81,57 @@ void XCut_Ctor(XCut *unit) { void XCut_next(XCut *unit, int inNumSamples) { RGen& tgen = *unit->mParent->mRGen; + int requested, numInputs; + float ratio; + + char crossfading = unit->crossfading; + int envlen = unit->envlen; + int current = unit->current; + uint32 offset_timer = unit->offset_timer; + float offset_start = unit->offset_start; + float offset_current = unit->offset_current; + float *in = IN(3 + current); + float *out = OUT(0); + + for(int i=0; i < inNumSamples; ++i) { + requested = (int)ZIN0(0); + if(requested != current) { // switch + float oldval, newval, offset; + oldval = in[i] + offset_current; + current = requested; + in = IN(3 + current); + newval = in[i]; + + offset = oldval - newval; + offset_start = offset; + offset_current = offset; + + //printf("oldval was %f, newval is %f, offset is %f\n",oldval,newval,offset); + crossfading = 1; + offset_timer = envlen; + } + + //printf("applying offset of %f to %f\n",offset_current,in[i]); + out[i] = in[i] + offset_current; + + if(crossfading) { + --offset_timer; + + if(offset_timer > 0) { + ratio = (offset_timer / ENVLEN); + offset_current = offset_start * ratio; + } else { + crossfading = 0; + offset_current = 0.; + } + } + } + + unit->crossfading = crossfading; + unit->offset_timer = offset_timer; + unit->offset_start = offset_start; + unit->offset_current = offset_current; + unit->current = current; } void XCut_Dtor(XCut *unit) {