mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-01 15:09:47 +00:00
TITANIC: Implemented CMusicWave read method
This commit is contained in:
parent
feaccfd7c9
commit
a44720e565
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user