surge-synthesizer / surge

Synthesizer plug-in (previously released as Vember Audio Surge)
https://surge-synthesizer.github.io/
GNU General Public License v3.0
3.15k stars 400 forks source link

Expanded distortion effect #1213

Closed baconpaul closed 5 years ago

baconpaul commented 5 years ago

I’d like to improve the distortion section a little. I like the fact that it has pre-EQ and post-EQ, allowing it better mimic a guitar amp’s preamp and speaker. I had previously thought that it used a soft-clipping distortion but on closer inspection I think it may be hard clipping (or hard clipping is occurring between internal stages) because it’s difficult to not have a harsh sound. If it is hard clipping, I’d prefer a soft-clipping, tube-like distortion. Also, I’d prefer a whole lot more gain, around 500x.

my response

The distortion I haven’t spent a lot of time with. Looking now it seems the drive pushes you up multiplicatively (so input <- drive * input); and then you go through a tanh waveshape - the same waveshaper that’s in the filter section. I would need to poke at it a bit more. The one thing that occurs to me is that the distortion could easily have the waveshaper table as a parameter (right now it defaults to waveshape 0 which is, I thnk, the tahnh one) and then you would have at least the various mapping tables. tanh at drive is pretty close to hard clipping yeah. Range on the gain is pretty easy too. Let me toss that in as a github issue.

mortfell commented 5 years ago

It would be really great if the distortion fx allowed us to just drop in different algo's...

I actually have had a few ideas for the distortion so I will put them here as well:

Annotation 2019-09-25 124617

baconpaul commented 5 years ago

Yeah cool ideas! Absolutely the easiest thing is to allow the other waveshapers to be in the mix. It just hard codes to tanh!

mkruselj commented 5 years ago

tanh at drive is pretty close to hard clipping yeah

Actually no, tanh curve is closer to soft clipping, since it tapers smoothly on the top and bottom. It's a very standard and often used soft saturation curve. Hard clip would be discontinuities on the top and bottom.

baconpaul commented 5 years ago

Yeah here’s the actual code for the tables in surge

for (int i = 0; i < 1024; i++)
   {
      double x = ((double)i - 512.0) * mult;
      waveshapers[0][i] = (float)tanh(x);                            // wst_tanh,
      waveshapers[1][i] = (float)pow(tanh(pow(::abs(x), 5.0)), 0.2); // wst_hard
      if (x < 0)
         waveshapers[1][i] = -waveshapers[1][i];
      waveshapers[2][i] = (float)shafted_tanh(x + 0.5) - shafted_tanh(0.5);       // wst_assym
      waveshapers[3][i] = (float)sin((double)((double)i - 512.0) * M_PI / 512.0); // wst_sinus
      waveshapers[4][i] = (float)tanh((double)((double)i - 512.0) * mult);        // wst_digi
   }

Of those at lower drive the tanh will be less hard than hard (good!) more hard than sin; the same as digi just without the artifacts; weirdly different than asym. So tanh is sort of the lower-middle of the waveshaper we have available you are right at low drive.

I meant “at high drive tanh is pretty close to hard clipping” though since it all just saturates.

But what we should really do is just add a parameter to distortion so you can pick between these just like you do with the filter waveshaper. The distortion also right now just hardcodes a ‘0’ in itself and has a parameter slot left.

mkruselj commented 5 years ago

Yes, that would be a very nice improvement of the distortion effect, changing the shaper curve. I'm all for it :)

Also, when you have large enough gain factors, pretty much anything will sound like a square wave, or just noise, anyways. :)

baconpaul commented 5 years ago

Alrighty! I just pushed a few changes to the distortion effect for what will be a (small) 1.6.3 release probably in early Nov - along with the VST3 fixes.

There are two changes

  1. The distortion now has a “waveshaper” parameter which picks among the waveshaping tables which are available. The default is tanh which is what used to be there

  2. The gain control is by default unchanged but now supports an extended range (so you can do right mouse / extend on both the pre and post gains). This takes the range from +/- 48db to +/- 144db. At that high a range on the positive side basically you drive the system well beyond stable

It’s pretty easy to get some crazy squeals and instabilities and nastiness out of it. Some of it is really fun. Some of it is also sound. But there’s lots of interesting new settings.

Of course, when playing with the effect, you probably want a limiter after surge in your DAW in case you blow up something; and you probably don’t want to use in-ear headphones. At least until you get a feel for those higher gain responses.

Look forward to feedback.

baconpaul commented 5 years ago

Had a report from user zvenx on slack that patch Bass2 was running hotter on nightly than 1.6.2.1 so I may have screwed up the patch upstreaming (since bass2 uses distortion). To be investigated!

baconpaul commented 5 years ago

Tagging @zvenx

baconpaul commented 5 years ago

Right so absolutely the case that 1.6.2.1 with fddee1d cherry-picked in has higher gain. Only a few places to look really so I'll look at them!

baconpaul commented 5 years ago

Duh dumb bug - found it. Entirely my fault! PR coming.

baconpaul commented 5 years ago

I realized I should play the same xpand trick in drive so will do so before I close this and shop 163

baconpaul commented 5 years ago

So I am pretty sure this isn't needed (the drive extension).

At +24db on a regular sine input this is the output with the Hard waveshaper

Screen Shot 2019-10-17 at 5 48 00 PM

That's pretty square. So I'm calling the gain extensions good enough and closing this issue.