SDL-Mixer-X icon indicating copy to clipboard operation
SDL-Mixer-X copied to clipboard

MOD music playing through libmodplug doesn't respect restart position

Open zeesworth opened this issue 1 year ago • 10 comments

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

zeesworth avatar Sep 30 '24 12:09 zeesworth

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

Wohlstand avatar Sep 30 '24 12:09 Wohlstand

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

zeesworth avatar Sep 30 '24 12:09 zeesworth

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

Wohlstand avatar Sep 30 '24 13:09 Wohlstand

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

zeesworth avatar Sep 30 '24 13:09 zeesworth

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

zeesworth avatar Oct 04 '24 08:10 zeesworth

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 avatar Oct 04 '24 08:10 Wohlstand

Fixed that detection quickly on MixerX side.

Wohlstand avatar Oct 04 '24 08:10 Wohlstand

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 avatar Oct 04 '24 09:10 zeesworth

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;

zeesworth avatar Oct 04 '24 10:10 zeesworth

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

Wohlstand avatar Oct 04 '24 10:10 Wohlstand