Skip to content

Commit

Permalink
music.c: Move MP3 detection code down
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed Aug 30, 2023
1 parent 1c81110 commit 24e3ee2
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,28 +676,6 @@ Mix_MusicType detect_music_type(SDL_RWops *src)
return MUS_MID;
}

#ifdef ID3_EXTRA_FORMAT_CHECKS
if (SDL_memcmp(magic, "ID3", 3) == 0) {
id3len = get_id3v2_length(src);

/* Check if there is something not an MP3, however, also has ID3 tag */
if (id3len > 0) {
SDL_RWseek(src, id3len, SDL_RW_SEEK_CUR);
readlen = SDL_RWread(src, submagic, 4);
SDL_RWseek(src, start, SDL_RW_SEEK_SET);

if (readlen == 4) {
if (SDL_memcmp(submagic, "fLaC", 4) == 0)
return MUS_FLAC;
}
}
}

/* Detect MP3 format by frame header [needs scanning of bigger part of the file] */
if (detect_mp3(submagic, src, start, id3len)) {
return MUS_MP3;
}

/* GME Specific files */
if (SDL_memcmp(magic, "ZXAY", 4) == 0)
return MUS_GME;
Expand All @@ -724,6 +702,27 @@ Mix_MusicType detect_music_type(SDL_RWops *src)
if (SDL_memcmp(magic, "\x1f\x8b", 2) == 0)
return MUS_GME;

if (SDL_memcmp(magic, "ID3", 3) == 0) {
id3len = get_id3v2_length(src);

/* Check if there is something not an MP3, however, also has ID3 tag */
if (id3len > 0) {
SDL_RWseek(src, id3len, SDL_RW_SEEK_CUR);
readlen = SDL_RWread(src, submagic, 4);
SDL_RWseek(src, start, SDL_RW_SEEK_SET);

if (readlen == 4) {
if (SDL_memcmp(submagic, "fLaC", 4) == 0)
return MUS_FLAC;
}
}
}

/* Detect MP3 format by frame header [needs scanning of bigger part of the file] */
if (detect_mp3(submagic, src, start, id3len)) {
return MUS_MP3;
}

/* Assume MOD format.
*
* Apparently there is no way to check if the file is really a MOD,
Expand Down

0 comments on commit 24e3ee2

Please sign in to comment.