mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 12:17:45 +00:00
LibDSP: Move to constexpr wherever possible
This commit is contained in:
parent
3a4ec49131
commit
557be4649d
2 changed files with 10 additions and 7 deletions
|
@ -19,7 +19,7 @@ using Sample = Audio::Sample;
|
||||||
Sample const SAMPLE_OFF = { 0.0, 0.0 };
|
Sample const SAMPLE_OFF = { 0.0, 0.0 };
|
||||||
|
|
||||||
struct RollNote {
|
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 on_sample;
|
||||||
u32 off_sample;
|
u32 off_sample;
|
||||||
|
|
|
@ -16,12 +16,13 @@ namespace LibDSP {
|
||||||
class Transport final : public Core::Object {
|
class Transport final : public Core::Object {
|
||||||
C_OBJECT(Transport)
|
C_OBJECT(Transport)
|
||||||
public:
|
public:
|
||||||
u32 const& time() const { return m_time; }
|
constexpr u32& time() { return m_time; }
|
||||||
u16 beats_per_minute() const { return m_beats_per_minute; }
|
constexpr u16 beats_per_minute() const { return m_beats_per_minute; }
|
||||||
double current_second() const { return m_time / m_sample_rate; }
|
constexpr double current_second() const { return static_cast<double>(m_time) / m_sample_rate; }
|
||||||
double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; }
|
constexpr 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; }
|
constexpr double sample_rate() const { return m_sample_rate; }
|
||||||
double current_measure() const { return m_time / samples_per_measure(); }
|
constexpr double ms_sample_rate() const { return m_sample_rate / 1000.; }
|
||||||
|
constexpr double current_measure() const { return m_time / samples_per_measure(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Transport(u16 beats_per_minute, u8 beats_per_measure, u32 sample_rate)
|
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 };
|
u32 m_time { 0 };
|
||||||
u16 const m_beats_per_minute { 0 };
|
u16 const m_beats_per_minute { 0 };
|
||||||
u8 const m_beats_per_measure { 0 };
|
u8 const m_beats_per_measure { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue