mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibDSP: Make the note frequencies an AK::Array instead of a C array
This was a leftover from the early days of Piano, and there's no reason to leave it that way especially if we want to use more complex collection APIs in the future.
This commit is contained in:
parent
bcb331b862
commit
f23aea0c4b
5 changed files with 6 additions and 7 deletions
|
@ -16,7 +16,7 @@ Sample AudioClip::sample_at(u32 time)
|
||||||
|
|
||||||
void NoteClip::set_note(RollNote note)
|
void NoteClip::set_note(RollNote note)
|
||||||
{
|
{
|
||||||
VERIFY(note.pitch >= 0 && note.pitch < note_count);
|
VERIFY(note.pitch >= 0 && note.pitch < note_frequencies.size());
|
||||||
VERIFY(note.off_sample < m_length);
|
VERIFY(note.off_sample < m_length);
|
||||||
VERIFY(note.length() >= 2);
|
VERIFY(note.length() >= 2);
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,10 @@ class NoteClip final : public Clip {
|
||||||
public:
|
public:
|
||||||
void set_note(RollNote note);
|
void set_note(RollNote note);
|
||||||
|
|
||||||
Array<SinglyLinkedList<RollNote>, note_count> const& notes() const { return m_notes; }
|
Array<SinglyLinkedList<RollNote>, note_frequencies.size()> const& notes() const { return m_notes; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Array<SinglyLinkedList<RollNote>, note_count> m_notes;
|
Array<SinglyLinkedList<RollNote>, note_frequencies.size()> m_notes;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ struct Signal : public Variant<Sample, RollNotes> {
|
||||||
// We calculate note frequencies relative to A4:
|
// We calculate note frequencies relative to A4:
|
||||||
// 440.0 * pow(pow(2.0, 1.0 / 12.0), N)
|
// 440.0 * pow(pow(2.0, 1.0 / 12.0), N)
|
||||||
// Where N is the note distance from A.
|
// Where N is the note distance from A.
|
||||||
constexpr double note_frequencies[] = {
|
constexpr Array<double, 84> note_frequencies = {
|
||||||
// Octave 1
|
// Octave 1
|
||||||
32.703195662574764,
|
32.703195662574764,
|
||||||
34.647828872108946,
|
34.647828872108946,
|
||||||
|
@ -177,7 +177,6 @@ constexpr double note_frequencies[] = {
|
||||||
3729.3100921447249,
|
3729.3100921447249,
|
||||||
3951.0664100489994,
|
3951.0664100489994,
|
||||||
};
|
};
|
||||||
constexpr size_t const note_count = array_size(note_frequencies);
|
|
||||||
|
|
||||||
constexpr double const middle_c = note_frequencies[36];
|
constexpr double const middle_c = note_frequencies[36];
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ Signal Classic::process_impl(Signal const& input_signal)
|
||||||
|
|
||||||
// "Press" the necessary notes in the internal representation,
|
// "Press" the necessary notes in the internal representation,
|
||||||
// and "release" all of the others
|
// and "release" all of the others
|
||||||
for (u8 i = 0; i < note_count; ++i) {
|
for (u8 i = 0; i < note_frequencies.size(); ++i) {
|
||||||
if (auto maybe_note = in.get(i); maybe_note.has_value())
|
if (auto maybe_note = in.get(i); maybe_note.has_value())
|
||||||
m_playing_notes.set(i, maybe_note.value());
|
m_playing_notes.set(i, maybe_note.value());
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ private:
|
||||||
ProcessorRangeParameter m_release;
|
ProcessorRangeParameter m_release;
|
||||||
|
|
||||||
RollNotes m_playing_notes;
|
RollNotes m_playing_notes;
|
||||||
Array<double, note_count> last_random;
|
Array<double, note_frequencies.size()> last_random;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue