grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.53k stars 319 forks source link

Scalar variables for 1-sample delay lines #567

Open mikeoliphant opened 3 years ago

mikeoliphant commented 3 years ago

Because single-sample feedback is so common, Faust often generates a lot of 2-value arrays for feedback handling.

This ends up being quite expensive in languages like C# where array access has more overhead than C++.

It would be great if the compiler could instead generate a pair of scalar variables for the single-sample delay case.

ie: instead of:

double[] fRec9 = new double[2];

it would generate something like:

double fRec9_0; double fRec9_1

In C#, this simple change can result in massive performance increases for very typical Faust use cases. It doesn't seem to make much of a difference for C++, but it may help other backends.

sletz commented 3 years ago

Yes indeed. Yann is currently working on a whole new infrastructure in the compiler that will (in particular but even some more improvements ...) allow to solve this kind of issues. See Yann IFC 2020 presentation: https://ifc20.sciencesconf.org and https://www.youtube.com/watch?v=vb7LU7ue5hk.

mikeoliphant commented 3 years ago

Great - I look forward to the new compiler!

sletz commented 2 years ago

@mikeoliphant could not find another way to contact you ! Do you have a small presentation text of the use-case for your contributed C# backend in Faust ?

mikeoliphant commented 2 years ago

Hi @sletz - my main use case was simply to be able to generate plugins in C# rather than having to use C#/C++ interop (which isn't difficult, but is unpleasant and make for more complicated project structure). I also am using the ability of the C# compiler to do dynamic assembly generation from Faust code. One goal of this would be to have runtime editing of Faust code within a VST inside a DAW (something I've experimented with, but haven't had time to fully explore).

sletz commented 2 years ago

Thanks. How do you do use the C# compiler to do dynamic assembly generation from Faust code ?

mikeoliphant commented 2 years ago

Right now, I spawn off Faust to generate the C# code (although it could be integrated more tightly by compiling in the Faust libs). Once I have C# source code, the .NET compiler system can be invoked at runtime to create an in-memory assembly that can be used just like any other. I don't know much about LLVM, but I assume it is similar.

sletz commented 2 years ago

OK thanks, yes using LLVM backend, we do DSP ==> LLVM IR ==> JIT ==> executable code in memory.

mikeoliphant commented 1 month ago

Hi @sletz - figured I'd contact you here because of our previous discussion.

I've finally gotten around to making more progress on one of my use cases for the C# faust compiler.

I just released the first version of:

https://github.com/mikeoliphant/FaustVst

It dynamically compiles faust dsp code into a C# assembly while running inside a VST plugin. It makes for a very good workflow for quick iteration and testing inside a DAW.

sletz commented 1 month ago

Thanks, added here.

mikeoliphant commented 1 month ago

👍