t2techno / Faug

A Minimoog Model D emulation with the DSP portion written in Faust. Moog + Faust = Faug
26 stars 0 forks source link

Issue with variables #3

Open t2techno opened 1 year ago

t2techno commented 1 year ago

Hi @sletz,

I was hoping you could take a look and give me some insight into the issue I'm running into with my attempts at a basic diode clipper.

Now that I’ve got my base synth functional, I wanted to try and start replacing various components with analog models. To that end, I was watching From Circuit to Code: Under the Hood of Analog Modelling - Andrew Simper - ADC20 and attempting to implement the initial basic diode clipper as seen ~17:40 in the video.

My issue is in the nr_loop method, the faust compiler, based on the diagram view, overrides my id1eq and gd1 with id2eq and gd2, respectively when id2eq is included at the top of the division. Attached is a screenshot of what I see. The issue is completely resolved if I change vd2 to a constant so I assumed it was an issue with my use of v2_guess more than once, however separate arguments obviously didn’t work either. diode_issue

sletz commented 1 year ago

Not sure I fully understand: can you send the whole DSP with this basic diode clipper model? Some general remarks the may help:

t2techno commented 1 year ago

The full code is here https://github.com/t2techno/Faug/blob/main/FaustDsp/basicDiode.dsp

In short, the issue is that the diagram generated does not seem to match my code. However, changing vd2 to a constant corrects the diagram.

Since I'm still just trying to learn, once I got this bug ironed out I was going to use a hardcoded loop of 50 steps as it was noted in the video that was sufficient to converge. For the loop I was picturing something to the effect of v2 = nr_loop(input, 0.0, 0.0) <: seq(i,50,nrloop(input, , _));

I'll re-create a minimal version of the issue that's a little clearer and try one of the channels mentioned, thanks for your help!

sletz commented 1 year ago

Yes, please prepare the simplest code that show the problem.

sletz commented 1 year ago

My understanding is that:

vd1 = 0.0-v2_guess1;
ed1 = exp(vd1/vt1);
id1 = is1*ed1-is1;
gd1 = is1*ed1/vt1;
id1eq = id1 - gd1*vd1;

and:

vd2 = v2_guess2-0.0;
ed2 = exp(vd2/vt2);
id2 = is2*ed2-is2;
gd2 = is2*ed2/vt2;
id2eq = id2 - gd2*vd2;

are seen as exactly the same expression when v2_guess1 = v2_guess2 = 0.0, is1 = is2, vt1=vt2. So the SVG display takes one of them, like ideq2. @orlarey: so we really want that is that case ?