From be6daf5d787de17ce5fabf36ac2e9c5488d79f1b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 30 Dec 2015 19:13:28 +0100 Subject: [PATCH] - 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. --- src/sound/music_mus_midiout.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/sound/music_mus_midiout.cpp b/src/sound/music_mus_midiout.cpp index 5f7d2d5031..5f5d39d18a 100644 --- a/src/sound/music_mus_midiout.cpp +++ b/src/sound/music_mus_midiout.cpp @@ -43,6 +43,7 @@ #include "doomdef.h" #include "m_swap.h" #include "files.h" +#include "s_sound.h" // MACROS ------------------------------------------------------------------ @@ -211,20 +212,34 @@ bool MUSSong2::CheckDone() void MUSSong2::Precache() { WORD *work = (WORD *)alloca(MusHeader->NumInstruments * sizeof(WORD)); - const WORD *used = (WORD *)MusHeader + sizeof(MUSHeader) / sizeof(WORD); - int i, j; + const BYTE *used = (BYTE *)MusHeader + sizeof(MUSHeader) / sizeof(BYTE); + 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) { - 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? - 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); }