Paccumbounce : Paccum


An accumulator -- repeatedly performs a binary operation on the previous stream value and the result of a second stream. Each output value becomes the input value for the next calculation.


Where Pseries adds a constant value on successive iterations, here the second operand is variable.


Paccumbounce differs from Paccum in that the value reflects or "bounces" back from the (lo, hi) boundary. Once the boundary is hit, the step values will be negated so that the value will move in the opposite direction.



*new(lo = -inf, hi = inf, step, length = inf, start)


lo = minimum output value; values lower than this are .fold-ed back in range

hi = maximum output value

step = pattern for the second operand

length = number of values to output

start = starting value; if not given, the stream will start with rrand(lo, hi)



Examples:


This stream should "stagger" in a positive direction until it crashes into the upper boundary, then stagger in a negative direction until turning around again at the lower boundary.


p = Paccumbounce(-1.0, 1.0, Pwhite(-0.05, 0.1, inf), inf).asStream;

r = fork { loop { p.next.postln; 0.1.wait } };


r.stop;


p.reset;

p.nextN(200).plot;