mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 06:37:35 +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:
parent
885e35e92c
commit
413e212ea8
5 changed files with 51 additions and 9 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FixedArray.h>
|
||||
#include <LibAudio/Sample.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
|
||||
|
@ -18,6 +19,12 @@ class WaveWidget final : public GUI::Frame {
|
|||
public:
|
||||
virtual ~WaveWidget() override = default;
|
||||
|
||||
ErrorOr<void> set_sample_size(size_t sample_size)
|
||||
{
|
||||
TRY(m_samples.try_resize(sample_size));
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
// Scales the sample-y value down by a bit, so that it doesn't look like it is clipping.
|
||||
static constexpr float rescale_factor = 1.2f;
|
||||
|
@ -29,4 +36,5 @@ private:
|
|||
int sample_to_y(float sample, float sample_max) const;
|
||||
|
||||
TrackManager& m_track_manager;
|
||||
Vector<Audio::Sample> m_samples;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue