Closed Wohlstand closed 3 years ago
I built current git version of libxmp and xmp-cli on i686 linux. It loads and plays that SONG6.PSM for me, reporting 1min16s duration.
Okay, I have checked out the repo, I have pulled the most new stuff and I have tried to use it... works!
libxmp/examples $ LD_LIBRARY_PATH=../lib ./player-sdl SONG6.PSM
(Epic MegaGames MASI PSM)
^C3/ 31 8/ 48
btw, the module loader is used xmp_load_module
by filename. The loading was failed when loading this file from a memory... will try to make a trick and check the result...
Okay, just now I made an ugly test on a VERY quick hand: player-sdl-mem.c.zip and, it plays SONG1.psm file, but SONG6 fails as at me
$ make player-sdl
$ LD_LIBRARY_PATH=../lib ./player-sdl 'SONG1.PSM'
(Epic MegaGames MASI PSM)
^C0/ 12 13/ 64
$ LD_LIBRARY_PATH=../lib ./player-sdl 'SONG6.PSM'
./player-sdl: error loading SONG6.PSM
It's failing here: https://github.com/cmatsuoka/libxmp/blob/master/src/loaders/iff.c#L101
Possibly an issue with the hio layer in libxmp. Will try tracing.
Seems like this hio_seek() call fails: https://github.com/cmatsuoka/libxmp/blob/master/src/loaders/masi_load.c#L702 .. and it carries over its error.
BTW, hio error for memory buffers is broken: it sets h->error to
good old errno
, but it has nothing to do with errno...
Seems like this hio_seek() call fails: https://github.com/cmatsuoka/libxmp/blob/master/src/loaders/masi_load.c#L702 .. and it carries over its error.
Using the debug printf()s I added to memio.c, it fails like this: MSEEK: m->size: 55003, offset: 197664, m->pos: 4256, CAN_READ: 50747
Obviously the required offset is crazy. An ugly workaround would be clearing the error from hio like (most probably not for merging):
diff --git a/src/loaders/masi_load.c b/src/loaders/masi_load.c
index 5da0270..267683d 100644
--- a/src/loaders/masi_load.c
+++ b/src/loaders/masi_load.c
@@ -700,6 +700,7 @@ static int get_song_2(struct module_data *m,
default:
hio_seek(f, subchunk_size, SEEK_CUR);
+ hio_error(f); /* clear possible error flag */
}
}
... which makes your particular file to play for me using memory buffers.
Looks odd, btw, why it works from the file at the same time? :thinking:
Obviously the required offset is crazy. An ugly workaround would be
clearing the error from hio like (most probably not for merging):
Maybe add the edge check to don't try to seek an impossible offset? and print the debug message about that? Is the file itself is odd?
Looks odd, btw, why it works from the file at the same time? thinking
Play with fseek() using crazy offsets and see.
Asked questions to @cmatsuoka in private mail.
Simplifying mseek() in src/memio.c like the following makes it work:
int mseek(MFILE *m, long offset, int whence)
{
switch (whence) {
default:
case SEEK_SET:
break;
case SEEK_CUR:
offset += m->pos;
break;
case SEEK_END:
offset = m->size + offset;
break;
}
if (offset < 0) return -1;
if (offset > m->size)
offset = m->size;
m->pos = offset;
return 0;
}
But I don't know about merits of the size negativity checks in there, and there will be more to adjust along the way I think. So @cmatsuoka should join the discussion.
This file is from Jazz Jackrabit game: SONG6.PSM.zip
it's only one which can't be loaded. Modplug still can load it.
The debug log that I have got: