grame-cncm / faustlibraries

The Faust libraries
https://faustlibraries.grame.fr
183 stars 59 forks source link

add mi.repeat #164

Closed DBraun closed 9 months ago

DBraun commented 9 months ago

This idea is only a minor adjustment from the Exemple d'evaluation page here: https://github.com/orlarey/presentation-compilateur-faust/blob/master/slides.pdf

The most basic code is

repeat(1,f) = f;
repeat(1,f) = f <: _, repeat(n-1,f) :> _;
N = 3;
FX = mem;
process = repeat(N,FX);

but I have adapted it to work for f of arbitrary size.

repeat(1, FX) = FX;
repeat(n, FX) = FX <: si.bus(N), repeat(n-1, FX) :> si.bus(N)
with {
    N = outputs(FX);
};

and then put this more advanced example in the faustlibraries docs

N = 4;
C = 2;
fx(i) = i+1, par(j, C, @(i*5000));
process = 0, si.bus(C) : repeat(N, fx) : !, par(i, C, _*.2/N);

The 0 is passed to each fx and incremented along the way, allowing fx to act with awareness of its index.

Try it in the IDE.

sletz commented 9 months ago

Thanks !