diff options
| author | octorock <79596758+octorock@users.noreply.github.com> | 2021-09-17 22:52:05 +0200 |
|---|---|---|
| committer | octorock <79596758+octorock@users.noreply.github.com> | 2021-10-16 22:44:46 +0200 |
| commit | a46697c2d08cc7ddc2b73fca850689d92bce3edc (patch) | |
| tree | 502f2fe8bf3a21ec0a916f61da865b4cca42f8ed /tools | |
| parent | bc858317ec0c1d96b4b5aac00db91b4f0280a256 (diff) | |
Fix last music conversion issues
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/agb2mid/agb.cpp | 41 | ||||
| -rwxr-xr-x | tools/mid2agb/agb.cpp | 5 |
2 files changed, 29 insertions, 17 deletions
diff --git a/tools/agb2mid/agb.cpp b/tools/agb2mid/agb.cpp index 92be7d43..f79acc0f 100755 --- a/tools/agb2mid/agb.cpp +++ b/tools/agb2mid/agb.cpp @@ -152,7 +152,7 @@ void ReadAgbTracks() { - int addedPadding = 0; + int addedPadding = 8; // TODO configurable??? g_midiTimeDiv = 24; @@ -180,19 +180,27 @@ void ReadAgbTracks() { int loopStartTime = 0; unsigned int trackEnd = - (trackPointers.size() > count ? trackPointers[count] : (g_fileStartOffset + REDUCE_POINTERS)) - 10 - - addedPadding; // Use offset to header as end for last track + (trackPointers.size() > count ? trackPointers[count] : (g_fileStartOffset + REDUCE_POINTERS)) ; // Use offset to header as end for last track if (g_verbose) std::printf("End of track: %X\n", trackEnd); Seek(FILE_OFFSET + trackEnd - REDUCE_POINTERS); // search for a few bytes whether there is a loop end - for (int i = 0; i < 5 + addedPadding; i++) { + for (int i = 5; i < 10 + addedPadding; i++) { + if (trackEnd - i < trackPointer) { + // Ignore GOTOs from the previous track. + continue; + } + Seek(FILE_OFFSET + trackEnd - REDUCE_POINTERS -i); if (ReadInt8() == GOTO) { if (g_verbose) std::printf("Has loop: %d\n", i); - hasLoop = true; loopAddress = lReadInt32() + FILE_OFFSET - REDUCE_POINTERS; + if (loopAddress > 0x1000000) { + // The 0xB1 was probably part of the pointer or something. + continue; + } + hasLoop = true; if (g_verbose) { std::printf("Addr: %X\n", GetCurrentPtr()); std::printf("Addr: %X\n", loopAddress); @@ -266,6 +274,17 @@ void ReadAgbTracks() { while (!endOfTrack) { // std::printf("type: %X\n", type); + if (hasLoop && !foundLoop && GetCurrentPtr()-1 == loopAddress) { + if (g_verbose) + std::printf("<<<< inserted loop start\n"); + //foundLoop = true; + loopStartTime = currentTime; + Event event; + event.time = loopStartTime; + event.type = EventType::LoopBegin; + events.push_back(event); + } + if (g_verbose) std::printf("%X|@%d\t ", GetCurrentPtr() - 1, currentTime); if (type < 0x80) { @@ -449,6 +468,7 @@ void ReadAgbTracks() { } else { type = note; note = lastNote; + velocity = lastVelocity; lastNoteUsed = true; lastVelocityUsed = true; } @@ -769,16 +789,7 @@ void ReadAgbTracks() { break; } - if (hasLoop && !foundLoop && GetCurrentPtr() == loopAddress) { - if (g_verbose) - std::printf("<<<< inserted loop start\n"); - //foundLoop = true; - loopStartTime = currentTime; - Event event; - event.time = loopStartTime; - event.type = EventType::LoopBegin; - events.push_back(event); - } + // TODO notes, waits, type = ReadInt8(); diff --git a/tools/mid2agb/agb.cpp b/tools/mid2agb/agb.cpp index 83882c24..9e0feb8c 100755 --- a/tools/mid2agb/agb.cpp +++ b/tools/mid2agb/agb.cpp @@ -470,9 +470,10 @@ void PrintAgbTrack(std::vector<Event>& events) PrintSeqLoopLabel(event); break; case EventType::LoopEnd: - PrintByte("GOTO"); + PrintByte("GOTO"); PrintWord("%s_%u_B%u", g_asmLabel.c_str(), g_agbTrack, loopEndBlockNum); - PrintSeqLoopLabel(event); + //PrintSeqLoopLabel(event); // Breaks same note in EOT bgmCrenelStorm 0xDD4356 + PrintWait(event.time); // instead just print the wait break; case EventType::LoopEndBegin: PrintByte("GOTO"); |
