Skip to content

Commit

Permalink
Read untagged 15-channel mods
Browse files Browse the repository at this point in the history
  • Loading branch information
jangler committed Jul 17, 2018
1 parent 5d6aca4 commit 3302e8e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
28 changes: 24 additions & 4 deletions fmt/mod.c
Expand Up @@ -107,8 +107,21 @@ int fmt_mod_read_info(dmoz_file_t *file, const uint8_t *data, size_t length)

/* loads everything but old 15-instrument mods... yes, even FLT8 and WOW files
(and the definition of "everything" is always changing) */
int fmt_mod31_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
{
return fmt_mod_load_song(song, fp, lflags, 0);
}

/* loads everything including old 15-instrument mods. this is a separate
function so that it can be called later in the format-checking sequence. */
int fmt_mod15_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
{
return fmt_mod_load_song(song, fp, lflags, 1);
}

int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
/* force determines whether the loader will force-read untagged files as
15-sample mods */
int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags, int force)
{
uint8_t tag[4];
int n, npat, pat, chan, nchan, nord;
Expand All @@ -123,6 +136,7 @@ int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
uint8_t restart;
long samplesize = 0;
const char *tid = NULL;
int nsamples = 31; /* default; tagless mods have 15 */

/* check the tag (and set the number of channels) -- this is ugly, so don't look */
slurp_seek(fp, 1080, SEEK_SET);
Expand Down Expand Up @@ -188,6 +202,11 @@ int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
tid = "%d Channel TakeTracker";
else
tid = "%d Channel MOD";
} else if (force) {
/* some old modules don't have tags, so try loading anyway */
nchan = 4;
nsamples = 15;
tid = "%d Channel MOD";
} else {
return LOAD_UNSUPPORTED;
}
Expand All @@ -204,7 +223,7 @@ int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)
song->title[20] = 0;

/* sample headers */
for (n = 1; n < 32; n++) {
for (n = 1; n < nsamples + 1; n++) {
slurp_read(fp, song->samples[n].name, 22);
song->samples[n].name[22] = 0;

Expand Down Expand Up @@ -296,7 +315,8 @@ int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)

// http://llvm.org/viewvc/llvm-project?view=rev&revision=91888
sprintf(song->tracker_id, tid ? tid : "%d Channel MOD", nchan);
slurp_seek(fp, 1084, SEEK_SET);
/* 15-sample mods don't have a 4-byte tag… or the other 16 samples */
slurp_seek(fp, nsamples == 15 ? 600 : 1084, SEEK_SET);

/* pattern data */
if (startrekker) {
Expand Down Expand Up @@ -340,7 +360,7 @@ int fmt_mod_load_song(song_t *song, slurp_t *fp, unsigned int lflags)

/* sample data */
if (!(lflags & LOAD_NOSAMPLES)) {
for (n = 1; n < 32; n++) {
for (n = 1; n < nsamples + 1; n++) {
if (song->samples[n].length == 0)
continue;

Expand Down
10 changes: 8 additions & 2 deletions include/fmt-types.h
Expand Up @@ -75,8 +75,11 @@ READ_INFO(669) LOAD_SONG(669)
/* Since so many programs have added noncompatible extensions to the mod format, there are about 30 strings to
compare against for the magic. Also, there are special cases for WOW files, which even share the same magic
as plain ProTracker, but are quite different; there are some really nasty heuristics to detect these... ugh,
ugh, ugh. However, it has to be above the formats with the magic at the beginning... */
READ_INFO(mod) LOAD_SONG(mod)
ugh, ugh. However, it has to be above the formats with the magic at the beginning...
This only handles 31-sample mods; 15-sample ones have no identifying
information and are therefore placed much lower in this list. */
READ_INFO(mod) LOAD_SONG(mod31)

/* S3M needs to be before a lot of stuff. */
READ_INFO(s3m) LOAD_SONG(s3m) SAVE_SONG(s3m)
Expand Down Expand Up @@ -135,6 +138,9 @@ at all. I might move this toward the top if I can figure out how to identify an
READ_INFO(mp3)
#endif

/* 15-sample mods have literally no identifying information */
READ_INFO(mod) LOAD_SONG(mod15)

/* not really a type, so no info reader for these */
LOAD_SAMPLE(raw) SAVE_SAMPLE(raw)

Expand Down

0 comments on commit 3302e8e

Please sign in to comment.