unmo3 as a library?

Started by saga, 26 Oct '08 - 22:31

saga

Hey Ian,
I was wondering if you could provide the unmo3 thingy rather as library than an executable? That way, it would probably be easier to be implemented into other applications and you sure want this be done. :) I'm thinking about OpenModplug in this case, I joined the devteam some weeks ago. It would be a nice thing to have this as a library as this would be less confusing to users (what? 2 executables in the folder?) and prolly also easier to handle (call a function, pass the filename, get a pointer).

Ian @ un4seen

That may be possible. Give it a few days, and I'll see what I can do :)

saga

any news on this? :)

what i forgot to mention above is that also the length of the uncompressed module has to be returned, so a function like this would be fine:

convertmo3(filename, pointer, length)and the library would fill in the pointer and length stuff.

Ian @ un4seen

OK, here's something to try :)

   www.un4seen.com/stuff/unmo3dll.zip

Let me know if there any problems with it.

saga

#4
i'll try it as soon as i can find some spare time and let you know if there's anything that's not clear. :)
I have one question in advance, though: is there a way to include the library into the program's exe?

Ian @ un4seen

Would that be permitted by Modplug's GPL licence? I'm not sure.

Interestingly, there is a GPL UNMO3 package made from the unofficial specs, which should be fine for you to incorporate into Modplug...

   http://gnu.ethz.ch/debian/unmo3/

saga

i guess i'd have to talk with the other devs about gpl issues first then. although i have in mind that some license changes were planned / discussed some time ago, but i don't know exactly...

saga

okay, so today I've finally tried to work on the mo3 import again. :)
Everything is working nicely, but I've found that a little change in the .dll may be useful because of the lacking of a proper header in .MOD files.
Due to the way our code is structured, I need a little change in the parameters of UNMO3_Decode.
Instead of passing a filename, I would like to try to pass the pointer to the compressed module and the length and receive a new pointer and a new length. Could you please update the dll for this? :)
-saga

BTW: We've moved on to the BSD license now. :)

Ian @ un4seen

Quote from: saga on 18 Jan '09 - 19:36Due to the way our code is structured, I need a little change in the parameters of UNMO3_Decode.
Instead of passing a filename, I would like to try to pass the pointer to the compressed module and the length and receive a new pointer and a new length. Could you please update the dll for this? :)

Yep, here's an update to try...

   www.un4seen.com/stuff/unmo3dll.zip

saga


kode54

What is the license on this and is it okay to redistribute this? I'm thinking of using this instead of unmo3.exe for foo_dumb. It would be a lot more convenient and possibly more secure than piping the module out of unmo3.exe, as I don't really have many security checks on the pipe process. I also tried piping both in and out simultaneously, which failed, and probably not because I was trying to do it all in a single thread. I found this while digging in relation to Open ModPlug Tracker, heh.

(Scatterbrained post brought to you by lack of sleep, a first for me in months.)

Ian @ un4seen

Quote from: kode54 on 11 Oct '09 - 04:23What is the license on this and is it okay to redistribute this? I'm thinking of using this instead of unmo3.exe for foo_dumb.

The UNMO3.DLL is free for non-commercial use (like UNMO3.EXE), so that sounds fine.

Zarggg


kode54

#13
Any chance of Linux 32/64 bit .so or OS X fat .dylib versions of this?

EDIT: Having it signed would also be nice as well, but I bet Petite is incompatible with code signing.

saga

#14
And since OpenMPT might go 64-bit soon-ish, a Win64 build would be nice as well, while we're at it ;) A Linux .so would also be interesting for libopenmpt, I guess.

Ian @ un4seen

I think that should be possible. I'll try to get something ready next week.

Ian @ un4seen

OK. Here's an updated UNMO3 library package for you to try...

   www.un4seen.com/stuff/unmo3lib.zip

Support is included for x86/x64 on Windows and Linux, and x86/x64/ppc on OSX. This update also adds a "no sample processing" option, which could be useful (faster) for when you just want to get info/texts without playing.

Let me know if you encounter any problems (it hasn't been tested much yet).

kode54

OS X x86_64 verified working, and it seems to be quite a bit faster at decoding PvZ.mo3 (Plants vs. Zombies soundtrack) than the Windows 32 bit version. Of course, it could just be placebo.

One minor problem, I had to typedef or define DWORD myself. I decided to import stdint.h and typedef it from uint32_t.

saga

#18
Windows x64 tested and confirmed to be working. Thanks a lot! :)
It's kinda unfortunate that old library versions will crash when using the new UNMO3_Decode specification, though, not sure if anything in the interface could be changed to avoid that. Otherwise the host programm will have to check the DLL version, I guess. :)

PSXGamerPro1

Or maybe It can check the MD5 of the dll. I know of a program that does that. And if the MD5 does not match the program will close saying "'<file name>.dll' Invalid."

saga

#20
...which would result in way more code than importing UNMO3_GetVersion and you'd still have to differentiate between several DLL versions, so is a worse solution. Please go away with your senseless suggestions, you are not being helpful at all.

kode54

Or you could supply your own copy of the library so you always link against the version you developed for, assuming redistribution is compatible with the licenses of unmo3 and your program or library.

Ian @ un4seen

Quote from: kode54 on  1 Nov '13 - 19:32One minor problem, I had to typedef or define DWORD myself. I decided to import stdint.h and typedef it from uint32_t.

Oops. I had intentionally avoided using Windows types in the UNMO3.H header previously, but forgot to so in this update. I have now changed it to use "unsigned" instead of "DWORD".

Quote from: saga on  1 Nov '13 - 19:50It's kinda unfortunate that old library versions will crash when using the new UNMO3_Decode specification, though, not sure if anything in the interface could be changed to avoid that. Otherwise the host programm will have to check the DLL version, I guess. :)

Yep, you could use UNMO3_GetVersion to check that the appropriate DLL version is loaded. You don't necessarily need to call it though; it was introduced at the same time as the UNMO3_Decode "flags" parameter, so its presence alone is enough to confirm the UNMO3_Decode signature :)

Anyway, good to hear that the update is working well so far. Let me know if any problems do crop up.

saga

Yeah, I guess that's the most sensible approach for now. Luckily, calling the new DLL from an old program expecting the two-parameter signature (without flags) still works, so that's at least something.

kode54

A fairly minor problem I've discovered. Or at least it's minor because I can work around it rather than letting my users crash frequently.

Namely, the library does not appear to be thread safe. Unpacking more than one MO3 at a time from different threads results in crashes.

I can work around this by dynamically loading the module and copying it around to random names in the temporary folder when I need more than one instance at a time.