summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibDSP/Clip.cpp
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-08-27 16:18:11 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-08-31 17:03:55 +0430
commita749b166748f46aa562b1f46eb400351f5a9a87a (patch)
tree053ffbcb40c5afc4a9ff2b193f6607a71354d0d0 /Userland/Libraries/LibDSP/Clip.cpp
parent8f4b5774059bbf283915b73d35104167cb8090f7 (diff)
downloadserenity-a749b166748f46aa562b1f46eb400351f5a9a87a.zip
Libraries: Add LibDSP
LibDSP is a library for digital signal processing, and is primarily intended to support the future DAW version of Piano.
Diffstat (limited to 'Userland/Libraries/LibDSP/Clip.cpp')
-rw-r--r--Userland/Libraries/LibDSP/Clip.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Libraries/LibDSP/Clip.cpp b/Userland/Libraries/LibDSP/Clip.cpp
new file mode 100644
index 0000000000..38335d64a9
--- /dev/null
+++ b/Userland/Libraries/LibDSP/Clip.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "Clip.h"
+
+namespace LibDSP {
+
+Sample AudioClip::sample_at(u32 time)
+{
+ VERIFY(time < m_length);
+ return m_samples[time];
+}
+
+void NoteClip::set_note(RollNote note)
+{
+ VERIFY(note.pitch >= 0 && note.pitch < note_count);
+ VERIFY(note.off_sample < m_length);
+ VERIFY(note.length() >= 2);
+
+ auto& notes = m_notes[note.pitch];
+ for (auto it = notes.begin(); !it.is_end();) {
+ auto iterated_note = *it;
+ if (iterated_note.on_sample > note.off_sample) {
+ notes.insert_before(it, note);
+ return;
+ }
+ if (iterated_note.on_sample <= note.on_sample && iterated_note.off_sample >= note.on_sample) {
+ notes.remove(it);
+ return;
+ }
+ if ((note.on_sample == 0 || iterated_note.on_sample >= note.on_sample - 1) && iterated_note.on_sample <= note.off_sample) {
+ notes.remove(it);
+ it = notes.begin();
+ continue;
+ }
+ ++it;
+ }
+
+ notes.append(note);
+}
+
+}