1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:17:45 +00:00

Piano: Cache buffers in Track and WaveWidget

The Track itself caches the Samples after each processing step which
allows it to be queried without the need to process it every time.

This result is queried by the WaveWidget which then caches the result to
prevent unnecessary heap allocations every paint event.
This commit is contained in:
Fabian Neundorf 2023-03-12 21:03:56 +01:00 committed by Jelle Raaijmakers
parent 885e35e92c
commit 413e212ea8
5 changed files with 51 additions and 9 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/DisjointChunks.h>
#include <AK/FixedArray.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/Weakable.h>
@ -31,6 +32,8 @@ public:
// Creates the current signal of the track by processing current note or audio data through the processing chain.
void current_signal(FixedArray<Sample>& output_signal);
void write_cached_signal_to(Span<Sample> output_signal);
// We are informed of an audio buffer size change. This happens off-audio-thread so we can allocate.
ErrorOr<void> resize_internal_buffers_to(size_t buffer_size);
@ -66,6 +69,11 @@ protected:
Signal m_secondary_sample_buffer { FixedArray<Sample> {} };
// A note buffer possibly used by the processor chain.
Signal m_secondary_note_buffer { RollNotes {} };
private:
Atomic<bool> m_sample_lock;
FixedArray<Sample> m_cached_sample_buffer = {};
};
class NoteTrack final : public Track {