libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
424 stars 146 forks source link

Issues with Mix_LoadMUSType_RW() reading MOD files? #622

Closed malespiaut closed 3 months ago

malespiaut commented 3 months ago

OS: ArchLinux SDL2 v2.30.5 SDL2_mixer v2.8.0

Hello,

I've coded a little demo in SDL2 and Zig in December 2023 that was playing a .mod file that was loaded in memory as an array of bytes.

Nowadays, my code stopped working. The Mix_LoadMUSType_RW() throws the error Unrecognized audio format.

I've tried different MOD files, but I get the same result.

The MOD files I've used is the following: https://ftp.modland.com/pub/modules/Protracker/-%20unknown/christmas96.mod

My Zig code for my music function is the following:

fn music_init() !void {
    if (c.Mix_OpenAudio(44100, c.MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
        c.SDL_Log("Unable to initialize SDL_mixer: %s", c.Mix_GetError());
        return error.MixOpenAudioFailed;
    }

    const music_mod: []const u8 = @embedFile("christmas96.mod");
    const rw: *c.SDL_RWops = c.SDL_RWFromConstMem(music_mod.ptr, @as(c_int, @intCast(music_mod.len))) orelse {
        c.SDL_Log("Unable to get RWFromConstMem: %s", c.SDL_GetError());
        return error.SDLRWFromConstMemFailed;
    };
    defer std.debug.assert(c.SDL_RWclose(rw) == 0);

    const music = c.Mix_LoadMUSType_RW(rw, c.MUS_MOD, 0) orelse {
        c.SDL_Log("Unable to load MOD music RW: %s", c.Mix_GetError());
        return error.MixLoadMUSTypeRWFailed;
    };

    if (c.Mix_PlayMusic(music, -1) == -1) {
        c.SDL_Log("Unable to play music: %s", c.Mix_GetError());
        return error.MixPlayMusicFailed;
    }
}

I don't know if my code is faulty, of if some changes have happened in the SDL2 library between December 2023 and today.

Best regards.

madebr commented 3 months ago

Does playmus play the MOD? (my Linux distro renamed it to playmus2)

malespiaut commented 3 months ago

@madebr No, the playmus does not play the MOD.

I would like to stress out that my software was playing the exact same MOD, no problem, when I made it in December 2023. The christmas96.mod MOD isn't faulty.

$> ./a.out christmas96.mod
INFO: Opened audio at 44100 Hz 16 bit stereo 4096 bytes audio buffer
INFO: Couldn't load christmas96.mod: Unrecognized audio format
madebr commented 3 months ago

Are you sure SDL2_mixer has been built with MOD support, provided by libxmp, libxmp-lite or libmodplug?

The file is fine, and I verified it plays with playmus from my system SDL2_mixer, current SDL2_mixer and SDL3_mixer.

malespiaut commented 3 months ago

That's a good point @madebr. On Arch Linux, SDL2 Mixer is configured wih the flags --enable-music-ogg-vorbis, --enable-music-flac-libflac, --enable-music-mp3-mpg123, --disable-music-ogg-stb, --disable-music-flac-drflac, --disable-music-mp3-drmp3, and --disable-static.

I'll try compile SDL2 Mixer on my own an see if there's any difference.

malespiaut commented 3 months ago

Alright, here's the end of the story. I already had libmodplug, but I installed libxmp and rebuilt the SDL2 Mixer package, and now everything works. So it was a system issue. Thank you very much @madebr for helping me. I'll know it next time!