Cabbage Logo
Back to Cabbage Site

Using Faust programs in Csound/Cabbage

Hi,

One of my current projects involves modeling a linear circuit, and thanks to Faust’s WDF filter it can be done easily in Faust. There is a way to use Faust code in Csound thanks to the faust plugin.

Before going further I have two questions:

  • Are they ways to use the UI parameters (knobs, sliders…) in the Faust code?
    Based on my understanding of the code below, the faust code would need to be re-compiled everytime we’d like to pass a new parameter. And I’m not really sure the syntax allow us to add a variable in the faust code. https://csound.com/docs/manual/faustaudio.html
  • Is it realistic to ship the Faust plugin (opcodes) with my VST? There are no compiled binaries so I would need to do it myself for each architecture. I think it is as straightforward as installing Csound but maybe I’m missing something…

If it’s something that wouldn’t be performant and too hard to implement I’ll skip this project, but I wanted to check if someone tried it first and if it was potentially feasible.

Thanks!

Julien

I don’t think you can update parameters in realtime but I’m awaiting confirmation from the author. You can output your faust code to c++. In which case you could build your own opcode, or I can look into doing it for you if you like. I think that would be the simplest, and then I could embed that opcode into your pro build so you don’t need to worry about including dlls and what not.

You can control parameters using faustctl. And you can also output Csound opcode code from Faust directly. I think that might be the best approach.

Thanks Rory!

I’ll take a look at faustctl, I totally missed it while doing my research. And I’ll see if I can output a Csound opcode, it can definitely be a great way to implement it!

I’ll keep you updated. FYI I’m trying to implement features of the Pultec EQP-1A passive EQ and doing it in Csound only looks very hard, which is why I’m trying to use Faust.

I’ll post the code here once I manage to make it work.

Julien

1 Like

Hi @rorywalsh,

Thanks for your help, here is a guide and a working example:

This is how you can use the “osc.dsp” example from Faust in Cabbage. The controls can be done with Cabbage, and control the freq and gain parameters in Faust.

1/ Go here: https://faustide.grame.fr/

2/ Export your Faust code as an opcode:

3/ Import the opcode in Cabbage and use it

<Cabbage>
form caption("Faust Opcode") size(400, 300), guiMode("queue") pluginId("def1") colour(0,0,0)
rslider bounds(30, 98, 75, 72), channel("opcodegain"), range(-96, 0, 0, 1, 0.01), text("OpcodeGain")
rslider  bounds(32, 16, 70, 70), channel("opcodefreq"), text("OpcodeFreq"), range(20, 20000, 1000, 0.333)
rslider bounds(266, 178, 100, 100), channel("gain"), range(0, 1, 0, 1, 0.01), text("Gain")

</Cabbage>
<CsoundSynthesizer>

<CsOptions>
-n -d --opcode-lib=full_path_to_opcode/osc.dylib
</CsOptions>

<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
kGain cabbageGetValue "gain"
kOpcodeGain cabbageGetValue "opcodegain"
kOpcodeFreq cabbageGetValue "opcodefreq"

; Generate osc with custom opcode 
asig   osc  kOpcodeFreq, kOpcodeGain
outs asig*kGain, asig*kGain
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

And that’s it!

I still need to figure out a few things:

  • Loading the .dylib file wasn’t working because of security issues. I codesigned the file but the error was the same. I had to manually open the dylib to be able to load the file in Cabbage
  • You need one export per platform (osx, windows…). I’m not sure this is compatible with Intel and ARMS macs for example. I need to test it.

But is is encouraging! Next step for me: convert and use the Pultec .dsp code.

Wow, I didn’t think it would compile it for you too. That’s neat. The simplest way around the signing issues is for me to build the opcode into your pro build of Cabbage. Then you don’t have to worry about compiling for different platforms. At least that’s how I would approach it.

I agree, this is impressive!

I’m worried about the maintenance cost/time it would imply. It means that everytime the opcode needs to be updated, I would need to send it to you and it would be time consuming for you (even though I imagine these opcodes would be rarely updated…)

I will first test the Pultec code and see if I want to release it as a VST and get back to you if needed! Maybe I could also try to build it in my Azure Pipeline so I can do it on my own. I never did that so I don’t know how hard it is though.

I would just need to understand how to use faust2csound in my pipeline: https://faustdoc.grame.fr/manual/tools/

Thank you very much for your help!

I wouldn’t imagine that I would not have to build them in until you are almost ready to release your plugin and by that stage the opcode will be pretty much finished? Anyway, keep me posted on your progress, it’s definitely a cool way of harnessing the power of FAUST in a plugin.