From 2dc791906e4f2a7a7e76ec298908d3ce5c5f60fd Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Mon, 16 Sep 2019 16:16:36 +0100 Subject: [PATCH] clamped thresholds in nb_of_slices --- release-packaging/ignore/Examples/nb_of_slices.scd | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/release-packaging/ignore/Examples/nb_of_slices.scd b/release-packaging/ignore/Examples/nb_of_slices.scd index 7f6bc5e..be136bc 100644 --- a/release-packaging/ignore/Examples/nb_of_slices.scd +++ b/release-packaging/ignore/Examples/nb_of_slices.scd @@ -7,8 +7,8 @@ c = Buffer.new(s); // with basic params Routine{ var startTime, goal, startThresh, prevThresh, curThresh, curVal, prevVal, iters, maxIters, dVal, dThresh; - startTime = Main.elapsedTime; - prevThresh = 0.1; //initial threshold + startTime = Main.elapsedTime; + prevThresh = 0.1; //initial threshold (between 0.00001 and 0.99999 goal = 10; //number of slices desired maxIters = 100; //max number of iterations acceptable @@ -17,9 +17,9 @@ Routine{ s.sync; //makes a second iteration if ( (prevVal < goal), { - curThresh = prevThresh * 0.5; + curThresh = (prevThresh * 0.5).max(0.000001); }, { - curThresh = prevThresh * 2; + curThresh = (prevThresh * 2).min(0.999999); }); FluidBufNoveltySlice.process(s,b, indices: c, threshold:curThresh,action:{|x|curVal = x.numFrames}); s.sync; @@ -38,10 +38,10 @@ Routine{ if ( (dVal == 0), { //if we have not change results between the last 2 passes, make the variation of threshold bigger - curThresh = dThresh + curThresh; + curThresh = (dThresh + curThresh).min(0.999999).max(0.000001); },{ //if we have - curThresh = ((dThresh / dVal) * (goal - curVal)) + curThresh; + curThresh = (((dThresh / dVal) * (goal - curVal)) + curThresh).min(0.999999).max(0.000001); }); FluidBufNoveltySlice.process(s,b, indices: c, threshold:curThresh,action:{|x|curVal = x.numFrames}); s.sync; @@ -58,4 +58,4 @@ Routine{ } ); }.play -) \ No newline at end of file +)