GNU Info

Info Node: (mikmod.info)A Skeleton Program

(mikmod.info)A Skeleton Program


Next: Playing Modules Prev: MikMod Concepts Up: Tutorial
Enter node , (file) or (file)node

A Skeleton Program
==================

   To use MikMod in your program, there are a few steps required:

   * Include `mikmod.h' in your program.

   * Register the MikMod drivers you need.

   * Initialize the library with MikMod_Init() before using any other
     MikMod function.

   * Give up resources with MikMod_Exit() at the end of your program,
     or before when MikMod is not needed anymore.

   * Link your application with the MikMod sound library.

   Here's a program which meets all those conditions:

     /* MikMod Sound Library example program: a skeleton */
     
     #include <mikmod.h>
     
     main()
     {
     	/* register all the drivers */
     	MikMod_RegisterAllDrivers();
     
     	/* initialize the library */
     	MikMod_Init("");
     
     	/* we could play some sound here... */
     
     	/* give up */
     	MikMod_Exit();
     }

   This program would be compiled with the following command line: `cc
-o example example.c `libmikmod-config --cflags` `libmikmod-config
--libs`'

   Although this programs produces no useful result, many things happen
when you run it. The call to `MikMod_RegisterAllDrivers' registers all
the drivers embedded in the MikMod library. Then, `MikMod_Init' chooses
the more adequate driver and initializes it. The program is now ready
to produce sound.  When sound is not needed any more, `MikMod_Exit' is
used to relinquish memory and let other programs have access to the
sound hardware.


automatically generated by info2www version 1.2.2.9