diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-09-28 17:52:17 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-11 09:19:17 +0100 |
commit | 557be4649d96ac9432fa82599364118e1e9f6055 (patch) | |
tree | 27bd62868be0e874aa906e332246d65932fad574 /Userland | |
parent | 3a4ec4913183f3816a4010d58e61876966dbd422 (diff) | |
download | serenity-557be4649d96ac9432fa82599364118e1e9f6055.zip |
LibDSP: Move to constexpr wherever possible
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibDSP/Music.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Transport.h | 15 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Userland/Libraries/LibDSP/Music.h b/Userland/Libraries/LibDSP/Music.h index 306b3c6193..f495cf7a3b 100644 --- a/Userland/Libraries/LibDSP/Music.h +++ b/Userland/Libraries/LibDSP/Music.h @@ -19,7 +19,7 @@ using Sample = Audio::Sample; Sample const SAMPLE_OFF = { 0.0, 0.0 }; struct RollNote { - u32 length() const { return (off_sample - on_sample) + 1; } + constexpr u32 length() const { return (off_sample - on_sample) + 1; } u32 on_sample; u32 off_sample; diff --git a/Userland/Libraries/LibDSP/Transport.h b/Userland/Libraries/LibDSP/Transport.h index 9fc77da63c..bb631bc339 100644 --- a/Userland/Libraries/LibDSP/Transport.h +++ b/Userland/Libraries/LibDSP/Transport.h @@ -16,12 +16,13 @@ namespace LibDSP { class Transport final : public Core::Object { C_OBJECT(Transport) public: - u32 const& time() const { return m_time; } - u16 beats_per_minute() const { return m_beats_per_minute; } - double current_second() const { return m_time / m_sample_rate; } - double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; } - double sample_rate() const { return m_sample_rate; } - double current_measure() const { return m_time / samples_per_measure(); } + constexpr u32& time() { return m_time; } + constexpr u16 beats_per_minute() const { return m_beats_per_minute; } + constexpr double current_second() const { return static_cast<double>(m_time) / m_sample_rate; } + constexpr double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; } + constexpr double sample_rate() const { return m_sample_rate; } + constexpr double ms_sample_rate() const { return m_sample_rate / 1000.; } + constexpr double current_measure() const { return m_time / samples_per_measure(); } private: Transport(u16 beats_per_minute, u8 beats_per_measure, u32 sample_rate) @@ -35,6 +36,8 @@ private: { } + // FIXME: You can't make more than 24h of (48kHz) music with this. + // But do you want to, really? :^) u32 m_time { 0 }; u16 const m_beats_per_minute { 0 }; u8 const m_beats_per_measure { 0 }; |