Oh, you don't have any inputs. I thought you had, before
posting too quickly.

I guess it works if you somehow sends the output of the
previous call to rand2() into the next, but I don't see
immediately how to do that elegantly...



On Fri, Apr 25, 2014 at 6:41 PM, Kjetil Matheussen <[email protected]
> wrote:

> Perhaps something like this:
>
>
> rand(x) = fn(x) / RAND_MAX
> with {
>   fn = ffunction(int rand2(float), <math.h>, "");
>   RAND_MAX = fconstant(int RAND_MAX, <math.h>);
> };
>
> process = rand, rand, rand, rand;
>
>
> where "rand2" looks like this:
> static int rand2(float val){return rand();}
>
>
>
> On Fri, Apr 25, 2014 at 6:33 PM, Timo Westkämper <
> [email protected]> wrote:
>
>> Hi Yann.
>>
>> Thanks for the explanation. It appears I misinterpreted the documentation
>> then. I thought because parameterless functions have special treatment they
>> are considered functions with side effects, but it appears they are
>> something like pure functions in the scope of a single sample.
>>
>> What workaround do you suggest?
>>
>> Br,
>> Timo
>>
>>
>> On Fri, Apr 25, 2014 at 7:21 PM, Orlarey Yann <[email protected]> wrote:
>>
>>>  Hi Timo,
>>>
>>> The current behavior of the compiler is correct. Faust expressions have
>>> a precise and purely "functional" semantics. This is why, no matter how
>>> many time you repeat the foreign C function ffunction(int rand(),
>>> <math.h>, ""),  it will *always* produce the same output signal. Let me
>>> try to explain why.
>>>
>>> A Faust expression denotes a function (in the mathematical sens, not in
>>> the C sens) that maps a (possibly empty) group of input signals to a
>>> (possibly empty) group of output signals. For example the Faust primitive +
>>> maps a pair of signals (x,y) to a single signal (z) such that z(n) =
>>> x(n)+y(n). The Faust primitive ! maps any single signal (x) to the empty
>>> group of signals (). A Faust expression with no inputs, for example the
>>> Faust number 3, is also a function. The Faust number 3 maps the empty group
>>> of signals () to the single signal (z) such that z(n) = 3. Being a
>>> mathematical function means that with the same input will *always* produce
>>> the same output : (x,y)=(u,v) => f(x,y)=f(u,v). Therefore any function that
>>> maps the empty group of signals () to some group of output signals, will
>>> *always* produce the same group of output signals: ()=() => f() = f(). This
>>> is why ffunction(int rand(), <math.h>, "") always produces the same
>>> output signal, no matter how many time it is repeated.
>>>
>>> The property of Faust expressions being mathematical functions is
>>> crucial for the Faust compiler and the optimizations it can perform. If a
>>> function f is applied several times to the same group of input signals,
>>> there is no need to recompute it, because it will always produce the same
>>> group of output signals. Moreover for any f that maps the empty group
>>> of signals () to a single signal (z), you have expected properties like f+f
>>> = 2*f, and f-f = 0, etc. no matter how complex f is. For example :   par(i,
>>> 10, ffunction(int rand(), <math.h>, "")) :> _  is equal to
>>> 10*ffunction(int rand(), <math.h>, "") and ffunction(int rand(), <math.h>,
>>> "") - ffunction(int rand(), <math.h>, "") is equal to 0.
>>>
>>> Cheers
>>>
>>> Yann
>>>
>>>
>>>
>>>
>>> Le 25/04/2014 08:14, Timo Westkämper a écrit :
>>>
>>>  I'd prefer a real fix to this issue. Piping signals into rand is also
>>> tricky because they also need to be unique otherwise pure function
>>> invocations are optimized.
>>>
>>> Having just pure functions and functions with side effects would be
>>> easier.
>>>
>>>
>>>
>>> On Fri, Apr 25, 2014 at 12:15 AM, Julius Smith 
>>> <[email protected]>wrote:
>>>
>>>>  Well it IS being called at the sampling rate, but it's apparently
>>>> assumed to have the same value/side-effects at any given time instant.
>>>> Therefore, it's called only once per sample no matter how many places it is
>>>> used in the block diagram.
>>>>
>>>> It should work to give your rand function a signal argument (that it
>>>> ignores) and pass different signals through different instances:
>>>>
>>>>   ...
>>>>   fn = ffunction(int rand(float), <math.h>, "")/RAND_MAX;
>>>>   process = fn,fn,fn,fn;
>>>>
>>>> I suppose this is a bit of a hack, making the faust2firefox
>>>> block-diagrams unnecessarily messy.
>>>>
>>>> - Julius
>>>>
>>>>
>>>> At 01:31 PM 4/24/2014, Timo Westkämper wrote:
>>>>
>>>> Hi.
>>>>
>>>>  Based on the Faust documentation it should be treated as a function
>>>> with side effects:
>>>>
>>>> "Foreign functions with input parameters are considered pure math
>>>> functions. They are therefore considered free of side effects and called
>>>> only when their parameters change (that is at the rate of the fastest
>>>> parameter).
>>>>  Exceptions are functions with no input parameters. A typical example
>>>> is the CÂ
>>>>
>>>> rand()Â function. In this case the compiler generate code to call the
>>>> function at sample rate."
>>>>
>>>>
>>>> http://faust.grame.fr/index.php/documentation/references/12-documentation/reference/48-faust-syntax-reference-art#tth_sEc3.4.5
>>>>
>>>> So it looks like it shouldn't be optimized as it is now. While it is
>>>> called at sample rate, the parallel execution is not treated correctly.
>>>>
>>>> Timo
>>>>
>>>> On Thu, Apr 24, 2014 at 11:23 PM, Julius Smith <[email protected]> 
>>>> wrote:
>>>>   Maybe it should be possible declare "volatile" foreign functions
>>>> that are not optimized in this way?
>>>>
>>>>
>>>>   At 03:26 AM 4/24/2014, Timo Westkämper wrote:
>>>>
>>>> Hi.
>>>>
>>>>  Could I get a clarification concerning parameterless functions?
>>>>
>>>>  I tried this code
>>>>
>>>>  // stateless random generator
>>>>  rand = fn / RAND_MAX
>>>>  with {
>>>>    fn = ffunction(int rand(), <math.h>, "");
>>>>    RAND_MAX = fconstant(int RAND_MAX, <math.h>);
>>>>
>>>>  };
>>>>
>>>>  process = rand, rand, rand, rand;
>>>>
>>>>
>>>>   and got the following result
>>>>
>>>>      virtual void compute (int count, FAUSTFLOAT** input,
>>>> FAUSTFLOAT** output) {
>>>>
>>>>
>>>>   FAUSTFLOAT* output0 = output[0];
>>>>  FAUSTFLOAT* output1 = output[1];
>>>>  FAUSTFLOAT* output2 = output[2];
>>>>  FAUSTFLOAT* output3 = output[3];
>>>>  for (int i=0; i<count; i++) {
>>>>  float fTemp0 = (float(rand()) / float(RAND_MAX));
>>>>  output0[i] = (FAUSTFLOAT)fTemp0;
>>>>  output1[i] = (FAUSTFLOAT)fTemp0;
>>>>  output2[i] = (FAUSTFLOAT)fTemp0;
>>>>  output3[i] = (FAUSTFLOAT)fTemp0;
>>>>  }
>>>>  }
>>>>
>>>>  I expected four random numbers in parallel.
>>>>
>>>>  What is the right way to call rand() from Faust?
>>>>
>>>>  Br,
>>>>  Timo
>>>>
>>>> ------------------------------------------------------------------------------
>>>>  Start Your Social Network Today - Download eXo Platform
>>>>  Build your Enterprise Intranet with eXo Platform Software
>>>>  Java Based Open Source Intranet - Social, Extensible, Cloud Ready
>>>>  Get Started Now And Turn Your Intranet Into A Collaboration Platform
>>>>  http://p.sf.net/sfu/ExoPlatform
>>>>  _______________________________________________
>>>>  Faudiostream-users mailing list
>>>>  [email protected]
>>>>   https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>>>
>>>>
>>>>
>>>> Julius O. Smith III <[email protected] >
>>>>  Professor of Music and, by courtesy, Electrical Engineering
>>>>  CCRMA, Stanford University
>>>>  http://ccrma.stanford.edu/~jos/
>>>>
>>>>
>>>> Julius O. Smith III <[email protected]>
>>>> Professor of Music and, by courtesy, Electrical Engineering
>>>> CCRMA, Stanford University
>>>>  http://ccrma.stanford.edu/~jos/
>>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Start Your Social Network Today - Download eXo Platform
>>> Build your Enterprise Intranet with eXo Platform Software
>>> Java Based Open Source Intranet - Social, Extensible, Cloud Ready
>>> Get Started Now And Turn Your Intranet Into A Collaboration 
>>> Platformhttp://p.sf.net/sfu/ExoPlatform
>>>
>>>
>>>
>>> _______________________________________________
>>> Faudiostream-users mailing 
>>> [email protected]https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>>
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Start Your Social Network Today - Download eXo Platform
>> Build your Enterprise Intranet with eXo Platform Software
>> Java Based Open Source Intranet - Social, Extensible, Cloud Ready
>> Get Started Now And Turn Your Intranet Into A Collaboration Platform
>> http://p.sf.net/sfu/ExoPlatform
>> _______________________________________________
>> Faudiostream-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>
>>
>
------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Faudiostream-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to