diff options
author | clyne <clyne@bitgloo.com> | 2021-03-21 16:34:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-21 16:34:21 -0400 |
commit | 9b926b81ef1e8a4c7266494ae2a1369380e01b35 (patch) | |
tree | 746095fa69eccccdc1c2830fdd0c06bac01848f5 /source/samplebuffer.cpp | |
parent | e080a26651f90c88176140d63a74c93c2f4041a2 (diff) | |
parent | a4f1482a8b23d5f761f60d6f3821c84190d89e2f (diff) |
Merge pull request #3 from tcsullivan/stm32h7
Stm32h7
Diffstat (limited to 'source/samplebuffer.cpp')
-rw-r--r-- | source/samplebuffer.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/samplebuffer.cpp b/source/samplebuffer.cpp new file mode 100644 index 0000000..24cc424 --- /dev/null +++ b/source/samplebuffer.cpp @@ -0,0 +1,60 @@ +#include "samplebuffer.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; + m_modified = m_buffer; + for (Sample *d = m_buffer, *s = data; s != data + size;) + *d++ = *s++; +} +__attribute__((section(".convcode"))) +void SampleBuffer::midmodify(Sample *data, unsigned int srcsize) { + auto size = srcsize < m_size / 2 ? srcsize : m_size / 2; + m_modified = middata(); + for (Sample *d = middata(), *s = data; s != data + size;) + *d++ = *s++; +} + +void SampleBuffer::setModified() { + m_modified = m_buffer; +} + +void SampleBuffer::setMidmodified() { + 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); +} + |