mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 00:52:12 +00:00
Audio: Fix code smells and issues found by static analysis
This fixes all current code smells, bugs and issues reported by SonarCloud static analysis. Other issues are almost exclusively false positives. This makes much code clearer, and some minor benefits in performance or bug evasion may be gained.
This commit is contained in:
parent
a757f3f421
commit
8af97d0ce7
12 changed files with 99 additions and 77 deletions
|
@ -10,7 +10,8 @@
|
|||
#include <AK/Math.h>
|
||||
|
||||
namespace Audio {
|
||||
using namespace AK::Exponentials;
|
||||
using AK::Exponentials::exp;
|
||||
using AK::Exponentials::log;
|
||||
// Constants for logarithmic volume. See Sample::linear_to_log
|
||||
// Corresponds to 60dB
|
||||
constexpr double DYNAMIC_RANGE = 1000;
|
||||
|
@ -23,7 +24,7 @@ struct Sample {
|
|||
constexpr Sample() = default;
|
||||
|
||||
// For mono
|
||||
constexpr Sample(double left)
|
||||
constexpr explicit Sample(double left)
|
||||
: left(left)
|
||||
, right(left)
|
||||
{
|
||||
|
@ -63,13 +64,13 @@ struct Sample {
|
|||
// - Linear: 0.0 to 1.0
|
||||
// - Logarithmic: 0.0 to 1.0
|
||||
|
||||
ALWAYS_INLINE double linear_to_log(double const change)
|
||||
ALWAYS_INLINE double linear_to_log(double const change) const
|
||||
{
|
||||
// TODO: Add linear slope around 0
|
||||
return VOLUME_A * exp(VOLUME_B * change);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE double log_to_linear(double const val)
|
||||
ALWAYS_INLINE double log_to_linear(double const val) const
|
||||
{
|
||||
// TODO: Add linear slope around 0
|
||||
return log(val / VOLUME_A) / VOLUME_B;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue