aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel/music.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2010-10-13 03:57:44 +0000
committerJohannes Schickel2010-10-13 03:57:44 +0000
commit75e8452b6e6a2bf4fb2f588aa00b428a60d873b5 (patch)
treef29541d55309487a94bd1d38e8b53bb3dde9aec6 /engines/tinsel/music.cpp
parent48ee83b88957dab86bc763e9ef21a70179fa8679 (diff)
parente9f50882ea5b6beeefa994040be9d3bab6a1f107 (diff)
downloadscummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.gz
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.bz2
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.zip
OPENGL: Merged from trunk, from rev 52105 to 53396.
This includes an rather hacky attempt to merge all the recent gp2x backend changes into the branch. I suppose the gp2x backend and probably all new backends, i.e. gph, dingux etc., might not compile anymore. Since I have no way of testing those it would be nice if porters could look into getting those up to speed in this branch. svn-id: r53399
Diffstat (limited to 'engines/tinsel/music.cpp')
-rw-r--r--engines/tinsel/music.cpp153
1 files changed, 78 insertions, 75 deletions
diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index cb246bc8b3..0901cd08b8 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -69,42 +69,8 @@ static SOUND_BUFFER midiBuffer = { 0, 0 };
static SCNHANDLE currentMidi = 0;
static bool currentLoop = false;
-static const SCNHANDLE midiOffsetsGRAVersion[] = {
- 4, 4534, 14298, 18828, 23358, 38888, 54418, 57172, 59926, 62450,
- 62952, 67482, 72258, 74538, 79314, 87722, 103252, 115176, 127100, 127898,
- 130256, 132614, 134972, 137330, 139688, 150196, 152554, 154912, 167422, 174762,
- 182102, 194612, 198880, 199536, 206128, 206380, 216372, 226364, 235676, 244988,
- 249098, 249606, 251160, 252714, 263116, 268706, 274296, 283562, 297986, 304566,
- 312028, 313524, 319192, 324860, 331772, 336548, 336838, 339950, 343062, 346174,
- 349286, 356246, 359358, 360434, 361510, 369966, 374366, 382822, 384202, 394946,
- 396022, 396730, 399524, 401020, 403814, 418364, 419466, 420568, 425132, 433540,
- 434384, 441504, 452132, 462760, 472804, 486772, 491302, 497722, 501260, 507680,
- 509726, 521858, 524136, 525452, 533480, 538236, 549018, 559870, 564626, 565306,
- 566734, 567616, 570144, 574102, 574900, 582518, 586350, 600736, 604734, 613812,
- 616566, 619626, 623460, 627294, 631128, 634188, 648738, 663288, 667864, 681832,
- 682048, 683014, 688908, 689124, 698888, 708652, 718416, 728180, 737944, 747708,
- 752238, 765522, 766554, 772944, 774546, 776148, 776994, 781698, 786262, 789016,
- 794630, 796422, 798998
-};
-
-static const SCNHANDLE midiOffsetsSCNVersion[] = {
- 4, 4504, 11762, 21532, 26070, 28754, 33254, 40512, 56310, 72108,
- 74864, 77620, 80152, 80662, 85200, 89982, 92268, 97050, 105466, 121264,
- 133194, 145124, 145928, 148294, 150660, 153026, 155392, 157758, 168272, 170638,
- 173004, 185522, 192866, 200210, 212728, 217000, 217662, 224254, 224756, 234754,
- 244752, 245256, 245950, 255256, 264562, 268678, 269192, 270752, 272312, 282712,
- 288312, 293912, 303186, 317624, 324210, 331680, 333208, 338884, 344560, 351478,
- 356262, 356552, 359670, 362788, 365906, 369024, 376014, 379132, 380214, 381296,
- 389758, 394164, 402626, 404012, 414762, 415844, 416552, 419352, 420880, 423680,
- 438236, 439338, 440440, 445010, 453426, 454276, 461398, 472032, 482666, 492716,
- 506690, 511226, 517654, 521198, 527626, 529676, 541814, 546210, 547532, 555562,
- 560316, 571104, 581962, 586716, 587402, 588836, 589718, 592246, 596212, 597016,
- 604636, 608474, 622862, 626860, 635944, 638700, 641456, 645298, 649140, 652982,
- 655738, 670294, 684850, 689432, 703628, 703850, 704816, 706350, 706572, 716342,
- 726112, 735882, 745652, 755422, 765192, 774962, 784732, 794502, 804272, 814042,
- 823812, 832996, 846286, 847324, 853714, 855324, 856934, 857786, 862496, 867066,
- 869822, 875436, 877234, 879818
-};
+// We allocate 155 entries because that's the maximum, used in the SCN version
+static SCNHANDLE midiOffsets[155];
static const int enhancedAudioGRAVersion[] = {
1, 2, 1, 1, 3, 3, 4, 4, 5, 6, // 1-10
@@ -139,34 +105,41 @@ static const int enhancedAudioSCNVersion[] = {
77, 78, 79, 80, 4, 4, 82, 83, 77, 4, // 111-120
84, 85, 86, 3124, 88, 89, 90, 88, 2, 2, // 121-130
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 131-140
- 3141, 91, 92, 93, 94, 94, 95, 96, 52, 4, // 141-150
+ 3142, 91, 92, 93, 94, 94, 95, 96, 52, 4, // 141-150
97, 98, 99, 99 // 151-154
};
+// TODO. This mapping is wrong
+static const int enhancedAudioSCNVersionALT[] = {
+ 301, 302, 2, 1, 1, 301, 302, 3, 3, 4, // 1-10
+ 4, 5, 6, 1, 7, 8, 9, 10, 8, 11, // 11-20
+ 11, 12, 13, 13, 13, 13, 13, 14, 13, 13, // 21-30
+ 15, 16, 17, 15, 18, 19, 20, 338, 21, 21, // 31-40
+ 341, 342, 22, 22, 23, 24, 25, 26, 27, 28, // 41-50
+ 29, 30, 31, 32, 33, 34, 35, 35, 36, 37, // 51-60
+ 38, 39, 39, 39, 39, 40, 39, 41, 41, 42, // 61-70
+ 43, 42, 44, 45, 41, 46, 48, 47, 48, 49, // 71-80
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, // 81-90
+ 60, 61, 62, 63, 61, 64, 65, 66, 67, 68, // 91-100
+ 69, 70, 68, 71, 72, 73, 74, 75, 12, 76, // 101-110
+ 77, 78, 79, 80, 4, 4, 82, 83, 77, 4, // 111-120
+ 84, 85, 86, 3124, 88, 89, 90, 88, 2, 2, // 121-130
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 131-140
+ 3142, 91, 92, 93, 94, 94, 95, 96, 52, 4, // 141-150
+ 97, 98, 99 // 151-153
+};
+
int GetTrackNumber(SCNHANDLE hMidi) {
- if (_vm->getFeatures() & GF_SCNFILES) {
- for (int i = 0; i < ARRAYSIZE(midiOffsetsSCNVersion); i++) {
- if (midiOffsetsSCNVersion[i] == hMidi)
- return i;
- }
- } else {
- for (int i = 0; i < ARRAYSIZE(midiOffsetsGRAVersion); i++) {
- if (midiOffsetsGRAVersion[i] == hMidi)
- return i;
- }
- }
+ for (int i = 0; i < ARRAYSIZE(midiOffsets); i++)
+ if (midiOffsets[i] == hMidi)
+ return i;
return -1;
}
SCNHANDLE GetTrackOffset(int trackNumber) {
- if (_vm->getFeatures() & GF_SCNFILES) {
- assert(trackNumber < ARRAYSIZE(midiOffsetsSCNVersion));
- return midiOffsetsSCNVersion[trackNumber];
- } else {
- assert(trackNumber < ARRAYSIZE(midiOffsetsGRAVersion));
- return midiOffsetsGRAVersion[trackNumber];
- }
+ assert(trackNumber < ARRAYSIZE(midiOffsets));
+ return midiOffsets[trackNumber];
}
/**
@@ -184,7 +157,11 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) {
if (TinselV1PSX) return false;
if (_vm->_config->_musicVolume != 0) {
- SetMidiVolume(_vm->_config->_musicVolume);
+ bool mute = false;
+ if (ConfMan.hasKey("mute"))
+ mute = ConfMan.getBool("mute");
+
+ SetMidiVolume(mute ? 0 : _vm->_config->_musicVolume);
}
// the index and length of the last tune loaded
@@ -198,7 +175,9 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) {
int trackNumber = GetTrackNumber(dwFileOffset);
int track = 0;
if (trackNumber >= 0) {
- if (_vm->getFeatures() & GF_SCNFILES)
+ if (_vm->getFeatures() & GF_ALT_MIDI)
+ track = enhancedAudioSCNVersionALT[trackNumber];
+ else if (_vm->getFeatures() & GF_SCNFILES)
track = enhancedAudioSCNVersion[trackNumber];
else
track = enhancedAudioGRAVersion[trackNumber];
@@ -383,6 +362,34 @@ void OpenMidiFiles() {
}
}
+ // Now scan through the contents of the MIDI file to find the offset
+ // of each individual track, in order to create a mapping from MIDI
+ // offset to track number, for the enhanced MIDI soundtrack.
+ // The first song is always at position 4. The subsequent ones are
+ // calculated dynamically.
+ uint32 curOffset = 4;
+ uint32 curTrack = 0;
+ uint32 songLength = 0;
+
+ // Init
+ for (int i = 0; i < ARRAYSIZE(midiOffsets); i++)
+ midiOffsets[i] = 0;
+
+ while (!midiStream.eos() && !midiStream.err()) {
+ if (curOffset + (4 * curTrack) >= (uint32)midiStream.size())
+ break;
+
+ assert(curTrack < ARRAYSIZE(midiOffsets));
+ midiOffsets[curTrack] = curOffset + (4 * curTrack);
+ //printf("%d: %d\n", curTrack, midiOffsets[curTrack]);
+
+ songLength = midiStream.readUint32LE();
+ curOffset += songLength;
+ midiStream.skip(songLength);
+
+ curTrack++;
+ }
+
midiStream.close();
}
@@ -963,8 +970,12 @@ void RestoreMidiFacts(SCNHANDLE Midi, bool Loop) {
currentLoop = Loop;
if (_vm->_config->_musicVolume != 0 && Loop) {
+ bool mute = false;
+ if (ConfMan.hasKey("mute"))
+ mute = ConfMan.getBool("mute");
+
PlayMidiSequence(currentMidi, true);
- SetMidiVolume(_vm->_config->_musicVolume);
+ SetMidiVolume(mute ? 0 : _vm->_config->_musicVolume);
}
}
@@ -978,29 +989,21 @@ void dumpMusic() {
int outFileSize = 0;
char buffer[20000];
- int total = (_vm->getFeatures() & GF_SCNFILES) ?
- ARRAYSIZE(midiOffsetsSCNVersion) :
- ARRAYSIZE(midiOffsetsGRAVersion);
+ const int total = 155; // maximum (SCN version)
for (int i = 0; i < total; i++) {
+ if (midiOffsets[i] == 0)
+ break;
+
sprintf(outName, "track%03d.xmi", i + 1);
outFile.open(outName);
- if (_vm->getFeatures() & GF_SCNFILES) {
- if (i < total - 1)
- outFileSize = midiOffsetsSCNVersion[i + 1] - midiOffsetsSCNVersion[i] - 4;
- else
- outFileSize = midiFile.size() - midiOffsetsSCNVersion[i] - 4;
-
- midiFile.seek(midiOffsetsSCNVersion[i] + 4, SEEK_SET);
- } else {
- if (i < total - 1)
- outFileSize = midiOffsetsGRAVersion[i + 1] - midiOffsetsGRAVersion[i] - 4;
- else
- outFileSize = midiFile.size() - midiOffsetsGRAVersion[i] - 4;
+ if (i < total - 1)
+ outFileSize = midiOffsets[i + 1] - midiOffsets[i] - 4;
+ else
+ outFileSize = midiFile.size() - midiOffsets[i] - 4;
- midiFile.seek(midiOffsetsGRAVersion[i] + 4, SEEK_SET);
- }
+ midiFile.seek(midiOffsets[i] + 4, SEEK_SET);
assert(outFileSize < 20000);
midiFile.read(buffer, outFileSize);