diff --git a/Userland/Libraries/LibDSP/Clip.h b/Userland/Libraries/LibDSP/Clip.h index 38a1dad17d..9e950d22f9 100644 --- a/Userland/Libraries/LibDSP/Clip.h +++ b/Userland/Libraries/LibDSP/Clip.h @@ -47,7 +47,7 @@ class NoteClip final : public Clip { public: void set_note(RollNote note); - Array, note_count>& notes() { return m_notes; } + Array, note_count> const& notes() const { return m_notes; } private: Array, note_count> m_notes; diff --git a/Userland/Libraries/LibDSP/Music.h b/Userland/Libraries/LibDSP/Music.h index 9b76960f3e..501f364472 100644 --- a/Userland/Libraries/LibDSP/Music.h +++ b/Userland/Libraries/LibDSP/Music.h @@ -15,10 +15,9 @@ namespace LibDSP { -// FIXME: Audio::Frame is 64-bit float, which is quite large for long clips. using Sample = Audio::Sample; -Sample const SAMPLE_OFF = { 0.0, 0.0 }; +constexpr Sample const SAMPLE_OFF = { 0.0, 0.0 }; struct RollNote { constexpr u32 length() const { return (off_sample - on_sample) + 1; } @@ -28,7 +27,7 @@ struct RollNote { u8 pitch; i8 velocity; - Envelope to_envelope(u32 time, u32 attack_samples, u32 decay_samples, u32 release_samples) + constexpr Envelope to_envelope(u32 time, u32 attack_samples, u32 decay_samples, u32 release_samples) const { i64 time_since_end = static_cast(time) - static_cast(off_sample); // We're before the end of this note. @@ -58,7 +57,7 @@ struct RollNote { return Envelope::from_release(static_cast(time_since_end) / static_cast(release_samples)); } - constexpr bool is_playing(u32 time) { return on_sample <= time && time <= off_sample; } + constexpr bool is_playing(u32 time) const { return on_sample <= time && time <= off_sample; } }; enum class SignalType : u8 { @@ -178,8 +177,8 @@ constexpr double note_frequencies[] = { 3729.3100921447249, 3951.0664100489994, }; -constexpr size_t note_count = array_size(note_frequencies); +constexpr size_t const note_count = array_size(note_frequencies); -constexpr double middle_c = note_frequencies[36]; +constexpr double const middle_c = note_frequencies[36]; } diff --git a/Userland/Libraries/LibDSP/Processor.h b/Userland/Libraries/LibDSP/Processor.h index f08421b9be..c9e26d830d 100644 --- a/Userland/Libraries/LibDSP/Processor.h +++ b/Userland/Libraries/LibDSP/Processor.h @@ -34,6 +34,7 @@ public: SignalType input_type() const { return m_input_type; } SignalType output_type() const { return m_output_type; } Vector& parameters() { return m_parameters; } + Vector const& parameters() const { return m_parameters; } private: SignalType const m_input_type; diff --git a/Userland/Libraries/LibDSP/Synthesizers.cpp b/Userland/Libraries/LibDSP/Synthesizers.cpp index 561cd474ce..8b583adf3d 100644 --- a/Userland/Libraries/LibDSP/Synthesizers.cpp +++ b/Userland/Libraries/LibDSP/Synthesizers.cpp @@ -66,7 +66,7 @@ Signal Classic::process_impl(Signal const& input_signal) } // Linear ADSR envelope with no peak adjustment. -double Classic::volume_from_envelope(Envelope const& envelope) +double Classic::volume_from_envelope(Envelope const& envelope) const { switch (static_cast(envelope)) { case EnvelopeState::Off: @@ -102,12 +102,12 @@ double Classic::wave_position(u8 note) VERIFY_NOT_REACHED(); } -double Classic::samples_per_cycle(u8 note) +double Classic::samples_per_cycle(u8 note) const { return m_transport->sample_rate() / note_frequencies[note]; } -double Classic::sin_position(u8 note) +double Classic::sin_position(u8 note) const { double spc = samples_per_cycle(note); double cycle_pos = m_transport->time() / spc; @@ -115,14 +115,14 @@ double Classic::sin_position(u8 note) } // Absolute value of the saw wave "flips" the negative portion into the positive, creating a ramp up and down. -double Classic::triangle_position(u8 note) +double Classic::triangle_position(u8 note) const { double saw = saw_position(note); return AK::fabs(saw) * 2 - 1; } // The first half of the cycle period is 1, the other half -1. -double Classic::square_position(u8 note) +double Classic::square_position(u8 note) const { double spc = samples_per_cycle(note); double progress = AK::fmod(static_cast(m_transport->time()), spc) / spc; @@ -130,7 +130,7 @@ double Classic::square_position(u8 note) } // Modulus creates inverse saw, which we need to flip and scale. -double Classic::saw_position(u8 note) +double Classic::saw_position(u8 note) const { double spc = samples_per_cycle(note); double unscaled = spc - AK::fmod(static_cast(m_transport->time()), spc); diff --git a/Userland/Libraries/LibDSP/Synthesizers.h b/Userland/Libraries/LibDSP/Synthesizers.h index f0133f3bb3..01654d99cb 100644 --- a/Userland/Libraries/LibDSP/Synthesizers.h +++ b/Userland/Libraries/LibDSP/Synthesizers.h @@ -49,13 +49,13 @@ public: private: virtual Signal process_impl(Signal const&) override; - double volume_from_envelope(Envelope const&); + double volume_from_envelope(Envelope const&) const; double wave_position(u8 note); - double samples_per_cycle(u8 note); - double sin_position(u8 note); - double triangle_position(u8 note); - double square_position(u8 note); - double saw_position(u8 note); + double samples_per_cycle(u8 note) const; + double sin_position(u8 note) const; + double triangle_position(u8 note) const; + double square_position(u8 note) const; + double saw_position(u8 note) const; double noise_position(u8 note); double get_random_from_seed(u64 note); diff --git a/Userland/Libraries/LibDSP/Track.cpp b/Userland/Libraries/LibDSP/Track.cpp index da1e965fd7..f04b541b2a 100644 --- a/Userland/Libraries/LibDSP/Track.cpp +++ b/Userland/Libraries/LibDSP/Track.cpp @@ -79,8 +79,8 @@ void NoteTrack::compute_current_clips_signal() return; // FIXME: performance? - for (auto& note_list : playing_clip->notes()) { - for (auto& note : note_list) { + for (auto const& note_list : playing_clip->notes()) { + for (auto const& note : note_list) { if (note.on_sample >= time && note.off_sample >= time) break; if (note.on_sample <= time && note.off_sample >= time) diff --git a/Userland/Libraries/LibDSP/Track.h b/Userland/Libraries/LibDSP/Track.h index bd9d614218..d3af5b7abc 100644 --- a/Userland/Libraries/LibDSP/Track.h +++ b/Userland/Libraries/LibDSP/Track.h @@ -27,7 +27,7 @@ public: Sample current_signal(); NonnullRefPtrVector const& processor_chain() const { return m_processor_chain; } - NonnullRefPtr const transport() const { return m_transport; } + NonnullRefPtr transport() const { return m_transport; } protected: Track(NonnullRefPtr transport) diff --git a/Userland/Libraries/LibDSP/Transport.h b/Userland/Libraries/LibDSP/Transport.h index 45f1b8af61..0acd8d725f 100644 --- a/Userland/Libraries/LibDSP/Transport.h +++ b/Userland/Libraries/LibDSP/Transport.h @@ -16,6 +16,7 @@ namespace LibDSP { class Transport final : public RefCounted { public: constexpr u32& time() { return m_time; } + constexpr u32 time() const { return m_time; } constexpr u16 beats_per_minute() const { return m_beats_per_minute; } constexpr double current_second() const { return static_cast(m_time) / m_sample_rate; } constexpr double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; }