arnaud-carre / LSPlayer

Fastest Amiga Module player ever
MIT License
97 stars 8 forks source link

Apple Clang and Ubuntu GCC output different .lsmusic files #14

Closed asimilon closed 5 months ago

asimilon commented 5 months ago

With some minor edits I got the converter to compile on both macOS and Ubuntu in CLion, but there is a big issue with neither of the resulting binaries outputting the same .lsmusic as MSVC (.lsbank is fine).

This is more of a "is there anyone else out there who would like to get involved" request than an "issue" so to speak, unless Arnaud cares that it's not portable. 😉

You can find a macOS branch on my fork here : https://github.com/asimilon/LSPlayer which has a CMakeLists.txt to make things more cross-platform,

I've not been able to figure out thus far why the following is happening using rink-a-dink.mod as the test data:

The first 0x194 bytes are identical, then it diverges like so:

MSVC  : 55080064 11203351 01005108 3F325500 10083044 3F630040 3C620311 10010310 11081508 05000400 3C223F73 54083F33 00813340 15803F72 10103C00
Clang : 00643351 11205508 01005108 3F325500 10083044 3F630040 3C620311 03101001 15081108 05000400 54083C22 3F333F73 15800081 33403F72 10103C00
GCC   : 33511120 55080064 01005108 3F325500 10083044 3F630040 3C620311 10010310 11081508 05000400 3F735408 3C223F33 00811580 33403F72 0C221010

as you can see it's the same 16 bit words, but some of them are out of order, in different ways on the different platforms!

Until 0x34C there is this issue with out-of-order words, after which they stay in sync until 0x2924 where it starts going wrong again, but this time it's single bytes and I haven't seen any pattern about the differences.

The first set of discrepencies arise from writing the m_cmdEncoder contents (https://github.com/asimilon/LSPlayer/blob/macOS/src/LSPEncoder.cpp#L1164), so when I am able I'm planning to do some debugging between Windows and macOS to see if I can figure out at which point the two platforms diverge. My "hunch" is that perhaps qsort in https://github.com/asimilon/LSPlayer/blob/macOS/src/ValueEncoder.cpp#L155 is platform dependant, or certainly some aspect of ValueEncoder is not behaving the same between the platforms.

arnaud-carre commented 5 months ago

what happen if you try the -amigapreview command? Is the produced wav completly off, or does it sound good?

asimilon commented 5 months ago

I need to do some proper testing with a .mod I'm more familiar with, but actually seems OK on the face of it. It never occurred to me that different platforms would create different outputs and yet still be valid. If all goes according to plan I'll rework my changes to be less destructive regards the original source and make a PR. Would you be happy with me removing the .sln, as can reproduce it from CMake and it keeps everything a bit tidier?

arnaud-carre commented 5 months ago

both .lsmusic and .lsbank files should be exactly identical on PC or MAC. If not, there is an issue we should fix. Using cmake for the MAC version is ok, but I want to keep the .sln for windows version. Doesn't need additional cmake to install and more user friendly for both visual studio and 10xeditor users :)

arnaud-carre commented 5 months ago

oh you're right, the issue is that "qsort" isn't stable across platforms. I just pushed a quick fix to make it stable. Just pull the new code and it should produce the exact same file on any platform.

asimilon commented 5 months ago

Output is now identical on all platforms, thanks for fixing that!