1
Fork 0
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:
kleines Filmröllchen 2021-11-15 22:27:28 +01:00 committed by Linus Groh
parent a757f3f421
commit 8af97d0ce7
12 changed files with 99 additions and 77 deletions

View file

@ -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;