Cabbage Logo
Back to Cabbage Site

How to remove click?

Hi I am trying to make this first instrument. It is a kind of drone machine so I don’t need midi keyboard. I have noticed a click whenever I switch on/off checkbox. I tried several things to remove this click without succeed. This is my csd file:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")

checkbox bounds(312, 20, 80, 17), text("On/Off"), channel("onoff"), , fontColour:0(0, 0, 0, 255), fontColour:1(0, 0, 0, 255), colour:1(255, 255, 0, 255)
rslider bounds(8, 48, 60, 60) channel("osc1Gain") range(0, 1, 0, 1, 0.001)
rslider bounds(86, 48, 60, 60) channel("osc2Gain") range(0, 1, 0, 1, 0.001)
rslider bounds(164, 48, 60, 59) channel("osc3Gain") range(0, 1, 0, 1, 0.001)
rslider bounds(238, 48, 60, 60) channel("osc4Gain") range(0, 1, 0, 1, 0.001)
rslider bounds(310, 44, 84, 69) channel("freq") range(50, 1000, 100, 1, 0.001) colour(238, 123, 155, 255) outlineColour(111, 173, 23, 255) markerColour(160, 209, 92, 255)

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


gisine	ftgen	0,0,4096,10,1
instr    1
    koscgain1 chnget    "osc1Gain"
    koscgain2 chnget    "osc2Gain"
    koscgain3 chnget    "osc3Gain"
    koscgain4 chnget    "osc4Gain"
    kfreq     chnget    "freq"
    konoff    chnget    "onoff"
        
    

    k1 oscili  kfreq * koscgain1, kfreq, gisine
    k2 oscili  kfreq * koscgain2, kfreq * 5, gisine
    k3 oscili  kfreq * koscgain3, kfreq * 3, gisine
    k4 oscili  kfreq * koscgain4, kfreq * 2, gisine
    k5 oscili  kfreq, k1 + k2, gisine
    k6 oscili  kfreq, k3 + k4, gisine
    if konoff = 0 then
        aAntiClick	linsegr	0,0.01,1,0.01,0
        aout oscili 0 * aAntiClick, k1 + k2, gisine
    else
        aAntiClick	linsegr	0,0.01,1,0.01,0
        aout oscili 1 * aAntiClick, k1 + k2, gisine
    endif
    outs aout, aout
    skip:
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
f1 0 16384 10 1 0
i 1 0 [60*60*24*7]    ;instrument that reads in widget data
</CsScore>
</CsoundSynthesizer>

Nice instrument :+1: Here a trick I learned from reading @iainmccurdy’s code:

k1 oscili  kfreq * koscgain1, kfreq, gisine
k2 oscili  kfreq * koscgain2, kfreq * 5, gisine
k3 oscili  kfreq * koscgain3, kfreq * 3, gisine
k4 oscili  kfreq * koscgain4, kfreq * 2, gisine
k5 oscili  kfreq, k1 + k2, gisine
k6 oscili  kfreq, k3 + k4, gisine

kAntiClick	portk konoff, 1
aout oscili kAntiClick, k1 + k2, gisine

outs aout, aout

Using a portk opcode works great in this context as it will slide nicely between 0 and 1. Plus you can easily control the fade times.

1 Like

Hi Thank you.

I am trying this.

(And big Thanks to make cabbage possible :wink:)

It works . That’s very cool. Thanks again

1 Like