[Scummvm-git-logs] scummvm branch-2-6 -> 27172de6295db03e9695b0c2c0665a00b24ab56e
AndywinXp
noreply at scummvm.org
Mon Oct 10 19:31:13 UTC 2022
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f399332f94 SCUMM: DiMUSE: Clarify and document IMuseDigital::tracksLipSync()
27172de629 SCUMM: DiMUSE: Fix endianness issues with speech lipsync
Commit: f399332f94f2bb30d291bdfd1095671d402c9f13
https://github.com/scummvm/scummvm/commit/f399332f94f2bb30d291bdfd1095671d402c9f13
Author: AndywinXp (andywinxp at gmail.com)
Date: 2022-10-10T21:28:19+02:00
Commit Message:
SCUMM: DiMUSE: Clarify and document IMuseDigital::tracksLipSync()
Changed paths:
engines/scumm/imuse_digi/dimuse_tracks.cpp
diff --git a/engines/scumm/imuse_digi/dimuse_tracks.cpp b/engines/scumm/imuse_digi/dimuse_tracks.cpp
index 388b6ec83a0..9ed01167f21 100644
--- a/engines/scumm/imuse_digi/dimuse_tracks.cpp
+++ b/engines/scumm/imuse_digi/dimuse_tracks.cpp
@@ -489,23 +489,21 @@ int IMuseDigital::tracksGetParam(int soundId, int opcode) {
}
int IMuseDigital::tracksLipSync(int soundId, int syncId, int msPos, int32 &width, int32 &height) {
- int32 h, w;
+ int32 w, h;
byte *syncPtr = nullptr;
int32 syncSize = 0;
IMuseDigiTrack *curTrack;
- uint16 msPosDiv;
- uint16 *tmpPtr;
- int32 loopIndex;
int16 val;
- h = 0;
w = 0;
+ h = 0;
curTrack = _trackList;
if (msPos >= 0) {
- msPosDiv = msPos >> 4;
+ // Check for an invalid timestamp:
+ // this has to be a suitable 2-bytes word...
if (((msPos >> 4) & 0xFFFF0000) != 0) {
return -5;
} else {
@@ -534,20 +532,36 @@ int IMuseDigital::tracksLipSync(int soundId, int syncId, int msPos, int32 &width
}
if (syncSize && syncPtr) {
- tmpPtr = (uint16 *)(syncPtr + 2);
- loopIndex = (syncSize >> 2) - 1;
- if (syncSize >> 2) {
- do {
- if (*tmpPtr >= msPosDiv)
- break;
- tmpPtr += 2;
- } while (loopIndex--);
+ // SYNC data is packed in a number of 4-bytes entries, in the following order:
+ // - Width and height values, packed as one byte each, next to each other;
+ // - The time position of said values, packed as an unsigned word (2-bytes).
+
+ // Given an input timestamp (in ms), we're going to get its representation as 60Hz
+ // increments by dividing it by 16, then we're going to search the SYNC data from
+ // the beginning to find the first entry with a timestamp being equal or greater
+ // our 60Hz timestamp.
+ uint16 inputTs = msPos >> 4;
+ int32 numOfEntries = (syncSize >> 2);
+ uint16 *syncDataWordPtr = (uint16 *)syncPtr;
+ uint16 curEntryTs = 0;
+ int idx;
+ for (idx = 0; idx < numOfEntries; idx++) {
+ curEntryTs = READ_LE_UINT16(&syncDataWordPtr[idx * 2 + 1]);
+ if (curEntryTs >= inputTs) {
+ break;
+ }
}
- if (loopIndex < 0 || *tmpPtr > msPosDiv)
- tmpPtr -= 2;
+ // If no relevant entry is found, or if the found entry timestamp is strictly greater
+ // than ours, then we get the previous entry. If no entry was found, this will get the
+ // last entry in our data block.
+ if (idx == numOfEntries || curEntryTs > inputTs) {
+ idx--;
+ }
- val = *(tmpPtr - 1);
+ // Finally, extract width and height values and remove
+ // their signs by performing AND operations with 0x7F...
+ val = READ_LE_INT16(&syncDataWordPtr[idx * 2]);
w = (val >> 8) & 0x7F;
h = val & 0x7F;
}
Commit: 27172de6295db03e9695b0c2c0665a00b24ab56e
https://github.com/scummvm/scummvm/commit/27172de6295db03e9695b0c2c0665a00b24ab56e
Author: AndywinXp (andywinxp at gmail.com)
Date: 2022-10-10T21:28:19+02:00
Commit Message:
SCUMM: DiMUSE: Fix endianness issues with speech lipsync
Changed paths:
engines/scumm/imuse_digi/dimuse_dispatch.cpp
diff --git a/engines/scumm/imuse_digi/dimuse_dispatch.cpp b/engines/scumm/imuse_digi/dimuse_dispatch.cpp
index c7a82a091bf..977ccea313c 100644
--- a/engines/scumm/imuse_digi/dimuse_dispatch.cpp
+++ b/engines/scumm/imuse_digi/dimuse_dispatch.cpp
@@ -921,6 +921,7 @@ int IMuseDigital::dispatchNavigateMap(IMuseDigiDispatch *dispatchPtr) {
continue;
case MKTAG('S', 'Y', 'N', 'C'):
+ {
// SYNC block (fixed size: x bytes)
// - The tag 'SYNC' (4 bytes)
// - SYNC size in bytes (4 bytes)
@@ -935,28 +936,38 @@ int IMuseDigital::dispatchNavigateMap(IMuseDigiDispatch *dispatchPtr) {
// four bytes of the next block in our syncPtr; but this is exactly what happens
// within the interpreter, so I'm not going to argue with it
+ int32 targetSyncSize = READ_UINT32(mapCurEvent + 4); // As per specifications above, we fetch the size
+ uint8 *mapEventStart = mapCurEvent + 4 + 4 + 4; // We skip the 'SYNC' tag, the size, and an additional 4-bytes dword
+
+ // Allocate space for the data block and fill it, 4 bytes at a time...
+ byte *syncData = (byte *)malloc(targetSyncSize);
+ uint32 *syncDwordPtr = (uint32 *)syncData;
+ uint32 *mapEventsDwordPtr = (uint32 *)mapEventStart;
+ if (syncData) {
+ for (int i = 0; i < (targetSyncSize >> 2); i++) {
+ WRITE_LE_UINT32(&syncDwordPtr[i], mapEventsDwordPtr[i]);
+ }
+ }
+
if (!dispatchPtr->trackPtr->syncPtr_0) {
- dispatchPtr->trackPtr->syncPtr_0 = (byte *)malloc(READ_UINT32(mapCurEvent + 4));
- memcpy(dispatchPtr->trackPtr->syncPtr_0, mapCurEvent + 3 * 4, READ_UINT32(mapCurEvent + 4));
- dispatchPtr->trackPtr->syncSize_0 = READ_UINT32(mapCurEvent + 4);
+ dispatchPtr->trackPtr->syncPtr_0 = syncData;
+ dispatchPtr->trackPtr->syncSize_0 = targetSyncSize;
} else if (!dispatchPtr->trackPtr->syncPtr_1) {
- dispatchPtr->trackPtr->syncPtr_1 = (byte *)malloc(READ_UINT32(mapCurEvent + 4));
- memcpy(dispatchPtr->trackPtr->syncPtr_1, mapCurEvent + 3 * 4, READ_UINT32(mapCurEvent + 4));
- dispatchPtr->trackPtr->syncSize_1 = READ_UINT32(mapCurEvent + 4);
+ dispatchPtr->trackPtr->syncPtr_1 = syncData;
+ dispatchPtr->trackPtr->syncSize_1 = targetSyncSize;
} else if (!dispatchPtr->trackPtr->syncPtr_2) {
- dispatchPtr->trackPtr->syncPtr_2 = (byte *)malloc(READ_UINT32(mapCurEvent + 4));
- memcpy(dispatchPtr->trackPtr->syncPtr_2, mapCurEvent + 3 * 4, READ_UINT32(mapCurEvent + 4));
- dispatchPtr->trackPtr->syncSize_2 = READ_UINT32(mapCurEvent + 4);
+ dispatchPtr->trackPtr->syncPtr_2 = syncData;
+ dispatchPtr->trackPtr->syncSize_2 = targetSyncSize;
} else if (!dispatchPtr->trackPtr->syncPtr_3) {
- dispatchPtr->trackPtr->syncPtr_3 = (byte *)malloc(READ_UINT32(mapCurEvent + 4));
- memcpy(dispatchPtr->trackPtr->syncPtr_3, mapCurEvent + 3 * 4, READ_UINT32(mapCurEvent + 4));
- dispatchPtr->trackPtr->syncSize_3 = READ_UINT32(mapCurEvent + 4);
+ dispatchPtr->trackPtr->syncPtr_3 = syncData;
+ dispatchPtr->trackPtr->syncSize_3 = targetSyncSize;
}
continue;
+ }
case MKTAG('F', 'R', 'M', 'T'):
// Format block (fixed size: 28 bytes)
// - The tag 'FRMT' (4 bytes)
More information about the Scummvm-git-logs
mailing list