# Reverse Engineering for Engine Parameters



## Big Bob (Mar 6, 2009)

Hi All,

One by one, I have been 'reverse engineering' many of Kontakt's ep control functions and posting the formulae. In addition, I have been updating the *KSP Math Library *periodically by adding new format conversion routines to assist with using engine parameter control of various parameters such as volume, pitch, EQ, envelope time, etc.

However, before I update all the documentation and prepare for release of *V215* of the *KSP Math Library *package, I'd like to give you an opportunity to tell me if there are any ep format conversion formulae that are still needed? If so, drop a post about it and, if possible, I'll try to include some routines to handle it in the upcoming V215 update.

Maranatha,

Bob


----------



## tmhuud (Mar 6, 2009)

Looking forward to your new efforts Bob!

Cheers,


----------



## Big Bob (Mar 6, 2009)

Thanks Terry,

But, just to clarify, there aren't any new efforts yet :lol: As of the last source module update, V212, there are now 15 format conversion routines (not counting the legacy alias for Get_db).

What I am interested in knowing is whether or not any of you have been wishing for another conversion routine or two? Perhaps some of you have been working around the problem by using a lookup table (array) and if so, and If I can deduce the function that Kontakt is using, I'll try to include a routine or two in V215 to handle it.

So, please let me know if there is some transfer function that you need that is not yet covered in V212. For example, the most recent request was for the formula relating EQ Frequency to its corresponding engine parameter. That led to the 6 new EQ functions added with V212.

Maranatha,

Bob


----------



## Big Bob (Mar 9, 2009)

OK Last Call,

Any ep control functions that need reverse engineering?

I'm just about done updating the Documenatation package for V215 of the KSP Math Library. When its done, if no one has posted anything here, I'll just ask Andrew to update the download package.

Last Call :lol: 

Maranatha,

Bob


----------



## Thonex (Mar 9, 2009)

Big Bob @ Mon Mar 09 said:


> OK Last Call,
> 
> Any ep control functions that need reverse engineering?
> 
> ...



I'm swamped Bob... let me think about this for 1/2 a minute.... any longer and I know you'll already have reversed engineered it and solved the national dept too :lol:


----------



## gh (Mar 9, 2009)

Hi Bob!

Thank you for your continuous efforts to make things easier. You are truly an inspiration.

Maybe it’s too late for this release of the wonderful math lib but how about a conversion routine for the speed parameter of the source module? I noticed in the description of version 212 that the Root3 function could be used for time conversion but I simply can’t figure out how.

Best 
Günter


----------



## Thonex (Mar 10, 2009)

Bob,

I'm not at my studio right now.. so I can't see what you've already covered.

One thing that may be useful is a Envelope Attack Time to EP conversion.

Cheers,

Andrew K


----------



## Dynamitec (Mar 10, 2009)

@Andrew:

AtkTime_to_ep(t,N)

Already there


----------



## Big Bob (Mar 10, 2009)

> but how about a conversion routine for the speed parameter of the source module?



Hi Günter,

Thanks for the suggestion, I'll look into this before I release V215.

And Andrew,

I see that Benjamin has already responded about this but, I might mention that *AtkTime_to_ep *was added in V211 already :roll: You really must be busy if you didn't see that thread :shock: Come up for air once in a while to smell the roses my friend, there should be more to life than work, work, work :lol: 

(I should talk, I haven't had a free moment since I retired over 20 years ago. I wonder how I ever found time to make a living? :? )

God Bless,

Bob

BTW Benjamin, have you noticed this newcomer using the name Dynamick, too similar to your screen name :? Between that and trying to swat Andrew's Bug running around the bottom of his posts, I'm going nuts. :roll:


----------



## Thonex (Mar 10, 2009)

Bob... You probably already know this... but maybe this can help in some way:

Speed on the Time Machine can lock to tempo. If you right-click on the "%" sign of the Speed knob, you'll see a drop-down menu of all the different beats. 

Cheers,

T


----------



## Big Bob (Mar 10, 2009)

Thanks Günter, I'll try to tackle it tomorrow then but, no promises because it may be a brainbuster :lol: 



> Bob... You probably already know this... but maybe this can help in some way:



No Andrew, I didn't know that because I have never used the tone/beat modes. I tried right clicking the % sign but I don't see the drop down you indicated (just a list of the usual modulators), perhaps it appears only when runnng Kontakt as a plugin? I only tried K2 standalone, maybe K3 is different?

In any case, I'm not sure what difference this would make insofar as the transfer function is concerned. I presume that the relationship between Speed and its corresponding engine parameter is unaffected by these sync issues, No? :roll: 

To be continued .....

Bob


----------



## Thonex (Mar 10, 2009)

Big Bob @ Tue Mar 10 said:


> Thanks Günter, I'll try to tackle it tomorrow then but, no promises because it may be a brainbuster :lol:
> 
> 
> 
> ...



Hi Bob, 

I just tried clicking on the "%" sign under the "Speed" heading and I was able to get the drop-down. And this is with a stand-alone Kontakt 3. I'm 99.9% sure it's the same with K2.

Make sure you click on the actual % sign. It's funny that way.

Cheers,

Andrew


----------



## Big Bob (Mar 10, 2009)

Doesn't do it for me Andrew :? I tried both K2 and K3. I loaded a new default instrument, set the source module to one of its tone/beat modes and then right clicked on the % sign. All I get is the usual menu of modulators. What am I doing wrong?

Bob

EDIT: Whoops, if I left click I see it. Now where did I get the idea you said right click? :oops:


----------



## Thonex (Mar 10, 2009)

Big Bob @ Tue Mar 10 said:


> EDIT: Whoops, if I left click I see it. Now where did I get the idea you said right click? :oops:



ummm... that would be from me :oops: o I meant the "other" right 0oD


----------



## Big Bob (Mar 11, 2009)

Hi Günter,

I'm glad Andrew brought up the tempo-sync stuff because *it does alter the transfer function*. So now the Speed/Engine-Parameter function is even more of a royal mess. The default function itself is a very difficult curve to fit but now we have the complication of the sync to tempo modes.

So, before I spend any more time on this, please describe for me how you intend to use this format-conversion routine. As I indicated earlier, I don't use the tone, time, or beat machine modes so you will have to be very detailed in your description of what you would want this conversion routine to do for you. Do you sync to tempo? If so, do you then want this function to change? etc, etc, etc.

And Andrew, I don't know why it took me so long to pick up on the fact that you meant my 'other' right mouse button, it was sitting right there with my 'left-handed' monkey wrench. :lol:


----------



## Dynamitec (Mar 11, 2009)

Nobody every replied to my post here:
http://vi-control.net/forum/viewtopic.php?t=8739

But the tempo (Percent) to EP function works pretty well.


----------



## Big Bob (Mar 11, 2009)

Hi Benjamin,

Thanks for the links. I vaguely remember seeing this but since I don't use this stuff I never studied it. I notice that Peter commented on the strangeness of the default Speed curve and noted that for the right half from N = 500000 to N = 1000000 the cubic would work, ie (N/500000)^3. However, it really doesn't work, not even in the right half. It misses by a mile at N = 750000 where Speed is supposed to be 132 but the cubic would produce 337%.

So far the best fit I found for the right half is a double exponential but then it doesn't fit the left half. As I said a few posts back, it may not be a continuous function. But, it does look a bit +/- symetrical about a mean of N = 420,800. In any case, this has got to be the oddest NI function yet. But, why would they use such an obscure curve? :? Maybe this is something real simple internally but I sure haven't nailed it yet if it is. :roll: 

However, Günter, perhaps you could accomplish your objective with Benjamin's script? Remember I've put this on hold until I hear back from you with answers to the questions I posted just prior to this.

I'll hold the release of V215 open for a few days yet, but, please let me know one way or the other how this turns out. If there really is a vital need for me to 'crack' this function I'll take another whack at it but, it won't be easy so I would just as soon avoid it :lol: 

God Bless,

Bob


----------



## gh (Mar 11, 2009)

Hi Bob!

Thank you for taking the time to look into the speed function. Like Benjamin I have been using a lookup table approach in the past. 

I 

a)	was just curious how the ep of 0 – 1000000 relates to 0% to 800%
b)	want to get rid of the lookup tables

Both, an ep -> % and a % -> ep function would be nice but it’s NOT a big issue. Don’t spend your valuable time if you don’t find a quick solution.

Best
Günter


----------



## Big Bob (Mar 11, 2009)

I have a double exponential worked out now that I think will do the job. But, I had to set it aside until I get a reasonable block of time to finish it up. As soon as I have the time I'll finish it up and post it, plus I'll add it to the V215 Library. Stay tuned....

Bob


----------



## Big Bob (Mar 12, 2009)

My double exponential (that tracked the right half of the curve) only needed one more constant to enable it to track the left half also. Here are the formulae for the Speed function. 

```
for Speed in terms of N:
Speed = 2^[K*(X^3 + 1) + A] - 50/3  where K = 2.807354922 and A = 4.05889369
          and X is the bipolar engine parameter N, ie X = (N - 500000)/500000

        or for N in terms of Speed:
X = {[Lg(3*Speed + 50)]/K - B}^1/3    where B = 3.010382137
```

I have also recast these expressions for the all-integer arithmetic of the KSP and as soon as I have them optimized for the Math Library I will post them here and, of course, I will also include them in the V215 release (coming soon).

Maranatha,

Bob


----------



## Thonex (Mar 12, 2009)

Big Bob @ Thu Mar 12 said:


> My double exponential (that tracked the right half of the curve) only needed one more constant to enable it to track the left half also. Here are the formulae for the Speed function.
> 
> ```
> for Speed in terms of N:
> ...



WOw :shock: 

Do you think that's what NI used? I mean... it is 100% accurate in your testing?

That would be amazing if it was.
This is great Bob... I don;t know how you do it... but I'm consistently blown away.

Cheers,

Andrew k


----------



## Big Bob (Mar 12, 2009)

Hi Andrew,



> Do you think that's what NI used? I mean... it is 100% accurate in your testing?



We can never be sure that any of our 'reverse-ingineered' functions are precisely what NI is doing (unless they tell us). However, it may not really matter much because all we are interested in is how well our formulae track the actual control function itself (over the entire domain of interest). 8) 

I have no idea why NI chose such a complex function for Speed but apparently they did. Even if we don't have it precisely the same, they must be doing something very similar (in order to achieve the curve they are following). :? 

I haven't quite finished optimizing the KSP version yet but I'm attaching an .nki with the current version so you can see for yourself how well it tracks. Incidentally, the optimization I'm referring to is not tweaking the formulae but rather arranging the arithmetic operations for maximum precision. Keep in mind that NI uses floating point internally whereas we're stuck with all-integer arithmetic.

For the Demo Script, the value of the KSP panel Speed knob (which displays its own setting as a value from 0 to 800) is converted by the *Speed_to_ep *routine and the calculated *ep* is displayed on the first line of the Info Box. This *ep* value is then sent to Kontakt's Speed knob and it's displayed value (via _get_engine_par_disp) is mirrored on the 3rd line as *K Speed*. Finally, the routine *ep_to_Speed *is used to calculate the equivalent speed value which is displayed on the 2nd line as *ep Speed*. Therefore, the value displayed for *ep Speed *is double converted (ie run through both* Speed_to_ep *and *ep_to_Speed*).

I may be able to improve this slightly when I get another block of time to finish the optimization process. However, even if it gets no better, I think it tracks quite well over the entire range. :mrgreen: 

*Attention Günter and Andrew*
Of course I haven't the faintest idea of how the sync to tempo stuff works and what you use it for. I do notice that the numbers that Kontakt displays for the Speed knob seem to be quite different than for the default mode. So, maybe these routines will only be appropriate for the default mode. You guys that use this stuff will have to tell me whether this is or isn't what you wanted. :? 

God Bless,

Bob


----------



## gh (Mar 13, 2009)

Andrew: we simply have to admit: he is a genius. I would not have figured that out in a hundred years.

Bob: Thank you. I will check the demo patch. I ususally don't use the "linked" mode so I don't care.

Best
Günter


----------



## Thonex (Mar 13, 2009)

Bob,

I just tried out your scrip... it's very very accurate.... especially where it really counts!!!

From 50%-200% it's pretty much DEAD ON. Beyond that, it's still very accurate.... but when doing speed of 200% or more in Kontakt... there is a fair amount of audible artifacting... so I try to sòÛ+   ˜FzÛ,   ˜EµÛ,   ˜E¶Û,   ˜F{Û,   ˜F|Û,   ˜F}Û,   ˜F~Û,   ˜FÛ,   ˜F€Û,   ˜FÛ,   ˜F‚Û,   ˜FƒÛ,   ˜F„Û,   ˜F…Û,   ˜F†Û,   ˜F‡Û,   ˜FˆÛ,


----------



## Big Bob (Mar 13, 2009)

gh @ Fri Mar 13 said:


> Andrew: we simply have to admit: he is a genius. I would not have figured that out in a hundred years.
> 
> Bob: Thank you. I will check the demo patch. I ususally don't use the "linked" mode so I don't care.
> 
> ...



I was fortunate to stumble into a shortcut that allowed me to shave at least an hour or two off from the hundred years :lol: 

Since the tempo-synched mode is not important to you, I guess I'm done then except for finishing the arithmetic optimization. When that's done, I'll post the KSP routines and then add them to the V215 Math Library.

Thanks for the suggestion to include these functions in the Library.

God Bless,

Bob

BTW Thank you all for your encouraging remarks.


----------



## Big Bob (Mar 13, 2009)

> Bob... the tempo-synched mode is VERY important to me.. but I 'm not sure if it makes sense to do any calculations since one can always use $eP = $DURATION_QUARTER or similar.



Hi Andrew,

To clarify, *I know nothing *about using this feature. However, I did notice that when one of the non-default options is chosen, the Speed knob then displays something quite different from what it displays in the '<Default>' mode. In fact, it seems to display something different for each sync-to-tempo option.

I was merely asking if I was supposed to do something with these new format conversion routines to handle that in some way (or am I supposed to cook up more conversion routines :( ). If so, you would first have to educate me as to what it all means, etc and/or define what kind of format-conversion functions would be required in those modes. Naturally, I would just as soon not get involved beyond what I already have done because I'm already in way over my head :roll: As I said from the beginning, I have never used these modes at all :oops: 

In the meantime, I have finished the arithmetic optimization, so here are the two KSP routines for those of you who just can't wait for the release of V215 :lol: 

_{-------------------------------------------------------------------- 
ep_to_Speed(N,S) Convert Engine Parameter value, N,
to its equivalent Speed value, S

'N' = Input Engine Parameter, 0..1,000,000
'S' = Output Speed value, 0..800%

This function implements S = 2^[K*(X^3 + 1) + A] - 50/3
where X = (N - 500000)/500000, K = 2.807354922,
and A = 4.05889369 }_ 

*function* ep_to_Speed(N,S)
``*declare* u
```````````````````````````````````_{ X = (N - 500000)/500000 }_
``u := (N + 25)/50 - 10000`````````_{ u = 10000*X }_
``u := u*((u*u + 500)/1000)/1000```_{ u = 1000000*X^3 }_ 
``u := (991*(u + 1000000) + 177)/353 + 4058894 _{ u = 1000000*[K*(X^3 + 1) + A] }_
``Exp2(u,S)```````````_{ S = 2^[K*(X^3 + 1) + A }_
``S := (6*S - 97)/6```_{ S = S - 50/3 }_
*end function* _{ ep_to_Speed }_

_{-------------------------------------------------------------------- 
Speed_to_ep(S,N) Convert Speed value, S, to its
equivalent engine parameter, N

'S' = Input Speed value, 0..800%
'N' = Output Engine Parameter, 0..1,000,000

This function implements X = [Lg(3*S + 50)/K - B]^1/3
where X = (N - 500000)/500000, K = 2.807354922,
and B = 3.010382137 }_ 

*function* Speed_to_ep(S,N)
``*declare* u
``````````````````````````_{ X = (N - 500000)/500000 or N = 500000*X + 500000 }_
``u := 3*S + 50
``Log2(u,N)```````````````_{ N' = 10000*Lg(3*S + 50) }_
``u := 100*N - 8451211````_{ u = 1000000*[Lg(3*S + 50) - B*K] }_
``Root3(u,N)``````````````_{ N' = 10^7*[Lg(3*S + 50) - B*K]^1/3 = X*10^7*K^1/3}_
``N := (131*N + 1848)/3696 + 500000``_{ N = K'*N' + 500000 }_
``_{ where K' = 500000/(10^7*K^1/3) = 0.03544357852 = 131/3696 }_
*end function* _{ Speed_to_ep }_ 

I intend to release V215 just as soon as I can update the Tech Guide to include these new format-conversion routines so, hopefully, you will be willing to replace V210 on your web site with the updated package when I send it to you? 

God Bless,

Bob


----------



## Thonex (Mar 13, 2009)

Hi Bob,





Big Bob @ Fri Mar 13 said:


> I was merely asking if I was supposed to do something with these new format conversion routines to handle that in some way (or am I supposed to cook up more conversion routines :( ). If so, you would first have to educate me as to what it all means, etc and/or define what kind of format-conversion functions would be required in those modes. Naturally, I would just as soon not get involved beyond what I already have done because I'm already in way over my head :roll: As I said from the beginning, I have never used these modes at all :oops:



I wouldn't bother with it. It's easy to just use the $DURATION_ variables to get the desired tempo and whatnot. You've already done so much.. it don't think there's really be a point to reverse engineer the Tempo stuff. At least that I can see.


Cheers for all your great work Bob... I'm sure I'm not alone in saying that we would be lost without all your contributions.

Cheers,

T


----------



## Dynamitec (Mar 17, 2009)

I read a study recently which said that there is prove (according to neurologists) that the efficiency of our brain starts to decrease at the age of 27. While I can find some indication myself :mrgreen: I'm really wondering about two things 1) is this really true and 2) if so, what kind of brain would Bob have had when he was 25 >8o -- given the constant release of stunning insights into technical aspects of things some of us might use (if at all) but don't really understand


----------



## Big Bob (Mar 17, 2009)

> the efficiency of our brain starts to decrease at the age of 27



Wow, if that's true Benjamin, then you've already started on the downslope :shock: 

As for me, I must have crashed and burned a long time ago. :lol: 

But thanks for the kind words anyway. Now if only I could remember what I was planning to do next (Hmmmmmm)????

Bob


----------



## ComposerDude (Mar 18, 2009)

The rumors of Einstein's death have been exaggerated. Stymied on the Unified Field Theory, he went into retirement, finally got a haircut and a shave, wears sunglasses to remain incognito, and keeps mentally active scripting Kontakt under an assumed name.


----------



## Thonex (Mar 18, 2009)

ComposerDude @ Wed Mar 18 said:


> The rumors of Einstein's death have been exaggerated. Stymied on the Unified Field Theory, he went into retirement, finally got a haircut and a shave, wears sunglasses to remain incognito, and keeps mentally active scripting Kontakt under an assumed name.




:lol: :lol: :lol: 

I was totally laughing out loud on that one.....

:mrgreen:


----------



## Big Bob (Mar 18, 2009)

Then the value of a haircut must have gone up. It was formerly thought that in the world of e = mc^2, a haircut = 0 :lol: 

Oh well, just goes to show you that nothing is unchanging :roll:

BTW Peter, how is your Super Sampler coming along?


----------

