aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound/audio_buffer.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2017-09-14 22:34:04 -0400
committerPaul Gilbert2017-09-14 22:34:04 -0400
commit3ed7ef57aec38a39d7887a520c8eaf510f19804e (patch)
tree9018ecf269c414c141c76ff3a5440c6c86c88a23 /engines/titanic/sound/audio_buffer.cpp
parent8607b702edd594264378f15dfe420fb0fc5881d0 (diff)
downloadscummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.tar.gz
scummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.tar.bz2
scummvm-rg350-3ed7ef57aec38a39d7887a520c8eaf510f19804e.zip
TITANIC: Moved queue logic within CAUdioBuffer to new FixedQueue class
This is a cleaner implementation, since all the pointer logic and queue management is now better encapsulated in it's own class. I felt a new FixedQueue class was necessary because the standard Queue class uses a Common::List internally, which would be unsuitable for containing 100,000 elements, since each int value would need it's own list node. This way uses an array internally, like FixedStack
Diffstat (limited to 'engines/titanic/sound/audio_buffer.cpp')
-rw-r--r--engines/titanic/sound/audio_buffer.cpp33
1 files changed, 6 insertions, 27 deletions
diff --git a/engines/titanic/sound/audio_buffer.cpp b/engines/titanic/sound/audio_buffer.cpp
index 636f4a5107..0b0b6a53ad 100644
--- a/engines/titanic/sound/audio_buffer.cpp
+++ b/engines/titanic/sound/audio_buffer.cpp
@@ -26,45 +26,24 @@
namespace Titanic {
CAudioBuffer::CAudioBuffer(int maxSize) : _finished(false) {
- _data.resize(maxSize);
reset();
}
void CAudioBuffer::reset() {
- _frontP = _backP = &_data[0];
+ _data.clear();
}
void CAudioBuffer::push(int16 value) {
- assert(!full());
- compact();
-
- *_backP++ = value;
+ _data.push(value);
}
-void CAudioBuffer::push(int16 *values, int count) {
- compact();
- assert(freeSize() >= count);
-
- Common::copy(values, values + count, _backP);
- _backP += count;
+void CAudioBuffer::push(const int16 *values, int count) {
+ for (; count > 0; --count, ++values)
+ _data.push(*values);
}
int16 CAudioBuffer::pop() {
- assert(!empty());
- return *_frontP++;
-}
-
-void CAudioBuffer::compact() {
- if (_frontP != &_data[0]) {
- Common::copy(_frontP, _backP, &_data[0]);
- _backP -= _frontP - &_data[0];
- _frontP = &_data[0];
- }
-}
-
-int CAudioBuffer::freeSize() {
- compact();
- return &_data[0] + _data.size() - _backP;
+ return _data.pop();
}
void CAudioBuffer::enterCriticalSection() {