hello,
-- put custom code or variables here
function example(s)
local y = sin(SAMPLECOUNTER/SRATE * 2*PI*s)
return (y + 1) / 2
end
The Init code of Formula Device…What is ‘s’ variable? …A ‘NAN’?
hello,
-- put custom code or variables here
function example(s)
local y = sin(SAMPLECOUNTER/SRATE * 2*PI*s)
return (y + 1) / 2
end
The Init code of Formula Device…What is ‘s’ variable? …A ‘NAN’?
It’s an input parameter to the function example
.
In the y =
row of the Formula you can call the function with a parameter like
y = example(B)
where B
will get subsituted for s
inside the function.
In the case of your example, the B
slider will control the rate of the oscillation.
If you call it without anything like example()
then s
will be NAN
which means “not a number” and you’ll get an error.
Ok…Strange but OK
Thank you👍
Having parameters (or arguments) like this is a common idea in programming to help you separate implementation from usage. Doing it this way means you don’t have to go through the source and find all occurences of some variable to be able to finetune the output of the function and you can reuse it with different parameters.
That said, I guess s
should be renamed to freq
here to be more self-explanatory, especially since this is an example meant to demonstrate.
When coding on formula,I will take the habits to not rename the inputs…
I will renamed the inputs when code is complete and working
Backend then Frontend