Hi Jean-Louis,

If the content is known at compile-time, an efficient approach to implement
a lookup table is to use a waveform and a read-only table. Here are two
examples.

The first one is very minimal, with no protection on the read index:

l1(i) = waveform{1,2,7,4,5,6}, i : rdtable;
process = 2 : l1 : hbargraph("value", 0, 10);

The second one makes use of a more general lut(wf) function with some
protection of the index:

lut(wf) = wf,fii : rdtable with {
n = wf : _,!; // n is the size of the waveform (first output)
fii = int,n : %; // makes sure incomming index is between 0 and n-1
};

l2 = lut(waveform{1,2,7,4,5,6});
process = hslider("index",0,0,20,1) : l2 : hbargraph("value", 0, 10);

Have a look at the corresponding block diagram, it is probably easier to
understand what's going on.

Concerning Stephane's example, the parallel composition (,) is missing
between the two expressions.

Cheers,

Yann


Le ven. 14 janv. 2022 à 11:24, Jean-Louis Paquelin <jean-lo...@paquelin.net>
a écrit :

> Hello Stéphane,
>
> I'm not 100% sure about what's going on when I run the line you wrote:
>
> process = _ <: (lut1 : hbargraph("B", 1, 5)) (lut2 : hbargraph("C", 1, 5));
>
> By writing _ <: you feed an audio data stream to the two lut functions
> instead of a lower rate data provided by the hslider. Am I right?
>
> And btw, I don't understand the syntax, I should have put a comma
> between the two lut calls.
>
> (I'm currently learning Faust. I'm in the 4th lesson of the Kadenze
> course. Please excuse me if it's noob question)
>
> Thanks,
>
> jlp
>
> Le jeu. 13 janv. 2022 à 19:27, Stéphane Letz <l...@grame.fr> a écrit :
>
>> Note that your examples does the actual computation once per block. To
>> test the CPU, its better to have lut1/lut2 runs each sample, using
>> something like:
>>
>> process = _ <: (lut1 : hbargraph("B", 1, 5)) (lut2 : hbargraph("C", 1,
>> 5));
>>
>> Assuming you have installed faust locally, you can then use faustbench of
>> faustbench-lvm tools to measure CPU usage, see:
>>
>>
>> https://github.com/grame-cncm/faust/tree/master-dev/tools/benchmark#faustbench
>>
>>
>> https://github.com/grame-cncm/faust/tree/master-dev/tools/benchmark#faustbench-llvm
>>
>> Stéphane
>>
>> > Le 13 janv. 2022 à 19:05, Jean-Louis Paquelin <jean-lo...@paquelin.net>
>> a écrit :
>> >
>> > @James and @bart, thank you for your quick reply.
>> >
>> > So (if I understand you well) pattern matching should be thought of as
>> a static rewriting tool.
>> > And, btw, you're right
>> > process = 2 : lut : hbargraph("B", 1, 5);
>> > sets the bargraph to 2, while
>> > process = lut(2) : hbargraph("B", 1, 5);
>> > sets it to 3 (as expected).
>> >
>> > I came with 2 ways to write the lut() function I need:
>> >
>> > lut1(n) = 1,3,4,2,5 : ba.selectn(5, n - 1);
>> > lut2(n) = ((n == 1) | (n == 5)) * n + (n == 2) * 3 + (n == 3) * 4 + (n
>> == 4) * 2;
>> > process = hslider("A", 1, 1, 5, 1) <: (lut1 : hbargraph("B", 1, 5)),
>> (lut2 : hbargraph("C", 1, 5));
>> >
>> > Both functions seem to provide the service I'm asking for. But the
>> first one is more readable than the second.
>> > Any idea which one is the lightest for the CPU?
>> >
>> > Thanks again,
>> >
>> > jlp
>>
>> _______________________________________________
> Faudiostream-users mailing list
> Faudiostream-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>
_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to