aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2017-02-05 22:57:56 -0500
committerPaul Gilbert2017-02-05 22:57:56 -0500
commit8f193017bd0fe32b6bf6a4c9a9ce58b2f809b0ac (patch)
tree1ebfa562d3ac3c96330667120d162ae50fa3f817
parent6bf2ddde13e9872359fa139e813a0ed94164c5ea (diff)
downloadscummvm-rg350-8f193017bd0fe32b6bf6a4c9a9ce58b2f809b0ac.tar.gz
scummvm-rg350-8f193017bd0fe32b6bf6a4c9a9ce58b2f809b0ac.tar.bz2
scummvm-rg350-8f193017bd0fe32b6bf6a4c9a9ce58b2f809b0ac.zip
TITANIC: Renamings and cleanups for music room handler & audio buffer
-rw-r--r--engines/titanic/sound/audio_buffer.cpp34
-rw-r--r--engines/titanic/sound/audio_buffer.h36
-rw-r--r--engines/titanic/sound/music_room.cpp3
-rw-r--r--engines/titanic/sound/music_room_handler.cpp55
-rw-r--r--engines/titanic/sound/music_room_handler.h10
-rw-r--r--engines/titanic/sound/music_wave.cpp1
6 files changed, 83 insertions, 56 deletions
diff --git a/engines/titanic/sound/audio_buffer.cpp b/engines/titanic/sound/audio_buffer.cpp
index 67a3d67958..6798c8b312 100644
--- a/engines/titanic/sound/audio_buffer.cpp
+++ b/engines/titanic/sound/audio_buffer.cpp
@@ -35,48 +35,48 @@ CAudioBuffer::~CAudioBuffer() {
void CAudioBuffer::reset() {
_flag = true;
- _fieldC = _field10 = _buffer.size() / 2;
+ _fieldC = _writeBytesLeft = _buffer.size() / 2;
}
-byte *CAudioBuffer::getDataPtr1() {
+byte *CAudioBuffer::getBegin() {
return _flag ? &_buffer[_buffer.size() / 2] : &_buffer[0];
}
-byte *CAudioBuffer::getDataPtr2() {
+byte *CAudioBuffer::getEnd() {
return _flag ? &_buffer[0] : &_buffer[_buffer.size() / 2];
}
byte *CAudioBuffer::getPtr1() {
- byte *ptr = getDataPtr1();
+ byte *ptr = getBegin();
return ptr + (_buffer.size() / 2 - _fieldC);
}
-uint16 *CAudioBuffer::getPtr2() {
- byte *ptr = getDataPtr2();
- return (uint16 *)(ptr + (_buffer.size() / 2 - _field10));
+uint16 *CAudioBuffer::getWritePtr() {
+ byte *ptr = getEnd();
+ return (uint16 *)(ptr + (_buffer.size() / 2 - _writeBytesLeft));
}
void CAudioBuffer::setC(int val) {
_fieldC -= val;
if (_fieldC < 0) {
_fieldC = 0;
- } else if (val && !_field10) {
- update();
+ } else if (val && !_writeBytesLeft) {
+ reverse();
}
}
-void CAudioBuffer::set10(int val) {
- _field10 -= val;
- if (_field10 < 0) {
- _field10 = 0;
- } else if (val && !_field10) {
- update();
+void CAudioBuffer::advanceWrite(int size) {
+ _writeBytesLeft -= size;
+ if (_writeBytesLeft < 0) {
+ _writeBytesLeft = 0;
+ } else if (size && !_fieldC) {
+ reverse();
}
}
-void CAudioBuffer::update() {
+void CAudioBuffer::reverse() {
_flag = !_flag;
- _fieldC = _field10 = _buffer.size() / 2;
+ _fieldC = _writeBytesLeft = _buffer.size() / 2;
}
void CAudioBuffer::enterCriticalSection() {
diff --git a/engines/titanic/sound/audio_buffer.h b/engines/titanic/sound/audio_buffer.h
index b65f0bb8cc..5b6fb11072 100644
--- a/engines/titanic/sound/audio_buffer.h
+++ b/engines/titanic/sound/audio_buffer.h
@@ -31,10 +31,25 @@ namespace Titanic {
class CAudioBuffer {
private:
Common::Mutex _mutex;
+private:
+ /**
+ * Gets the beginning of stored audio data
+ */
+ byte *getBegin();
+
+ /**
+ * Gets the end of the stored audio data
+ */
+ byte *getEnd();
+
+ /**
+ * Reverses the audio buffer
+ */
+ void reverse();
public:
Common::Array<byte> _buffer;
int _fieldC;
- int _field10;
+ int _writeBytesLeft;
bool _flag;
int _field18;
public:
@@ -42,15 +57,22 @@ public:
~CAudioBuffer();
void reset();
- byte *getDataPtr1();
- byte *getDataPtr2();
+
byte *getPtr1();
- uint16 *getPtr2();
+ uint16 *getWritePtr();
int getC() const { return _fieldC; }
- int get10() const { return _field10; }
void setC(int val);
- void set10(int val);
- void update();
+
+ /**
+ * Returns how many bytes can be written before hitting the
+ * end of the audio buffer
+ */
+ int getWriteBytesLeft() const { return _writeBytesLeft; }
+
+ /**
+ * Advances the write pointer by the specified number of bytes
+ */
+ void advanceWrite(int size);
/**
* Enters a critical section
diff --git a/engines/titanic/sound/music_room.cpp b/engines/titanic/sound/music_room.cpp
index 4ef3b1dfc7..c2e5b5e380 100644
--- a/engines/titanic/sound/music_room.cpp
+++ b/engines/titanic/sound/music_room.cpp
@@ -85,7 +85,8 @@ void CMusicRoom::setupMusic(int volume) {
_musicHandler->setMuteControl(idx, instr._muteControl);
}
- _musicHandler->setVolume(volume);
+ // Set up the music handler
+ _musicHandler->setup(volume);
}
}
diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index d4ae89fa67..e716ebc233 100644
--- a/engines/titanic/sound/music_room_handler.cpp
+++ b/engines/titanic/sound/music_room_handler.cpp
@@ -35,10 +35,10 @@ CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *sound
_startTicks = _soundStartTicks = 0;
Common::fill(&_musicWaves[0], &_musicWaves[4], (CMusicWave *)nullptr);
for (int idx = 0; idx < 4; ++idx)
- _array3[idx] = new CMusicObject(idx);
- Common::fill(&_array4[0], &_array4[4], 0);
+ _musicObjs[idx] = new CMusicObject(idx);
+ Common::fill(&_startPos[0], &_startPos[4], 0);
Common::fill(&_array5[0], &_array5[4], 0.0);
- Common::fill(&_array6[0], &_array6[4], 0);
+ Common::fill(&_position[0], &_position[4], 0);
_audioBuffer = new CAudioBuffer(176400);
}
@@ -46,7 +46,7 @@ CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *sound
CMusicRoomHandler::~CMusicRoomHandler() {
stop();
for (int idx = 0; idx < 4; ++idx)
- delete _array3[idx];
+ delete _musicObjs[idx];
delete _audioBuffer;
}
@@ -73,7 +73,7 @@ CMusicWave *CMusicRoomHandler::createMusicWave(MusicInstrument instrument, int c
return _musicWaves[instrument];
}
-void CMusicRoomHandler::setVolume(int volume) {
+void CMusicRoomHandler::setup(int volume) {
_volume = volume;
_audioBuffer->reset();
@@ -82,12 +82,12 @@ void CMusicRoomHandler::setVolume(int volume) {
MusicRoomInstrument &ins2 = _array2[idx];
if (ins1._directionControl == ins2._directionControl) {
- _array4[idx] = 0;
+ _startPos[idx] = 0;
} else {
- _array4[idx] = _array3[idx]->size();
+ _startPos[idx] = _musicObjs[idx]->size() - 1;
}
- _array6[idx] = _array4[idx];
+ _position[idx] = _startPos[idx];
_array5[idx] = 0.0;
}
@@ -203,30 +203,33 @@ bool CMusicRoomHandler::update() {
void CMusicRoomHandler::updateAudio() {
_audioBuffer->enterCriticalSection();
- int size = _audioBuffer->get10();
+ int size = _audioBuffer->getWriteBytesLeft();
int count;
uint16 *ptr;
if (size > 0) {
- uint16 *audioPtr = _audioBuffer->getPtr2();
- Common::fill(audioPtr, audioPtr + size, 0);
+ // Null out the destination write area
+ uint16 *audioPtr = _audioBuffer->getWritePtr();
+ Common::fill(audioPtr, audioPtr + size / sizeof(uint16), 0);
- for (int waveIdx = 0; waveIdx < 4; ++waveIdx) {
- CMusicWave *musicWave = _musicWaves[waveIdx];
+ for (int instrIdx = 0; instrIdx < 4; ++instrIdx) {
+ CMusicWave *musicWave = _musicWaves[instrIdx];
+ // Iterate through each of the four instruments and do an additive
+ // read that will merge their data onto the output buffer
for (count = size, ptr = audioPtr; count > 0; ) {
int amount = musicWave->read(ptr, count);
if (amount > 0) {
count -= amount;
ptr += amount / sizeof(uint16);
- } else if (!fn2(waveIdx)) {
+ } else if (!fn2(instrIdx)) {
--_field108;
break;
}
}
}
- _audioBuffer->set10(size);
+ _audioBuffer->advanceWrite(size);
}
_audioBuffer->leaveCriticalSection();
@@ -240,8 +243,8 @@ void CMusicRoomHandler::fn1() {
CMusicWave *musicWave = _musicWaves[idx];
// Is this about checking playback position?
- if (_array6[idx] < 0 || ins1._muteControl || _array6[idx] >= _array3[idx]->size()) {
- _array6[idx] = -1;
+ if (_position[idx] < 0 || ins1._muteControl || _position[idx] >= _musicObjs[idx]->size()) {
+ _position[idx] = -1;
continue;
}
@@ -249,18 +252,18 @@ void CMusicRoomHandler::fn1() {
double val = (double)ticks * 0.001 - 0.6;
if (val >= musicWave->_floatVal) {
- _array5[idx] += fn3(idx, _array6[idx]);
+ _array5[idx] += fn3(idx, _position[idx]);
- const CValuePair &vp = (*_array3[idx])[_array6[idx]];
+ const CValuePair &vp = (*_musicObjs[idx])[_position[idx]];
if (vp._field0 != 0x7FFFFFFF) {
- int amount = getPitch(idx, _array6[idx]);
+ int amount = getPitch(idx, _position[idx]);
_musicWaves[idx]->start(amount);
}
if (ins1._directionControl == ins2._directionControl) {
- _array6[idx]++;
+ _position[idx]++;
} else {
- _array6[idx]--;
+ _position[idx]--;
}
}
}
@@ -268,13 +271,13 @@ void CMusicRoomHandler::fn1() {
}
bool CMusicRoomHandler::fn2(int index) {
- int &arrIndex = _array4[index];
+ int &arrIndex = _startPos[index];
if (arrIndex < 0) {
_musicWaves[index]->reset();
return false;
}
- const CMusicObject &mObj = *_array3[index];
+ const CMusicObject &mObj = *_musicObjs[index];
if (arrIndex >= mObj.size()) {
arrIndex = -1;
_musicWaves[index]->reset();
@@ -299,7 +302,7 @@ bool CMusicRoomHandler::fn2(int index) {
}
double CMusicRoomHandler::fn3(int index, int arrIndex) {
- const CValuePair &vp = (*_array3[index])[arrIndex];
+ const CValuePair &vp = (*_musicObjs[index])[arrIndex];
switch (_array1[index]._speedControl + _array2[index]._speedControl + 3) {
case 0:
@@ -320,7 +323,7 @@ double CMusicRoomHandler::fn3(int index, int arrIndex) {
}
int CMusicRoomHandler::getPitch(int index, int arrIndex) {
- const CMusicObject &mObj = *_array3[index];
+ const CMusicObject &mObj = *_musicObjs[index];
const CValuePair &vp = mObj[arrIndex];
int val = vp._field0;
const MusicRoomInstrument &ins1 = _array1[index];
diff --git a/engines/titanic/sound/music_room_handler.h b/engines/titanic/sound/music_room_handler.h
index 5f615ccd84..38c1748ab4 100644
--- a/engines/titanic/sound/music_room_handler.h
+++ b/engines/titanic/sound/music_room_handler.h
@@ -52,10 +52,10 @@ private:
CMusicWave *_musicWaves[4];
MusicRoomInstrument _array1[4];
MusicRoomInstrument _array2[4];
- CMusicObject *_array3[4];
- int _array4[4];
+ CMusicObject *_musicObjs[4];
+ int _startPos[4];
+ int _position[4];
double _array5[4];
- int _array6[4];
bool _active;
CWaveFile *_waveFile;
@@ -88,9 +88,9 @@ public:
CMusicWave *createMusicWave(MusicInstrument instrument, int count);
/**
- * TODO: Verify - this starts the given music?
+ * Main setup for the music room handler
*/
- void setVolume(int volume);
+ void setup(int volume);
/**
* Flags whether the music handler is active
diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp
index ecf23824b6..2dc7b02c3e 100644
--- a/engines/titanic/sound/music_wave.cpp
+++ b/engines/titanic/sound/music_wave.cpp
@@ -162,6 +162,7 @@ void CMusicWave::start(int val) {
_gameObjects[0]->movieSetAudioTiming(true);
_gameObjects[0]->playMovie(0, 512, MOVIE_STOP_PREVIOUS);
_floatVal = 0.6;
+ break;
case 62:
_gameObjects[0]->playMovie(828, 1023, MOVIE_STOP_PREVIOUS);