Possibly not a big deal, but the reason why ba.pulse checks for the
derivative is that ba.period is likely to wrap around and end up at value
different than zero when you lower the period, which can result in missed
pulses.

See this example:

import("stdfaust.lib");
period(p) = %(int(p)) ~ +(1) : mem;
pulse2(p) = period(p) : \(x).(x <= x');
pulse(p) = period(p) == 0;
process = 100 - (10 @ 90) - (10 @ 170) - (10 @ 240) <: period , pulse*100 ,
pulse2*100;

Dr Dario Sanfilippo
http://dariosanfilippo.com


On Sat, 25 Nov 2023 at 16:23, Oleg Nesterov <o...@redhat.com> wrote:

> Stephane,
>
> I am shy to disturb https://github.com/grame-cncm/faustlibraries with
> such a trivial/random change(s), but I'd like to "finish" the recent
> discussion on discord. Note that even ba.time is obviously suboptimal.
> I can make a PR if you think this makes any sense.
>
> - ba.time: eliminate -(1)
>
>   before:
>         iRec0[0] = iRec0[1] + 1;
>         output0[i0] = FAUSTFLOAT(iRec0[0] + -1);
>         iRec0[1] = iRec0[0];
>   after:
>         iRec0[0] = iRec0[1] + 1;
>         output0[i0] = FAUSTFLOAT(iRec0[1]);
>         iRec0[1] = iRec0[0];
>
> - ba.period: eliminate the delay line created by 1'
>   with p == 10
>
>   before:
>         iVec0[0] = 1;
>         iRec0[0] = (iVec0[1] + iRec0[1]) % 10;
>         output0[i0] = FAUSTFLOAT(iRec0[0]);
>         iVec0[1] = iVec0[0];
>         iRec0[1] = iRec0[0];
>   after:
>         iRec0[0] = (iRec0[1] + 1) % 10;
>         output0[i0] = FAUSTFLOAT(iRec0[1]);
>         iRec0[1] = iRec0[0];
>
>   this change is not 100% compatible when p modulates,
>   but I don't think this can break something.
>
> - ba.pulse: simplify the condition, obvious.
> ---
>  basics.lib | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/basics.lib b/basics.lib
> index 6c1fc87..ed3e9c5 100644
> --- a/basics.lib
> +++ b/basics.lib
> @@ -448,7 +448,7 @@ sweep = %(int(*:max(1)))~+(1);
>  // time : _
>  // ```
>  //------------------------
> -time = (+(1)~_) - 1;
> +time = +(1)~_ : mem;
>
>
>  //-------`(ba.)ramp`----------
> @@ -525,7 +525,7 @@ tempo(t) = (60*ma.SR)/t;
>  // * `p`: period as a number of samples
>  //------------------------
>  // NOTE: may be this should go in oscillators.lib
> -period(p) = %(int(p))~+(1');
> +period(p) = %(int(p)) ~ +(1) : mem;
>
>
>  //-------`(ba.)pulse`----------
> @@ -542,7 +542,7 @@ period(p) = %(int(p))~+(1');
>  // * `p`: period as a number of samples
>  //------------------------
>  // NOTE: may be this should go in oscillators.lib
> -pulse(p) = period(p) : \(x).(x <= x');
> +pulse(p) = period(p) == 0;
>
>
>  //-------`(ba.)pulsen`----------
> --
> 2.25.1.362.g51ebf55
>
>
>
>
> _______________________________________________
> Faudiostream-users mailing list
> Faudiostream-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>
_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to