forked from toniebox-reverse-engineering/hackiebox_cfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoxAudioBufferTriple.cpp
75 lines (66 loc) · 2.4 KB
/
BoxAudioBufferTriple.cpp
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
72
73
74
75
#include "BoxAudioBufferTriple.h"
void BoxAudioBufferTriple::init() {
for (uint16_t i = 0; i < _dataBufferSize; i++)
_dataBuffer[i] = 0x00;
for (uint8_t i = 0; i < _bufferCount; i++) {
_bufferStruct[i].index = i;
_bufferStruct[i].buffer = (uint16_t*)(_dataBuffer + 2*i*_bufferSize); //bytes
_bufferStruct[i].size = _bufferSize; //words
_bufferStruct[i].position = 0;
_bufferStruct[i].state = BufferState::READY_FOR_WRITE;
_bufferStruct[i].next = &_bufferStruct[i+1];
}
_bufferStruct[0].state = BufferState::READY_FOR_READ;
_bufferStruct[_bufferCount-1].next = &_bufferStruct[0];
_bufferRead = &_bufferStruct[0];
_bufferWrite = &_bufferStruct[1];
}
void BoxAudioBufferTriple::logState() {
Log.info("BoxAudioBufferTriple state");
for (uint8_t i = 0; i < _bufferCount; i++)
logState(&_bufferStruct[i]);
}
bool BoxAudioBufferTriple::flip(BoxAudioBufferTriple::BufferType type) {
if (type == BufferType::READ) {
if (_bufferRead->next->state == BufferState::READY_FOR_READ) {
_bufferRead->state = BufferState::READY_FOR_WRITE;
_bufferRead = _bufferRead->next;
_bufferRead->position = 0;
return true;
}
} else if (type == BufferType::WRITE) {
if (_bufferWrite->next->state == BufferState::READY_FOR_WRITE) {
_bufferWrite->state = BufferState::READY_FOR_READ;
_bufferWrite = _bufferWrite->next;
_bufferWrite->position = 0;
return true;
}
}
return false;
}
void BoxAudioBufferTriple::logState(BoxAudioBufferTriple::BufferStruct* buffer) {
Log.info(" [%i] buffer=%X, size=%X, state=%X, nextBuffer=%X", buffer->index, buffer->buffer, buffer->size, buffer->state, buffer->next->buffer);
}
BoxAudioBufferTriple::BufferStruct* BoxAudioBufferTriple::getBuffer(BoxAudioBufferTriple::BufferType type) {
switch (type) {
case BufferType::READ:
return _bufferRead;
case BufferType::WRITE:
return _bufferWrite;
case BufferType::WAIT:
return NULL;
}
return NULL;
}
bool BoxAudioBufferTriple::isFull() {
if (_bufferWrite->next->state != BufferState::READY_FOR_WRITE) {
return true;
}
return false;
}
bool BoxAudioBufferTriple::isEmpty() {
if (_bufferRead->next->state != BufferState::READY_FOR_READ) {
return true;
}
return false;
}