SynthMaker

tutorial - from sm primitives to code to asm

Archive · 2009 15 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

MichaelBenjamin ·

i made a small tutorial for beginners, how to put a basic math operation into a code expression and then into an asm module. basically you should atleast do this with all sm math primitives in your schematic before you release it to the public. this easily saves ~50% of cpu processing time and makes the processing more stable, less spikey. if you want to learn more about asm, a good next step would be exonerates asm tutorial at the wiki: [old link] note, that you can usually save much more cpu the bigger the code modules and the bigger your dedication to puzzling around with 8 xmm registers is.

Nu Audio Science ·

When you say all math do you mean just stream math right ? Not green math I'm a little confused on that

Oh and thanks for the tutorial 😉

NAS

hansdump ·

Nice Tutorial. Newbies will be happy!!

H.

AlexT ·

Thanks for that. It's a nice tutorial and certainly helps those of us that no nothing or very little about ASM. 🙂

Neptune ·

hansdump wrote: Nice Tutorial. Newbies will be happy!! H.

Yes, i'm really happy about it Thanks a lot!! But how about a little complexer example like this

I tried to do it in code but failed as expected 🙂

MichaelBenjamin ·

yes this is a bit harder. look at the end - something gets added to left and substracted to right (its the result of the multiplication)

so lets say the result of the multiplication is x

out1=in1+x; out2=in2-x;

so what is x?

x is something multiplied with the dezipper, so x=y*dezip now y: y is left input minus something, so y=in1-z

almost there, now its easy, because z is (left+right)/5 - note that you need the parentheses because first left and right needs to be aded, then the result is divided. now you can write: y: in1-((in1+in2)/5) and x: (in1-((in1+in2)/5))*dezip

and now as code: streamin in1; streamin in2; streamin amount; //was dezip, but amount makes more sense streamout out1; streamout out2; float mix;//temp variable to store the number that gets added and substracted

mix=(in1-((in1+in2)/5))*amount; out1= in1+mix; out2= in2-mix;

as an additional optimisation you can exchange divisions with constants by a multiplication with 1/constant, this saves cpu time so instead of /5, write *0.2

mix=(in1-((in1+in2)*0.2))*amount; out1= in1+mix; out2= in2-mix;

Nu Audio Science ·

just used this to shave some CPU out of one of my schematics, only simple stuff I combined a balance and auto balancer and converted to ASM then converted my stereo wet/dry to ASM cheers for this MB has given me a tiny understanding of ASM

NAS

Nu Audio Science ·

You know what i just done some heavy duty tests and to be honest i wish i had kept the coded versions over the ASM versions for some of my plugs because compiled the ASM is using significantly more CPU than the ASM And that is a straight 1:1 code to ASM comparison If i can find the coded versions in an older save on my drive i will put together a comparison OSM but i have to be honest at this point i dont think the 1:1 code to ASM thing is of any use at all I would guess you need to heavily optomise the ASM once copied to even get close to the straight code in these examples

NAS

aliasant ·

Nu Audio Science wrote: You know what i just done some heavy duty tests and to be honest i wish i had kept the coded versions over the ASM versions for some of my plugs because compiled the ASM is using significantly more CPU than the ASM And that is a straight 1:1 code to ASM comparison If i can find the coded versions in an older save on my drive i will put together a comparison OSM but i have to be honest at this point i dont think the 1:1 code to ASM thing is of any use at all I would guess you need to heavily optomise the ASM once copied to even get close to the straight code in these examples

NAS

Hmm. SOmething is wrong. When I take a code block, convert it to asm and optimize it I at least save 40%. Often more. If I can combine several code blocks into one before optimizing it I will save even more.

Edit: I read you ENTIRE post now 😉. Yes. Code to ASm 1:1 doesnt do anything. Not that I know of. Its not until you start optimizing it that you see the gains.

Update: Heres an example of what I did today.

I had the original RMS code that someone made. Sorry. Cant remember who.

It uses 78.2 on my machine. It is 4 channels and 2 blocks of code. Not very efficient. Now I only needed 1 channel since Im using it for mono so I converted it to asm, ripped out 3 channels, optimized some + added the squareroot part in the same asm block. The new one now uses 43 cycles so I gained 35 cycles on that. And as others have mentioned, it makes the code run more stable. Im planning to combine this part with several other parts and I think that will save me even more on this project 🙂

Here is the Mono RMS code. Maybe someone can optimize it even further?

streamin in; streamout out; float smIntVarTemp=0.0; int smIntVarArrayIndex=0; float smIntVarZero=0; float arymax=255; float n=0; float acum=0; float in2=0; float F0=0; float F256=256; float F1=1; float ary[256]; movaps xmm3,F0; movaps xmm7,in; mulps xmm7,xmm7; movaps in2,xmm7; addps xmm7,acum; movaps xmm6,n; maxps xmm6,smIntVarZero; minps xmm6,arymax; cvtps2dq xmm6,xmm6; movaps smIntVarArrayIndex,xmm6; push eax; mov eax,smIntVarArrayIndex[0]; shl eax,4; fld ary[eax]; fstp smIntVarTemp[0]; movaps xmm1,smIntVarTemp; pop eax; subps xmm7,xmm1; maxps xmm7,xmm3; movaps acum,xmm7; movaps xmm4,n; maxps xmm4,smIntVarZero; minps xmm4,arymax; cvtps2dq xmm4,xmm4; movaps smIntVarArrayIndex,xmm4; push eax; mov eax,smIntVarArrayIndex[0]; shl eax,4; fld in2[0]; fstp ary[eax]; pop eax; divps xmm7,F256; movaps xmm0,n; addps xmm0,F1; movaps n,xmm0; mov eax,ecx; and eax,255; cmp eax,0; jnz end0; movaps n,xmm3; end0: sqrtps xmm1,xmm7; movaps out,xmm1;

infuzion ·

aliasant wrote: Here is the Mono RMS code. Maybe someone can optimize it even further?

... divps xmm7,F256;...

Maybe acum/256 = aculm*(1/256)?

MyCo ·

@aliasant: in the code you removed the other 3 SSE channels, so it won't work on a polyphone system

aliasant ·

MyCo wrote: @aliasant: in the code you removed the other 3 SSE channels, so it won't work on a polyphone system

Lol. Yes. I said so in my post too. I only needed a mono version.

MyCo ·

damn... haven't read it... too much text 😈

aliasant ·

MyCo wrote: damn... haven't read it... too much text 😈

LOL Sorry 🙂

robrokken ·

This is really great stuff! I'm just at the point of learning whats actually inside the code boxes!!!

Excellent!

Rob.

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.