Browse Source

Merge pull request #71932 from raulsntos/dotnet/lin2db-to-math

C#: Move `LinearToDb` and `DbToLinear` to Mathf
Rémi Verschelde 2 years ago
parent
commit
a17e0a0250

+ 0 - 31
modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs

@@ -49,17 +49,6 @@ namespace Godot
             return Variant.CreateTakingOwnershipOfDisposableValue(ret);
             return Variant.CreateTakingOwnershipOfDisposableValue(ret);
         }
         }
 
 
-        /// <summary>
-        /// Converts from decibels to linear energy (audio).
-        /// </summary>
-        /// <seealso cref="LinearToDb(real_t)"/>
-        /// <param name="db">Decibels to convert.</param>
-        /// <returns>Audio volume as linear energy.</returns>
-        public static real_t DbToLinear(real_t db)
-        {
-            return (real_t)Math.Exp(db * 0.11512925464970228420089957273422);
-        }
-
         private static string[] GetPrintParams(object[] parameters)
         private static string[] GetPrintParams(object[] parameters)
         {
         {
             if (parameters == null)
             if (parameters == null)
@@ -111,26 +100,6 @@ namespace Godot
             return InteropUtils.UnmanagedGetManaged(NativeFuncs.godotsharp_instance_from_id(instanceId));
             return InteropUtils.UnmanagedGetManaged(NativeFuncs.godotsharp_instance_from_id(instanceId));
         }
         }
 
 
-        /// <summary>
-        /// Converts from linear energy to decibels (audio).
-        /// This can be used to implement volume sliders that behave as expected (since volume isn't linear).
-        /// </summary>
-        /// <seealso cref="DbToLinear(real_t)"/>
-        /// <example>
-        /// <code>
-        /// // "slider" refers to a node that inherits Range such as HSlider or VSlider.
-        /// // Its range must be configured to go from 0 to 1.
-        /// // Change the bus name if you'd like to change the volume of a specific bus only.
-        /// AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
-        /// </code>
-        /// </example>
-        /// <param name="linear">The linear energy to convert.</param>
-        /// <returns>Audio as decibels.</returns>
-        public static real_t LinearToDb(real_t linear)
-        {
-            return (real_t)(Math.Log(linear) * 8.6858896380650365530225783783321);
-        }
-
         /// <summary>
         /// <summary>
         /// Loads a resource from the filesystem located at <paramref name="path"/>.
         /// Loads a resource from the filesystem located at <paramref name="path"/>.
         /// The resource is loaded on the method call (unless it's referenced already
         /// The resource is loaded on the method call (unless it's referenced already

+ 31 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs

@@ -323,6 +323,17 @@ namespace Godot
             return d;
             return d;
         }
         }
 
 
+        /// <summary>
+        /// Converts from decibels to linear energy (audio).
+        /// </summary>
+        /// <seealso cref="LinearToDb(real_t)"/>
+        /// <param name="db">Decibels to convert.</param>
+        /// <returns>Audio volume as linear energy.</returns>
+        public static real_t DbToLinear(real_t db)
+        {
+            return (real_t)Math.Exp(db * 0.11512925464970228420089957273422);
+        }
+
         /// <summary>
         /// <summary>
         /// Converts an angle expressed in degrees to radians.
         /// Converts an angle expressed in degrees to radians.
         /// </summary>
         /// </summary>
@@ -514,6 +525,26 @@ namespace Godot
             return from + (distance * weight);
             return from + (distance * weight);
         }
         }
 
 
+        /// <summary>
+        /// Converts from linear energy to decibels (audio).
+        /// This can be used to implement volume sliders that behave as expected (since volume isn't linear).
+        /// </summary>
+        /// <seealso cref="DbToLinear(real_t)"/>
+        /// <example>
+        /// <code>
+        /// // "slider" refers to a node that inherits Range such as HSlider or VSlider.
+        /// // Its range must be configured to go from 0 to 1.
+        /// // Change the bus name if you'd like to change the volume of a specific bus only.
+        /// AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
+        /// </code>
+        /// </example>
+        /// <param name="linear">The linear energy to convert.</param>
+        /// <returns>Audio as decibels.</returns>
+        public static real_t LinearToDb(real_t linear)
+        {
+            return (real_t)(Math.Log(linear) * 8.6858896380650365530225783783321);
+        }
+
         /// <summary>
         /// <summary>
         /// Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
         /// Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
         ///
         ///