Cabbage Logo
Back to Cabbage Site

Smoothing out lfo on/off

Hey guys!

I’m trying to smooth out lfo switching on/off with linseg, because it was clicking while sound was going thru.
I’m taking the lfo output and multiply it by linseg outpup from 0 to 1 when turning enabling, and from 1 to 0 when disableing it, sounds good, right??? Except it still clicks, so it seems like I’m doing it wrong! Thanks in advance!

Here are snippets from my code:

checkbox bounds(432, 212, 15, 15), channel(“lfo2b”), colour:0(“white”), colour:1(“black”)
klfo2 chnget “lfo2”
klfo2B chnget “lfo2b”
klfo2Int chnget “lfo2int”

klfof lfo klfo2Int, klfo2, 0

if(klfo2B == 1) then
al linseg 0.0, 0.5, 1.0
af1 moogladder ar1, kcf+klfofal, kres
af2 moogladder ar2, kcf+klfof
al, kres
else
al2 linseg 1.0, 0.5, 0.0
af1 moogladder ar1, kcf+klfofal2, kres
af2 moogladder ar2, kcf+klfof
al2, kres
endif

You shouldn’t be using linseg with a MIDI instrument. Use madsr or even linsegr. They have a release section. An ADSR could easily do what you want:

kGain madsr .5, 0, 1, .5

That takes care of both you fade in and your fade out.

Thank you @rorywalsh for your reply!

Unfortunately, that’s not really what I need (or pherhaps I don’t understand sth). I’m not trying to smooth gain/fade in/fade out. I’m trying to smooth the moment of lfo on/off.

As in the code above - klfo2B controls if lfo is influencing the moogladder frequency. When I change the klfo2B value from UI I get a click. This happens only when there’s signal passing thru the effect (it’s effect, not instrument). So I suspect that happens because of a sudden value change of freq in moogladder, that is why I tried to smooth it out with a linseg. I multiply lfo output by linseg, so I just assume it will smoothly go
from 0 to 1.
But it doesn’t help, it still clicks. Any other ideas? Maybe I’m implementing it in a wrong way?

It’s hard to say without a seeing a full example? Can you post a full, minimal, .csd that illustrates the problem?

Sorry it took me so long.

If you press the button while sth is going thru the effect it clicks, I suppouse it’s problem with parameter smoothing. Any tips to how to improve it will be amazing!

Here’s the code:

<Cabbage> 

form caption("P") size(470, 400), colour(205, 225, 220), pluginid("P0001")


rslider bounds(30, 128, 100, 100), channel("lowpass"), range(1200, 16000, 2000, 1, 1), text("lowpass"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lowpass
rslider bounds(130, 128, 100, 100), channel("res"), range(0.1, 0.8, 0.6, 1, 0.01), text("res"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black")
rslider bounds(230, 128, 100, 100), channel("lfo2"), range(0.1, 25.0, 20.0, 1, 0.01), text("lfo2 freq"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lpf lfo
rslider bounds(330, 128, 100, 100), channel("lfo2int"), range(120, 1000, 520, 1, 1), text("lfo2 intensity"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lpf lfo inte






checkbox bounds(432, 212, 15, 15), channel("lfo2b"), colour:0("white"), colour:1("black")


</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d 
;-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1






klfo2 chnget "lfo2"
klfo2B chnget "lfo2b"
klfo2Int chnget "lfo2int"


klfof lfo klfo2Int, klfo2, 0



kcf chnget "lowpass"
kres chnget "res"


a1 inch 1
a2 inch 2



if(klfo2B == 1) then
af1     moogladder a1, kcf+klfof, kres
af2     moogladder a2, kcf+klfof, kres
else
af1     moogladder a1, kcf, kres
af2     moogladder a2, kcf, kres
endif




outs af1, af2
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>

I’ll take a look at this when i get a chance. For future reference, the </> buttons in the message editor format code so we can see it properly. I’ve gone ahead and reformatted your message.

Runs fine for me here, although I was able to create glitches by selecting non-ASIO audio drivers. What audio drivers are you using? Directsound and Windows sound drivers are pretty bad. Always use ASIO drivers if you can. ASIO4ALL is worth installing.

Were you able to get this sorted? Did the ASIO drivers help?

Not really, but I have another idea to make it work, will check it later today, and let you know. :slight_smile:

Just to note, yesterday I reduced the entire thing to

instr 1
a1 inch 1
a2 inch 2
outs a1, a1
endin

and I still got poor audio using DirectSound and Windows Audio. The only thing that helped was switching to ASIO. Let me know how it goes.

Unfortunately I wasn’t able to make it work the way I see it.
I checked your suggestions @rorywalsh, and tried number of different audio drivers as well, but it didn’t influence behaviour of my problem :(.
What I need is the way to gradually turn on/off LFO influence for moogladder freq parameter. Kind of like in this example:
http://www.csounds.com/manual/html/lfo.html
you have LFO there, but kamp of lfo is driven by line (tied to score values). The result is it starts gradually in the beginning.

Obviously, I will need it faster, coss it’s just for param smoothing, and I will need another evnelope when turning it off.
So I tried to do sth similar, but can’t make it working. And, since it’s effect, and I’m not playing a score, I can’t tie line to score values. Can’t really figure out the workaround for this. Tried linseg for this instead of line, but didnt’ work either. Would be gratefull if someone pointed me towards any solution.

Can you confirm that audio works fine if you bypass the moogladder?

Yes, audio works perfectly fine.

My problem is releated to parameter smoothing, not to audio drivers/playback buffer or anything like it. I don’t get audio dropouts, I get click when I turn LFO on with a button. It’s the same like changing gain parameter to fast and getting clicks because of not a smooth change. But with different parameters.

Sorry, now I understand the issue. It usually doesn’t take me this long :joy: There are quite a few ways to deal with this. What I’ve done below is to interpolate between the different filters depending on the value of the button. Works fine. No more clicks.

<Cabbage> 
form caption("P") size(470, 400), colour(205, 225, 220), pluginid("P0001")
rslider bounds(30, 128, 100, 100), channel("lowpass"), range(1200, 16000, 2000, 1, 1), text("lowpass"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lowpass
rslider bounds(130, 128, 100, 100), channel("res"), range(0.1, 0.8, 0.6, 1, 0.01), text("res"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black")
rslider bounds(230, 128, 100, 100), channel("lfo2"), range(0.1, 25.0, 20.0, 1, 0.01), text("lfo2 freq"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lpf lfo
rslider bounds(330, 128, 100, 100), channel("lfo2int"), range(120, 1000, 520, 1, 1), text("lfo2 intensity"), trackercolour(0,0,0), outlinecolour(0, 0, 0, 50), textcolour("black") ;lpf lfo inte
checkbox bounds(432, 212, 15, 15), channel("lfo2b"), colour:0("white"), colour:1("black")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d 
;-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    klfo2 chnget "lfo2"
    klfo2B chnget "lfo2b"
    klfo2Int chnget "lfo2int"
    klfof lfo klfo2Int, klfo2, 0
    kSmooth tonek klfo2B, 10
    kcf chnget "lowpass"
    kres chnget "res"

    a1 inch 1
    a2 inch 2

    af1     moogladder a1, kcf+klfof, kres
    af2     moogladder a2, kcf+klfof, kres
    af3     moogladder a1, kcf, kres
    af4     moogladder a2, kcf, kres

    aLeft ntrpol af1, af3, kSmooth
    aRight ntrpol af2, af3, kSmooth

    outs aLeft, aRight
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>

LOL…:joy:

Yes, that was what I needed! Thank you very much!!!