From 98e1c1994b8bd75113ffe971eebbfb0acf0d2e81 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Mon, 24 Sep 2018 02:00:09 -0500 Subject: Completely blind guess to fix compression score --- tools/mid2agb/midi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index c7a4389b9..744ef42e8 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -836,7 +836,7 @@ int CalculateCompressionScore(std::vector& events, int index) } else { - score += 2; + score++; } } @@ -900,7 +900,7 @@ void Compress(std::vector& events) return; } - if (CalculateCompressionScore(events, i) > 6) + if (CalculateCompressionScore(events, i) >= 6) { CompressWholeNote(events, i); } -- cgit v1.2.3 From 48b65eecee4675415605b2734fe32f3048382a9c Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 25 Sep 2018 01:26:09 -0500 Subject: Match compression behavior, for real --- tools/mid2agb/midi.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 744ef42e8..1458a32b3 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -773,14 +773,16 @@ void CalculateWaits(std::vector& events) } } +// This code is (purposely) buggy as shit, to mimic how the real mid2agb worked int CalculateCompressionScore(std::vector& events, int index) { int score = 0; - std::uint8_t lastParam1 = events[index].param1; + std::uint8_t lastParam1 = (std::uint8_t)events[index].type; std::uint8_t lastVelocity = 0x80u; EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; std::uint8_t lastNote = 0x80u; + std::int32_t lastParam2; if (events[index].time > 0) score++; @@ -791,10 +793,11 @@ int CalculateCompressionScore(std::vector& events, int index) { int val = 0; - if (events[i].note != lastNote) + // BUG: uses type instead of note + if ((std::uint8_t)events[i].type != lastNote) { val++; - lastNote = events[i].note; + lastNote = (std::uint8_t)events[i].type; } if (events[i].param1 != lastVelocity) @@ -840,7 +843,10 @@ int CalculateCompressionScore(std::vector& events, int index) } } - lastParam1 = events[i].param1; + // BUG: uses type instead of param1 + lastParam1 = (std::uint8_t)events[i].type; + // unused + lastParam2 = events[i].param2; lastType = events[i].type; if (events[i].time) -- cgit v1.2.3 From af4ff89e550455bbd503a44ac26ba6b1bc2857f7 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 25 Sep 2018 01:32:13 -0500 Subject: Comment out unused variable so GCC doesn't complain --- tools/mid2agb/midi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 1458a32b3..8a84a0945 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -782,7 +782,7 @@ int CalculateCompressionScore(std::vector& events, int index) EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; std::uint8_t lastNote = 0x80u; - std::int32_t lastParam2; + //std::int32_t lastParam2; if (events[index].time > 0) score++; @@ -846,7 +846,7 @@ int CalculateCompressionScore(std::vector& events, int index) // BUG: uses type instead of param1 lastParam1 = (std::uint8_t)events[i].type; // unused - lastParam2 = events[i].param2; + //lastParam2 = events[i].param2; lastType = events[i].type; if (events[i].time) -- cgit v1.2.3 From 7f38a03093cf20e1db57ec739029fff316e69686 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 25 Sep 2018 11:41:18 -0500 Subject: mid2agb compression algorithm less buggy than originally thought --- tools/mid2agb/midi.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 8a84a0945..be5454d4e 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -773,7 +773,6 @@ void CalculateWaits(std::vector& events) } } -// This code is (purposely) buggy as shit, to mimic how the real mid2agb worked int CalculateCompressionScore(std::vector& events, int index) { int score = 0; @@ -782,7 +781,12 @@ int CalculateCompressionScore(std::vector& events, int index) EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; std::uint8_t lastNote = 0x80u; - //std::int32_t lastParam2; + + if (events[index].type == EventType::Note) + { + // Bug reintroduction + lastParam1 |= events[index].note + 0x40; + } if (events[index].time > 0) score++; @@ -793,11 +797,10 @@ int CalculateCompressionScore(std::vector& events, int index) { int val = 0; - // BUG: uses type instead of note - if ((std::uint8_t)events[i].type != lastNote) + if (events[i].note != lastNote) { val++; - lastNote = (std::uint8_t)events[i].type; + lastNote = events[i].note; } if (events[i].param1 != lastVelocity) @@ -845,8 +848,12 @@ int CalculateCompressionScore(std::vector& events, int index) // BUG: uses type instead of param1 lastParam1 = (std::uint8_t)events[i].type; - // unused - //lastParam2 = events[i].param2; + if (events[i].type == EventType::Note) + { + // Bug reintroduction + lastParam1 |= events[i].note + 0x40; + } + lastType = events[i].type; if (events[i].time) -- cgit v1.2.3 From d86b290419169579ecbca29aafcc46bb5a53f34f Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 25 Sep 2018 11:43:46 -0500 Subject: Change initial state of lastNote --- tools/mid2agb/midi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index be5454d4e..b49970282 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -780,7 +780,7 @@ int CalculateCompressionScore(std::vector& events, int index) std::uint8_t lastVelocity = 0x80u; EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; - std::uint8_t lastNote = 0x80u; + std::uint8_t lastNote = 0x40u; if (events[index].type == EventType::Note) { -- cgit v1.2.3 From f143e184a87d95338b95a34bfd64a3aff7258dee Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 25 Sep 2018 23:09:18 -0500 Subject: Fix compression score code bug reintroduction --- tools/mid2agb/midi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index b49970282..e506fcb09 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -785,7 +785,7 @@ int CalculateCompressionScore(std::vector& events, int index) if (events[index].type == EventType::Note) { // Bug reintroduction - lastParam1 |= events[index].note + 0x40; + lastParam1 = events[index].note + 0x40; } if (events[index].time > 0) @@ -842,7 +842,7 @@ int CalculateCompressionScore(std::vector& events, int index) } else { - score++; + score += 2; } } @@ -851,7 +851,7 @@ int CalculateCompressionScore(std::vector& events, int index) if (events[i].type == EventType::Note) { // Bug reintroduction - lastParam1 |= events[i].note + 0x40; + lastParam1 = events[i].note + 0x40; } lastType = events[i].type; -- cgit v1.2.3 From 6a82bbe973740afa871a488022550711ff37de12 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Sat, 29 Sep 2018 14:46:59 -0500 Subject: Fix the fix that was buggy --- tools/mid2agb/midi.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index e506fcb09..93600d30e 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -776,18 +776,12 @@ void CalculateWaits(std::vector& events) int CalculateCompressionScore(std::vector& events, int index) { int score = 0; - std::uint8_t lastParam1 = (std::uint8_t)events[index].type; + std::uint8_t lastParam1 = events[index].param1; std::uint8_t lastVelocity = 0x80u; EventType lastType = events[index].type; std::int32_t lastDuration = 0x80000000; std::uint8_t lastNote = 0x40u; - if (events[index].type == EventType::Note) - { - // Bug reintroduction - lastParam1 = events[index].note + 0x40; - } - if (events[index].time > 0) score++; @@ -846,18 +840,11 @@ int CalculateCompressionScore(std::vector& events, int index) } } - // BUG: uses type instead of param1 - lastParam1 = (std::uint8_t)events[i].type; - if (events[i].type == EventType::Note) - { - // Bug reintroduction - lastParam1 = events[i].note + 0x40; - } - + lastParam1 = events[i].param1; lastType = events[i].type; if (events[i].time) - ++score; + score++; } return score; -- cgit v1.2.3 From c13d2b567c28f2e837be2210c83a250c0de4778f Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 2 Oct 2018 12:07:02 -0500 Subject: mid2agb fix: compare whole note details before compression --- tools/mid2agb/midi.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tools/mid2agb/midi.cpp') diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 93600d30e..fa7d9ce28 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -852,6 +852,12 @@ int CalculateCompressionScore(std::vector& events, int index) bool IsCompressionMatch(std::vector& events, int index1, int index2) { + if (events[index1].type != events[index2].type || + events[index1].note != events[index2].note || + events[index1].param1 != events[index2].param1 || + events[index1].time != events[index2].time) + return false; + index1++; index2++; -- cgit v1.2.3