grame-cncm / faust

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

faust2supercollider "Audio Rate inputs" #565

Closed Hyppasus closed 3 years ago

Hyppasus commented 3 years ago

Is it possible to implement the choice of rates (Audio, Control) for the inputs of the produced Ugen? The UGen generated by the script assumes Control Rate (kr) inputs. Audio Rate (ar) inputs are crucial for audio rate modulations such as FM. To illustrate the point see the SuperCollider code below.


/*
faust2supercollider -noprefix SimpleOsc.dsp
*/

/*
//SimpleOsc.dsp
import("stdfaust.lib");
decimalpart(x) = x-int(x);
phase(f) = f/ma.SR : (+ : decimalpart) ~_;
osc(f) = phase(f) * 2 * ma.PI : sin;
out = osc(hslider("freq", 440, 0, 10000, 1) )* hslider("gain", 0.961, 0.0, 1.0, 0.001);
process = out <: _,_;
*/

{SimpleOsc.ar(200)}.play

x={arg freq=1, amp=0.5;SimpleOsc.ar(SinOsc.ar(freq,0,400,400)!2)*amp}.play
y={arg freq=1, amp=0.5;SinOsc.ar(SinOsc.ar(freq,0,400,400)!2)*amp}.play

x.set(\freq, 200);
y.set(\freq, 200);
sletz commented 3 years ago

The UGen generated by the script assumes Control Rate (kr) inputs.

Not sure to understand here. Where do you see that?

BTW discussion the issue on Faust Slack channel (see https://faust.grame.fr/community/help/) will probably be easier.

Hyppasus commented 3 years ago

When the resulting Ugen is modulated at the audio rate it can be heard that the input is calculated at a lower rate. Moving towards Slack. Thnak you.

Hyppasus commented 3 years ago

The solution is to use an audio input with si.bus

//SimpleOsc.dsp
import("stdfaust.lib");
decimalpart(x) = x-int(x);
phase(f) = f/ma.SR : (+ : decimalpart) ~_;
osc(f) = phase(f) * 2 * ma.PI : sin;
out = osc(si.bus(1) )* hslider("gain", 0.961, 0.0, 1.0, 0.001);
process = out <: _,_;

Then in supercollider the input should be AR such as

{SimpleOsc.ar(DC.ar(1200),0.1)}.play