Yot ·
I'm looking for some module like the Rectify in the reaktor. dose anyone know where to find it ? thank u
From the original SynthMaker forum (2004–2014), with its members’ names and dates.
Yot ·
I'm looking for some module like the Rectify in the reaktor. dose anyone know where to find it ? thank u
oddson ·
I think the following code snippet should work:
streamin in; streamout out;
out = in - (in<0 & 2*in);
It says
out = in - 0, if in>=0
and
out = in - 2*in (which is minus 'in'), if in<0
I'm sure the assembly language crowd could knock a few cycles off it but I'm pretty sure it will work.
You can search on 'absolute value' to see what else is on the forum on this as that's what a rectified signal is.
edit - try this thread: Which Abs is faster?
stw ·
oddson wrote: I think the following code snippet should work:
streamin in; streamout out;
out = in - (in<0 & 2*in);
It says
out = in - 0, if in>=0
and
out = in - 2*in (which is minus 'in'), if in<0
I don't know what the rectify code should do, but this throws out the absolute value of in. in-2*in in case of a negative value is plus in. E.g. -2 - (2 * -2) = -2 -(-4) = -2+4 = 2
Yot ·
thanks
MichaelBenjamin ·
in asm you can later then exchange the complete line with a single andps command to get the absolute value. it is some trick with zeros and ones and integer and floats that one bright mind found out, and i dont understand how, but it works anyway. btw can anybody explain why that integer andpsed with something makes all negative positive?
here is the example:
streamin in; streamout absolute; int absmask=2147483647; //magic number movaps xmm0,in; andps xmm0,absmask; //magic number in action movaps absolute,xmm0;
exonerate ·
MichaelBenjamin wrote: in asm you can later then exchange the complete line with a single andps command to get the absolute value. it is some trick with zeros and ones and integer and floats that one bright mind found out, and i dont understand how, but it works anyway. btw can anybody explain why that integer andpsed with something makes all negative positive?
here is the example:
streamin in; streamout absolute; int absmask=2147483647; //magic number movaps xmm0,in; andps xmm0,absmask; //magic number in action movaps absolute,xmm0;
Well the number 2147483647 is the largest number possible for a signed integer.
That number in binary is 0111 1111 1111 1111 1111 1111 1111 1111.
In binary the first bit is the sign bit, 0 is positive, 1 is negative.
So you can see that anding a number with 2147483647 will set the sign bit to 0, hence positive.
Well I guess this is only obvious if you understand what anding is doing at a binary level (I'm assuming you do).
Cheers 😉
Exo
MyCo ·
This integer is in binary presentation a zero in the MSB followed with 31 ones: 01111111111111111111111111111111
a 32bit float stores the sign in the MSB (the first bit), so if the first bit is one, the whole float is negative, if it is zero, the whole float is positive. And I guess you know what AND does...
You can't define a float with this bitmask, because in float representation, this float is not a number (a postive NaN)
I've attached a file to demonstrate Integer bitmask relations
MyCo ·
damn! Exo was 3 minutes faster in writing his post 🙂
MichaelBenjamin ·
ah i see, thanks for the explanation. so with special integers you could do other computationally cheap effects, maybe a some kind of bitcrusher that zeroes some information on the right side of bits. do you know of any other tricks with integer masking that work like this?
MyCo ·
no, you can't do much magical bitmasking because the float format is realy complicated.
Here are some other things that you can do:
signing a value:
streamout o; int mask=-2147483648; float test = 1.2345;
movaps xmm0,test; orps xmm0,mask; movaps o,xmm0;
divide by two (not very accurate):
streamout o; int mask=-8388608; float test = 1.2345;
movaps xmm0,test; paddd xmm0,mask; movaps o,xmm0;
multiply by two:
streamout o; int mask=8388608; float test = 1.2345;
movaps xmm0,test; paddd xmm0,mask; movaps o,xmm0;
you can do this multiply by 2^x stuff with mask = 8388608*x
eg. multiply by 4 -> mask = 8388608 * 2 eg. multiply by 8 -> mask = 8388608 * 3 eg. multiply by 16 -> mask = 8388608 * 4
same goes with divide:
eg. divide by 4 -> mask = -8388608 * 2 eg. divide by 8 -> mask = -8388608 * 3 eg. divide by 16 -> mask = -8388608 * 4
MichaelBenjamin ·
thank you, especially the sign one looks useful.
Wrote something here? To have a post removed or your name hidden, write to [email protected].