diff options
author | Hendiadyoin1 <leon2002.la@gmail.com> | 2022-02-03 12:48:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-15 11:39:42 +0100 |
commit | cd21e0322510bdd95c5d53075f80c49efcb2f24d (patch) | |
tree | c735ef5b046067f3da5fd961b6b74600451b4b5b /Userland/Libraries/LibAudio | |
parent | 47fe911196b5551f5b4a829a1a310ca66cf12e99 (diff) | |
download | serenity-cd21e0322510bdd95c5d53075f80c49efcb2f24d.zip |
AK+Everywhere: Add sincos and use it in some places
Calculating sin and cos at once is quite a bit cheaper than calculating
them individually.
x87 has even a dedicated instruction for it: `fsincos`.
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r-- | Userland/Libraries/LibAudio/Sample.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Libraries/LibAudio/Sample.h b/Userland/Libraries/LibAudio/Sample.h index ec52cd90c1..b3b5e57e2f 100644 --- a/Userland/Libraries/LibAudio/Sample.h +++ b/Userland/Libraries/LibAudio/Sample.h @@ -97,8 +97,10 @@ struct Sample { double const pi_over_2 = AK::Pi<double> * 0.5; double const root_over_2 = AK::sqrt(2.0) * 0.5; double const angle = position * pi_over_2 * 0.5; - left *= root_over_2 * (AK::cos(angle) - AK::sin(angle)); - right *= root_over_2 * (AK::cos(angle) + AK::sin(angle)); + double s, c; + AK::sincos(angle, s, c); + left *= root_over_2 * (c - s); + right *= root_over_2 * (c + s); return *this; } @@ -116,7 +118,7 @@ struct Sample { return *this; } - constexpr Sample operator*(double const mult) + constexpr Sample operator*(double const mult) const { return { left * mult, right * mult }; } @@ -134,7 +136,7 @@ struct Sample { return *this; } - constexpr Sample operator+(Sample const& other) + constexpr Sample operator+(Sample const& other) const { return { left + other.left, right + other.right }; } |