Speed knob scaling formula?

Reid115
Reid115 Member Posts: 47 Member
edited January 2022 in Scripting Workshop

https://vi-control.net/community/threads/what-is-the-formula-for-this.3978/

https://www.native-instruments.com/forum/threads/calling-nicki-marinic-or-other-scripters-good-at-math.37073/#post-233780

These are the only real discussions I could find on this topic, and they're from 2006. Basically I need the percent value (0-800%) that's set with the speed knob in TM2 mode. I need this value because I need to determine how long it takes for a part of my sample to play. Approximations won't work for my needs -- even a few milliseconds of error could be a problem. What is the current best solution for this? Has anyone ever figured out the formula(s)? If not, is the lookup table given in that forum post the furthest anyone has gotten? I figured I could have my speed knob snap to whole percent values and then look up the 0-1000k value to send to the real speed knob. The lookup table in those threads starts jumping by 10 at 150.

https://pastebin.com/raw/MSXs19gm

Best Answer

  • EvilDragon
    EvilDragon Moderator Posts: 1,021 mod
    edited January 2022 Answer ✓

    If you use SublimeKSP, you can use these two conversion functions, for engine par to real-world value, and vice versa:

       define int(x) := real_to_int(x)
       define real(x) := int_to_real(x)
    
       function math.log2(value) -> return
           return := log(value) / log(2.0)
       end function
    
       function math.cbrt(value) -> return
           return := pow(value, 1.0 / 3.0)
       end function
    
       {
           USAGE
           E2V -> Engine Parameter to Real-World
           V2E -> Real-World to Engine Parameter
    
           ARGS
           x - input number for equation.
    
           INFO
           Fundamental equation: speed = 2^[K * (X^3 + 1) + A, K = 2.807354922, A = 7.380821784
           E2V output and V2E input: 0.0% to 800.0% (scaled by 10)
           Accepts and returns only integers!
       }
       define E2V.SPEED_BASE(ep) := int(round(pow(2.0, 2.807354922 * (pow(((float(ep) - 500000.0) / 500000.0), 3.0) + 1.0) + 7.380821784) - 166.666666))
       define V2E.SIGN(ep) := ((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0) / abs(((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0))
       define V2E.SPEED_BASE(ep) := int(math.cbrt(abs((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0)) * (V2E.SIGN(ep) * 500000.0) + 500000.0)
    
       function E2V.speed(x) -> return
           return := E2V.SPEED_BASE(x)
       end function
    
       function V2E.speed(x) -> return
           return := V2E.SPEED_BASE(x)
       end function
    

Answers

  • Wolinger
    Wolinger Member Posts: 19 Helper

    @Matt @ NI knows anyone can help this guy? I never seen this before and i don't know how to help him.

  • Matt_NI
    Matt_NI Administrator Posts: 1,088 admin

    This is way beyond my level of expertise 😅

    It's something for @EvilDragon perhaps.

  • EvilDragon
    EvilDragon Moderator Posts: 1,021 mod
    edited January 2022 Answer ✓

    If you use SublimeKSP, you can use these two conversion functions, for engine par to real-world value, and vice versa:

       define int(x) := real_to_int(x)
       define real(x) := int_to_real(x)
    
       function math.log2(value) -> return
           return := log(value) / log(2.0)
       end function
    
       function math.cbrt(value) -> return
           return := pow(value, 1.0 / 3.0)
       end function
    
       {
           USAGE
           E2V -> Engine Parameter to Real-World
           V2E -> Real-World to Engine Parameter
    
           ARGS
           x - input number for equation.
    
           INFO
           Fundamental equation: speed = 2^[K * (X^3 + 1) + A, K = 2.807354922, A = 7.380821784
           E2V output and V2E input: 0.0% to 800.0% (scaled by 10)
           Accepts and returns only integers!
       }
       define E2V.SPEED_BASE(ep) := int(round(pow(2.0, 2.807354922 * (pow(((float(ep) - 500000.0) / 500000.0), 3.0) + 1.0) + 7.380821784) - 166.666666))
       define V2E.SIGN(ep) := ((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0) / abs(((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0))
       define V2E.SPEED_BASE(ep) := int(math.cbrt(abs((math.log2(float(ep) + 166.66666) - 7.380821784) / 2.807354922 - 1.0)) * (V2E.SIGN(ep) * 500000.0) + 500000.0)
    
       function E2V.speed(x) -> return
           return := E2V.SPEED_BASE(x)
       end function
    
       function V2E.speed(x) -> return
           return := V2E.SPEED_BASE(x)
       end function
    
  • Reid115
    Reid115 Member Posts: 47 Member

    Awesome, thanks ED.

Back To Top