COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 01-02-2017, 02:30 PM   #1
debian
Human being with feelings
 
debian's Avatar
 
Join Date: Nov 2008
Posts: 35
Default gain db control?

How do I present to the user a gaincontrol from -94 db(completely silence) to +6 db(twice the volume)?

Can you help me how to think?
What I try to do was:

GetParam(kGain)->InitDouble("Gain", 0.0, -94.0, 6.0, 0.01, "db");
GetParam(kGain)->SetShape(2.0);

then in OnParamChange()
case kGain:
mGain = (GetParam(kGain)->Value()+94.0) / 100.;
mGain = mGain * 2.0;

But the result is not so good.. very little control between 0 and +6...
__________________
ojoj...
debian is offline   Reply With Quote
Old 01-03-2017, 01:02 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Well, this is how you normally would calculate from dB to linear:

Code:
GetParam(kGain)->InitDouble("Gain", 0.0, -94.0, 6.0, 0.01, "dB");
And then in OnParamChange():

Code:
    case kGain:
      mGain = pow(10, GetParam(kGain)->Value() / 20);
      break;
Or if you want -94.0 to map to exactly zero:

Code:
    case kGain:
    {
      const double value = GetParam(kGain)->Value();
      mGain = value > -94.0 ? pow(10, value / 20) : 0;
      break;
    }
However, this will still have much more control between -94 and 0 than between 0 and 6, but mabe you can tweak this to liking using SetShape().
Tale is offline   Reply With Quote
Old 01-03-2017, 09:01 AM   #3
debian
Human being with feelings
 
debian's Avatar
 
Join Date: Nov 2008
Posts: 35
Default

Excellent!
Thanks a lot Tale!
with SetShape(0.095) it turned out perfect :-)
__________________
ojoj...
debian is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.