1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 19:17:44 +00:00

LibDSP+Piano: Convert DSP APIs to accept entire sample ranges

This has mainly performance benefits, so that we only need to call into
all processors once for every audio buffer segment. It requires
adjusting quite some logic in most processors and in Track, as we have
to consider a larger collection of notes and samples at each step.

There's some cautionary TODOs in the currently unused LibDSP tracks
because they don't do things properly yet.
This commit is contained in:
kleines Filmröllchen 2022-05-11 23:24:46 +02:00 committed by Linus Groh
parent 4d65607649
commit 9035d9e845
9 changed files with 123 additions and 75 deletions

View file

@ -6,7 +6,9 @@
#pragma once
#include <AK/FixedArray.h>
#include <AK/HashMap.h>
#include <AK/Noncopyable.h>
#include <AK/Types.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
@ -66,13 +68,29 @@ enum class SignalType : u8 {
Note
};
using RollNotes = OrderedHashMap<u8, RollNote>;
// Perfect hashing for note (MIDI) values. This just uses the note value as the hash itself.
class PerfectNoteHashTraits : Traits<u8> {
public:
static constexpr bool equals(u8 const& a, u8 const& b) { return a == b; }
static constexpr unsigned hash(u8 value)
{
return static_cast<unsigned>(value);
}
};
struct Signal : public Variant<Sample, RollNotes> {
using RollNotes = OrderedHashMap<u8, RollNote, PerfectNoteHashTraits>;
struct Signal : public Variant<FixedArray<Sample>, RollNotes> {
using Variant::Variant;
AK_MAKE_NONCOPYABLE(Signal);
public:
Signal& operator=(Signal&&) = default;
Signal(Signal&&) = default;
ALWAYS_INLINE SignalType type() const
{
if (has<Sample>())
if (has<FixedArray<Sample>>())
return SignalType::Sample;
if (has<RollNotes>())
return SignalType::Note;