Saturday, July 5, 2008

Hello MikMod!

As promised earlier, I've packaged an obligatory example of how to use the iPhone port of libmikmod which I've talked about recently. Go grab this tarball which implements a very simple "Hello World!":
  • It shows how to play a module within a UIKit application. This is an adaptation of the skeleton program found in MikMod Documentation.
  • It shows how to use the higher level sound API Celestial to control mikmod output. For instance, how to react to volume change events when iPhone buttons are pressed.
What to do with this archive once you've extracted it?
  tar -zxf HelloMikMod.tar.gz
  cd HelloMikMod
Simple! Modify the Makefile to set the location of the AudioQueue.h header, as well as the location where you've installed libmikmod. Once you're done, the makefile should look like:
  # directory where AudioQueue.h is located
  AQDIR=$(HOME)/local/audioqueue
  # directory where MikMod is located
  MMDIR=$(HOME)/local/mikmod-iphone
  # comment the following line when the previous settings are OK for you
  #$(error configure AudioQueue and Mikmod location in the Makefile first)
Then, just build and install the app by typing:
  make
  scp -r HelloMikMod.app root@iphone:/Applications
Where iphone stands for the hostname or the IP of your iPhone. Note that you will need either curl or wget installed or your machine so that the build process is able to download the module played in this example app (fortunately, one of those should always be available on MacOS X or on your favorite Linux distro). For your convenience, the HelloMikMod.app directory is standalone: it contains the app itself linked statically to libmikmod, a launcher descriptor for Springboard and the module to play. For my own pleasure, the mod played is Stardust Memories by Jester / Sanity, my all time favorite Amiga mod (see the compo World of Commodore). This is only a simple example of how to use MikMod on iPhone. I've started implementing a more complex app that mimics the iPod interface for playing mods (Module DB, Screenshot of associated demos...). Now if only I could use Nectarine or Pouet.net DB to make some kind of systematic indexing available!! (sigh....)

4 comments:

Yorgle said...

Hi!

http://umlautllama.com/iphone/mikmod/

On there, you can find my port/work to integrate your AudioQueue driver into an iPhone SDK-ready library, for use in SDK-based applications.

It's a static lib, so any app it's used with needs to have source available, but there you go!

I also included a demo "utility" app that uses it, with notes about the things you need to do with a new app to link it in and such.

Yay! and Thanks!

Yorgle said...

And also, I just figured this one out.

My MikMod port for iPhone SDK (Objective C) had a conflicting type for "BOOL". MikMod defines it as type 'int' whereas Objective C defines it as type 'char'.

I hacked mikmod_build.h and mikmod.h to comment out the previous declarations, and replaced the types with my own.

typedef char BOOL;

Yorgle said...

Okay... slight problem with my last solution. It works, redefining BOOL in mikmodworld to be a char, but not always. Some mods ("littleli.it" for example) fail loading with no error.

I instead did a search and replace on all files from "BOOL" to "MIKBOOL" and defined it always as type 'int', and that works perfectly. (320+ changes across all files. super easy to do within XCode. :)

Dam said...

Hi Yorgle!

I was finding it odd that I could not see this pb with my code, until you pinpoint the real issue, which is BOOL definition for mikmod vs objective C.

Maybe the pb did not show because of the order in which I include the headers in my code.

Concerning you patch, I find it a bit invasive for mikmod, maybe inserting a simple __align__ statement after BOOL fields in mikmod structures would fit the need.

However, I confess that I would prefer if mikmod were defining MIKBOOL as you do. Their code is not as clean as I would like. In this respect, XMB's codebase is far better!