I think it should be possible but I haven't time to work out the
details now. I guess it would be defined as a par() of n functions,
taking n from the length of its list argument. Each of the n functions
would apply the operator to the nth item in the list, leaving the
other arg open (so this might look something like op(_, ba.selector(i,
N, list)), or if you don't care about argument order you could use the
slightly more concise op(ba.selector(i, N, list))). This will yield a
list of n 1-input functions, which is equivalent to an n-input
function, which I believe you should then be able to use in the way
you would like.

Again, I don't have time to work out the exact syntax but I hope that
points you in the right direction. Or perhaps someone else will fill
in the details, or point out another way of achieving it. (There's
always another way.)

Hope that helps,
James


On 9/7/21, Lucian Boca <lucianb...@gmail.com> wrote:
> I'm getting started with Faust and haven't been able to figure out a simple
> way to apply an operator between two blocks of N parallel signals. For
> example:
>
> ```
> N = 2;
> a = par(i, N, 0.5);
> b = par(i, N, 0.1);
> ```
>
> I'm looking to create a third set of N parallel signals (`c`) where `c[i] =
> a[i] + b[i]`
>
> The most straight-forward way I could imagine for doing this would be to
> simply write `c = a+b` but this doesn't seem to work for values of `N>1`
> because + can only take two inputs.
>
> So I implemented a generic "bus operator" as follows:
>
> ```
> bop(f, a : b) = par(i, N, f(a: ba.selector(i, N), b: ba.selector(i, N)) );
> ```
>
> Now I can define `c = bop(+, a : b)` and this seems to be working fine for
> arbitrary values of N. However, when chaining multiple blocks of parallel
> signals, the invocation syntax is not ideal. For three blocks x, y, z of N
> signals each I'd have to write:
>
> ```
> bop(+, bop(*, x : y) : z)
> ```
>
> Is there any way to rewrite the bop function so that it can be invoked in a
> more intuitive way? For example:
>
> ```
> s = x : bop(*, y) : bop(+, z)
> ```
>
> would result in N parallel signals `s[i] = x[i]*y[i] + z[i]`.
>
> Alternatively, I'd be happy to use a best practice / recommended pattern
> for dealing with parallel operators.
>


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

Reply via email to