From d002746e25237738ab45b472c1fff6e8fbe4183b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 10 Oct 2021 09:45:37 -0400 Subject: [PATCH] wip: better samplebuffer filling --- Makefile | 2 +- source/samplebuffer.cpp | 58 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 44f4c8a..3dcfd94 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ TARGET_PLATFORM = L4 # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nosys.specs + USE_OPT = -Os -g3 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nosys.specs endif # C specific options here (added to USE_OPT). diff --git a/source/samplebuffer.cpp b/source/samplebuffer.cpp index 1acf2f4..6f588b1 100644 --- a/source/samplebuffer.cpp +++ b/source/samplebuffer.cpp @@ -19,17 +19,63 @@ void SampleBuffer::clear() { } __attribute__((section(".convcode"))) void SampleBuffer::modify(Sample *data, unsigned int srcsize) { - auto size = srcsize < m_size ? srcsize : m_size; + auto size = std::min(srcsize, m_size); + size = (size + 15) & 0xFF0; + m_modified = m_buffer; - for (Sample *d = m_buffer, *s = data; s != data + size;) - *d++ = *s++; + const int *src = reinterpret_cast(data); + const int * const srcend = src + (size / 2); + int *dst = reinterpret_cast(m_buffer); + do { + int a = src[0]; + int b = src[1]; + int c = src[2]; + int d = src[3]; + int e = src[4]; + int f = src[5]; + int g = src[6]; + int h = src[7]; + dst[0] = a; + dst[1] = b; + dst[2] = c; + dst[3] = d; + dst[4] = e; + dst[5] = f; + dst[6] = g; + dst[7] = h; + src += 8; + dst += 8; + } while (src < srcend); } __attribute__((section(".convcode"))) void SampleBuffer::midmodify(Sample *data, unsigned int srcsize) { - auto size = srcsize < m_size / 2 ? srcsize : m_size / 2; + auto size = std::min(srcsize, m_size / 2); + size = (size + 15) & 0xFF0; + m_modified = middata(); - for (Sample *d = middata(), *s = data; s != data + size;) - *d++ = *s++; + const int *src = reinterpret_cast(data); + const int * const srcend = src + (size / 2); + int *dst = reinterpret_cast(middata()); + do { + int a = src[0]; + int b = src[1]; + int c = src[2]; + int d = src[3]; + int e = src[4]; + int f = src[5]; + int g = src[6]; + int h = src[7]; + dst[0] = a; + dst[1] = b; + dst[2] = c; + dst[3] = d; + dst[4] = e; + dst[5] = f; + dst[6] = g; + dst[7] = h; + src += 8; + dst += 8; + } while (src < srcend); } void SampleBuffer::setModified() {