Author Topic: Implementing a simple softclip algo, pr voice.  (Read 11138 times)

Paradox Uncreated

  • Guest
Implementing a simple softclip algo, pr voice.
« on: April 16, 2012, 11:52:15 »
As you know, in the 8-bit days, one usually clipped the samples a bit, to increase SNR.

I just made a very simple and optimal softclip, using two x-(x*x*x*0.3etc), in series with a threshold. This gives the third-order distortion of vintage gear, driven mixers, and often what people like with "hot" signals, on whatever it may be, on typically analog gear.

I recently tried OpenMPT on one of my old tracks, and with the Blackman Exact interpolation, it sounded actually quite good. I did however remember driving the levels there quite hot, but with the sampler of the time, (and most of them I think) there was no softclipping. So that can be retrofitted to the samples :) (probably pr. voice, before interpolation?)

What do you think?

(Edit: having the softclippers in parallel might be even better!)
« Last Edit: February 04, 2019, 16:28:35 by Weedsuz & The Háchi O' Iȃw »

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #1 on: April 16, 2012, 19:08:50 »
I actually tried a batch-process on the samples now, with the softclip algo.
And it definately sounds smoother. Maybe I`ll adjust it abit, because I was used to the hardclipping overtones being present. But it`s already quite low -3.6dB knee.

I tried downloading the source, but I haven`t got visual studio installed, just an old MSVC6.0. So for the time being, me doing the tweak is not going to happen.
« Last Edit: February 04, 2019, 16:29:01 by Weedsuz & The Háchi O' Iȃw »

Offline LPChip

  • Administrator
  • *****
  • Posts: 5,065
    • http://lpchip.nl
  • Operating System: Windows 10 Pro x64
Re: Implementing a simple softclip algo, pr voice.
« Reply #2 on: April 16, 2012, 19:57:32 »
I'm not a developer, but this sounds very nice. :)
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #3 on: April 16, 2012, 20:17:58 »
Yes, it is one of those things you can actually do to remedy hardclipped samples. Ofcourse it`s mostly a problem with older modules probably. Maybe someone used noisy 16bit converters and felt the need to drive the levels hot too.

It`s actually a big discussion out there, about hardclip vs softclip. And the sound of softclip. And doing the softclip I am doing, is close to some good sounding transistors. It is actually optimized for transparent clipping, and therefore even preferrable to analog, for me.

So in addition to improving the sound with Blackman Exact, and smooth level changes, you can do this too :)

Knee-adjustments might need finetuning resolution, of two decimals. For the use here, on samples knees from 0 - -6dB is probably the range we are talking about.

Also ofcourse processing in 8bit would be bad, which I doubt is happening. So conversion to the resolution used, would be required.

Peace.
« Last Edit: April 16, 2012, 20:21:36 by Paradox Uncreated »

Offline LPChip

  • Administrator
  • *****
  • Posts: 5,065
    • http://lpchip.nl
  • Operating System: Windows 10 Pro x64
Re: Implementing a simple softclip algo, pr voice.
« Reply #4 on: April 16, 2012, 20:33:39 »
Can you provide an audio example that shows the difference between normal hardclipping and your softclipping version?
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #5 on: April 16, 2012, 20:34:46 »
Yes, the mod only, or do you want to hear it with the mastering effects aswell?

Paradox Uncreated

  • Guest
« Last Edit: February 04, 2019, 16:30:50 by Weedsuz & The Háchi O' Iȃw »

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #7 on: April 16, 2012, 21:47:25 »
I am still tweaking the algo a bit.

It`s the kind of thing were two decimalplaces matter, if you know what I mean. So doing batchprocessing on that, reloading samples, setting vols/tune, is a bit tedious, to actually try and find that value in practise.
« Last Edit: February 04, 2019, 16:31:31 by Weedsuz & The Háchi O' Iȃw »

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #8 on: April 17, 2012, 01:08:14 »
Notice particulary on the 303 sound there, that some digital edgyness is gone. That was purely due to hardclip.

Maybe a better name for the usage of this particular algorithm in this context, would be Softclip/De-hardclipping-knee.

Peace.
« Last Edit: February 04, 2019, 16:32:27 by Weedsuz & The Háchi O' Iȃw »

Offline LPChip

  • Administrator
  • *****
  • Posts: 5,065
    • http://lpchip.nl
  • Operating System: Windows 10 Pro x64
Re: Implementing a simple softclip algo, pr voice.
« Reply #9 on: April 17, 2012, 10:05:44 »
Cool. I'll check them out tonight when am at home.
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #10 on: April 17, 2012, 12:51:41 »
:-)

Do you have any idea if/when the developers might insert this tweak into the code?

And if they are busy maybe they could just say where in the code it would need to be inserted, and I might get someone else with the compiler installed, to do it. And maybe, if it is asm or not, maybe that complicates things.
« Last Edit: February 04, 2019, 16:33:46 by Weedsuz & The Háchi O' Iȃw »

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #11 on: April 17, 2012, 13:57:20 »
Maybe it is ratetransposer.cpp..

Offline LPChip

  • Administrator
  • *****
  • Posts: 5,065
    • http://lpchip.nl
  • Operating System: Windows 10 Pro x64
Re: Implementing a simple softclip algo, pr voice.
« Reply #12 on: April 17, 2012, 14:14:37 »
Do you have any idea if/when the developers might insert this tweak into the code?

And if they are busy maybe they could just say where in the code it would need to be inserted, and I might get someone else with the compiler installed, to do it. And maybe, if it is asm or not, maybe that complicates things.
Jojo is pretty active on the forums too. He'll probably answer that himself. :)
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #13 on: April 17, 2012, 14:20:39 »
Anyone has this compiling?
« Last Edit: February 04, 2019, 16:35:50 by Weedsuz & The Háchi O' Iȃw »

Paradox Uncreated

  • Guest
Re: Implementing a simple softclip algo, pr voice.
« Reply #14 on: April 17, 2012, 14:48:45 »
I think the function would look something like this:

double kn(double val)
{
   // antihcknee (anti-hardclipping-knee) should probably be a double, and a setting in the gui.(range 0..-6dB)
   // 0 being 0dB (no knee, which can also be optimized) and 1 being -6dB.  Two digit decimals in dB is probably good. e.g: -2.51dB knee.
   double b_knam = pow(2,(((antihcknee)*-6))/ 6); // should probably be placed somewhere else..
   double b_3rdmul = 1; b_3rdmul = b_3rdmul / 3; double b_3rdnorm = 1/(1-b_3rdmul); // same
 
   if (val > 1) {val = 1;} else if (val < -1) {val = -1;} // can be optimzed out, if there is no weirdness anywhere.

   double valr = val;
   if (valr < 0) {valr = -valr;}
   if (valr > b_knam) {
    valr = valr - b_knam;
    valr = valr / (1-b_knam);

   valr = (valr - (valr * valr * valr * b_3rdmul)) * b_3rdnorm;
   valr = (valr - (valr * valr * valr * b_3rdmul)) * b_3rdnorm; // can reduce the 3rdnorm here, and a div in the next.
   valr = (valr / b_3rdnorm) / b_3rdnorm;

    valr = valr * (1-b_knam);
    valr = valr + b_knam;
    if (val < 0) {valr = -valr;}
    val = valr;
   }
   return val;
}

This would do the monosamples anyway. It seems he has different code for stereo.. Someone would have to modify that aswell, if they want to use it on stereostuff.
« Last Edit: February 04, 2019, 16:34:57 by Weedsuz & The Háchi O' Iȃw »