home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / cmf_play.zip / CMF-READ.C < prev    next >
C/C++ Source or Header  |  1995-09-22  |  5KB  |  154 lines

  1. /*  This program and all it's includes were written and tested in QC v2.0    *
  2.  *  (Pretty lame, huh) I was too lazy to convert it to Watcom 10.5 :)        *
  3.  *  I have included all the source necessary to load and play a CMF file.    *
  4.  *  The SBFMDRV.COM must be loaded first in order to use the functions        *
  5.  *  The driver has also been included.  It's up to you to make sure that it's     *
  6.  *  loaded. (This means that this only works with Soundblasters (or clones).    *
  7.  *  All files included in this ZIP are freeware.  I just wanted to contribute my*
  8.  *  share back to the community that helped me when I knew nothing of coding.    *
  9.  *  Use this however you see fit.  All that I ask is that you do not        *
  10.  *  redistribute this package altered in any way. ;-)                *
  11.  *                                                                              *
  12.  *  I have not yet found a decent CMF composer, but I have found several    *
  13.  *  conversion utilities to convert other formats to .CMF                       *
  14.  *                                                                              *
  15.  *  This was compiled using a HUGE memory model.  Look for other comments in the*
  16.  *  'README.TXT' file.                                                          *
  17.  *                                                                              *
  18.  *  E-mail you comments to me: ZarrinW@aol.com                                  *
  19.  ********************************************************************************/
  20. #include <graph.h>
  21. #include <stdio.h>
  22. #include <malloc.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <fcntl.h>
  26. #include <dos.h>
  27. #include <conio.h>
  28. #include <io.h>
  29.  
  30. #include "sound.h"        //My CMF functions
  31.                 //You can print the prototypes for easier
  32.                 // use from 'PROTOTYP.TXT'
  33.  
  34. //  <<<<  This is just a simple demo to show how it works >>>>
  35.  
  36. void main(void)
  37. {
  38.  union REGS regs;
  39.  struct SREGS segs;
  40.  long           length=0,count=0;
  41.  int            a=0,b=0,c=0;
  42.  char     file_id[4],
  43.         channel[16],
  44.         *text,
  45.         filename[30],
  46.         huge *cmfdata;
  47.  
  48.  unsigned int
  49.         version=0,
  50.         inst_off=0,
  51.         music_off=0,
  52.         ticks_quarter=0,
  53.         ticks_second=0,
  54.         title_off=0,
  55.         author_off=0,
  56.         remarks_off=0,
  57.         num_inst=0,
  58.         tempo=0;
  59.  
  60.  if(!findcmfdriver())                   // This function does not work on QC2
  61.   if (system("SBFMDRV.COM")==-1)
  62.   {
  63.    puts("FM Driver not found.");
  64.    exit(-1);
  65.   }
  66.  printf("File and extention: ");
  67.  scanf("%s",filename);
  68.  
  69.  _clearscreen(_GCLEARSCREEN);
  70.  
  71.  length=getlength(filename);
  72.  
  73.  if ((cmfdata=(char huge *)halloc(length,1))==NULL)
  74.  {
  75.   printf("Unable to allocate %lu bytes for file.\n",length);
  76.   exit(-1);
  77.  }
  78.  
  79.  printf("Loading CMF file '%s' - %lu bytes\n",filename,length);
  80.  loadcmf(cmfdata,filename,length);
  81.  strncpy(file_id,cmfdata,4);
  82.  
  83.  inst_off=      cmfdata[ 6]+cmfdata[ 7]*256;
  84.  music_off=     cmfdata[ 8]+cmfdata[ 9]*256;
  85.  ticks_quarter= cmfdata[10]+cmfdata[11]*256;
  86.  ticks_second=  cmfdata[12]+cmfdata[13]*256;
  87.  title_off=     cmfdata[14]+cmfdata[15]*256;
  88.  author_off=    cmfdata[16]+cmfdata[17]*256;
  89.  remarks_off=   cmfdata[18]+cmfdata[19]*256;
  90.  num_inst=      cmfdata[36]+cmfdata[37]*256;
  91.  tempo=         cmfdata[38]+cmfdata[39]*256;
  92.  
  93.  printf("\t\t\t\tOffsets:\n");
  94.  printf("\t\t\t\t  Author:      0x%04x\n",author_off);
  95.  printf("\t\t\t\t  Remarks:     0x%04x\n",remarks_off);
  96.  printf("\t\t\t\t  Title:       0x%04x\n",title_off);
  97.  printf("\t\t\t\t  Instrument:  0x%04x\n",inst_off);
  98.  printf("\t\t\t\t  Music:       0x%04x\n",music_off%256);
  99.  
  100.  _settextposition(2,1);
  101.  
  102.  printf("ID:            %s\n",file_id);
  103.  printf("Version:       %u.%u\n",cmfdata[4],cmfdata[5]);
  104.  printf("Instruments:   %3u\n",num_inst);
  105.  printf("Ticks/Quarter: %3u\n",ticks_quarter);
  106.  printf("Ticks/Second:  %3u\n",ticks_second);
  107.  printf("Tempo:         %3u\n",tempo%256);
  108.  if(author_off)  printf("Author:  %s\n",cmfdata+author_off);
  109.  if(remarks_off) printf("Remarks: %s\n",cmfdata+remarks_off);
  110.  if(title_off)   printf("Title:   %s\n",cmfdata+title_off);
  111.  printf("\n");
  112.  printf("Channels:\n");
  113.  for (a=0;a<16;a+=8)
  114.  {
  115.   printf("  %2u:%3s  %2u:%3s  %2u:%3s  %2u:%3s  %2u:%3s  %2u:%3s  %2u:%3s  %2u:%3s\n",
  116.     a  ,cmfdata[a+20] ? "On":"---",
  117.     a+1,cmfdata[a+21] ? "On":"---",
  118.     a+2,cmfdata[a+22] ? "On":"---",
  119.     a+3,cmfdata[a+23] ? "On":"---",
  120.     a+4,cmfdata[a+24] ? "On":"---",
  121.     a+5,cmfdata[a+25] ? "On":"---",
  122.     a+6,cmfdata[a+26] ? "On":"---",
  123.     a+7,cmfdata[a+27] ? "On":"---",
  124.     a+8,cmfdata[a+28] ? "On":"---");
  125.  }
  126.  printf("----------------------------------------------------------------\n");
  127.  printf("Driver Version: %u.%u  ", getcmfdriverversion()>>8, getcmfdriverversion()%256);
  128.  setcmfstatusbyte();
  129.  
  130.  printf("Status Byte: %04x:%04x\n",FP_SEG(cmf_status),FP_OFF(cmf_status));
  131.  puts("\n\nThe computer can count and play a song simultaneously.\nPress a key to stop playing...");
  132.  if (cmfplay(cmfdata)==1) puts("Error playing CMF.");
  133.  while (cmf_status[0])
  134.  {
  135.   _settextposition(14,50);
  136.   printf("Status: %3u\n%u\n",cmf_status[0],count++);
  137.   if (kbhit())
  138.   {
  139.    if (getch()==8) exit(8);
  140.    else stopcmfplayback();
  141.   }
  142.  }
  143.  _settextposition(14,50);
  144.  printf("Status: %3u\n",cmf_status[0]);
  145.  
  146.  setsystemclock(25);
  147.  initcmfdriver();
  148.  freestatusbyte();
  149.  hfree((char huge *)cmfdata);
  150.  
  151.  printf("\n\n\n");
  152.  exit(0);
  153. }
  154.