OK fine,

Note that using min/max based guard can be a better alternative than using «  
ba.if ».

You can read the "Does select2 behaves as a standard C/C++ like if ? » in the 
FAQ:  
https://github.com/grame-cncm/faustdoc/blob/master/mkdocs/docs/manual/faq.md  
and especially the last section.

HTH,

Stéphane 

> Le 22 déc. 2020 à 15:22, Daniele Pagliero <daniele.pagli...@gmail.com> a 
> écrit :
> 
> Thak-you Stéphane,
> 
> I've read the recursion paragraph many times! :-D
> 
> By the way, it was my code that was buggy, because I had a division by zero 
> error...very noob fault!
> 
> Here is my working version, checking before that loopSize is bigger than zero:
> 
>     readIndex = ba.if(loopSize>0, ((_~+(1) : %(loopSize)) : int) , 0)
> 
> and this is the final version with speed and loop length:
> 
>     import("stdfaust.lib");
> 
>     sampleRate = 48000;
>     maxTime = 1;
>     maxSamples = sampleRate * maxTime;
> 
>     btn = button("[5]trigger");
>     readSpeed = hslider("[3]read_speed", 1, -3, 3, 0.1) : si.smoo;
>     loopLength = hslider("[4]loop_length", 1, 0, 1, 0.01);
> 
>     loopSize = ba.sAndH(btn, fi.pole(btn, btn)) : int : 
> hbargraph("[0]loop_size", 0, maxSamples);
>     readIndex = ba.if((loopSize * loopLength)>0, ((_~+(1 * readSpeed) : 
> %(loopSize * loopLength)) : int) , 0) : hbargraph("        [1]read_index", 0, 
> maxSamples);
>     recIndex = (+(1) : %(maxSamples)) ~ *(btn) : int : 
> hbargraph("[2]rec_index", 0, maxSamples);
> 
>     looper = rwtable(maxSamples,0.0,recIndex,_,readIndex);
> 
>     process = looper <: _,_;
> 
> It needs more work to become usable but in my journey to understand faust 
> pattern language it covered a lot of topics.
> 
> Thanks a lot!
> 
> Daniele
> 
> On 22/12/20 14:53, Stéphane Letz wrote:
>> 
>>> Le 22 déc. 2020 à 14:29, Daniele Pagliero <daniele.pagli...@gmail.com> a 
>>> écrit :
>>> 
>>> this statement is clear:
>>> 
>>>     recIndex = (+(1) : %(maxSamples)) ~ *(btn)
>>> 
>>> and I can translate it in something like:
>>> 
>>>     recIndex = ((recIndex + 1) %  maxSamples) * btn
>> No, you cannot write the second version with «  recIndex »  appearing on 
>> both sides.
>> 
>> I suggest you read again the documentation of the recursive operator:
>> 
>> https://faustdoc.grame.fr/manual/syntax/#recursive-composition
>> 
>> And possibly this workshop that implements a phasor using a recursion:  
>> https://faustdoc.grame.fr/workshops/2018-12-01-paw/ ?
>> 
>> Stéphane



_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to