Author Topic: unmo3 as a library?  (Read 91960 times)

saga

  • Posts: 2754
unmo3 as a library?
« on: 26 Oct '08 - 22:31 »
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

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #1 on: 27 Oct '08 - 14:52 »
That may be possible. Give it a few days, and I'll see what I can do :)

saga

  • Posts: 2754
Re: unmo3 as a library?
« Reply #2 on: 15 Nov '08 - 13:44 »
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:

Code: [Select]
convertmo3(filename, pointer, length)and the library would fill in the pointer and length stuff.

Ian @ un4seen

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #3 on: 17 Nov '08 - 15:06 »
OK, here's something to try :)

   www.un4seen.com/stuff/unmo3dll.zip

Let me know if there any problems with it.

saga

  • Posts: 2754
Re: unmo3 as a library?
« Reply #4 on: 17 Nov '08 - 17:57 »
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?
« Last Edit: 17 Nov '08 - 17:59 by saga »

Ian @ un4seen

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #5 on: 19 Nov '08 - 16:35 »
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

  • Posts: 2754
Re: unmo3 as a library?
« Reply #6 on: 19 Nov '08 - 19:43 »
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

  • Posts: 2754
Re: unmo3 as a library?
« Reply #7 on: 18 Jan '09 - 19:36 »
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

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #8 on: 19 Jan '09 - 15:30 »
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? :)

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

   www.un4seen.com/stuff/unmo3dll.zip

saga

  • Posts: 2754
Re: unmo3 as a library?
« Reply #9 on: 19 Jan '09 - 17:45 »
Thanks a lot, that did the trick :)

kode54

  • Posts: 124
Re: unmo3 as a library?
« Reply #10 on: 11 Oct '09 - 04:23 »
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

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #11 on: 12 Oct '09 - 15:38 »
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.

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

Zarggg

  • Posts: 1242
Re: unmo3 as a library?
« Reply #12 on: 14 Oct '09 - 15:36 »
Good to see you here, kode54. :)

kode54

  • Posts: 124
Re: unmo3 as a library?
« Reply #13 on: 25 Oct '13 - 04:35 »
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.
« Last Edit: 25 Oct '13 - 05:14 by kode54 »

saga

  • Posts: 2754
Re: unmo3 as a library?
« Reply #14 on: 25 Oct '13 - 08:35 »
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.
« Last Edit: 25 Oct '13 - 17:15 by saga »

Ian @ un4seen

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #15 on: 25 Oct '13 - 17:12 »
I think that should be possible. I'll try to get something ready next week.

Ian @ un4seen

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #16 on: 1 Nov '13 - 16:54 »
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

  • Posts: 124
Re: unmo3 as a library?
« Reply #17 on: 1 Nov '13 - 19:32 »
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

  • Posts: 2754
Re: unmo3 as a library?
« Reply #18 on: 1 Nov '13 - 19:50 »
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. :)
« Last Edit: 1 Nov '13 - 20:25 by saga »

PSXGamerPro1

  • Posts: 261
Re: unmo3 as a library?
« Reply #19 on: 1 Nov '13 - 21:25 »
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

  • Posts: 2754
Re: unmo3 as a library?
« Reply #20 on: 1 Nov '13 - 21:28 »
...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.
« Last Edit: 1 Nov '13 - 21:30 by saga »

kode54

  • Posts: 124
Re: unmo3 as a library?
« Reply #21 on: 1 Nov '13 - 23:06 »
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

  • Administrator
  • Posts: 26108
Re: unmo3 as a library?
« Reply #22 on: 2 Nov '13 - 12:35 »
One 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".

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. :)

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

  • Posts: 2754
Re: unmo3 as a library?
« Reply #23 on: 2 Nov '13 - 14:01 »
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

  • Posts: 124
Re: unmo3 as a library?
« Reply #24 on: 12 Dec '13 - 04:09 »
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.