aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound
diff options
context:
space:
mode:
authorPaul Gilbert2017-02-05 10:42:51 -0500
committerPaul Gilbert2017-02-05 10:42:51 -0500
commita44720e565a2456ebc2f054af9751d109bd3f5fd (patch)
treee7f73d86337d6a31fa2bf14e8eaf8a696adf5dce /engines/titanic/sound
parentfeaccfd7c9a7ecaa6121265fe4e20ee3cfb474ec (diff)
downloadscummvm-rg350-a44720e565a2456ebc2f054af9751d109bd3f5fd.tar.gz
scummvm-rg350-a44720e565a2456ebc2f054af9751d109bd3f5fd.tar.bz2
scummvm-rg350-a44720e565a2456ebc2f054af9751d109bd3f5fd.zip
TITANIC: Implemented CMusicWave read method
Diffstat (limited to 'engines/titanic/sound')
-rw-r--r--engines/titanic/sound/audio_buffer.cpp4
-rw-r--r--engines/titanic/sound/audio_buffer.h2
-rw-r--r--engines/titanic/sound/music_room_handler.cpp14
-rw-r--r--engines/titanic/sound/music_wave.cpp83
-rw-r--r--engines/titanic/sound/music_wave.h22
-rw-r--r--engines/titanic/sound/wave_file.cpp14
-rw-r--r--engines/titanic/sound/wave_file.h12
7 files changed, 112 insertions, 39 deletions
diff --git a/engines/titanic/sound/audio_buffer.cpp b/engines/titanic/sound/audio_buffer.cpp
index 425b5b3ef8..67a3d67958 100644
--- a/engines/titanic/sound/audio_buffer.cpp
+++ b/engines/titanic/sound/audio_buffer.cpp
@@ -51,9 +51,9 @@ byte *CAudioBuffer::getPtr1() {
return ptr + (_buffer.size() / 2 - _fieldC);
}
-byte *CAudioBuffer::getPtr2() {
+uint16 *CAudioBuffer::getPtr2() {
byte *ptr = getDataPtr2();
- return ptr + (_buffer.size() / 2 - _field10);
+ return (uint16 *)(ptr + (_buffer.size() / 2 - _field10));
}
void CAudioBuffer::setC(int val) {
diff --git a/engines/titanic/sound/audio_buffer.h b/engines/titanic/sound/audio_buffer.h
index ea05688377..b65f0bb8cc 100644
--- a/engines/titanic/sound/audio_buffer.h
+++ b/engines/titanic/sound/audio_buffer.h
@@ -45,7 +45,7 @@ public:
byte *getDataPtr1();
byte *getDataPtr2();
byte *getPtr1();
- byte *getPtr2();
+ uint16 *getPtr2();
int getC() const { return _fieldC; }
int get10() const { return _field10; }
void setC(int val);
diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index ad7105bd63..f25bee727a 100644
--- a/engines/titanic/sound/music_room_handler.cpp
+++ b/engines/titanic/sound/music_room_handler.cpp
@@ -205,20 +205,20 @@ void CMusicRoomHandler::updateAudio() {
_audioBuffer->enterCriticalSection();
int size = _audioBuffer->get10();
int count;
- byte *ptr;
+ uint16 *ptr;
if (size > 0) {
- byte *audioPtr = _audioBuffer->getPtr2();
+ uint16 *audioPtr = _audioBuffer->getPtr2();
Common::fill(audioPtr, audioPtr + size, 0);
for (int waveIdx = 0; waveIdx < 4; ++waveIdx) {
CMusicWave *musicWave = _musicWaves[waveIdx];
for (count = size, ptr = audioPtr; count > 0; ) {
- int amount = musicWave->setData(ptr, count);
+ int amount = musicWave->read(ptr, count);
if (amount > 0) {
count -= amount;
- ptr += amount;
+ ptr += amount / sizeof(uint16);
} else if (!fn2(waveIdx)) {
--_field108;
break;
@@ -282,12 +282,12 @@ bool CMusicRoomHandler::fn2(int index) {
}
const CValuePair &vp = mObj[arrIndex];
- int freq = static_cast<int>(fn3(index, arrIndex) * 44100.0) & ~1;
+ int size = static_cast<int>(fn3(index, arrIndex) * 44100.0) & ~1;
if (vp._field0 == 0x7FFFFFFF || _array1[index]._muteControl)
- _musicWaves[index]->setState(freq);
+ _musicWaves[index]->setSize(size);
else
- _musicWaves[index]->fn1(getPitch(index, arrIndex), freq);
+ _musicWaves[index]->processArray(getPitch(index, arrIndex), size);
if (_array1[index]._directionControl == _array2[index]._directionControl) {
++arrIndex;
diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp
index 1d6642adc9..821a4fd0f4 100644
--- a/engines/titanic/sound/music_wave.cpp
+++ b/engines/titanic/sound/music_wave.cpp
@@ -54,10 +54,10 @@ CMusicWave::CMusicWave(CProjectItem *project, CSoundManager *soundManager, Music
Common::fill(&_gameObjects[0], &_gameObjects[4], (CGameObject *)nullptr);
_floatVal = 0.0;
_field34 = -1;
- _field38 = 0;
- _field3C = 0;
- _field40 = 0;
- _field44 = 0;
+ _readPos = 0;
+ _readIncrement = 0;
+ _size = 0;
+ _count = 0;
_field4C = 0;
switch (instrument) {
@@ -87,7 +87,7 @@ CMusicWave::CMusicWave(CProjectItem *project, CSoundManager *soundManager, Music
}
}
-void CMusicWave::setSize(uint count) {
+void CMusicWave::setFilesCount(uint count) {
assert(_items.empty());
_items.resize(count);
}
@@ -254,30 +254,73 @@ void CMusicWave::trigger() {
void CMusicWave::reset() {
_field34 = 0;
- _field38 = 0;
- _field3C = 0;
- _field40 = 0;
- _field44 = 0;
+ _readPos = 0;
+ _readIncrement = 0;
+ _size = 0;
+ _count = 0;
}
-void CMusicWave::setState(int val) {
+void CMusicWave::setSize(uint total) {
_field34 = -1;
- _field38 = 0;
- _field3C = 0;
- _field40 = val;
- _field44 = 0;
+ _readPos = 0;
+ _readIncrement = 0;
+ _size = total;
+ _count = 0;
}
-int CMusicWave::setData(const byte *data, int count) {
- // TODO: Implement
- return 0;
+int CMusicWave::read(uint16 *ptr, uint size) {
+ if (!_size)
+ return 0;
+
+ if (size >= _size)
+ size = _size;
+
+ if (_field34 != -1) {
+ const byte *data = _items[_field34]._waveFile->lock(0, 0);
+ assert(data);
+ const uint16 *src = (const uint16 *)data;
+
+ // Loop through copying over data
+ for (uint idx = 0; idx < size; idx += 2, _readPos += _readIncrement) {
+ uint srcPos = _readPos >> 8;
+ if (srcPos >= _count)
+ break;
+
+ uint16 val = READ_LE_UINT16(src + srcPos);
+ *ptr++ = val;
+ }
+
+ _items[_field34]._waveFile->unlock(data);
+ }
+
+ _size -= size;
+ return size;
}
-void CMusicWave::fn1(int minVal, int maxVal) {
- // TODO
+void CMusicWave::processArray(int index, int size) {
+ if (!_array)
+ setupArray(-36, 36);
+
+ int minVal = _items[0]._value - index;
+ int minIndex = 0;
+ for (uint idx = 1; idx < _items.size(); ++idx) {
+ int val = _items[idx]._value - index;
+ if (val < minVal) {
+ minVal = val;
+ minIndex = idx;
+ }
+ }
+
+ int arrIndex = _arrayIndex - _items[minIndex]._value + index;
+
+ _field34 = minIndex;
+ _readPos = 0;
+ _readIncrement = (int)(_array[arrIndex] * 256);
+ _size = size;
+ _count = _items[minIndex]._waveFile->getSize() / 2;
}
-void CMusicWave::fn2(int minVal, int maxVal) {
+void CMusicWave::setupArray(int minVal, int maxVal) {
delete[] _array;
// TODO: Figure out if the weird shift can be represented as a simpler equation
diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h
index 6dea734cb1..d1ccb33f30 100644
--- a/engines/titanic/sound/music_wave.h
+++ b/engines/titanic/sound/music_wave.h
@@ -55,10 +55,10 @@ private:
CProjectItem *_project;
CGameObject *_gameObjects[4];
int _field34;
- int _field38;
- int _field3C;
- int _field40;
- int _field44;
+ int _readPos;
+ int _readIncrement;
+ uint _size;
+ uint _count;
int _field4C;
private:
/**
@@ -66,7 +66,7 @@ private:
*/
CWaveFile *createWaveFile(const CString &name);
- void fn2(int val1, int val2);
+ void setupArray(int minVal, int maxVal);
public:
double _floatVal;
public:
@@ -85,7 +85,7 @@ public:
/**
* Sets the maximum number of allowed files that be defined
*/
- void setSize(uint count);
+ void setFilesCount(uint count);
/**
* Loads a new file into the list of available entries
@@ -109,10 +109,14 @@ public:
void trigger();
void reset();
- void setState(int val);
+ void setSize(uint total);
- int setData(const byte *data, int count);
- void fn1(int val1, int val2);
+ /**
+ * Reads sound data and passes it to the provided buffer
+ */
+ int read(uint16 *ptr, uint size);
+
+ void processArray(int index, int freq);
};
} // End of namespace Titanic
diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp
index 6112d36fa9..78be580801 100644
--- a/engines/titanic/sound/wave_file.cpp
+++ b/engines/titanic/sound/wave_file.cpp
@@ -116,4 +116,18 @@ void CWaveFile::reset() {
_stream->rewind();
}
+uint CWaveFile::getSize() const {
+ // TODO
+ return _stream->getLength().totalNumberOfFrames() * 2;
+}
+
+const byte *CWaveFile::lock(int val1, int val2) {
+ // TODO
+ return nullptr;
+}
+
+void CWaveFile::unlock(const byte *ptr) {
+ // TODO
+}
+
} // End of namespace Titanic z
diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h
index c9a4c7d323..560188576b 100644
--- a/engines/titanic/sound/wave_file.h
+++ b/engines/titanic/sound/wave_file.h
@@ -92,6 +92,18 @@ public:
* Resets the music stream
*/
void reset();
+
+ uint getSize() const;
+
+ /**
+ * Lock sound data for access
+ */
+ const byte *lock(int val1, int val2);
+
+ /**
+ * Unlock sound data after a prior call to lock
+ */
+ void unlock(const byte *ptr);
};
} // End of namespace Titanic