home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 25 / GNOME_DEMO.iso / amiga / music / mikmod.lzx / mikmod / mikxmod.c < prev    next >
C/C++ Source or Header  |  1997-02-18  |  5KB  |  245 lines

  1. /*
  2.  
  3. Name:
  4. MIKMOD.C
  5.  
  6. Description:
  7. Modplaying example of mikmod - bare linux (unix?) version.
  8.  
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "mikmod.h"
  13.  
  14. char helptext[]=
  15.  
  16. "Available switches (CaSe SeNsItIvE!):\n"
  17. "\n"
  18. "  -d x    use device-driver #x for output (0 is autodetect). Default=0\n"
  19. "  -ld     List all available device-drivers\n"
  20. "  -ll     List all available loaders\n"
  21. "  -x      disables protracker extended speed\n"
  22. "  -p      disables panning effects (9fingers.mod)\n"
  23. "  -v xx   Sets volume from 0 (silence) to 100. Default=100\n"
  24. "  -f xxxx Sets mixing frequency. Default=22050\n"
  25. "  -m      Force mono output (so sb-pro can mix at 44100)\n"
  26. "  -8      Force 8 bit output\n"
  27. "  -i      Use interpolated mixing\n"
  28. "  -r      Restart a module when it's done playing";
  29.  
  30.  
  31. /*
  32.     declarations for boring old sys-v style getopt *yawn*:
  33. */
  34. int     getopt(int argc, char *argv[], char *optionS);
  35. extern char *optarg;
  36. extern int optind;
  37. extern int opterr;
  38.  
  39.  
  40. void tickhandler(void)
  41. {
  42.     MP_HandleTick();    /* play 1 tick of the module */
  43.     MD_SetBPM(mp_bpm);
  44. }
  45.  
  46.  
  47. int main(int nargc,char *nargv[])
  48. {
  49.     UNIMOD *mf;
  50.     int cmderr=0;                   /* error in commandline flag */
  51.     int morehelp=0;                 /* set if user wants more help */
  52.     int quit;
  53.     int t;
  54.  
  55.     puts(mikbanner);
  56.  
  57.     /*
  58.         Initialize soundcard parameters.. you _have_ to do this
  59.         before calling MD_Init(), and it's illegal to change them
  60.         after you've called MD_Init()
  61.     */
  62.  
  63.     md_mixfreq      =22050;                     /* standard mixing freq */
  64.     md_dmabufsize   =10000;                     /* standard dma buf size */
  65.     md_mode         =DMODE_16BITS|DMODE_STEREO; /* standard mixing mode */
  66.     md_device       =0;                                                     /* standard device: autodetect */
  67.  
  68.     /*
  69.         Register the loaders we want to use..
  70.     */
  71.  
  72.     ML_RegisterLoader(&load_m15);    /* if you use m15load, register it as first! */
  73.     ML_RegisterLoader(&load_mod);
  74.     ML_RegisterLoader(&load_mtm);
  75.     ML_RegisterLoader(&load_s3m);
  76.     ML_RegisterLoader(&load_stm);
  77.     ML_RegisterLoader(&load_ult);
  78.     ML_RegisterLoader(&load_uni);
  79.     ML_RegisterLoader(&load_xm);
  80.  
  81.     /*
  82.         Register the drivers we want to use:
  83.     */
  84.  
  85.     MD_RegisterDriver(&drv_nos);
  86.     MD_RegisterDriver(&drv_raw);
  87.         MD_RegisterDriver(&drv_pau);
  88.         MD_RegisterDriver(&drv_p14);
  89.  
  90.     MD_RegisterPlayer(tickhandler);
  91.  
  92.     /* Parse option switches using standard getopt function: */
  93.  
  94.     opterr=0;
  95.  
  96.     while( !cmderr &&
  97.           (t=getopt(nargc,nargv,"ohxpm8irv:f:l:d:")) != EOF ){
  98.  
  99.         switch(t){
  100.  
  101.             case 'd':
  102.                 md_device=atoi(optarg);
  103.                 break;
  104.  
  105.             case 'l':
  106.                 if(optarg[0]=='d') MD_InfoDriver();
  107.                 else if(optarg[0]=='l') ML_InfoLoader();
  108.                 else{
  109.                     cmderr=1;
  110.                     break;
  111.                 }
  112.                 exit(0);
  113.  
  114.             case 'r':
  115.                 mp_loop=1;
  116.                 break;
  117.  
  118.             case 'm':
  119.                 md_mode&=~DMODE_STEREO;
  120.                 break;
  121.  
  122.             case '8':
  123.                 md_mode&=~DMODE_16BITS;
  124.                 break;
  125.  
  126.             case 'i':
  127.                 md_mode|=DMODE_INTERP;
  128.                 break;
  129.  
  130.             case 'x':
  131.                 mp_extspd=0;
  132.                 break;
  133.  
  134.             case 'p':
  135.                 mp_panning=0;
  136.                 break;
  137.  
  138.             case 'v':
  139.                 if((mp_volume=atoi(optarg))>100) mp_volume=100;
  140.                 break;
  141.  
  142.             case 'f':
  143.                 md_mixfreq=atol(optarg);
  144.                 break;
  145.  
  146.             case 'h':
  147.                 morehelp=1;
  148.                 cmderr=1;
  149.                 break;
  150.  
  151.             case '?':
  152.                 puts("\07Invalid switch or option needs an argument\n");
  153.                 cmderr=1;
  154.                 break;
  155.         }
  156.     }
  157.  
  158.     if(cmderr || optind>=nargc){
  159.  
  160.         /*
  161.             there was an error in the commandline, or there were no true
  162.             arguments, so display a usage message
  163.         */
  164.  
  165.         puts("Usage: MIKMOD [switches] <fletch.mod> ... \n");
  166.  
  167.         if(morehelp)
  168.             puts(helptext);
  169.         else
  170.                         puts("Type MIKMOD -h for more help.");
  171.  
  172.         exit(-1);
  173.     }
  174.  
  175.     /*  initialize soundcard */
  176.  
  177.     if(!MD_Init()){
  178.         printf("Driver error: %s.\n",myerr);
  179.         return 0;
  180.     }
  181.  
  182.     printf("Using %s for %d bit %s %s sound at %u Hz\n\n",
  183.             md_driver->Name,
  184.             (md_mode&DMODE_16BITS) ? 16:8,
  185.             (md_mode&DMODE_INTERP) ? "interpolated":"normal",
  186.             (md_mode&DMODE_STEREO) ? "stereo":"mono",
  187.             md_mixfreq);
  188.  
  189.     for(quit=0; !quit && optind<nargc; optind++){
  190.  
  191.         printf("File    : %s\n",nargv[optind]);
  192.  
  193.         /* load the module */
  194.  
  195.         mf=ML_LoadFN(nargv[optind]);
  196.  
  197.         /* didn't work -> exit with errormsg. */
  198.  
  199.         if(mf==NULL){
  200.             printf("MikMod Error: %s\n",myerr);
  201.             break;
  202.         }
  203.  
  204.         /*      initialize modplayer to play this module */
  205.  
  206.         MP_Init(mf);
  207.  
  208.         printf( "Songname: %s\n"
  209.                 "Modtype : %s\n"
  210.                 "Periods : %s,%s\n",
  211.                 mf->songname,
  212.                 mf->modtype,
  213.                 (mf->flags&UF_XMPERIODS) ? "XM type" : "mod type",
  214.                 (mf->flags&UF_LINEAR) ? "Linear" : "Log");
  215.  
  216.         /*
  217.             set the number of voices to use.. you
  218.             could add extra channels here (e.g. md_numchn=mf->numchn+4; )
  219.             to use for your own soundeffects:
  220.         */
  221.  
  222.         md_numchn=mf->numchn;
  223.  
  224.         /*  start playing the module: */
  225.  
  226.         MD_PlayStart();
  227.  
  228.         while(!MP_Ready()){
  229.  
  230.             MD_Update();
  231.  
  232.             /* no need to wait with linux voxware */
  233.  
  234.         }
  235.  
  236.         MD_PlayStop();          /* stop playing */
  237.         ML_Free(mf);            /* and free the module */
  238.  
  239.         puts("\n");
  240.     }
  241.  
  242.     MD_Exit();
  243.     return 0;
  244. }
  245.