sandboxed user algorithm
parent
1a14ef827e
commit
4f59610a00
@ -1,61 +0,0 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
using Sample = uint16_t;
|
||||
|
||||
// gives 8000
|
||||
constexpr unsigned int MAX_SAMPLE_BUFFER_BYTESIZE = 16384;
|
||||
constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = MAX_SAMPLE_BUFFER_BYTESIZE / sizeof(Sample);
|
||||
|
||||
class SampleBuffer
|
||||
{
|
||||
public:
|
||||
SampleBuffer(Sample *buffer) :
|
||||
m_buffer(buffer) {}
|
||||
|
||||
void clear() {
|
||||
std::fill(m_buffer, m_buffer + m_size, 2048);
|
||||
}
|
||||
void modify(Sample *data, unsigned int srcsize) {
|
||||
auto size = srcsize < m_size ? srcsize : m_size;
|
||||
std::copy(data, data + size, m_buffer);
|
||||
m_modified = m_buffer;
|
||||
}
|
||||
void midmodify(Sample *data, unsigned int srcsize) {
|
||||
auto size = srcsize < m_size / 2 ? srcsize : m_size / 2;
|
||||
std::copy(data, data + size, middata());
|
||||
m_modified = middata();
|
||||
}
|
||||
|
||||
void setSize(unsigned int size) {
|
||||
m_size = size < MAX_SAMPLE_BUFFER_SIZE ? size : MAX_SAMPLE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
Sample *data() {
|
||||
return m_buffer;
|
||||
}
|
||||
Sample *middata() {
|
||||
return m_buffer + m_size / 2;
|
||||
}
|
||||
uint8_t *bytedata() {
|
||||
return reinterpret_cast<uint8_t *>(m_buffer);
|
||||
}
|
||||
|
||||
Sample *modified() {
|
||||
auto m = m_modified;
|
||||
m_modified = nullptr;
|
||||
return m;
|
||||
}
|
||||
unsigned int size() const {
|
||||
return m_size;
|
||||
}
|
||||
unsigned int bytesize() const {
|
||||
return m_size * sizeof(Sample);
|
||||
}
|
||||
|
||||
private:
|
||||
Sample *m_buffer = nullptr;
|
||||
unsigned int m_size = MAX_SAMPLE_BUFFER_SIZE;
|
||||
Sample *m_modified = nullptr;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
#ifndef SAMPLEBUFFER_HPP_
|
||||
#define SAMPLEBUFFER_HPP_
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
using Sample = uint16_t;
|
||||
|
||||
// gives 8000
|
||||
constexpr unsigned int MAX_SAMPLE_BUFFER_BYTESIZE = 16384;
|
||||
constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = MAX_SAMPLE_BUFFER_BYTESIZE / sizeof(Sample);
|
||||
|
||||
class SampleBuffer
|
||||
{
|
||||
public:
|
||||
SampleBuffer(Sample *buffer);
|
||||
|
||||
void clear();
|
||||
|
||||
void modify(Sample *data, unsigned int srcsize);
|
||||
void midmodify(Sample *data, unsigned int srcsize);
|
||||
Sample *modified();
|
||||
|
||||
Sample *data();
|
||||
Sample *middata();
|
||||
uint8_t *bytedata();
|
||||
|
||||
void setSize(unsigned int size);
|
||||
unsigned int size() const;
|
||||
unsigned int bytesize() const;
|
||||
|
||||
private:
|
||||
Sample *m_buffer = nullptr;
|
||||
unsigned int m_size = MAX_SAMPLE_BUFFER_SIZE;
|
||||
Sample *m_modified = nullptr;
|
||||
};
|
||||
|
||||
#endif // SAMPLEBUFFER_HPP_
|
||||
|
Loading…
Reference in New Issue