Vco2 + distort + moogvcf2 break with certain parameters

I am experiencing a weird behaviour that I cannot understand using a combination of vco2, distort and the moogvcf2 filter. With certain parameter settings, the output simply stops working and cannot be recovered (so it stays silent even after changing the parameters back to values that were producing sound before). I guess something is getting zeroed, but I cannot understand why it can happen.

I have a single instrument that gets triggered once and stays alive for the whole performance.
This is the shortest code that reproduces this behaviour. Controls are made in Cabbage but you can easily reproduce the issue setting kDist to 0.99, kFiltFreq to 3000 and kFiltRes to anything above 0.44:

Interestingly, if I set kFiltRes to 0.43 (I tried values up to 0.430178396377), it is working for some seconds, then it stops, after producing some strange modulation, that looks very suspicious. Any value above that simply doesn’t produce sound from the start.

<Cabbage>
form caption("DIST FILT VCO") size(400, 300), guiMode("queue"), pluginId("def1")
vslider    bounds(10, 10, 60, 150), valueTextBox(1), textBox(1), text("Distortion"), channel("dist"),  range(0.05,  0.99, 0.75)
rslider    bounds(80, 10, 80, 80), valueTextBox(1), textBox(1), text("Filter Freq"), channel("filtFreq"),  range(0.01,  3000, 1200)
rslider    bounds(80, 90, 80, 80), valueTextBox(1), textBox(1), text("Filter Res"), channel("filtRes"),  range(0.01,  0.99, 0.2)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1

;giTanh  ftgen   0,0, 257, 9, .5,1,270,1.5,.33,90,2.5,.2,270,3.5,.143,90,4.5,.111,270    
giTanh  ftgen   2,0,257,"tanh",-10,10,0 ; same behaviour with both tanh functions

instr 1

  kDist init 0.99 
  kFiltFreq init 3000
  kFiltRes init 0.43    ; change this to 0.430178396377 and it stops producing sound

  kDist chnget "dist"
  kFiltFreq chnget "filtFreq"
  kFiltRes chnget "filtRes"
  aVco vco2 0.9, 200
  aDist distort  aVco, 1 - kDist, giTanh 
  aFilt moogvcf2 aDist, kFiltFreq, kFiltRes
  aEnv madsr 0.1, 0.001, 1, 0.1
  aSig = aFilt * aEnv
  outs aSig, aSig

endin

</CsInstruments>
<CsScore>
i1 0 z
</CsScore>
</CsoundSynthesizer>

It would be nice to understand what I’m doing wrong!
I strongly suspect that a combination of the hyperbolic tangent function with the filter can lead to no output, but I’m not sure why, so I’d like to know if I can overcome this in some way.

Also I’m not completely sure why I have to invert the kDist value if using vco2, the distort opcode behaves in the opposite way with it compared to other oscillators.

Hi gb. Long & short of it, would seem you’re kind of “exploding” the filter. When you drive it hard enough, with a resonance related to the note freq, the amp can suddenly go to ridiculous extremes. Csound seems to have a certain built-in protection from this so it cuts off the audio.

Try:
kAmp linseg 0.5, 5, .9
aVco vco2 kAmp, 200

Set the score for 10 seconds. The sound will cut off after about 2.5. Then view the console. The best way to see what’s going on is to render the first few seconds to audio & view in an editor.

Even when the sound starts, with an initial vco2 amp of .5, the actual output amp is very high.

Set the score to 2 seconds and view the console.

I’m not sure exactly how to prevent this aside from limiting the range of resonance.

I’ll look at the question of the kDist value later.

Best,
Scott

1 Like

Ok, this is actually kind of amusing in an odd way😆.

Turns out the distort opcode is essentially a simple way of performing a transfer function (see FLOSS manual example 04E01), it would appear.

So when using a tanh function with something like a sine wave input, as you increase the kdist you are essentially creating a rounded square (soft clipping) which is increasing the harmonic content.

But with a saw wave, as you increase kdist you end up with a rounded square which is actually removing harmonics and starts to sound softer than the saw.

So with kdist = 1 - .9 you would end up with a value of .1 which produces a soft saw:

With kdist = 1 - .1, a value of .9, you get a soft square:

So using the distort opcode with a saw as input and tanh as the “transfer function” (?) then it appears the more you distort it (higher kdist) what in fact happens is you are getting a more square sound (less harmonics) and a decrease in amplitude.

Kind of the inverse of what one might intuit😅

Compare that to using a sine for input to distort. Here’s kdist = .1:

And kdist = .9:

Bottom line, it would seem that regardless of the kdist value, using the distort opcode with a saw as input might alter the shape but ends up softening the sound of the saw a it removes harmonics it starts to get “squared off”.

One way to start with a saw like timbre and make it more “agressive” might be using something like gbuzz and raising kmul. Beyond that there are probably many other ways to “distort” a saw (eq, using an exciter opcode, wavefolding with the mirror opcode, wrap etc.).

Waveshaping is certainly an interesting subject!

1 Like

Thank you for these very detailed answers, they are super helpful!
I should definitely start analyzing the resulting waveforms, as they provide lots of information!
I will try different filters, it looks like there are a lot to experiment with :wink:
And I will look into alternatives to distort, what I really want is clipping the signal, maybe a limiter could be enough to achieve that.
I will experiment a bit then report here!
Thanks again! (I’m so glad you discovered Csound and joined the community, you are a great addition! :raised_hands:)

1 Like

Hi again gb😄 And thanks for the kind words, I’m learning but slowly.

I think the main question here is what do you want to achieve sonically?

The limit opcode will clip, but once again all that will do is to start squaring off the waveform, much the same as with the distort opcode.

kAmp linseg 0.6, 5, 30
aVco vco2 kAmp, 200
aLimit limit aVco, -.7, .7
out aLimit

You likely have some idea in your mind of how distorting/clipping the saw might alter it. Are you trying to make it sound more aggressive? Clipping will only make the saw sound like a square, although perhaps that’s what you want, and using limit allows keeping the amp consistant much easier than with distort.