SDL_mixer is recognizing MP3 as MOD

There’s one MP3 track that when trying to load it with Mix_LoadMUS_RW(),
SDL_mixer thinks it’s a MOD file and fails with “Module format not
recognized”. Is there anything I can do about it? When loading it, I
know it’s going to be MP3 data, but I can’t find any way to tell that to
SDL_mixer.

Touching the MP3 data itself is not an option, since the application is
a game engine (a bit like SCUMMVM) that runs pre-existing games made by
people I never heard about.

I’m out of ideas :-/

Verify the file in a different media player.? SDL_Mixer attempts to check “magic numbers” in a music file’s header against known values, and if it can’t find a match, it defaults to MOD.? What this behavior means is that the check against the known header magic number for an MP3 file is failing, which most likely means your file is corrupt in some way.________________________________
From: realnc@arcor.de (Nikos Chantziaras)
To: sdl at libsdl.org
Sent: Thursday, July 14, 2011 3:34 PM
Subject: [SDL] SDL_mixer is recognizing MP3 as MOD

There’s one MP3 track that when trying to load it with Mix_LoadMUS_RW(), SDL_mixer thinks it’s a MOD file and fails with “Module format not recognized”.? Is there anything I can do about it?? When loading it, I know it’s going to be MP3 data, but I can’t find any way to tell that to SDL_mixer.

Touching the MP3 data itself is not an option, since the application is a game engine (a bit like SCUMMVM) that runs pre-existing games made by people I never heard about.

I’m out of ideas :-/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Extracting the file and playing it with madplay and mpg123 works. The
file seems damaged though. madplay says:

error: frame 0: lost synchronization
error: frame 4: lost synchronization

but plays the file fine. The original Windows-only engine (which my
Linux/Mac application must be compatible with) is very tolerant on this
and plays MP3s even if they seem damaged (using code from mpg123), and
therefore there are games for that engine that seem to use damaged MP3s.
Obviously, I need to be able to do the same, otherwise I’m not going
to be compatible with the original Windows-engine.On 07/15/2011 01:45 AM, Mason Wheeler wrote:

Verify the file in a different media player. SDL_Mixer attempts to check
"magic numbers" in a music file’s header against known values, and if it
can’t find a match, it defaults to MOD. What this behavior means is that
the check against the known header magic number for an MP3 file is
failing, which most likely means your file is corrupt in some way.

From: Nikos Chantziaras
To: sdl at libsdl.org
Sent: Thursday, July 14, 2011 3:34 PM
Subject: [SDL] SDL_mixer is recognizing MP3 as MOD

There’s one MP3 track that when trying to load it with Mix_LoadMUS_RW(),
SDL_mixer thinks it’s a MOD file and fails with “Module format not
recognized”. Is there anything I can do about it? When loading it, I
know it’s going to be MP3 data, but I can’t find any way to tell that to
SDL_mixer.

Touching the MP3 data itself is not an option, since the application is
a game engine (a bit like SCUMMVM) that runs pre-existing games made by
people I never heard about.

I’m out of ideas :-/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, that’s what’s happening.? You’ve basically got three options.

  1. Use something else instead of SDL_Mixer
  2. Hack SDL_Mixer and make the verification work
  3. Monitor your music and dynamically fix the broken songs in memory before they get sent to SDL_Mixer________________________________
    From: realnc@arcor.de (Nikos Chantziaras)
    To: sdl at libsdl.org
    Sent: Thursday, July 14, 2011 4:17 PM
    Subject: Re: [SDL] SDL_mixer is recognizing MP3 as MOD

Extracting the file and playing it with madplay and mpg123 works.? The file seems damaged though.? madplay says:

? error: frame 0: lost synchronization
? error: frame 4: lost synchronization

but plays the file fine.? The original Windows-only engine (which my Linux/Mac application must be compatible with) is very tolerant on this and plays MP3s even if they seem damaged (using code from mpg123), and therefore there are games for that engine that seem to use damaged MP3s.? Obviously, I need to be able to do the same, otherwise I’m not going to be compatible with the original Windows-engine.

On 07/15/2011 01:45 AM, Mason Wheeler wrote:

Verify the file in a different media player. SDL_Mixer attempts to check
"magic numbers" in a music file’s header against known values, and if it
can’t find a match, it defaults to MOD. What this behavior means is that
the check against the known header magic number for an MP3 file is
failing, which most likely means your file is corrupt in some way.

From: Nikos Chantziaras
To: sdl at libsdl.org
Sent: Thursday, July 14, 2011 3:34 PM
Subject: [SDL] SDL_mixer is recognizing MP3 as MOD

There’s one MP3 track that when trying to load it with Mix_LoadMUS_RW(),
SDL_mixer thinks it’s a MOD file and fails with “Module format not
recognized”. Is there anything I can do about it? When loading it, I
know it’s going to be MP3 data, but I can’t find any way to tell that to
SDL_mixer.

Touching the MP3 data itself is not an option, since the application is
a game engine (a bit like SCUMMVM) that runs pre-existing games made by
people I never heard about.

I’m out of ideas :-/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello !

There’s one MP3 track that when trying to load it with Mix_LoadMUS_RW(), SDL_mixer thinks it’s a MOD file and fails with “Module format not recognized”. Is there anything I can do about it? When loading it, I know it’s going to be MP3 data, but I can’t find any way to tell that to SDL_mixer.

Touching the MP3 data itself is not an option, since the application is a game engine (a bit like SCUMMVM) that runs pre-existing games made by people I never heard about.

I’m out of ideas :-/

Would it be possible to publish a short MP3 that shows the problem
and is 5-10 seconds long ? It would allow people to do experiments with it.

CU

The whole file is just 2080 bytes. It only contains a small amount of
silence in it. The game tries to play it, and if it succeeds, it knows
that the system the engine is running in supports playback.

http://foss.aegean.gr/~realnc/file.mp3

From what I can tell at looking in the file, it was encoded with LAME.

I also have an FMOD backend implemented for the engine; FMOD plays it OK.On 07/15/2011 03:41 AM, Torsten Giebl wrote:

Hello !

There’s one MP3 track that when trying to load it with
Mix_LoadMUS_RW(), SDL_mixer thinks it’s a MOD file and fails with
"Module format not recognized". Is there anything I can do about it?
When loading it, I know it’s going to be MP3 data, but I can’t find
any way to tell that to SDL_mixer.

Touching the MP3 data itself is not an option, since the application
is a game engine (a bit like SCUMMVM) that runs pre-existing games
made by people I never heard about.

I’m out of ideas :-/

Would it be possible to publish a short MP3 that shows the problem
and is 5-10 seconds long ? It would allow people to do experiments with it.

http://foss.aegean.gr/~realnc/file.mp3

From what I can tell at looking in the file, it was encoded with LAME.

It is, strictly speaking, a corrupt MP3. It’s got a bunch of NULL bytes
at the front.

That being said, there are a lot of corrupt MP3 files that will play
without obvious problems if you let the player skip ahead until it finds
valid frames, so here’s a patch for Mix_LoadMUS() that will ignore the
magic in mp3 files. Please note that this won’t work for
Mix_LoadMUS_RW(), as that doesn’t take a filename. Basically this patch
says: if you say it’s an “.mp3”, we’ll believe you.

I don’t have SMPEG or libmad installed here, so you’ll have to tell me
if this works for you before I can commit it. Attached.

–ryan.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlmixer-no-mp3-magic-RYAN1.diff
Type: text/x-diff
Size: 1476 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110715/09a0e1d3/attachment.diff

Thanks, Ryan, but unfortunately, I’m using Mix_LoadMUS_RW(). There are
no individual MP3 files; everything is in a big, uncompressed, single file.On 07/16/2011 03:23 AM, Ryan C. Gordon wrote:

http://foss.aegean.gr/~realnc/file.mp3

From what I can tell at looking in the file, it was encoded with LAME.

It is, strictly speaking, a corrupt MP3. It’s got a bunch of NULL bytes
at the front.

That being said, there are a lot of corrupt MP3 files that will play
without obvious problems if you let the player skip ahead until it finds
valid frames, so here’s a patch for Mix_LoadMUS() that will ignore the
magic in mp3 files. Please note that this won’t work for
Mix_LoadMUS_RW(), as that doesn’t take a filename. Basically this patch
says: if you say it’s an “.mp3”, we’ll believe you.

I don’t have SMPEG or libmad installed here, so you’ll have to tell me
if this works for you before I can commit it. Attached.


From: realnc@arcor.de (Nikos Chantziaras)
Subject: Re: [SDL] SDL_mixer is recognizing MP3 as MOD

Thanks, Ryan, but unfortunately, I’m using Mix_LoadMUS_RW().? There are
no individual MP3 files; everything is in a big, uncompressed, single file.

Then you’re in a bind.? The load music function needs to have some way of telling what type of music to load.? If it’s loading from a file it can infer a type from the filename.? If not, it has to figure it out from the magic numbers in the file header.? Your MP3 player can play it with a corrupt header because it already knows that it’s dealing with am MP3.? But SDL_Mixer doesn’t know that.? You need some way for it to recognize what you have as an MP3.? What would you propose?

Thanks, Ryan, but unfortunately, I’m using Mix_LoadMUS_RW(). There are
no individual MP3 files; everything is in a big, uncompressed, single file.

Then you’re in a bind. The load music function needs to have some way of
telling what type of music to load. If it’s loading from a file it can
infer a type from the filename. If not, it has to figure it out from the
magic numbers in the file header. Your MP3 player can play it with a
corrupt header because it already knows that it’s dealing with am MP3.
But SDL_Mixer doesn’t know that. You need some way for it to recognize
what you have as an MP3. What would you propose?

An argument to Mix_LoadMUS_RW() for the type. But this breaks the API,
of course. So if there’s not going to be an SDL_mixer 2.0 any time
soon, a new Mix_LoadMUS_Type_RW() might do it.On 07/16/2011 08:17 AM, Mason Wheeler wrote:

From: Nikos Chantziaras
**Subject: Re: [SDL] SDL_mixer is recognizing MP3 as MOD

I now introduced a new function:

Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type)

‘type’ can be NULL, which means auto-detection will be performed. The
normal Mix_LoadMUS_RW() routine now has only a single line:

Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw)
{
return Mix_LoadMUSType_RW(rw, MUS_NONE);
}

Note that Mix_LoadMUS_RW() can’t be defined as a macro, since that
breaks binary compatibility.

I am attaching the patch against current Hg. It’s quite short, but
please take a look at it in case I screwed something up.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: mustype_support.patch
Type: text/x-patch
Size: 3716 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110716/67bf1f89/attachment.binOn 07/16/2011 08:46 AM, Nikos Chantziaras wrote:

On 07/16/2011 08:17 AM, Mason Wheeler wrote:

You need some way for it to recognize what you have as an MP3.
What would you propose?

An argument to Mix_LoadMUS_RW() for the type. But this breaks the API,
of course. So if there’s not going to be an SDL_mixer 2.0 any time soon,
a new Mix_LoadMUS_Type_RW() might do it.

Er, I obviously meant MUS_NONE, not NULL.On 07/16/2011 10:50 AM, Nikos Chantziaras wrote:

I now introduced a new function:

Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type)

‘type’ can be NULL, which means auto-detection will be performed.

So I suppose there’s no interest in including this in SDL_mixer?On 07/16/2011 10:50 AM, Nikos Chantziaras wrote:

On 07/16/2011 08:46 AM, Nikos Chantziaras wrote:

On 07/16/2011 08:17 AM, Mason Wheeler wrote:

You need some way for it to recognize what you have as an MP3.
What would you propose?

An argument to Mix_LoadMUS_RW() for the type. But this breaks the API,
of course. So if there’s not going to be an SDL_mixer 2.0 any time soon,
a new Mix_LoadMUS_Type_RW() might do it.

I now introduced a new function:

Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type)

[…]
I am attaching the patch against current Hg. It’s quite short, but
please take a look at it in case I screwed something up.

So I suppose there’s no interest in including this in SDL_mixer?

I hadn’t had a chance to look at it yet. I have now, though.

I think this patch should only check the magic if it needs to, instead
of filling in the magic based on the requested type.

Right now, the patch is doing something like:

if (want == MUS_OGG)
   strcpy(magic, "OggS");

// later...

if (strcmp(magic, "OggS") == 0)
    set_up_ogg_stuff();

The patch is better done like this…

  if (want == MUS_NONE)
  {
      // only do i/o and string manipulation if we have to...
      load_magic();
      if (strcmp(magic, "OggS") == 0)
          want = MUS_OGG;
  }

  // later...

  if (want == MUS_OGG)
      set_up_ogg_stuff();

Otherwise, I think the concept is good. If you clean that up, I’ll
commit the patch.

–ryan.

I went for something minimal. For doing it “the right way”, the patch
is a bit longer:

The auto-detection is now performed by detect_music_type() (static
helper). This is intended to also be used by Mix_LoadMUS() in order to
avoid the current code duplication. I didn’t change Mix_LoadMUS()
though; if this patch is good enough to be committed, I will follow with
another that will deal with Mix_LoadMUS().

I am attaching the new patch. I’m not sure if the coding style follows
your preferences, since it seems SDL_mixer’s code does not follow a
single style throughout, but deviates a bit (mostly spacing) so I was
not sure which one to use.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: mustype_support_v2.patch
Type: text/x-patch
Size: 9033 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110718/58ee26f6/attachment.binOn 07/18/2011 11:48 AM, Ryan C. Gordon wrote:

So I suppose there’s no interest in including this in SDL_mixer?

I think this patch should only check the magic if it needs to, instead
of filling in the magic based on the requested type.

[…]

The patch is better done like this…

if (want == MUS_NONE)
{
// only do i/o and string manipulation if we have to…
load_magic();
if (strcmp(magic, “OggS”) == 0)
want = MUS_OGG;
}

// later…

if (want == MUS_OGG)
set_up_ogg_stuff();

Otherwise, I think the concept is good. If you clean that up, I’ll
commit the patch.