- changed instrument lookup in MUS files.

Based on evidence from several songs in Eternal Doom the description in all known documents is wrong. The instruments are not stored in a 16-bit word but in an 8-bit byte, followed by some variable size data.

Known variations are:

* second byte is 0 - no additional data follows
* second byte is 1 - a third byte for the 'bank' value follows.
This commit is contained in:
Christoph Oelckers 2015-12-30 19:13:28 +01:00
parent 8f149d9048
commit be6daf5d78

View file

@ -43,6 +43,7 @@
#include "doomdef.h" #include "doomdef.h"
#include "m_swap.h" #include "m_swap.h"
#include "files.h" #include "files.h"
#include "s_sound.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -211,20 +212,34 @@ bool MUSSong2::CheckDone()
void MUSSong2::Precache() void MUSSong2::Precache()
{ {
WORD *work = (WORD *)alloca(MusHeader->NumInstruments * sizeof(WORD)); WORD *work = (WORD *)alloca(MusHeader->NumInstruments * sizeof(WORD));
const WORD *used = (WORD *)MusHeader + sizeof(MUSHeader) / sizeof(WORD); const BYTE *used = (BYTE *)MusHeader + sizeof(MUSHeader) / sizeof(BYTE);
int i, j; int i, j, k;
for (i = j = 0; i < MusHeader->NumInstruments; ++i) for (i = j = k = 0; i < MusHeader->NumInstruments; ++i)
{ {
WORD instr = LittleShort(used[i]); BYTE instr = used[k++];
WORD val;
if (instr < 128) if (instr < 128)
{ {
work[j++] = instr; val = instr;
} }
else if (used[i] >= 135 && used[i] <= 181) else if (instr >= 135 && instr <= 181)
{ // Percussions are 100-based, not 128-based, eh? { // Percussions are 100-based, not 128-based, eh?
work[j++] = instr - 100 + (1 << 14); val = instr - 100 + (1 << 14);
} }
BYTE moreparam = used[k++];
if (moreparam == 1)
{
BYTE bank = used[k++];
val |= (bank << 7);
}
else if (moreparam > 0)
{
// No information if this is even valid. Print a message so it can be investigated later
Printf("Unknown instrument data found in music\n");
}
work[j++] = val;
} }
MIDI->PrecacheInstruments(&work[0], j); MIDI->PrecacheInstruments(&work[0], j);
} }