-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPcmPlaybackOscillator.cpp
More file actions
68 lines (50 loc) · 1.41 KB
/
Copy pathPcmPlaybackOscillator.cpp
File metadata and controls
68 lines (50 loc) · 1.41 KB
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
/* Dependencies */
#include "PcmPlaybackOscillator.h"
namespace CheapTune {
PcmPlaybackOscillator::PcmPlaybackOscillator() :
_index(0), _limit(PCM_SAMPLES_COUNT) {
}
SampleCount_t PcmPlaybackOscillator::writeBufferData(Sample_t* src,
SampleCount_t count, SampleCount_t offset) {
/* Avoid overflow */
if ((count + offset) > PCM_SAMPLES_COUNT)
count = PCM_SAMPLES_COUNT - offset;
/* Copy data block */
for (SampleCount_t i = offset; i < count; ++i)
_buffer[i] = src[i];
/* Return the "real" count */
return count;
}
SampleCount_t PcmPlaybackOscillator::fillBuffer(Sample_t value,
SampleCount_t count, SampleCount_t offset) {
/* Avoid overflow */
if ((count + offset) > PCM_SAMPLES_COUNT)
count = PCM_SAMPLES_COUNT - offset;
/* Copy data block */
for (SampleCount_t i = offset; i < count; ++i)
_buffer[i] = value;
/* Return the "real" count */
return count;
}
void PcmPlaybackOscillator::reset() {
_index = 0;
_limit = PCM_SAMPLES_COUNT;
for (SampleCount_t i = 0; i < PCM_SAMPLES_COUNT; ++i)
_buffer[i] = 0;
}
void PcmPlaybackOscillator::setLogicalBufferSize(SampleCount_t size) {
_limit = size;
}
void PcmPlaybackOscillator::restartCycle() {
_index = 0;
}
Sample_t PcmPlaybackOscillator::getSample() {
/* get the current sample */
Sample_t sample = _buffer[_index];
/* Increment (and loop) the buffer index */
if (++_index == _limit)
_index = 0;
/* Return the sample */
return sample;
}
}