What's new

Need linear volume knob from 0 to 100 percent (done)

Julian Ray

New Member
Hello,

I am working on my first Kontakt Instrument and I'd like my custom volume knob to be linear and change volume from 0% to 100%. Is it possible to achieve and where should I start?

Thank you!
 
Sure, what dB level do you want at 0% as well as dB level at 100%? Do you want fractions in 100ths like 72.34% or maybe just 10ths, 72.3%?

I think For a good answer to your question, it would be important to know the answer to those questions.
 
Normally in digital 100% equals 1 and 0% = 0, where 1.1 is distortion, better 0.9
 
Hi Julian, I did this with a script a while back so I put together some simple code that might get you started.

You don't need C1 or C2, I just thought it was easier to read by using them. This will use the full scope of the Amplifier Volume knob. About 63.0% will give you 0.0dB.
Code:
on init
  declare C1
  declare C2
  declare ui_knob $Knob (0,1000,1)
    C1 := $Knob / 10
    C2 := $Knob mod 10
    set_engine_par($ENGINE_PAR_VOLUME,$Knob*1000,0,-1,-1)
    set_knob_label ($Knob,""&C1&"."&C2&"%")
    move_control ($Knob,1,1)
end on

on ui_control ($Knob)
  C1 := $Knob / 10
  C2 := $Knob mod 10
  set_engine_par($ENGINE_PAR_VOLUME,$Knob*1000,0,-1,-1)
  set_knob_label ($Knob,""&C1&"."&C2&"%")
end on

Edit: I just got to thinking, I did this for Kontakt 5.5, some of the later versions might treat the "C1 := $Knob / 10" a little differently. I haven't used the later versions for scripting yet, but they might use fractions, I'm not sure.
 
Thanks for prompt replies, guys!
Tod, thank you for the script sample - appreciate it!
Now I see how I can solve the percentage. I'm not sure, however, about 'exp to linear' conversion, because when I rotate UI $Knob the volume knob of amplifier rotates absolutely same way.
Or, maybe I just didn't get it right :D
 
I think the Amplifier volume knob is actually exponential, although I'm not 100% sure of that. However, I don't think it will make any difference, the script knob shouldn't change the way the amplifier knob works, your just basically changing the way it reads out on the script knob.

The Amplifier knob has a high of +12dB and with the script knob at 63.0% the Amplifier knob shows 0.0dB which is as it should be.
 
There are a couple of ways you can do that, this is a simple way.

Code:
on init
  declare C1
  declare C2
  declare ui_knob $Knob (0,1000,1)
    C1 := $Knob / 10
    C2 := $Knob mod 10
    set_engine_par($ENGINE_PAR_VOLUME,$Knob*1000,0,-1,-1)
    set_knob_label ($Knob,""&C1&"."&C2&"%")
    move_control ($Knob,1,1)
end on

on ui_control ($Knob)
  if ($Knob*1000 > 630000)
    $Knob:=630
  else
    C1 := $Knob / 10
    C2 := $Knob mod 10
    set_engine_par($ENGINE_PAR_VOLUME,$Knob*1000,0,-1,-1)
    set_knob_label ($Knob,""&C1&"."&C2&"%")
  end if
end on

Incidentally, I did a little testing and the Amplifier volume is not exponential. I'm not sure what it is, it's not exactly linear, but it's much closer to linear then it is exponential.
 
Hi Tod,
Thank you again !
Amplifier... Well, until now I was sure it is exponential :D
 
Tod, you're wrong :) ENGINE_PAR_VOLUME is indeed scaled exponentially (because volume is logarithmic). Here's how engine par values to real world values curve looks:

upload_2018-10-13_11-14-48.png


So yes, if you want to adjust volume as %, so that it's linear (at 50.0% you'd get -6 dB), you would have to linearize the curve. And this is how you do it:

Code:
on init
    declare ui_knob Vol (0, 1000, 10)
    set_knob_unit(Vol, KNOB_UNIT_PERCENT)
end on

function linearize_vol_ep(x) -> return
    return := real_to_int(pow(250000.0 * int_to_real(x), 1.0 / 3.0) * 1000.0)
end function

on ui_control (Vol)
    set_engine_par($ENGINE_PAR_VOLUME, linearize_vol_ep(Vol), 0, -1, -1)
end on
 
Last edited:
Okay Mario, but I was going by the test I made. In the picture below, I went from -inf to -3dB using midi controllers.

You can clearly see the difference, the Amplifier Volume is quite abrupt but still slightly rounded. The Instrument Volume has what I call an exponential curve.

I did the CC11 too, and in comparison it was totally abrupt, immediately on. I made some extensive tests about this back in 2005 to 2007, and they're all posted in this forum somewhere, I looked for them but couldn't find them.

Amp%20Inst%20Vol%20Test%201.png
 
Did you double-check that the range of MIDI CC #7 is set to maximum when you did the comparison?

In any case, the engine parameter is what matters here, and that curve is clearly exponential.
 
Thank you very much EvilDragon - it works perfectly!
On 50% of UI knob I get -6dB of Amplifier Volume.
Thank you all again :)
 
Last edited:
Yeah, the Instrument Volume was at 0.0dB.

I tried your script in Kontakt 7.1 but I got an error when I hit Apply. The "declare ui_knob Vol (0, 1000, 10)" was high lighted and the Status line said: "ERROR (line 3) variable expected". Everything looks okay, but like I said above, I'm still working with Kontakt 5.5 and I haven't delved into the math in the later versions.

I wanted to make some more tests using the script I made and the one you made to see the differences.

Thanks Mario.
 
Thanks Julian, and yes, I used Sublime for this too. What version of Kontakt do you have, I had the problem with 7.1, I haven't updated to latest version yet?
 
Last edited:
Humm, what do you think the problem could be Mario? Sublime had no problems with it.
 
Top Bottom