Cabbage Logo
Back to Cabbage Site

Gate triggered by random metro


I am creating a plugin effect to simulate a bad internet connection. My first idea was to use a gate, to cut off the audio signal. The intervals between these cutoffs are to be triggered by a randomized metro.

Is this possible? Is the logic correct or is there a better way to approach this idea?


Hi Wen! I played around with your code, but the main problem is that the metronome is constantly changing between a value of 1 and 0, which leaves no time to gate it and I get a clicking noise.

There is a gate effect example you can look at and see how to modify it for a random outcome. It is under File > Examples > Effects > Dynamics > Gate. Maybe someone else here has an idea on how to make a buffer that can be gated, or something like that.

Hello! thanks for the reply, yea I did experiment with different random range values but I think the clicking noise is actually just the metronome, no audio comes through~

I will check that out! thank you:)

1 Like

There are several ways you can do this. The current issue is that the metro only sends a value of 1 at the instant it triggers, not long enough to pass audio thru. And also you might want an envelope to avoid clicks (or not?). You could use a seperate trigger instr. or use something like triglinseg:

instr 1
  kTrig = gausstrig(1, 1, .6)
  iAmp  = .7
  aEnv  = triglinseg(kTrig, 0, .004, iAmp, .3, iAmp, .004, 0)
  aSig diskin2 "fox.wav", 1, 0, 1
  out aSig * aEnv

It can be difficult to control the envelope to not get clicks though. You could also try using metrobpm which has a gate (the trigger can stay open at 1) that can be randomized.

instr 1
  kFreq = randomh(20, 120, 2)
  kGate = randomh(.1, .7, 2)
  kTrig = metrobpm(kFreq, 0, kGate)
  kEnv  = portk(kTrig, .004)
  aSig diskin2 "fox.wav", 1, 0, 1
  out aSig * kEnv

Another slightly more esoteric approach is to use random noise as an envelope . In this ex. passing the noise thru a lpf & then multiplying it by itself creates a random unipolar signal. That is multiplied by a larger value (10^3) then limited from .3 to 1 to leave just the peaks, then .3 is subtracted to bring the lower parts of the signal back to 0. That creates a random envelope. You can play with various values (the rspline, lpf cutoff freq, power of [^] etc.) to get different results.

At the moment when the slider is 0 you only hear the gated signal (wet) & at 1 there’s no gating (dry). If you reverse the aSig * aEnv to:
aOut = ntrpol(aSig, aSig * aEnv, kMix)
then 0 will be fully dry.

instr 1
  kMix    chnget "slider1"
  kMod  = rspline(4, 8, .3, 1)
  aNoiz = noise(kMod, 0)
  aNoiz = butlp(aNoiz, 2)
  aNoiz *= aNoiz * 10^3
  aMult = aNoiz
  aEnv  = limit:a(aNoiz, .3, 1) - .3
  aSig diskin2 "fox.wav", 1, 0, 1
  aOut  = ntrpol(aSig * aEnv, aSig, kMix)
  out aOut