mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
LibDSP: Optimize note processing
Previously, a collection of notes (Vector or Array) would be created and promptly deleted for every sample (at least 44 thousand times per second!). This was measured to be one of the most significant performance drawbacks as well as the most obvious performance improvement I could currently find here. Although it will not cause Piano to lag currently (at least on virtualized systems), I see an incoming issue once we get the capability to use more processors. Now, we use a HashMap correlating pitches to notes, and Track reuses the data structure in order to avoid reallocations. That is the reason for introducing the fast clear_with_capacity to HashMap.
This commit is contained in:
parent
557be4649d
commit
c2340a1b1f
3 changed files with 33 additions and 25 deletions
|
@ -19,6 +19,7 @@ class Track : public Core::Object {
|
|||
public:
|
||||
Track(NonnullRefPtr<Transport> transport)
|
||||
: m_transport(move(transport))
|
||||
, m_current_signal(Sample {})
|
||||
{
|
||||
}
|
||||
virtual ~Track() override = default;
|
||||
|
@ -36,10 +37,12 @@ protected:
|
|||
bool check_processor_chain_valid_with_initial_type(SignalType initial_type) const;
|
||||
|
||||
// Subclasses override to provide the base signal to the processing chain
|
||||
virtual Signal current_clips_signal() = 0;
|
||||
virtual void compute_current_clips_signal() = 0;
|
||||
|
||||
NonnullRefPtrVector<Processor> m_processor_chain;
|
||||
NonnullRefPtr<Transport> const m_transport;
|
||||
NonnullRefPtr<Transport> m_transport;
|
||||
// The current signal is stored here, to prevent unnecessary reallocation.
|
||||
Signal m_current_signal;
|
||||
};
|
||||
|
||||
class NoteTrack final : public Track {
|
||||
|
@ -50,7 +53,7 @@ public:
|
|||
NonnullRefPtrVector<NoteClip> const& clips() const { return m_clips; }
|
||||
|
||||
protected:
|
||||
virtual Signal current_clips_signal() override;
|
||||
virtual void compute_current_clips_signal() override;
|
||||
|
||||
private:
|
||||
NonnullRefPtrVector<NoteClip> m_clips;
|
||||
|
@ -64,7 +67,7 @@ public:
|
|||
NonnullRefPtrVector<AudioClip> const& clips() const { return m_clips; }
|
||||
|
||||
protected:
|
||||
virtual Signal current_clips_signal() override;
|
||||
virtual void compute_current_clips_signal() override;
|
||||
|
||||
private:
|
||||
NonnullRefPtrVector<AudioClip> m_clips;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue