From 692e48a124617a664d72b098e2bb61c40999ce30 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 6 Jan 2021 15:48:47 +0000 Subject: [PATCH] Add comments explaining the last commit --- src/f_mus.c | 6 ++++++ src/mus2mid.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/f_mus.c b/src/f_mus.c index 368b5e0c..5f2430f5 100644 --- a/src/f_mus.c +++ b/src/f_mus.c @@ -163,6 +163,9 @@ _WM_ParseNewMus(uint8_t *mus_data, uint32_t mus_size) { mus_event[0] = 0x90 | (mus_data[mus_data_ofs] & 0x0f); mus_event[1] = mus_data[mus_data_ofs + 1] & 0x7f; mus_event[2] = mus_data[mus_data_ofs + 2]; + // The maximum volume is 127, but it is encoded as a byte. Some songs + // erroneously use values higher than 127, so we have to clamp them down. + // https://github.com/Mindwerks/wildmidi/pull/226 if (mus_event[2] > 0x7f) mus_event[2] = 0x7f; mus_event[3] = 0; mus_prev_vol[mus_data[mus_data_ofs] & 0x0f] = mus_event[2]; @@ -260,6 +263,9 @@ _WM_ParseNewMus(uint8_t *mus_data, uint32_t mus_size) { mus_event[0] = 0xb0 | (mus_data[mus_data_ofs] & 0x0f); mus_event[1] = 7; mus_event[2] = mus_data[mus_data_ofs + 2]; + // The maximum volume is 127, but it is encoded as a byte. Some songs + // erroneously use values higher than 127, so we have to clamp them down. + // https://github.com/Mindwerks/wildmidi/pull/226 if (mus_event[2] > 0x7f) mus_event[2] = 0x7f; mus_event[3] = 0; break; diff --git a/src/mus2mid.c b/src/mus2mid.c index 1f3eaea9..4c37751a 100644 --- a/src/mus2mid.c +++ b/src/mus2mid.c @@ -353,6 +353,9 @@ int _WM_mus2midi(const uint8_t *in, uint32_t insize, bit1 = *cur & 127; if (*cur++ & 128) { /* volume bit? */ channel_volume[channelMap[channel]] = *cur++; + /* The maximum volume is 127, but it is encoded as a byte. Some songs + erroneously use values higher than 127, so we have to clamp them down. + https://github.com/Mindwerks/wildmidi/pull/226 */ if (channel_volume[channelMap[channel]] > 127) channel_volume[channelMap[channel]] = 127; } bit2 = channel_volume[channelMap[channel]]; @@ -388,6 +391,9 @@ int _WM_mus2midi(const uint8_t *in, uint32_t insize, } bit1 = midimap[*cur++]; bit2 = *cur++; + /* The maximum volume is 127, but it is encoded as a byte. Some songs + erroneously use values higher than 127, so we have to clamp them down. + https://github.com/Mindwerks/wildmidi/pull/226 */ if (bit1 == 0x07 && bit2 > 127) bit2 = 127; } break;