> Le 9 oct. 2018 à 10:42, Oleg Nesterov <o...@redhat.com> a écrit :
> 
> On 10/08, Julius Smith wrote:
>> 
>> Very nice!  Stéphane's solution is to add the needed state in a
>> subclass of dsp defined in the architecture file.  See the attached
>> simple example ttfs = "test ffunction with state".
> 
> Heh. Thanks, now I understand what you mean.
> 
> This is very inconvenient and limited. And btw, this example doesn't look 
> right.
> 
>       import("stdfaust.lib");
> 
>       ff_smooth = ffunction(float ff_smooth(float,float),"","");
>       ff_init = ffunction(float ff_init(float),"","");
> 
>       smoothness0 = 0.5;
>       smoothness1 = 0.9;
>       smoother(smoothness) = ff_smooth(smoothness) : attach(ff_init(ma.SR));
>       smoother0 = smoother(smoothness0);
>       smoother1 = smoother(smoothness1);
> 
> but this will not create 2 smoothers, class State has a single "float state"
> initialized twice in a row, and then
> 
>       process = 1-1' <: smoother0 , smoother1;
> 
> ff_smooth() will be called twice too; the smoothness/x args are correct but
> again, both calls will play with the same "state".
> 
> 

Well the example with 2 states was actually this code, with explicit 2 State1 
and State2 classes…etc..

Attachment: ffs_steph1.tgz
Description: Binary data




> I modified tffs.dsp:
> 
>       smoother = FPP(smoothness, x) {
>       // shared by all instances, this is only needed to create the
>       // unique "$smoother" id printed below.
>       DECL:   int smoothers;
>       INIT:   smoothers = 0;
> 
>       // every instance has its own state/smother
>       decl:   int $smoother;
>               float $state;
> 
>       init:   $state = 0;
>               $smoother = smoothers++;
> 
>               std::cout << "created smoother " << $smoother << std::endl;
> 
>       exec:
>               $state = (1.0f - $smoothness) * $x + $smoothness * $state;
>               std::cout << "smoother " << $smoother << ": " << $smoothness << 
> ", x: " << $x << ", y: " << $state << std::endl;
>               $state;
>       };
> 
>       smoothness0 = 0.5;
>       smoothness1 = 0.9;
>       smoother0 = smoother(smoothness0);
>       smoother1 = smoother(smoothness1);
> 
>       process = 1-1' <: smoother0 , smoother1;
> 
> then changed Makefile to run fpp instead of faust, and the output is
> 
>       created smoother 0
>       created smoother 1
>       smoother 0: 0.5, x: 1, y: 0.5
>       smoother 1: 0.9, x: 1, y: 0.1
>       smoother 0: 0.5, x: 0, y: 0.25
>       smoother 1: 0.9, x: 0, y: 0.09
>       smoother 0: 0.5, x: 0, y: 0.125
>       smoother 1: 0.9, x: 0, y: 0.081
>       smoother 0: 0.5, x: 0, y: 0.0625
>       smoother 1: 0.9, x: 0, y: 0.0729
>       smoother 0: 0.5, x: 0, y: 0.03125
>       smoother 1: 0.9, x: 0, y: 0.06561
>       smoother 0: 0.5, x: 0, y: 0.015625
>       smoother 1: 0.9, x: 0, y: 0.059049
>       smoother 0: 0.5, x: 0, y: 0.0078125
>       smoother 1: 0.9, x: 0, y: 0.0531441
>       smoother 0: 0.5, x: 0, y: 0.00390625
>       smoother 1: 0.9, x: 0, y: 0.0478297
> 
> which looks correct.
> 
>       process = 1-1' <: par(i, 10, smoother((i+1)/10));
> 
> outputs
> 
>       created smoother 0
>       created smoother 1
>       created smoother 2
>       created smoother 3
>       created smoother 4
>       created smoother 5
>       created smoother 6
>       created smoother 7
>       created smoother 8
>       created smoother 9
>       smoother 0: 0.1, x: 1, y: 0.9
>       smoother 1: 0.2, x: 1, y: 0.8
>       smoother 2: 0.3, x: 1, y: 0.7
>       smoother 3: 0.4, x: 1, y: 0.6
>       smoother 4: 0.5, x: 1, y: 0.5
>       smoother 5: 0.6, x: 1, y: 0.4
>       smoother 6: 0.7, x: 1, y: 0.3
>       smoother 7: 0.8, x: 1, y: 0.2
>       smoother 8: 0.9, x: 1, y: 0.1
>       smoother 9: 1, x: 1, y: 0
>       ...
> 
> No need to create a subclass, no need to write the additional C++ code, etc.
> 
> Oleg.
> 

Julius initial demand was more limited, and the proposed solution was enough I 
think.

OK your solution seems more general,  so we are interested to see your FPP code 
((-;

Stéphane

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

Reply via email to