Normalizing

Sound synthesis techniques, DSP and related mathematics

Moderators: electrogear, exonerate

Re: Normalizing

Postby kirkagur on Fri May 23, 2008 4:39 pm

this code dont work well because its output can be below 0
if i put a max(in,0) its will still be faster then the original???

Code: Select all
streamin In;streamout Out;float over=0;
float F0=0;
//Assignment> sLeft=In
movaps xmm0,In;
movaps over,xmm0;
//movaps xmm0,over;
cmpps xmm0,F0,5;
//movaps xmm1,xmm0;
andps xmm1,over;
//Assignment> sLeft=xmm1
movaps over,xmm1;
//Assignment> sLeft=over
movaps xmm0,over;
movaps Out,xmm0;

User avatar
kirkagur
essemilian
 
Posts: 365
Joined: Mon Jul 10, 2006 3:14 pm

Re: Normalizing

Postby aliasant on Fri May 23, 2008 4:51 pm

=)

Here is a faster Power code to use in the dB to Linear module.
There is a problem with this code that I dont really understand. It only works in mono.
What happens is that, if the inputs are stream and you feed it with a packed stereo signal the output will only be the left channel. The right channel is gone some how.

Maybe this is a feature ? ... it is a very fast code. 211 cycles compared to the one you used that was about 800 or more cycles.

What I did to get around that problem was that I unpacked the signal and used 2 codes, one on each channel and then packed them again. This works and still saves at least 400 cycles.

Heres that code. Only in asm Im afraid.
Code: Select all
streamin exp;
streamin bas;
streamout out;
//--- Variables...
float fBas = 0.0;
float fExp = 0.0;
float fAns = 0.0;
float fHlf = 0.5;
//--- Get the base/exponent values...
movaps xmm0,bas;
movaps fBas,xmm0;
movaps xmm0,exp;
movaps fExp,xmm0;
//--- base^exponent [0]...
fld fExp[0];
fld fBas[0];
fyl2x;
fld st(0);
fld fHlf[0];
fsub;
frndint;
fxch;
fld st(1);
fsub;
f2xm1;
fld1;
fadd;
fxch;
fld1;
fscale;
fstp st(1);
fmul;
fstp fAns[0];
//--- Move the answer into 'out'...
movaps xmm0,fAns;
movaps out,xmm0;
//--- Done!
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: Normalizing

Postby aliasant on Fri May 23, 2008 4:55 pm

kirkagur wrote:this code dont work well because its output can be below 0
if i put a max(in,0) its will still be faster then the original???

Code: Select all
streamin In;streamout Out;float over=0;
float F0=0;
//Assignment> sLeft=In
movaps xmm0,In;
movaps over,xmm0;
//movaps xmm0,over;
cmpps xmm0,F0,5;
//movaps xmm1,xmm0;
andps xmm1,over;
//Assignment> sLeft=xmm1
movaps over,xmm1;
//Assignment> sLeft=over
movaps xmm0,over;
movaps Out,xmm0;




OK. Thats the threshold code.. and yes. Something went wrong with it. Looking at it again.

UPDATE:

Here is it working. OBS: I included the mulitply with 0.00001 in this code so that can be removed after it.
Must have mixed them up before posting it....
Code: Select all
streamin In;streamout Out;float over=0;
float F0=0;
float F1P00001=1.00001;
//Assignment> sLeft=In
movaps xmm0,In;
movaps over,xmm0;
//movaps xmm0,over;
cmpps xmm0,F0,5;
//movaps xmm1,xmm0;
andps xmm0,over;
//Assignment> sLeft=xmm1
//movaps over,xmm0;
//movaps xmm0,over;
mulps xmm0,F1P00001;
//Assignment> sLeft=xmm0
movaps Out,xmm0;


/ original code /
streamin In;
streamout Out;
float over;
over = In;
over = over >= 2 & over;
Out = over*1.00001;
Last edited by aliasant on Fri May 23, 2008 5:14 pm, edited 1 time in total.
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: Normalizing

Postby aliasant on Fri May 23, 2008 5:09 pm

Lol im spamming today.

I just had to tell you that so far I have taken your original limiter 1258cycles down to 883cycles.
Pretty good for a noob =)
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: Normalizing

Postby kirkagur on Fri May 23, 2008 5:13 pm

amazing

great work aliasant its even sounds better :)
User avatar
kirkagur
essemilian
 
Posts: 365
Joined: Mon Jul 10, 2006 3:14 pm

Re: Normalizing

Postby aliasant on Fri May 23, 2008 5:17 pm

kirkagur wrote:amazing

great work aliasant its even sounds better :)


Yes it does =). But now i found a bug in the threshold code.

Remember that I changed to 0 to a 2?
When I hooked an oscillator running at high freqs and gain sometimes I get a harsh high nasty tone. This only happens and some positive gain values. like for now +6.1 dB. This is the gain for the test tone oscillator. I changed that 2 back to a 0 and its gone. No idea what that was all about. I also changed my post here of that threshold code.
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: Normalizing

Postby Andrew J on Sat May 24, 2008 3:06 am

aliasant wrote:There is a problem with this code that I dont really understand. It only works in mono.


Martin - this code does it's main bit of work in non-SSE ASM. You'll see the fExp[0] that refers to just one channel of the fExp variable for example. If you want this to be fully stream compatible, you have to repeat the calculations on [1], [2] & [3] as well. Of course, this takes 4 times as long. Optimisation will depending on how you need to pack/un-pack the signals. You can either use the code as a mono component, or re-write it to work on 2 channels.
Andrew J
smanatic
 
Posts: 616
Joined: Tue May 29, 2007 4:53 am
Location: Australia

Re: Normalizing

Postby aliasant on Sat May 24, 2008 4:33 am

Andrew J wrote:
aliasant wrote:There is a problem with this code that I dont really understand. It only works in mono.


Martin - this code does it's main bit of work in non-SSE ASM. You'll see the fExp[0] that refers to just one channel of the fExp variable for example. If you want this to be fully stream compatible, you have to repeat the calculations on [1], [2] & [3] as well. Of course, this takes 4 times as long. Optimisation will depending on how you need to pack/un-pack the signals. You can either use the code as a mono component, or re-write it to work on 2 channels.



Aaah.

So..

Do you mean llike this?
Code: Select all
fld fExp[0];
fld fExp[1];
fld fBas[0];
fld fBas[1];
fyl2x;
fld st(0);
fld st(1);
fld fHlf[0];
fld fHlf[1];


Or this?
Code: Select all
fld fExp[0,1];
fld fBas[0,1];
fyl2x;
fld st(0,1);
fld fHlf[0,1];


Would any of those two work as a stereo code?
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: Normalizing

Postby Andrew J on Sat May 24, 2008 10:09 am

More like the first one, but you probably have to complete all the calculations on [0] before you do the ones on [1], otherwise you're just going to overwrite variables before anything much is done with them. (Too busy to explain this properly now, but email me the schematic if you like and I'll look at it another day).
Andrew J
smanatic
 
Posts: 616
Joined: Tue May 29, 2007 4:53 am
Location: Australia

Previous

Return to Sound

Who is online

Users browsing this forum: No registered users and 0 guests