Skip to content

Commit

Permalink
Add comments explaining the last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Clownacy authored and sezero committed Jan 6, 2021
1 parent e62c701 commit 692e48a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/f_mus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/mus2mid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 692e48a

Please sign in to comment.