home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / sndbords / proaudio / pas_sdk1 / pas / pcm / playfile.c < prev    next >
C/C++ Source or Header  |  1992-09-24  |  22KB  |  1,073 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   24 Sep 1992 08:59:20  $*/
  3. /*$Header:   X:/sccs/pcmapps/playfile.c_v   1.9   24 Sep 1992 08:59:20   DCODY  $*/
  4. /*$Log:   X:/sccs/pcmapps/playfile.c_v  $
  5.  * 
  6.  *    Rev 1.9   24 Sep 1992 08:59:20   DCODY
  7.  * changed MVGetHardware to mvGetHardware
  8.  * 
  9.  *    Rev 1.8   14 Sep 1992 17:22:38   SHAO_M
  10.  * Put all the text strings used in printf into playtext.h
  11.  * 
  12.  *    Rev 1.0   14 Sep 1992 17:01:30   unknown
  13.  * Initial revision.
  14.  * 
  15.  *    Rev 1.7   13 Aug 1992 08:26:18   DCODY
  16.  * corrected #if/#endif and } placement for TB stuff...
  17.  * 
  18.  *    Rev 1.6   04 Aug 1992 11:39:54   DCODY
  19.  * corrected t&l spelling
  20.  * 
  21.  *    Rev 1.5   28 Jul 1992 14:29:06   DCODY
  22.  * updated for Thunderboard and Thunder&Lightning
  23.  * 
  24.  *    Rev 1.4   20 Jul 1992 11:39:02   DCODY
  25.  * call to mvGetHWVersion now uses active I/O address detection.
  26.  * 
  27.  *    Rev 1.3   13 Jul 1992 18:54:14   DCODY
  28.  * removed initmvsound call
  29.  * 
  30.  *    Rev 1.2   01 Jul 1992 11:55:16   DCODY
  31.  * GaryL: Added OEM compiler flag checking for Welcome()
  32.  * to use the generic board name and to not display the MVI copyright.
  33.  * Note that the copyright is still present, as an imbedded static string.
  34.  * 
  35.  *    Rev 1.1   23 Jun 1992 16:09:50   DCODY
  36.  * pas2 update...
  37.  * 
  38.  *    Rev 1.0   15 Jun 1992 09:26:40   BCRANE
  39.  * Initial revision.
  40. */
  41. /*$Logfile:   X:/sccs/pcmapps/playfile.c_v  $*/
  42. /*$Modtimes$*/
  43. /*$Revision:   1.9  $*/
  44. /*$Workfile:   playfile.c  $*/
  45.  
  46.  
  47.     /*\
  48.     |*|----====< PLAYFILE.C >====----
  49.     |*|
  50.     |*| Play the voice file from disk to the PCM hardware
  51.     |*|
  52.     |*| Copyright (c) 1991, Media Vision, Inc. All rights reserved.
  53.     |*|
  54.     \*/
  55.  
  56. #ifndef OEM
  57. #define OEM    0    /* OEM compile flag                    */
  58. #endif
  59. #ifndef PROAS
  60. #define PROAS    0    /* Pro Audio Spectrum compile flag                    */
  61. #endif
  62. #ifndef THUNDER
  63. #define THUNDER 0    /* Thunder Board compile flag                        */
  64. #endif
  65.  
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <malloc.h>
  69. #include <signal.h>
  70. #include "playtext.h"
  71.  
  72. #if PROAS
  73. #include "play.h"
  74. #include "common.h"
  75. #include "pcmio.h"
  76. #endif
  77.  
  78. #if THUNDER
  79. #include "proto.h"
  80. #include "play.h"
  81. #include "common.h"
  82. #include "pcmio.h"
  83. #include "mvsound.h"
  84. #endif
  85.  
  86.  
  87.     /*\
  88.     |*|----====< Global Variables >====----
  89.     \*/
  90.  
  91.         extern int DMARunning;
  92.  
  93.         long mvGetHWVersion (int);
  94.  
  95.  
  96.     /*\
  97.     |*|----====< Local Variables >====----
  98.     \*/
  99.  
  100.         static FILE *inf;                /* user input file                */
  101.  
  102.         static long SampleRate = 11025L;/* default sample rate            */
  103.         static int    StereoMono = 0;     /* default to mono                */
  104.         static int    Filter       = -1;    /* filter override #            */
  105.         static int    Compression= FALSE; /* compressed data                */
  106.  
  107.         static int    DMAChannel = -1;    /* default to standard DMA        */
  108.         static int    IRQChannel = -1;    /* default to standard IRQ        */
  109.  
  110.         static int    speed = 100;        /* 100 percent                    */
  111.  
  112.         static int    UserStereoMono = -1;/* user's override flag = mono  */
  113.         static long UserSampleRate = -1;/* user's override = 11k        */
  114.         static long DataLength       = -1;/* -1 goes to EOF                */
  115.  
  116.         static int    maxsize    = 16;    /* 16k DMA buffer size            */
  117.         static int    maxdiv       = 4;     /* 4k divisions on the DMA        */
  118.         static int    datasize   = 8;     /* 8 bit or 16 bit pcm            */
  119.         static int    dsoverride = FALSE; /* data size override            */
  120.  
  121. #define ALLOTHERS    0                    /* assume an 8 bit data file    */
  122. #define WAVEFILE    1                    /* wave type of file            */
  123. #define VOCFILE     2                    /* .voc 8 bit pcm file            */
  124.         static int    FileType;            /* type of source file            */
  125.  
  126. #define BUFFLEN     4096
  127.         static char vocbuffer[BUFFLEN]; /* 4k worth of data             */
  128.         static long VOCBlockLength;     /* current block length         */
  129.         static char VOCBlockType;        /* current block type            */
  130.         static char VOCPackType;
  131.  
  132.         int  CommandLine    ( int, char *[] );
  133.         int  DoExit         ( int );
  134.         int  FetchVOCData   ( char * ); /* buffer of PCM data           */
  135.         int  PreProcessFile ( char * );
  136.         int  SetupPlayRate  ( );
  137.         void SetupSound     ( );
  138.  
  139.  
  140.     /*\
  141.     |*|----====< Main >====----
  142.     |*|
  143.     |*| Play the voice file out to the PCM hardware
  144.     |*|
  145.     \*/
  146.  
  147. main(argc,argv)
  148.     int  argc;
  149.     char *argv[];
  150. {
  151. char c;
  152.  
  153.     /* give the opening welcome & checkout the hardware                 */
  154.  
  155.         Welcome();
  156.  
  157.     /* set the runtime switches                                         */
  158.  
  159.         CommandLine (argc,argv);
  160.  
  161.     /* disable the ^C                                                   */
  162.  
  163.         signal (SIGINT,SIG_IGN);
  164.  
  165.     /* need a file name to play, exit if not found                        */
  166.  
  167.         PreProcessFile (argv[1]);
  168.  
  169.         if (OpenPCMBuffering(DMAChannel,IRQChannel,maxsize,maxdiv)) {
  170.             printf (TXT_MSG1);
  171.             DoExit (-1);
  172.         }
  173.  
  174.     /* setup how this file sounds                                        */
  175.  
  176.         SetupSound();
  177.  
  178.     /* Start the DMA & wait till an ESC is typed or data ends           */
  179.  
  180.         printf (TXT_MSG2);
  181.  
  182.         if (FileType <= WAVEFILE) {
  183.  
  184.             /* .WAV & all other files can go out using normal file I/O    */
  185.  
  186.             if (StartFileOutput( inf, DataLength )) {
  187.  
  188.                 while (1) {
  189.  
  190.                     /* if all done, then just break                     */
  191.  
  192.                         if (!ContinueFileOutput())
  193.                             break;
  194.  
  195.                     /* if ESC typed, kill the DMA & exit                */
  196.  
  197.                         if (kbhit()) {
  198.  
  199.                             if ((c = getch()) == 0x1b) {
  200.                                 StopDMAIO();
  201.                                 break;
  202.                             }
  203.                             if (c == ' ') {
  204.                                 PausePCM();
  205.                                 printf (TXT_MSG3);
  206.                                 GetKey();
  207.                                 printf (TXT_MSG4);
  208.                                 ResumePCM();
  209.                             }
  210.                         }
  211.                 }
  212.             }
  213.         }
  214.         else {
  215.  
  216.             /* if there is data available, play it...                    */
  217.  
  218.             if (FetchVOCData(vocbuffer)) {
  219.  
  220.                 /* start the output with the first block of data        */
  221.  
  222.                 if (StartBlockOutput( vocbuffer )) {
  223.  
  224.                     /* fetch the next block of data                     */
  225.  
  226.                     FetchVOCData(vocbuffer);
  227.  
  228.                     while (1) {
  229.  
  230.                         /* if the block can be passed, reload it        */
  231.  
  232.                             if (ContinueBlockOutput(vocbuffer)) {
  233.                                 if (!FetchVOCData(vocbuffer))
  234.                                     break;
  235.                             }
  236.  
  237.                         /* if ESC typed, kill the DMA & exit            */
  238.  
  239.                             if (kbhit()) {
  240.  
  241.                                 if ((c = getch()) == 0x1b) {
  242.                                     StopDMAIO();
  243.                                     DoExit(0);
  244.                                 }
  245.                                 if (c == ' ') {
  246.                                     PausePCM();
  247.                                     printf (TXT_MSG5);
  248.                                     GetKey();
  249.                                     printf (TXT_MSG6);
  250.                                     ResumePCM();
  251.                                 }
  252.                             }
  253.                     }
  254.  
  255.                     /* wait till the DMA finishes                        */
  256.  
  257.                     while (DMARunning) ;
  258.  
  259.                 }
  260.             }
  261.         }
  262.  
  263.     /* exit to DOS                                                        */
  264.  
  265.         DoExit(0);
  266.  
  267. }
  268.  
  269.  
  270.     /*\
  271.     |*|----====< CommandLine >====----
  272.     |*|
  273.     |*| process the command line switches
  274.     |*|
  275.     \*/
  276. int CommandLine(argc,argv)
  277.     int argc;
  278.     char *argv[];
  279. {
  280. char *s;
  281. int n,temp;
  282. long longtemp;
  283.  
  284.     /* exit if no additional parameters                                 */
  285.  
  286.         if (argc < 2) {
  287.             GiveHelps();
  288.             DoExit (-1);
  289.         }
  290.  
  291.         n = 2;
  292.         while (n < argc) {
  293.  
  294.             s = argv[n++];
  295.  
  296.             if (*s == '/') s++;
  297.             if (*s == '-') s++;
  298.  
  299.             switch (*s & 0x5f) {
  300.  
  301. #if PROAS
  302.                 case '1' & 0x5f:
  303.                 case '8' & 0x5f:
  304.                     if (*++s == '6')
  305.                         datasize   = 16;
  306.                     dsoverride = TRUE;
  307.  
  308.                     break;
  309.  
  310.                 case 'F':
  311.                     Filter = *++s - 0x30;
  312.                     if ((Filter > 6) || (Filter < 0))
  313.                         Filter = -1;
  314.                     break;
  315. #endif
  316.  
  317.                 case 'D':
  318.                     temp = *++s - 0x30;
  319.                     if ((temp <= 7) && (temp >= 1)) {
  320.                         if (temp == 4) temp = 0;
  321.                         DMAChannel = temp;
  322.                     }
  323.                     break;
  324.  
  325.                 case 'I':
  326.                     if (sscanf (++s,"%d",&temp) == 1) {
  327.                         if ((1 << temp) & 0x9CBC)
  328.                             IRQChannel = temp;
  329.                     }
  330.                     break;
  331.  
  332.                 case 'M':
  333.                     maxsize = 64;
  334.                     maxdiv    = 16;
  335.                     break;
  336.  
  337.                 case 'R':
  338.                     if (sscanf (++s,"%ld",&longtemp) == 1) {
  339.                         if ((longtemp >4000L) && (longtemp < 88200L))
  340.                             UserSampleRate = longtemp;
  341.                     }
  342.                     break;
  343.  
  344.                 case 'S':
  345.                     s++;
  346.  
  347.                     if (*s == '\0')
  348.                         UserStereoMono = 1;
  349.                     else {
  350.                         if (sscanf (s,"%d",&temp) == 1) {
  351.                             if ((temp >= 0) && ( temp <= 200))
  352.                                 speed = temp;
  353.                         }
  354.                     }
  355.                     break;
  356.  
  357.                 default:
  358.                     break;
  359.             }
  360.         }
  361. }
  362.  
  363.  
  364.     /*\
  365.     |*|----====< DoExit() >====----
  366.     |*|
  367.     |*| Exit to DOS
  368.     |*|
  369.     \*/
  370. int DoExit(cc)
  371.     int cc;
  372. {
  373.         ClosePCMBuffering();
  374.         exit (cc);
  375. }
  376.  
  377.  
  378.     /*\
  379.     |*|----====< GiveHelps() >====----
  380.     |*|
  381.     |*| print text helps & return
  382.     |*|
  383.     \*/
  384. int GiveHelps()
  385. {
  386.  
  387.     /* print & return...                                                */
  388.  
  389. #if PROAS
  390.         printf (TXT_MSG7);
  391.         printf (TXT_MSG8);
  392.         printf (TXT_MSG9);
  393.         printf (TXT_MSG10);
  394.         printf (TXT_MSG11);
  395.         printf (TXT_MSG12);
  396.         printf (TXT_MSG13);
  397.         printf (TXT_MSG14);
  398.         printf (TXT_MSG15);
  399.         printf (TXT_MSG16);
  400.         printf (TXT_MSG17);
  401. #endif
  402.  
  403. #if THUNDER
  404.         printf (TXT_MSG18);
  405.         printf (TXT_MSG19);
  406.         printf (TXT_MSG20);
  407.  #if THUNDER==2
  408.         printf (TXT_MSG21);
  409.         printf (TXT_MSG22);
  410.  #else
  411.         printf (TXT_MSG23);
  412.  #endif
  413.         printf (TXT_MSG24);
  414.         printf (TXT_MSG25);
  415.         printf (TXT_MSG26);
  416. #endif
  417. }
  418.  
  419.  
  420.     /*\
  421.     |*|----====< FetchVOCData >====----
  422.     |*|
  423.     |*| Get a new key
  424.     |*|
  425.     \*/
  426. int FetchVOCData(buff)
  427.     char *buff;
  428. {
  429. int loaded = 0, n;
  430. int looping = TRUE;
  431. int remaining = BUFFLEN;
  432.  
  433.     /* grab the next block of data                                        */
  434.  
  435.         looping = 1;
  436.         while (looping) {
  437.  
  438.             /* process the header                                        */
  439.  
  440.                 switch (VOCBlockType) {
  441.  
  442.                     case TERMINATOR:
  443.  
  444.                         for (;remaining;remaining--)
  445.                             *buff++ = 0x80;
  446.                         remaining = 0;
  447.                         looping = 0;        /* this will knock us out    */
  448.                         break;
  449.  
  450.                     case VOICECONTINUE:
  451.                     case VOICEDATA:
  452.  
  453.                         /* load the data, try to span blocks            */
  454.  
  455.                         if (VOCBlockLength < remaining) {
  456.                             remaining -= VOCBlockLength;
  457.                             n = fread (buff,1,(size_t)VOCBlockLength,inf);
  458.                             loaded += n;
  459.                             buff += n;
  460.                             VOCBlockLength = 0;
  461.                         }
  462.                         else {
  463.                             n = fread(buff,1,remaining,inf);
  464.                             loaded += n;
  465.                             VOCBlockLength -= n;
  466.                             looping = remaining = 0;
  467.                         }
  468.                         break;
  469.  
  470.                     case SILENCE:
  471.  
  472.                         /* load the data, try to span blocks            */
  473.  
  474.                         if (VOCBlockLength < remaining) {
  475.                             remaining -= VOCBlockLength;
  476.                             loaded += VOCBlockLength;
  477.                             for (;VOCBlockLength;VOCBlockLength--)
  478.                                 *buff++ = 0x80;
  479.                         }
  480.                         else {
  481.                             loaded = remaining;
  482.                             VOCBlockLength -= remaining;
  483.                             for (;remaining;remaining--)
  484.                                 *buff++ = 0x80;
  485.                             looping = remaining = 0;
  486.                         }
  487.                         break;
  488.  
  489.                     case MARKER:
  490.                     case REPEAT:
  491.                     case ENDREPEAT:
  492.                     case ASCIITEXT:
  493.  
  494.                         /* all the rest of the header were eaten by the     */
  495.                         /* "GetNextBlock" routine. We will continue till we */
  496.                         /* find data, or the terminating record             */
  497.  
  498.                     default:
  499.                         break;
  500.                 }
  501.  
  502.                 /* span blocks, but exit on EOF                             */
  503.  
  504.                 if (remaining) {
  505.                     if (!GetNextBlock()) {
  506.                         for (;remaining;remaining--)
  507.                             *buff++ = 0x80;
  508.                         looping = FALSE;
  509.                     }
  510.                 }
  511.         }
  512.  
  513.     /* return with data data block                                            */
  514.  
  515.         return(loaded);
  516. }
  517.  
  518.  
  519.     /*\
  520.     |*|----====< GetKey() >====----
  521.     |*|
  522.     |*| Get a new key
  523.     |*|
  524.     \*/
  525. int GetKey()
  526. {
  527. char c;
  528.  
  529.     while (kbhit()) getch();
  530.  
  531.     while (!kbhit()) ;
  532.     if (getch() == 0) getch();
  533.  
  534. }
  535.  
  536.  
  537.     /*\
  538.     |*|----====< GetNextBlock() >====----
  539.     |*|
  540.     |*| Process the header to the next block, & return TRUE if data is
  541.     |*| pointed to.
  542.     |*|
  543.     \*/
  544. int GetNextBlock()
  545. {
  546. int looping = TRUE;
  547. long l;
  548.  
  549.     /* get the record type & process to get the sample rate             */
  550.  
  551.         VOCBlockLength = 0;             /* we must end up with data!    */
  552.         while (looping) {
  553.  
  554.             switch (VOCBlockType = fgetc(inf)) {
  555.  
  556.                 case TERMINATOR:
  557.                     return(0);            /* if at the end, just exit     */
  558.  
  559.                 case SILENCE:
  560.                     fgetc(inf);fgetc(inf);fgetc(inf);
  561.                     VOCBlockLength  = fgetc(inf) & 0xff;
  562.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  563.                     SetupPlayRate(fgetc(inf) & 0xff);
  564.                     VOCBlockLength -= 3;    /* 3 less for header data    */
  565.                     looping = FALSE;
  566.                     break;
  567.  
  568.                 case VOICEDATA:
  569.                     VOCBlockLength    = fgetc(inf) & 0xff;
  570.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  571.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 16;
  572.                     SetupPlayRate(fgetc(inf) & 0xff);
  573.  
  574.                     /* determine mono/stereo                            */
  575.  
  576.                     StereoMono = 0;
  577.                     if (((VOCPackType = fgetc(inf)) & 0xff) == 5) {
  578.                         StereoMono = 1;
  579.                         VOCPackType = 0;
  580.                     }
  581. #if THUNDER
  582.                     /* determine compression                            */
  583.  
  584.                     if (VOCPackType <= 3)    /* types 0 - 3                */
  585.                         Compression = VOCPackType;
  586. #endif
  587.                     VOCBlockLength -= 2;    /* 2 less for header data   */
  588.                     looping = FALSE;
  589.                     break;
  590.  
  591.                 case ASCIITEXT:
  592.                     l  = fgetc(inf) & 0xff;
  593.                     l += ((long)(fgetc(inf) & 0xff)) << 8;
  594.                     l += ((long)(fgetc(inf) & 0xff)) << 16;
  595.                     for (;l;l--)
  596.                         fgetc(inf);
  597.                     break;
  598.  
  599.                 case MARKER:
  600.                 case REPEAT:
  601.                     fgetc(inf);fgetc(inf);
  602.                 case ENDREPEAT:
  603.                     fgetc(inf);fgetc(inf);fgetc(inf);
  604.                     break;
  605.  
  606.                 default:
  607.                     printf (TXT_MSG27);
  608.                     DoExit(-1);
  609.                     break;
  610.  
  611.             }
  612.         }
  613.  
  614.     /* we leave the file pointing to the first data byte                */
  615.  
  616.         return(1);
  617. }
  618.  
  619.     /*\
  620.     |*|----====< PreProcessFile >====----
  621.     |*|
  622.     |*| Fill the play buffer with the contents of the disk file
  623.     |*|
  624.     \*/
  625. int PreProcessFile (fn)
  626.     char *fn;
  627. {
  628. char buff[100];
  629. int n,looping;
  630. long psize,l;
  631. char *p,*b;
  632. long* ptr;
  633. FILE *wf;
  634.  
  635.     /* attempt to open the users disk file                                */
  636.  
  637.         if ((inf = fopen(fn,"rb")) == 0) {
  638.  
  639.             strcpy (buff,fn);
  640.             strcat (buff,".WAV");
  641.             if ((inf = fopen(buff,"rb")) == 0) {
  642.  
  643.                 strcpy (buff,fn);
  644.                 strcat (buff,".VOC");
  645.                 if ((inf = fopen(buff,"rb")) == 0) {
  646.  
  647.                     printf (TXT_MSG28,fn);
  648.                     DoExit (-1);
  649.                 }
  650.             }
  651.         }
  652.  
  653.     /* get the 1st 2 characters in the file                             */
  654.  
  655.         n = fgetc(inf) & 0xff;
  656.         n = n + ((fgetc(inf) & 0xff) << 8);
  657.  
  658.         fseek (inf,0L,SEEK_SET); /* rewind to the start                 */
  659.  
  660.     /* special case a .WAV file                                         */
  661.  
  662.         if (n == 0x4952) {
  663.              ProcessWAVFile();
  664.              return(0);
  665.         }
  666.  
  667.     /* special case anything else than a .VOC file                        */
  668.  
  669.         if (n != 0x7243) {        /* if NE to Creative..., then it's PCM  */
  670.              ProcessPCMFile();
  671.              return(0);
  672.         }
  673.  
  674.     /* .VOC type of source file                                         */
  675.  
  676.         FileType = VOCFILE;
  677.  
  678.     /* get the header of the voice file                                 */
  679.  
  680.         b = &buff[0];
  681.         fseek(inf,0L,SEEK_SET);         /* move to the first byte        */
  682.         for (n=0;n<(sizeof (VOCHDR));n++)
  683.             *b++ = fgetc(inf);
  684.  
  685.         if (feof(inf)) {
  686.             printf (TXT_MSG29);
  687.             DoExit (-1);
  688.         }
  689.  
  690.     /* Make sure it's a legit file                                      */
  691.  
  692.         if (strncmp (buff,"Creative Voice File",0x13) != 0) {
  693.             printf (TXT_MSG30);
  694.             DoExit (-1);
  695.         }
  696.  
  697.         p = &buff[0x14];                /* get a pointer to the offset    */
  698.  
  699.         psize = LONG(*p) & 0xffff;        /* get the 16 bit word            */
  700.  
  701.         fseek(inf,psize,SEEK_SET);        /* move to the first byte        */
  702.  
  703.         if (!GetNextBlock())            /* process the next header        */
  704.             DoExit(0);
  705.  
  706. }
  707.  
  708.  
  709.     /*\
  710.     |*|----====< ProcessWAVFile >====----
  711.     |*|
  712.     |*| load the header from our WAV file format
  713.     |*|
  714.     \*/
  715. int ProcessWAVFile(f)
  716. {
  717. int n;
  718. char *b,c;
  719. WaveInfo whd;
  720. DataHeader dhd;
  721.  
  722.     /* We are a WAVE file                                                */
  723.  
  724.         FileType = WAVEFILE;            /* type of source file          */
  725.  
  726.     /* eat the RIFF portion of the header                                */
  727.  
  728.         c = fgetc(inf);
  729.  
  730.         if (c == 'R') {
  731.             for (n=7;n;n--)
  732.                 fgetc(inf);
  733.             c = fgetc(inf);
  734.         }
  735.  
  736.     /* pas up the wave block header name                                */
  737.  
  738.         if (c != 'W') {
  739.             printf (TXT_MSG31);
  740.             DoExit(-1);
  741.         }
  742.         fgetc(inf); fgetc(inf); fgetc(inf);     /* move past the data    */
  743.  
  744.     /* pass up the format section name                                    */
  745.  
  746.         c = fgetc(inf);
  747.         if (c != 'f') {
  748.             printf (TXT_MSG32);
  749.             DoExit(-1);
  750.         }
  751.         for (n=7;n;n--)
  752.             fgetc(inf);                         /* move past the data    */
  753.  
  754.     /* load the actual header data                                        */
  755.  
  756.         b = (char *) &whd;
  757.         for (n=0;n<sizeof (WaveInfo);n++)
  758.             *b++ = fgetc(inf);
  759.  
  760.     /* grab the sample rate                                             */
  761.  
  762.         StereoMono = whd.nChannels - 1;
  763.         SampleRate = whd.nSamplesPerSec;
  764.  
  765.     /* setup the data size only if no override has been requested        */
  766.  
  767.         if (!dsoverride)
  768.             datasize   = whd.nBitsPerSample;
  769.  
  770.     /* go to the data section and get the data length                    */
  771.  
  772.         b = (char *) &dhd;
  773.         for (n=0;n<sizeof(DataHeader);n++)
  774.             *b++ = fgetc(inf);                    /* move past the data    */
  775.  
  776.         if (dhd.name[0] != 'd') {
  777.             printf (TXT_MSG33);
  778.             DoExit(-1);
  779.         }
  780.  
  781.         DataLength = dhd.length;
  782.  
  783. }
  784.  
  785.  
  786.     /*\
  787.     |*|----====< ProcessPCMFile >====----
  788.     |*|
  789.     |*| load the header from our PCM file format
  790.     |*|
  791.     \*/
  792. int ProcessPCMFile()
  793. {
  794. int n;
  795. char *b;
  796.  
  797.     /* we are some unknown data type                                    */
  798.  
  799.         FileType = ALLOTHERS;            /* type of source file            */
  800.  
  801.     /* ask for the sample rate                                          */
  802.  
  803.         if (UserSampleRate != -1) {
  804.             SampleRate = UserSampleRate;
  805.  
  806.             if (UserStereoMono == -1)
  807.                 UserStereoMono = 0;
  808.  
  809.             StereoMono = UserStereoMono;
  810.         }
  811.         else {
  812.  
  813.             SampleRate = 11025L;
  814.             printf (TXT_MSG34);
  815.             while (1) {
  816.                 if (scanf ("%ld",&SampleRate) == 1)
  817.                     break;
  818.             }
  819.  
  820.             printf (TXT_MSG35);
  821.             while (1) {
  822.                 if (scanf ("%d",&StereoMono) == 1) {
  823.                     StereoMono--;    /* make it zero based                */
  824.                     break;
  825.                 }
  826.             }
  827.         }
  828.  
  829.         if ((StereoMono < 0) || (StereoMono > 1))
  830.             StereoMono = 0;
  831. }
  832.  
  833.  
  834.     /*\
  835.     |*|----====< SetupPlayRate >====----
  836.     |*|
  837.     |*| Setup the playing rate of the interrupt routine.
  838.     |*|
  839.     \*/
  840. int SetupPlayRate(n)
  841.     int n;
  842. {
  843.  
  844.     /* we will use a default rate                                        */
  845.  
  846.         SampleRate = 11025L;
  847.  
  848.     /* search for the real rate                                         */
  849.  
  850.         while (1) {
  851.  
  852.             if (n <= 6) {
  853.                 SampleRate = 4000L;         /* 4000 kh sampling         */
  854.                 break;
  855.             }
  856.  
  857.             if (n <= 56) {
  858.                 SampleRate = 5000L;         /* 5000 kh sampling         */
  859.                 break;
  860.             }
  861.  
  862.             if (n <= 90) {
  863.                 SampleRate = 6000L;         /* 6000 kh sampling         */
  864.                 break;
  865.             }
  866.  
  867.             if (n <= 114) {
  868.                 SampleRate = 7000L;         /* 7000 kh sampling         */
  869.                 break;
  870.             }
  871.  
  872.             if (n <= 131) {
  873.                 SampleRate = 8000L;         /* 8000 kh sampling         */
  874.                 break;
  875.             }
  876.  
  877.             if (n <= 145) {
  878.                 SampleRate = 9000L;         /* 9000 kh sampling         */
  879.                 break;
  880.             }
  881.  
  882.             if (n <= 156) {
  883.                 SampleRate = 10000L;        /* 10000 kh sampling        */
  884.                 break;
  885.             }
  886.  
  887.             if (n <= 166) {
  888.                 SampleRate = 11000L;        /* 11000 kh sampling        */
  889.                 break;
  890.             }
  891.  
  892.             if (n <= 173) {
  893.                 SampleRate = 12000L;        /* 11000 kh sampling        */
  894.                 break;
  895.             }
  896.  
  897.             if (n <= 180) {
  898.                 SampleRate = 13000L;        /* 11000 kh sampling        */
  899.                 break;
  900.             }
  901.  
  902.             if (n <= 185) {
  903.                 SampleRate = 14000L;        /* 11000 kh sampling        */
  904.                 break;
  905.             }
  906.  
  907.             if (n <= 190) {
  908.                 SampleRate = 15000L;        /* 11000 kh sampling        */
  909.                 break;
  910.             }
  911.  
  912.             if (n <= 194) {
  913.                 SampleRate = 16000L;        /* 11000 kh sampling        */
  914.                 break;
  915.             }
  916.  
  917.             if (n <= 198) {
  918.                 SampleRate = 17000L;        /* 11000 kh sampling        */
  919.                 break;
  920.             }
  921.  
  922.             if (n <= 201) {
  923.                 SampleRate = 18000L;        /* 11000 kh sampling        */
  924.                 break;
  925.             }
  926.  
  927.             if (n <= 204) {
  928.                 SampleRate = 19000L;        /* 11000 kh sampling        */
  929.                 break;
  930.             }
  931.  
  932.             if (n <= 206) {
  933.                 SampleRate = 20000L;        /* 11000 kh sampling        */
  934.                 break;
  935.             }
  936.  
  937.             if (n <= 209) {
  938.                 SampleRate = 21000L;        /* 11000 kh sampling        */
  939.                 break;
  940.             }
  941.  
  942.             if (n <= 211) {
  943.                 SampleRate = 22000L;        /* 11000 kh sampling        */
  944.                 break;
  945.             }
  946.  
  947.             if (n <= 215) {
  948.                 SampleRate = 23000L;        /* 11000 kh sampling        */
  949.                 break;
  950.             }
  951.  
  952.             /* if unknown value, bomb out...                            */
  953.  
  954.                 printf (TXT_MSG36);
  955.                 DoExit(0);
  956.  
  957.         }
  958. }
  959.  
  960.  
  961.     /*\
  962.     |*|----====< SetupSound() >====----
  963.     |*|
  964.     |*| Setup the sample rate, stereo/mono.
  965.     |*|
  966.     \*/
  967. void SetupSound()
  968. {
  969.  
  970.     /* if the user wants it different...                                */
  971.  
  972.         if (UserSampleRate != -1)
  973.             SampleRate = UserSampleRate;
  974.  
  975.         if (UserStereoMono != -1)
  976.             StereoMono = UserStereoMono;
  977.  
  978.     /* speed is the user's %. from 0 to 200 %                           */
  979.  
  980.         SampleRate = ((SampleRate * speed) + 50) / 100;
  981.  
  982. #if PROAS
  983.         ChooseFilter( SampleRate, Filter );
  984. #endif
  985.  
  986.         PCMState (SampleRate, StereoMono, Compression, datasize );
  987. }
  988.  
  989.  
  990.     /*\
  991.     |*|----====< Welcome >====----
  992.     |*|
  993.     |*| Print the logo & check for the appropriate hardware
  994.     |*|
  995.     \*/
  996. Welcome()
  997. {
  998. long ver;
  999.  
  1000.     /* give the normal stuff...                                         */
  1001.  
  1002. #if OEM
  1003.  
  1004.  #if PROAS
  1005.         printf (TXT_MSG37);
  1006.  #endif
  1007.  
  1008.  #if THUNDER
  1009.         printf (TXT_MSG38);
  1010.  #endif
  1011.  
  1012.         {
  1013.                 static char    zsCopyright[] = "Copyright (c) 1991,1992 Media Vision, Inc. All Rights Reserved\n\n";
  1014.         }
  1015.  
  1016. #else
  1017.  
  1018.  #if PROAS
  1019.         printf (TXT_MSG39);
  1020.  #endif
  1021.  
  1022.  #if THUNDER
  1023.   #if THUNDER==2
  1024.         printf (TXT_MSG40);
  1025.   #else
  1026.         printf (TXT_MSG41);
  1027.   #endif
  1028.  #endif
  1029.  
  1030.         printf (TXT_MSG42);
  1031.  
  1032. #endif  //OEM
  1033.  
  1034.     /* check for the hardware                                            */
  1035.  
  1036. #if PROAS
  1037.         ver = mvGetHWVersion(USE_ACTIVE_ADDR); /* get the version               */
  1038.         if (ver == -1) {
  1039.  #if OEM
  1040.             printf (TXT_MSG43);
  1041.  #else     //OEM
  1042.             printf (TXT_MSG44);
  1043.  #endif  //OEM
  1044.             GiveHelps();
  1045.             exit(-1);
  1046.         }
  1047. #endif
  1048.  
  1049. #if THUNDER
  1050.         ver = mvGetHWVersion(0);        /* get the version, or something.. */
  1051.         if ((ver < 0) || ((ver & 0xffff0000) != 0x00010000)) {
  1052.  #if OEM
  1053.             printf (TXT_MSG45);
  1054.  #else     //OEM
  1055.   #if THUNDER==2
  1056.             printf (TXT_MSG46);
  1057.   #else
  1058.             printf (TXT_MSG47);
  1059.   #endif
  1060.  #endif
  1061.             GiveHelps();
  1062.             exit(-1);
  1063.         }
  1064.  
  1065. #endif  //THUNDER
  1066. }
  1067.  
  1068.     /*\
  1069.     |*| end of PLAYFILE.C
  1070.     \*/
  1071.  
  1072.  
  1073.