libmikmod is a library that the MikMod tracker music player uses internally. It is distributed under LGPL. It plays not only modules, but is also capable of playing single samples. It's able to use single files and load things from specified offset from opened file. The user doesn't need to worry of things like actual output drivers, unless they specifically want to. The library supports both software and hardware mixing.

In other words, an one-stop digital audio solution for game/demo musicians and programmers...

The library is available for many platforms - UNIXes and Windows at least. A port of an old - I dare to say ancient - version also exists for Java!

Famous programs that use libmikmod include XMMS and Winamp.

Following is an example of libMikMod code for C.


/*
  simpleplay.c
  (c) WWWWolf 6.2.1999
  Commented better by WWWWolf, 2001-11-13
  Do whatever you want with this, but keep this message here.
  No warranty whatsoever.

  Uses MikMod 3.1 library, no idea if it still compiles =)


  FIXME: Should check that we actually have something in varg[1] and
  that the parameters are correct - and we should bail out in case
  of errors, too. Some messages could do no harm either. =)
 */

#include <unistd.h>
#include <mikmod.h>
     
int main(int carg, char **varg)
{
  /* This is where our module is stored. */
  MODULE *mod;

  /* These will do exactly what's intended: Get all output drivers
      and module/file loaders up and running... */
  MikMod_RegisterAllDrivers();
  MikMod_RegisterAllLoaders();

  /* Initialize libmikmod. */     
  MikMod_Init();

  /* Load the module. */
  mod = Player_Load(varg[1],128,0);

  /* Start playing the module. */
  Player_Start(mod);

  /* While the thing is playing, update the mikmod status. Sleep
     for a while. After we've tossed stuff to the output driver,
     we *could* do stuff here with the output data, display cool
     numeric information, blah blah...
  */
  while(MikMod_Active()) {
    MikMod_Update();
    usleep(500);
  }

  /* Okay, done? Let's stop the module and free the module,
     and mop up the mikmod engine in general... */
  Player_Stop();
  Player_Free(mod);
  MikMod_Exit();
}