aboutsummaryrefslogtreecommitdiffstats
path: root/source/samplebuffer.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2021-01-27 11:18:33 -0500
committerClyne Sullivan <clyne@bitgloo.com>2021-01-27 11:18:33 -0500
commit4f59610a00da78639c1909acb09c7dfde4519a28 (patch)
treec4b9f18f4a0826c2f635ee3b16a3a88d7a195114 /source/samplebuffer.cpp
parent1a14ef827ed99a814b00d8ea4b98b8633582b945 (diff)
sandboxed user algorithm
Diffstat (limited to 'source/samplebuffer.cpp')
-rw-r--r--source/samplebuffer.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/samplebuffer.cpp b/source/samplebuffer.cpp
new file mode 100644
index 0000000..6932392
--- /dev/null
+++ b/source/samplebuffer.cpp
@@ -0,0 +1,52 @@
+#include "common.hpp"
+
+SampleBuffer::SampleBuffer(Sample *buffer) :
+ m_buffer(buffer) {}
+
+void SampleBuffer::clear() {
+ std::fill(m_buffer, m_buffer + m_size, 2048);
+}
+__attribute__((section(".convcode")))
+void SampleBuffer::modify(Sample *data, unsigned int srcsize) {
+ auto size = srcsize < m_size ? srcsize : m_size;
+ for (Sample *d = data, *s = m_buffer; d != data + size;)
+ *d++ = *s++;
+ m_modified = m_buffer;
+}
+__attribute__((section(".convcode")))
+void SampleBuffer::midmodify(Sample *data, unsigned int srcsize) {
+ auto size = srcsize < m_size / 2 ? srcsize : m_size / 2;
+ for (Sample *d = data, *s = middata(); d != data + size;)
+ *d++ = *s++;
+ m_modified = middata();
+}
+
+void SampleBuffer::setSize(unsigned int size) {
+ m_size = size < MAX_SAMPLE_BUFFER_SIZE ? size : MAX_SAMPLE_BUFFER_SIZE;
+}
+
+__attribute__((section(".convcode")))
+Sample *SampleBuffer::data() {
+ return m_buffer;
+}
+__attribute__((section(".convcode")))
+Sample *SampleBuffer::middata() {
+ return m_buffer + m_size / 2;
+}
+uint8_t *SampleBuffer::bytedata() {
+ return reinterpret_cast<uint8_t *>(m_buffer);
+}
+
+Sample *SampleBuffer::modified() {
+ auto m = m_modified;
+ m_modified = nullptr;
+ return m;
+}
+__attribute__((section(".convcode")))
+unsigned int SampleBuffer::size() const {
+ return m_size;
+}
+unsigned int SampleBuffer::bytesize() const {
+ return m_size * sizeof(Sample);
+}
+