Old 02-12-2024, 08:39 AM   #1
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default Volume automation value conversion to dB

I'm having hard time with this conversion. reaper.Envelope_Evaluate(volumeEnvelope, position, 0, 0) returns values between 0 and 1334.9297943142 for volume automation values between -infinity to +24dB. Does anyone know the exact conversion formula for this?
goateeproductions is offline   Reply With Quote
Old 02-12-2024, 11:52 AM   #2
Philbo King
Human being with feelings
 
Philbo King's Avatar
 
Join Date: May 2017
Posts: 3,201
Default

Geez, I just turn it up or down till it sounds right...
__________________
Tangent Studio - Philbo King
www.soundclick.com/philboking - Audio streams
Philbo King is offline   Reply With Quote
Old 02-12-2024, 11:54 AM   #3
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

google gemini says:

You're correct that reaper.Envelope_Evaluate(volumeEnvelope, position, 0, 0) in REAPER returns values between 0 and 1334.9297943142 for volume automation values between -infinity and +24 dB. Here's the exact conversion formula:

Formula:

envelope_value = (linear_gain - 1) / ((10^(max_db / 20)) - 1) * 1334.9297943142
Where:

envelope_value: The REAPER internal envelope value (between 0 and 1334.9297943142).
linear_gain: The linear gain calculated from the dB value using 10^(db / 20).
max_db: The maximum allowed dB value (usually 24 dB).
Explanation:

Convert dB to linear gain: The formula first converts the dB value to linear gain using the equation 10^(db / 20). This conversion is necessary because REAPER's internal envelope values are based on linear gain, not dB.
Normalize to range [0, 1]: The linear gain is then normalized to the range [0, 1] by subtracting 1 and dividing by the difference between the linear gain at the maximum allowed dB and 1. This normalization step ensures that the envelope value remains within the valid range.
Scale to REAPER's range: Finally, the normalized value is multiplied by 1334.9297943142 to scale it to the range used by REAPER's internal envelope.
Example:

To calculate the envelope value for a volume of -10 dB, you would use the following steps:

Calculate the linear gain: linear_gain = 10^(-10 / 20) = 0.1
Normalize to range [0, 1]: normalized_gain = (0.1 - 1) / ((10^(24 / 20)) - 1) = -0.0999999999999955
Scale to REAPER's range: envelope_value = -0.0999999999999955 * 1334.9297943142 = -61.47
Therefore, the envelope value for a volume of -10 dB in REAPER would be approximately -61.47.

I hope this explanation clarifies the conversion formula for you!
__________________
Track Freezing Scripts

Coachz Repo
Coachz is online now   Reply With Quote
Old 02-12-2024, 03:33 PM   #4
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default

Too bad it's hallucinating like members of the Beatles back in the day. First of all, there are no negative numbers in the parameter.

But I got it quite close already. Conversion to dB is about:
6 * (math.log(value / 716.21785031261) / math.log(1.22))

Quote:
Originally Posted by Coachz View Post
google gemini says:

You're correct that reaper.Envelope_Evaluate(volumeEnvelope, position, 0, 0) in REAPER returns values between 0 and 1334.9297943142 for volume automation values between -infinity and +24 dB. Here's the exact conversion formula:

Formula:

envelope_value = (linear_gain - 1) / ((10^(max_db / 20)) - 1) * 1334.9297943142
Where:

envelope_value: The REAPER internal envelope value (between 0 and 1334.9297943142).
linear_gain: The linear gain calculated from the dB value using 10^(db / 20).
max_db: The maximum allowed dB value (usually 24 dB).
Explanation:

Convert dB to linear gain: The formula first converts the dB value to linear gain using the equation 10^(db / 20). This conversion is necessary because REAPER's internal envelope values are based on linear gain, not dB.
Normalize to range [0, 1]: The linear gain is then normalized to the range [0, 1] by subtracting 1 and dividing by the difference between the linear gain at the maximum allowed dB and 1. This normalization step ensures that the envelope value remains within the valid range.
Scale to REAPER's range: Finally, the normalized value is multiplied by 1334.9297943142 to scale it to the range used by REAPER's internal envelope.
Example:

To calculate the envelope value for a volume of -10 dB, you would use the following steps:

Calculate the linear gain: linear_gain = 10^(-10 / 20) = 0.1
Normalize to range [0, 1]: normalized_gain = (0.1 - 1) / ((10^(24 / 20)) - 1) = -0.0999999999999955
Scale to REAPER's range: envelope_value = -0.0999999999999955 * 1334.9297943142 = -61.47
Therefore, the envelope value for a volume of -10 dB in REAPER would be approximately -61.47.

I hope this explanation clarifies the conversion formula for you!
goateeproductions is offline   Reply With Quote
Old 02-12-2024, 06:01 PM   #5
abnegative
Human being with feelings
 
Join Date: Sep 2022
Posts: 222
Default

from EEL Envelope Based Compressor:

Code:
// -- DB2VAL - VAL2DB ----------------------------
function DB2VAL(x)
(
  exp((x)*0.11512925464970228420089957273422);
);
//----------------------------
function VAL2DB(x)
  local(v)
(
  x < 0.0000000298023223876953125 ? (
    -150; 
  ) : (
    v = log(x)*8.6858896380650365530225783783321;
    v < -150 ? -150 : v;
  );
);
abnegative is offline   Reply With Quote
Old 02-13-2024, 02:13 AM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

https://github.com/justinfrankel/lic...e/WDL/db2val.h
nofish is offline   Reply With Quote
Old 02-13-2024, 04:26 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Here is lua code to convert from envelope value to dB


https://github.com/ReaTeam/ReaScript...20to%20Val.lua


Note that if faderScaling on the trck is active, use the related API function to convert back to non fader scaled value first.


@Coachz
Quote:
Therefore, the envelope value for a volume of -10 dB in REAPER would be approximately -61.47.
No. It would be 0.31622776601684. And 0 would -inf so the answer can't be negative.



So please, dont copy paste AI ChatBots results, especially when wrong and unverified 🙏. People can prompt them on their own if this is the kind of answer they are looking for.
This faulty calculations just add a layers of confusion.
X-Raym is offline   Reply With Quote
Old 02-14-2024, 04:59 AM   #8
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default

Thanks for answers. However, I don't mean the value to convert dB to multiplies (like +6dB to 1.995262315) but the value you get with reaper.Envelope_Evaluate(volumeEnvelope, position, 0, 0).

Here are some example returns:

+12dB 1000
+6dB 852.2869803
+0dB 716.22

This formula doesn't seem to be any log or exp function since when I approximate this with exponential function then the difference to ground truth seems to have at least third-degree polynomial nature. See the Google sheet:

https://docs.google.com/spreadsheets...it?usp=sharing
goateeproductions is offline   Reply With Quote
Old 02-14-2024, 05:44 AM   #9
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default

Thank you so much! It was the fader scaling that messed things up!

Quote:
Originally Posted by X-Raym View Post
Here is lua code to convert from envelope value to dB


https://github.com/ReaTeam/ReaScript...20to%20Val.lua


Note that if faderScaling on the trck is active, use the related API function to convert back to non fader scaled value first.


@Coachz

No. It would be 0.31622776601684. And 0 would -inf so the answer can't be negative.



So please, dont copy paste AI ChatBots results, especially when wrong and unverified 🙏. People can prompt them on their own if this is the kind of answer they are looking for.
This faulty calculations just add a layers of confusion.
goateeproductions is offline   Reply With Quote
Old 02-14-2024, 05:55 AM   #10
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default

So, if I want to read the amplitude scaled value of the track volume automation then I basically need also change the graph to show amplitude scaling? Are there any other possibilities? I would like to read the value while the track plays but would not want to mess with user settings.

So:
- Does anyone know formula to convert between fader scaling and amplitude scaling?
- Is there a way to read the automation in amplitude scaling without changing the preference?
goateeproductions is offline   Reply With Quote
Old 02-14-2024, 06:07 AM   #11
goateeproductions
Human being with feelings
 
Join Date: Feb 2020
Posts: 24
Default

Ok, success with:
reaper.ScaleFromEnvelopeMode(reaper.GetEnvelopeSca lingMode(volumeEnvelope), value)

Thanks X-Raym!
goateeproductions 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 12:48 PM.


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