Lightweight but decent limiter algo

Until our dedicated user library is in place you can post examples and modules here

Moderators: electrogear, exonerate

Lightweight but decent limiter algo

Postby bootsy on Wed Oct 29, 2008 2:35 pm

Hiho,

thanks to kirkagur who posted sometimes ago somewhere a simple but really decent limiter algorithm I've stripped it down to avoid the cpu expensive log encoding of the entire stream data. Saves tons of cpu without sounding worse.

I've attached both versions.

peace,
bootsy
Attachments
Basic_Limiter_SD.osm
Stripped down version
(2.11 KiB) Downloaded 399 times
Basic_Limiter.osm
Original
(3.39 KiB) Downloaded 339 times
Come and visit my Blog: Variety Of Sound
bootsy
essemilian
 
Posts: 370
Joined: Sat Jul 28, 2007 10:55 am
Location: Frankfurt, Germany

Re: Lightweight but decent limiter algo

Postby infuzion on Wed Oct 29, 2008 9:38 pm

Thanks for sharing!
For an even more light weight limiter:
Code: Select all
streamin i;streamout o;
float Fmin=0.999;
float Fmax=-0.999;
movaps xmm0,i;
minps xmm0,Fmin;
maxps xmm0,Fmax;
movaps o,xmm0;
But won't sound as sexy as the ones above, since this is more of a clipper-limiter, where that is more like a static-compressor-limiter :)
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Lightweight but decent limiter algo

Postby aliasant on Thu Oct 30, 2008 5:47 am

Hey. What is the difference between this static limiter and any clipper?
It's never to late to be late.....
http://martinrodensjo.smugmug.com/
User avatar
aliasant
smunatic
 
Posts: 2386
Joined: Sat Dec 30, 2006 5:49 pm
Location: Sweden

Re: Lightweight but decent limiter algo

Postby infuzion on Thu Oct 30, 2008 6:16 am

aliasant wrote:Hey. What is the difference between this static limiter and any clipper?
My ASM code is indeed a "clipper" which is a subset of limiters:
http://en.wikipedia.org/wiki/Limiting
I believe the above OSM has "soft limiting", due to a sort of compression to it.

Each have their uses; mine is better if an OSC or a ENV on rare occation touches outside of the +/-1.0 boundaries of a signal, as a final peak tamer when 99.99% of the signal is under max but you are pressing to CD, or if you crank up the volume & want that icky digital sound that dance tracks have now. Soft limiting is better for a more musical taming of peaks, like to hone in the occasional peaks of a vocal track after you compressed it, or part of the mastering process.
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Lightweight but decent limiter algo

Postby aliasant on Thu Oct 30, 2008 7:36 am

OK.
Well.
As I see it a limiter is a compressor with a high Ratio and high threshold.
Often the ratio is at or above 10:1 and the threshold might be -6 dB or so. There should be no attack but a variable release time. Thats why you had me a bit confused ;)
It's never to late to be late.....
http://martinrodensjo.smugmug.com/
User avatar
aliasant
smunatic
 
Posts: 2386
Joined: Sat Dec 30, 2006 5:49 pm
Location: Sweden

Re: Lightweight but decent limiter algo

Postby bootsy on Thu Oct 30, 2008 9:57 am

Be aware that soft-limiting introduces aliasing if not oversampled to the right amount and hard-clipping introduces heavy aliasing in any case (can't be compensated).
So an envelope driven approach (which features less distortion) might be more suitable in most cases.
Come and visit my Blog: Variety Of Sound
bootsy
essemilian
 
Posts: 370
Joined: Sat Jul 28, 2007 10:55 am
Location: Frankfurt, Germany

Re: Lightweight but decent limiter algo

Postby exonerate on Thu Oct 30, 2008 10:11 am

infuzion wrote:I believe the above OSM has "soft limiting", due to a sort of compression to it.


It's not correct to call it soft limiting, soft limiting/clipping doesn't actually clip it just distorts the waveshape so that it doesn't go above one. The higher the amplitude is above one the greater the distortion, which can be good sometimes for the 'analog' sound, basically a saturation algo on your output is soft limiting.

Hard limiting is actually clipping in that it clips the top of the waveform off, also affecting the sound.

Neither hard or soft limiting take into account the current amplitude.

kirkagurs/bootsys example would be a brickwall limiter, which justs adjusts the amplitude when it goes above one and doesn't distort the waveform like the other methods.

Thanks for this bootsy I think I'm going to use this on my synth, I've been playing around with limiting methods, I wanted to use a brickwall limiter but I couldn't make one efficent enough, but this one is thanks :D

Cheers ;)

Exo
The Developer Toolkit -- A collection of over 150 modules and counting. Available from the Registered Users forum.
User avatar
exonerate
smaniac
 
Posts: 1487
Joined: Sat Dec 30, 2006 1:57 pm
Location: England, West Yorkshire, Huddersfield

Re: Lightweight but decent limiter algo

Postby exonerate on Thu Oct 30, 2008 10:52 am

Ok I saw some glaring obvious optimizations so I just couldn't help my self :D .......
limiter ASM.osm
(1.98 KiB) Downloaded 370 times


Now the limiter is inside one ASM block, I've not checked the CPU usage but It will be considerabily less.

Cheers ;)

Exo
The Developer Toolkit -- A collection of over 150 modules and counting. Available from the Registered Users forum.
User avatar
exonerate
smaniac
 
Posts: 1487
Joined: Sat Dec 30, 2006 1:57 pm
Location: England, West Yorkshire, Huddersfield

Re: Lightweight but decent limiter algo

Postby bootsy on Thu Oct 30, 2008 12:42 pm

Awesome, Exo!

I'm now setting up a basic compressor without logencoding just to see how far we can go avoiding expensive log or exp operations. It already features attack and release control, simple ratio control and even soft knee.
The only drawback I can see at the moment is that the attack and release curve shape is different than on a logencoded stream but I maybe err on that.
Come and visit my Blog: Variety Of Sound
bootsy
essemilian
 
Posts: 370
Joined: Sat Jul 28, 2007 10:55 am
Location: Frankfurt, Germany

Re: Lightweight but decent limiter algo

Postby infuzion on Thu Oct 30, 2008 3:08 pm

bootsy wrote:...hard-clipping introduces heavy aliasing in any case (can't be compensated).
Very true! That's why most of the scenarios I listed I was expecting the signal to be over only 0.0001 or so.
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Lightweight but decent limiter algo

Postby aliasant on Thu Oct 30, 2008 3:40 pm

OK. Here is my latest small limiter code as asm. It is not optimized. I just turned it into asm to keep my secrets.
We really do need lockable modules!

There is a variable release ( same as the envelope follower we already have)
You can push it to about -60 dB reduction before it squeels. The louder the input the longer the release time needs to be.
At least if you dont want to much aliasing.

Oh. If you want to see how much it is compressing the signal use the red output. Hook it into a linear to dB converter.
You could do that in green.
Maybe someone can optimize this?
Code: Select all
//Limiter Code by Martin Rodensjo / aliasant
streamin in;
streamin release;
streamout out;
streamout red;
float rectified=0;
float c=0;
float thres=0;
float x=0;
float x1=0;
float env=0;
float F1=1;
float F0=0;
float F2=2;
float F1eM008=1e-008;
float F0P001=0.001;
float F1000=1000;
movaps xmm0,in;
cmpps xmm0,F0,1;
movaps xmm1,xmm0;
andps xmm1,F2;
movaps xmm2,F1;
subps xmm2,xmm1;
movaps xmm3,in;
mulps xmm3,xmm2;
movaps xmm4,xmm3;
addps xmm4,F1eM008;
//Assignment> sLeft=xmm4
movaps rectified,xmm4;
movaps xmm0,rectified;
subps xmm0,F0P001;
//Assignment> sLeft=xmm0
movaps x,xmm0;
movaps xmm0,F1000;
minps xmm0,x;
//Assignment> sLeft=xmm0
movaps x,xmm0;
movaps xmm0,F0;
maxps xmm0,x;
//Assignment> sLeft=xmm0
movaps x1,xmm0;
movaps xmm0,x1;
cmpps xmm0,env,5;
movaps xmm1,F0;
subps xmm1,release;
andps xmm0,xmm1;
movaps xmm1,release;
addps xmm1,xmm0;
//Assignment> sLeft=xmm1
movaps c,xmm1;
movaps xmm0,env;
subps xmm0,x1;
movaps xmm1,c;
mulps xmm1,xmm0;
movaps xmm2,xmm1;
addps xmm2,x1;
movaps xmm3,xmm2;
subps xmm3,F1eM008;
//Assignment> sLeft=xmm3
movaps env,xmm3;
movaps xmm0,env;
addps xmm0,F1;
movaps xmm1,F1;
divps xmm1,xmm0;
//Assignment> sLeft=xmm1
movaps red,xmm1;
movaps xmm0,red;
mulps xmm0,in;
//Assignment> sLeft=xmm0
movaps out,xmm0;
It's never to late to be late.....
http://martinrodensjo.smugmug.com/
User avatar
aliasant
smunatic
 
Posts: 2386
Joined: Sat Dec 30, 2006 5:49 pm
Location: Sweden

Re: Lightweight but decent limiter algo

Postby aliasant on Thu Oct 30, 2008 11:04 pm

Wow. I just compared the Kirkagur Limiter (optimised by you guys) and my own and they sound and act very very similar.
But the code is not that similar.
I made it in a different way and I think my limiter might sound better with shorter release times.
Probably because of the way I did the threshold but Im not sure.
They do sound alike with higher release times though. Very much alike.
It's never to late to be late.....
http://martinrodensjo.smugmug.com/
User avatar
aliasant
smunatic
 
Posts: 2386
Joined: Sat Dec 30, 2006 5:49 pm
Location: Sweden

Re: Lightweight but decent limiter algo

Postby exonerate on Thu Oct 30, 2008 11:24 pm

Bootsy do you mind me adding this limiter to the Developer toolkit ?

Cheers ;)

Exo
The Developer Toolkit -- A collection of over 150 modules and counting. Available from the Registered Users forum.
User avatar
exonerate
smaniac
 
Posts: 1487
Joined: Sat Dec 30, 2006 1:57 pm
Location: England, West Yorkshire, Huddersfield

Re: Lightweight but decent limiter algo

Postby infuzion on Fri Oct 31, 2008 3:53 am

exonerate wrote:Ok I saw some glaring obvious optimizations so I just couldn't help my self.. Now the limiter is inside one ASM block, I've not checked the CPU usage but It will be considerably less.
That's some tight ASM! I can't do better
/bow
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Lightweight but decent limiter algo

Postby bootsy on Fri Oct 31, 2008 9:14 am

exonerate wrote:Bootsy do you mind me adding this limiter to the Developer toolkit ?

Cheers ;)

Exo


If it's ok to kirkagur its fine to me :D
Come and visit my Blog: Variety Of Sound
bootsy
essemilian
 
Posts: 370
Joined: Sat Jul 28, 2007 10:55 am
Location: Frankfurt, Germany

Next

Return to Examples

Who is online

Users browsing this forum: Google [Bot] and 2 guests