So the main feature is the new FPP() keyword, probably it should have been
named fmacro().

Suppose you want to use random() in .dsp code, so currently you can do

        rand1 = ffunction(int random(), "","");

Now you can do

        rand2 = FPP() int { random(); };

and use rand2 just like rand1. And in fact, this is how fpp actually works;
it translates the code above into something like

        rand2 = ffunction(...);

and passes the modified .dsp code to faust, then it post-processes the .cpp
code generated by faust.

Thus FPP() can be used in any context which allows ffunction(), say,

        process = sin(FPP() int { random(); } + FPP() {123 + 456});

works fine and compiles to

        output0[i] = FAUSTFLOAT(std::sin((({ random(); }) + float(({ 123 + 456; 
})))));

-------------------------------------------------------------------------------
As you can guess, rand2 above returns "int". But FPP() can return ANY c/c++ 
type,
however in this case you should probably pass the result to another FPP() func.

Example:

        world = FPP() char * { "world" };
        hello = FPP(s) int { printf("Hello %s.\n", $s); };
        process = world : hello;

-------------------------------------------------------------------------------
FPP() can return a list of values of any type.

        process = FPP() const char *, int, float { "str", 10, 20.0 } :
                  FPP(s,i,f) int { printf("str=%s, i=%d, f=%f\n", $s,$i,$f) };

works too.

-------------------------------------------------------------------------------
However!

        FPP() float { ... };

means that it will actually return "float" even if -double or -quad was used. 
Use
_float_ (better name?) instead if you want to return float/double/quad depending
on compiler option; or simply do not specify the return type at all:

        FPP() { ... };

means the _float_ return type.

-------------------------------------------------------------------------------
Now suppose you have

        float plus_rand(float x)
        {
                return x + random();
        }

in "incfile.h". Again, lets define rand1 and rand2

        rand1 = ffunction(float plus_rand(float), <incfile.h>,"");

        rand2 = FPP(x) {
        FILE:   #include <incfile.h>
        exec:   plus_rand($x);
        };

they work almost the same way. Say,

        process = _ <: rand1, rand2;

compiles to

        output0[i] = FAUSTFLOAT(float(plus_rand(float(fTemp0))));
        output1[i] = FAUSTFLOAT(float(({ plus_rand(fTemp0); })));
                                                        
BUT! fpp assumes that FPP() _always_ have side effects (state). So

        process = rand1(10);

compiles to

        // instanceConstants()
        fConst0 = float(plus_rand(10.0f));

        // compute()
        output0[i] = FAUSTFLOAT(fConst0);

while

        process = rand2(10);

compiles to

        output0[i] = FAUSTFLOAT(float(({ plus_rand(10); })));


You can override this behaviour:

        rand2 = FPP(x) pure {
        FILE:   #include <incfile.h>
        exec:   plus_rand($x);
        };

this version of rand2 acts the same as rand1.

-------------------------------------------------------------------------------
Just in case... of course, rand2 can be also defined as


        rand2 = FPP(x) {
        FILE:
                float plus_rand(float x)
                {
                        return x + random();
                }
        exec:
                plus_rand($x);
        };

or just

        rand2 = FPP(x) { $x + random(); };

-------------------------------------------------------------------------------
Enough for today ;) but let me mention that FPP() can use faust's lists and
delay lines.

        z = FPP(n, x[n]) { $x[$n] };

works like @ operator. Say,

        process = par(i, 4, z(i));
and
        process = par(i, 4, @(i));
        
generate the same (almost) code.


Another example,

        fpp_fir = FPP(b{}, x[ba.count(b)-1]) {
                float x = 0;
                $b.for(n,b, x += b * $x[n]);
                x;
        };

is fi.fir() implemented in FPP(). You can use it the same way, say,

        b = (.1, .2, .3);
        process = no.noise <: fi.fir(b), fpp_fir(b) :> -;

should output zeroes.

        fpp_selector = FPP(i, n, inp{n}) { $inp{$i} };
        
works just like ba.selector,

        process = fpp_selector(2, 4);

outputs input2[i] and discards other inputs.

Oleg.



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

Reply via email to