WohlSoft / SDL-Mixer-X

SDL Mixer X (Or "MixerX" shortly) - An audio mixer library based on the SDL library, a fork of SDL_mixer
https://wohlsoft.github.io/SDL-Mixer-X/
Other
105 stars 26 forks source link

MOD music playing through libmodplug doesn't respect restart position #87

Open zeesworth opened 1 month ago

zeesworth commented 1 month ago

Hi, I'm starting to use this library for one of my projects, I'm noticing that whenever i load a .MOD file as Music with the ModPlug library enabled, the module's Restart Position does not get respected (haven't tested with XMP) I've attached an example MOD file that shows what I mean, the file should loop back to the point where the screaming starts. However playing this with the playmus example, it loops back to the beginning of the file after pausing for a moment. TEST.MOD.zip

Wohlstand commented 1 month ago

Let me check this, sounds like more like a bug, or setup confusion. Did you set the "loop infinite"?

zeesworth commented 1 month ago

Yes, the output in both my program, and the playmus example with the loop argument set, play identically

Wohlstand commented 1 month ago

I checked just now, looks like both libXMP and libModPlug has this bug. A good reason to report this problem to https://github.com/libxmp/libxmp

zeesworth commented 1 month ago

I'll report it there too, after getting libxmp compiled on my machine so I can test and verify

zeesworth commented 1 month ago

Boy do I feel like a dummy. The program I'm building uses the data from an external source, which uses MOD files to store some audio. I had neglected to test any of those original MOD files with playmus, and had only tested my example MOD, which was made in a newer software and had different handling.

The looping issue with my example file was in fact an external bug, but it wasn't the issue I thought it was. However, I cannot test any of the original files in playmus, since it doesn't seem to want to play it. It always outputs Unrecognized audio format and quits

Here is the file I'm trying to play: BIZARRETUNE.MOD.zip I can verify this file loops correctly in libxmp, but I haven't been able to test with libmodplug for the above reason

Wohlstand commented 1 month ago

Tested it just now, and it got been misdetected as an IdSoftware IMF file (a stream of raw OPL2 commands), that's another bug.

Wohlstand commented 1 month ago

Fixed that detection quickly on MixerX side.

zeesworth commented 1 month ago

I've had a chance to test this and the file does get loaded now, and I'm happy to report this song loops correctly with libxmp! However it does not loop correctly with libmodplug, that still needs to be figured out. I remember I had gotten it to work once in a different library using libmodplug by changing something, I'll have to look and see what exactly I changed

zeesworth commented 1 month ago

Looping in libmodplug can be fixed by uncommenting these lines in libmodplug/src/sndmix.cpp

                // End of song ?
                if ((m_nPattern == 0xFF) || (m_nCurrentPattern >= MAX_ORDERS))
                {
-                   //if (!m_nRepeatCount)
+                   if (!m_nRepeatCount)
                        return FALSE;     //never repeat entire song
                    if (!m_nRestartPos)
                    {
                        m_nMusicSpeed = m_nDefaultSpeed;
                        m_nMusicTempo = m_nDefaultTempo;
                            }
                        }
                    }
-                   //if (m_nRepeatCount > 0) m_nRepeatCount--;
+                   if (m_nRepeatCount > 0) m_nRepeatCount--;
                    m_nCurrentPattern = m_nRestartPos;
                    m_nRow = 0;
Wohlstand commented 1 month ago

Interesting, I should apply this at the copy of libModPlug at the AudioCodecs side (the collection of dependencies for MixerX).