Thanks to you and Josh for explaining. I’m basically just in the process of learning how Faust works and you both helped me a lot.
B. > On 9 Aug 2019, at 15:12, Kjetil Matheussen <k.s.matheus...@gmail.com> wrote: > > On Fri, Aug 9, 2019 at 2:49 PM Japina <bost...@japina.eu > <mailto:bost...@japina.eu>> wrote: >> >> I still can’t understand how the programming works in Faust in relation to >> samples. Just for me to understand it I wanted to create a script that >> changes output value at certain time. >> I know that such function already exists, but I would like to understand how >> code works in relation to time :) >> >> The idea is every 100 samples change output from 1 to -1 and back (so square >> signal). The code I’ve came up to is: >> >> out_value = 1.0; >> val = ba.if(ma.modulo(ba.time, 100) == 0, -out_value, out_value); >> process = val; >> >> But what I get is just one sample with negative value and not additional 100 >> samples. >> So I guess my assumptions about how Faust is working are wrong, but I just >> can’t get the idea how to do it. >> >> Any suggestions? >> > > It seems like ma.modulo doesn't do what you want. > This faust code: > > process = ma.modulo(ba.time,100.0); > > generates this c++ code: > > for (int i = 0; (i < count); i = (i + 1)) { > iRec0[0] = (iRec0[1] + 1); > output0[i] = FAUSTFLOAT(std::fmod((std::fmod(float((iRec0[0] + > -1)), 100.0f) + 100.0f), 100.0f)); > iRec0[1] = iRec0[0]; > } > > (I don't know what happens here) > > I guess you want to use % instead of ma.modulo: > > process = ba.time % 100.0; > > > But if I follow your thoughts correctly, it also seems like you need > to create a state. So that if state==-1, you return -1, and if > state==1, you return 1. In Faust, you can create a state by using the > recursive operator ~. > (https://faust.grame.fr/doc/manual/index.html#recursive-composition > <https://faust.grame.fr/doc/manual/index.html#recursive-composition>) > > For this specific task, though, I would simply do it like this instead: > val = ba.if((ba.time%200) < 100, -out_value, out_value); > But maybe this isn't good enough for what you really want to achieve?
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Faudiostream-users mailing list Faudiostream-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/faudiostream-users