aboutsummaryrefslogtreecommitdiffstats
path: root/source/samplebuffer.cpp
blob: 1acf2f46eacb15cda2c6a098af32585241ef074c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * @file samplebuffer.cpp
 * @brief Manages ADC/DAC buffer data.
 *
 * Copyright (C) 2021 Clyne Sullivan
 *
 * Distributed under the GNU GPL v3 or later. You should have received a copy of
 * the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

#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);
}