libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SDL3 + libxmp-lite can't play .xm files that aren't at the beginning of the stream

AntTheAlchemist opened this issue · comments

This used to work with SDL2, but with SDL3 Mix_LoadMUS_RW will fail to load a valid mod file if it's not at the beginning a stream. For instance, if you have a database file containing multiple .xm files.

I've found the offending code in libxmp/src/load.c when I went digging. Method load_module, line 251, hio_seek(h, 0, SEEK_SET);. The location of the module gets lost here if it's not at the beginning of the stream.

SDL3 is not the problem: The released versions of SDL2_mixer used to be
configured for libmodplug as module backend which loads the whole file
in memory - which can be a bad thing - and then operates on it. Current
SDL2 branch and also the SDL3 (main) branch now default to configuring
with libxmp by default as the module backend. I mean, if you build from
the current SDL2 branch you will have the same problem.

As for the issue: it is actually a can of worms.

A solution can be using a custom, start-position-aware RWops from your
end, and feeding the resulting rwops pointer to Mix_LoadMUS_RW().

@slouken: Any better advice on the matter? Anything we can actually do
in our music_xmp.c?

I miss libmodplug.

SDL works hard to retain the current stream position. Can we get the libxmp devs to do the same, rather than seek to the start of the stream?

I haven't looked into it, but can I create a duplicate RWops starting from the middle of another stream? If so, that sounds a good solution, or I could load into memory and supply a from memory RWops. No biggie.

It is a shame Mix_LoadMUS_RW & co only work on stand-alone separate files now. Does feel like a bug, especially when SDL works to retain the current stream pos.

After I call Mix_LoadMUS_RW, can I discard the SDL_RWFromConstMem? And the memory?

Yes

It seems like we ought to be able to do something similar internally. Can you attach a repro sample?

It seems like we ought to be able to do something similar internally.

There will be no end to it because issue is not limited to tracker modules.