home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / visvideo.zip / MPLAY.C_ / MPLAY.bin
Text File  |  1994-08-30  |  17KB  |  612 lines

  1. /*
  2.  * MPEG Master DOS Demo program.
  3.  *
  4.  *    Syntax:
  5.  *
  6.  *       mplay [-O]
  7.  *          Circle play CDI-FMV disc in the first attached CD-ROM drive.
  8.  *
  9.  *       mplay -K [n] [-O]
  10.  *          Circle play the nth song of KARAOKE disc in the first attached
  11.  *          CD-ROM drive if n specified.
  12.  *
  13.  *          Circle play KARAOKE disc from 1th song in the first attached
  14.  *          CD-ROM drive if n not specified.
  15.  *
  16.  *       mplay -F file  [-O]
  17.  *          Circle play the specified MPEG file.
  18.  *
  19.  *       If -O option presented, the MPLAY will not perform the circle play
  20.  *       at all of the above case.
  21.  *
  22.  */
  23. #include <stdio.h>
  24. #include <dos.h>
  25. #include <stdlib.h>
  26. #include <conio.h>
  27. #include <string.h>
  28. #include "mpeg.h"
  29. #include "music.h"
  30.  
  31. // Define Version number
  32. static char Version[20] = "Ver2.8";
  33.  
  34. #define SPACE  0x20
  35. #define UPAR   1
  36. #define DNAR   2
  37. #define DSPL   3  // F2
  38. #define DSPU   4  // F3
  39. #define DSPR   5  // F4
  40. #define DSPD   6  // F5
  41.  
  42. static int defVol      = 0xfc;          // default volume, 0db
  43. static int defBass     = 0xf6;          // default bass, 0db
  44. static int defTreble   = 0xf6;          // default treble, 0db
  45. static int nVol;     // current volume
  46. static int nBass;    // current bass
  47. static int nTreble;  // current treble
  48. static int nStereo;  // current stereo
  49.  
  50. static int minVol  = 0xda;
  51. static int maxVol  = 0xfe;
  52. static int minBass = 0xf2;
  53. static int maxBass = 0xfb;
  54. static int minTre  = 0xf2;
  55. static int maxTre  = 0xfa;
  56. static int nSongs;
  57. static BOOL fMute  = FALSE;
  58. static BOOL playing = FALSE;
  59. static BOOL pause  = FALSE;
  60. static int dspMode = VGA;
  61. static int cdType;                 // ALL, KARAOKE, CDIFMV
  62. static BOOL showOnVGA = FALSE;
  63. static int sync  = 1;              // 0 for scsi bus, 1 for at bus
  64.  
  65. // function prototype
  66. int  hotkeyProcess (void);
  67. char getKey (void);
  68. void errLoad (int);
  69. void errSyntax (void);
  70. void getINIStr (LPSTR);
  71. int initMpeg (void);
  72.  
  73.  
  74. void main (argc,argv)
  75. int argc;
  76. char *argv[];
  77. {
  78.    int rtn   = 0;
  79.    int media = 0;    // 1 for KARAOKE or CDI-FMV disc, 0 otherwise
  80.    int cdi   = 0;    // 1 for CDI-FMV disc, 0 otherwise
  81.    int cddrv_no = 0;
  82.    int songIndex = 1;
  83.    char mpgFile[128];
  84.    char name[128];
  85.    BOOL done = FALSE;
  86.    int  Repet= 0;
  87.    BOOL playStatus = TRUE;
  88.    BOOL firstPlay = TRUE;
  89.    int err;
  90.  
  91.    if (argc == 1){
  92.       cdType = CDIFMV;
  93.       cdi = 1;
  94.    }
  95.    else
  96.       if (argc == 2){
  97.          if (!strcmpi (argv[1],"-K")){
  98.             cdType = KARAOKE;
  99.             nSongs = 0;
  100.             songIndex = 1;
  101.          }
  102.          else                    // play all disc
  103.             if (!strcmpi (argv[1],"-O")){
  104.                cdType = CDIFMV;
  105.                cdi = 1;
  106.                Repet =1;
  107.             }
  108.             else{
  109.                errSyntax ();
  110.                exit (1);
  111.             }
  112.  
  113.       }
  114.       else
  115.          if (argc == 3){
  116.             if (!strcmpi (argv[1],"-F")){
  117.                if (strcmpi (argv[2],"-O")){
  118.                   cdType = ALL;
  119.                   strcpy (mpgFile,argv[2]);
  120.                }
  121.                else{
  122.                   errSyntax ();
  123.                   exit (1);
  124.                }
  125.             }
  126.             else
  127.                if (!strcmpi (argv[1],"-K")){
  128.                   if (strcmpi (argv[2],"-O")){
  129.                      cdType = KARAOKE;
  130.                      songIndex = atoi (argv[2]);
  131.                      nSongs = 1;
  132.                   }
  133.                   else{
  134.                      cdType = KARAOKE;
  135.                      nSongs = 0;
  136.                      songIndex = 1;
  137.                      Repet=1;
  138.                   }
  139.                }
  140.                else{
  141.                   errSyntax ();
  142.                   exit (1);
  143.                }
  144.          }
  145.          else
  146.             if (argc == 4){
  147.                if (!strcmpi (argv[1],"-F")){
  148.                   if (!strcmpi (argv[3],"-O")){
  149.                      cdType = ALL;
  150.                      strcpy (mpgFile,argv[2]);
  151.                      Repet=1;
  152.                   }
  153.                   else{
  154.                      errSyntax ();
  155.                      exit (1);
  156.                   }
  157.                }
  158.                else{
  159.                   if (!strcmpi (argv[1],"-K")){
  160.                      if (!strcmpi (argv[3],"-O")){
  161.                         cdType = KARAOKE;
  162.                         songIndex = atoi (argv[2]);
  163.                         nSongs = 1;
  164.                         Repet=1;
  165.                      }
  166.                   }
  167.                   else{
  168.                      errSyntax ();
  169.                      exit (1);
  170.                   }
  171.                }
  172.             }
  173.             else{
  174.                errSyntax ();
  175.                exit (1);
  176.             }
  177.  
  178.  
  179.    if (initMpeg ()){
  180.       printf ("Error initial MPEG Master board. !!\n");
  181.       exit (1);
  182.    }
  183.  
  184.    if (cdType == KARAOKE || cdType == CDIFMV){
  185.       media = 1;
  186.       cddrv_no = WMpegGetCDDriveID ();
  187.       if (cddrv_no == EMSCDEX){
  188.          printf ("MSCDEX not installed !!\n");
  189.          exit (1);
  190.       }
  191.  
  192.       if (cddrv_no == EDRIVE){
  193.          printf ("CD-ROM drive not attached !!\n");
  194.          exit (1);
  195.       }
  196.  
  197.       if ((cdType == KARAOKE) && !nSongs)
  198.          nSongs = WMpegGetCDSongs ((WORD)cddrv_no);
  199.    }
  200.  
  201.    printf ("╒════════════════════════════════════════════════════════════════╕\n");
  202.    printf ("│                Visionetics MPEG Master Demo program            │\n");
  203.    printf ("│                            %7s                             │\n",Version);
  204.    printf ("╞════════════════════════════════════════════════════════════════╡\n");
  205.    printf ("│  P -- Normal play.            1 -- Spatial.                    │\n");
  206.    printf ("│  Q -- Exit.                   2 -- Linear.                     │\n");
  207.    printf ("│  U -- Pause.                  3 -- Pseudo.                     │\n");
  208.    printf ("│  F -- Fast forward.           4 -- Mono.                       │\n");
  209.    printf ("│  L -- Slow motion.            M -- Mute on/off.                │\n");
  210.    printf ("│                               V -- Adjust volume.              │\n");
  211.    printf ("│                               T -- Adjust treble.              │\n");
  212.    printf ("│                               B -- Adjust bass.                │\n");
  213.    printf ("│  Up arrow -- Increase desired volume control.                  │\n");
  214.    printf ("│  Dn arrow -- Decrease desired volume control.                  │\n");
  215.    printf ("│  [SPACE]  -- Toggle VIDEO/VGA display.                         │\n");
  216.    printf ("│  [F2]     -- Adjust display screen left  to 1 pixel            │\n");
  217.    printf ("│  [F3]     -- Adjust display screen up    to 1 line             │\n");
  218.    printf ("│  [F4]     -- Adjust display screen right to 1 pixel            │\n");
  219.    printf ("│  [F5]     -- Adjust display screen down  to 1 line             │\n");
  220.    printf ("╘════════════════════════════════════════════════════════════════╛\n");
  221.  
  222.    printf ("Loading ");
  223.    if (cdType == CDIFMV){
  224.       printf ("CDI-FMV disc...\n");
  225.       strcpy (name,"1");
  226.    }else if (cdType == KARAOKE){
  227.       printf ("KARAOKE disc...\n");
  228.       sprintf (name,"%d",songIndex);
  229.    }else{
  230.       printf ("%s...\n",mpgFile);
  231.       strcpy (name,mpgFile);
  232.    }
  233.  
  234.    while (!done){
  235.       playing = TRUE;
  236.       pause = FALSE;
  237.  
  238.       rtn = WMpegLoad (media,name,(WORD)cddrv_no,sync,cdi);
  239.       if (rtn < 0){
  240.          errLoad (rtn);
  241.          break;
  242.       }
  243.  
  244.       Mute ((BYTE)fMute);
  245.       WMpegCommand (NPF);
  246.  
  247.       if (WMpegPlayEnable ((LPMSFTime)NULL)){
  248.          printf ("Error Init DSP !! (May be incorrect path)\n");
  249.          break;
  250.       }
  251.  
  252.       if (firstPlay){
  253.          Volume ((BYTE)nVol);
  254.          Bass ((BYTE)nBass);
  255.          Treble ((BYTE)nTreble);
  256.          Stereo ((BYTE)nStereo);
  257.          if (showOnVGA){
  258.             WMpegSwitcher (VIDEO);
  259.             dspMode = VIDEO;
  260.          }
  261.          firstPlay = FALSE;
  262.       }
  263.  
  264.       if (playStatus){
  265.          printf ("Playing ");
  266.          if (cdType == KARAOKE){
  267.             printf ("song #%s",name);
  268.             if (nSongs <= 1)
  269.                playStatus = FALSE;
  270.          }else
  271.             playStatus = FALSE;
  272.          printf ("...\n");
  273.       }
  274.       while (1){
  275.          if (!(err = WMpegTransfer ())){  // play to end
  276.             if (cdType == KARAOKE){
  277.                if (nSongs != 1){
  278.                   songIndex = (songIndex > nSongs) ? 1 : songIndex++;
  279.                   sprintf (name,"%d",songIndex);
  280.                }
  281.             }
  282.             WMpegCommand (STP);
  283.             break;
  284.          }else if (err > 1){              // fatal error on video
  285.             printf ("Video error %d !!!\n",err);
  286.             done = TRUE;
  287.             break;
  288.          }
  289.          if ( Repet==1 )
  290.             done = TRUE;
  291.  
  292.          if (hotkeyProcess ()){           // exit
  293.             done = TRUE;
  294.             break;
  295.          }
  296.       }
  297.    }
  298.    printf ("Stop.\n");
  299.    WMpegSwitcher (VGA);
  300.    WMpegCommand (STP);        // stop
  301.    WMpegAudioEnable (FALSE);  // disable audio
  302.    WMpegExit ();
  303.    exit (0);
  304. }/* main */
  305.  
  306.  
  307. #define F2     0x3c00
  308. #define F3     0x3d00
  309. #define F4     0x3e00
  310. #define F5     0x3f00
  311.  
  312. #define iVOLUME         17
  313. #define iTREBLE         18
  314. #define iBASS           19
  315. static  int idVol = iVOLUME;    // current volume id
  316.  
  317. /*
  318.  * Process hot key.
  319.  *
  320.  * f, F        Fast forward play.
  321.  * l, L        Slow motion play.
  322.  * m, M        Mute on/off.
  323.  * p, P        Normal play.
  324.  * q, Q        Stop play and exit program.
  325.  * s, S        Stop play.
  326.  * u, U        Pause.
  327.  * SPACE       Toggle VIDEO/VGA display.
  328.  */
  329. int hotkeyProcess (void)
  330. {
  331.    int key;
  332.  
  333.    if (!playing)
  334.       return (0);
  335.  
  336.    if (kbhit ()){
  337.       key = getKey ();
  338.       switch (key){
  339.          case 'F':                  // fast forward
  340.          case 'f':
  341.             WMpegCommand (FMF);
  342.             break;
  343.          case 'L':                  // slow motion
  344.          case 'l':
  345.             WMpegCommand(SMF);
  346.             break;
  347.          case 'M':                  // mute
  348.          case 'm':
  349.             fMute = !fMute;
  350.             Mute ((BYTE)fMute);
  351.             break;
  352.          case 'P':                  // normal play
  353.          case 'p':
  354.             WMpegCommand (NPF);
  355.             break;
  356.          case 'Q':                  // exit
  357.          case 'q':
  358.             return (1);
  359.          case 'U':                  // pause
  360.          case 'u':
  361.             pause = !pause;
  362.             if (pause)
  363.                WMpegCommand (PAU);
  364.             else
  365.                WMpegCommand (NPF);
  366.             break;
  367.          case SPACE:
  368.             if (dspMode == VGA)
  369.                dspMode = VIDEO;
  370.             else
  371.                dspMode = VGA;
  372.             WMpegSwitcher (dspMode);
  373.             break;
  374.          case '1':
  375.             nStereo = SPATIAL_STEREO;
  376.             Stereo ((BYTE)nStereo);
  377.             break;
  378.          case '2':
  379.             nStereo = LINEAR_STEREO;
  380.             Stereo ((BYTE)nStereo);
  381.             break;
  382.          case '3':
  383.             nStereo = PSEUDO_STEREO;
  384.             Stereo ((BYTE)nStereo);
  385.             break;
  386.          case '4':
  387.             nStereo = FORCED_MONO;
  388.             Stereo ((BYTE)nStereo);
  389.             break;
  390.          case 'V':                  // volume control
  391.          case 'v':
  392.             idVol = iVOLUME;
  393.             break;
  394.          case 'T':
  395.          case 't':
  396.             idVol = iTREBLE;
  397.             break;
  398.          case 'B':
  399.          case 'b':
  400.             idVol = iBASS;
  401.             break;
  402.          case UPAR:
  403.             switch (idVol){
  404.                case iVOLUME:
  405.                   nVol++;
  406.                   nVol = (nVol > maxVol) ? maxVol : nVol;
  407.                   Volume ((BYTE)nVol);
  408.                   break;
  409.                case iTREBLE:
  410.                   nTreble++;
  411.                   nTreble = (nTreble > maxTre) ? maxTre : nTreble;
  412.                   Treble ((BYTE)nTreble);
  413.                   break;
  414.                case iBASS:
  415.                   nBass++;
  416.                   nBass = (nBass > maxBass) ? maxBass : nBass;
  417.                   Bass ((BYTE)nBass);
  418.                   break;
  419.             }
  420.             break;
  421.          case DNAR:
  422.             switch (idVol){
  423.                case iVOLUME:
  424.                   nVol--;
  425.                   nVol = (nVol < minVol) ? minVol : nVol;
  426.                   Volume ((BYTE)nVol);
  427.                   break;
  428.                case iTREBLE:
  429.                   nTreble--;
  430.                   nTreble = (nTreble < minTre) ? minTre : nTreble;
  431.                   Treble ((BYTE)nTreble);
  432.                   break;
  433.                case iBASS:
  434.                   nBass--;
  435.                   nBass = (nBass < minBass) ? minBass : nBass;
  436.                   Bass ((BYTE)nBass);
  437.                   break;
  438.             }
  439.             break;
  440.          case DSPL:          // adjust display screen left  to 1 pixel
  441.             WMpegAdjustScreen (SCREEN_LF);
  442.             break;
  443.          case DSPU:          // adjust display screen up    to 1 line
  444.             WMpegAdjustScreen (SCREEN_UP);
  445.             break;
  446.          case DSPR:          // adjust display screen right to 1 pixel
  447.             WMpegAdjustScreen (SCREEN_RT);
  448.             break;
  449.          case DSPD:          // adjust display screen down  to 1 line
  450.             WMpegAdjustScreen (SCREEN_DN);
  451.             break;
  452.          default:
  453.             break;
  454.       }
  455.    }
  456.    return (0);
  457. }/* hotkeyProcess */
  458.  
  459.  
  460. char pStr[128];
  461.  
  462. int initMpeg (void)
  463. {
  464.    int rtn;
  465.  
  466.    nVol    = defVol;
  467.    nBass   = defBass;
  468.    nTreble = defTreble;
  469.  
  470.    getINIStr ((LPSTR)"Stereo");
  471.    if (!strcmp (pStr,(LPSTR)"Spatial"))
  472.       nStereo = SPATIAL_STEREO;
  473.    else if (!strcmp (pStr,(LPSTR)"Mono"))
  474.       nStereo = FORCED_MONO;
  475.    else if (!strcmp (pStr,(LPSTR)"Pseudo"))
  476.       nStereo = PSEUDO_STEREO;
  477.    else
  478.       nStereo = LINEAR_STEREO;
  479.  
  480.    getINIStr ((LPSTR)"ShowOnVGA");
  481.    if (!strcmpi (pStr,(LPSTR)"yes"))
  482.       showOnVGA = TRUE;
  483.    else
  484.       showOnVGA = FALSE;
  485.  
  486.    getINIStr ("BusType");
  487.    if (!strcmpi (pStr,"SCSI"))
  488.       sync = 0;
  489.    else
  490.       sync = 1;
  491.  
  492.    if (rtn = WMpegInit (0))
  493.       return (rtn);
  494.  
  495.    WMpegAudioEnable (TRUE);
  496.    return (0);
  497. }/* initMpeg */
  498.  
  499.  
  500. void getINIStr (key)
  501. LPSTR key;
  502. {
  503.    int  rtn;
  504.  
  505.    rtn = GetPrivateProfileString ((LPCSTR)"UserDef",     // Section
  506.                                   (LPCSTR)key,           // Entry
  507.                                   (LPCSTR)NULL,          // Default string
  508.                                   (LPSTR)pStr,           // string returned
  509.                                   (int)128,              // length
  510.                                   (LPCSTR)"dosmpeg.ini"  // Initialize filename
  511.                                  );
  512.    if (!rtn)
  513.       pStr[0] = '\0';
  514. }/* getINIStr */
  515.  
  516.  
  517. char getKey (void)
  518. {
  519.    union REGS r;
  520.    int key;
  521.    char key1;
  522.  
  523.    r.h.ah = 0;
  524.    key = int86 (0x16,&r,&r);
  525.  
  526.    switch (key){
  527.       case 0x4800:
  528.          return ((char)UPAR);
  529.          break;
  530.       case 0x5000:
  531.          return ((char)DNAR);
  532.          break;
  533.       case F2:
  534.          return (DSPL);
  535.          break;
  536.       case F3:
  537.          return (DSPU);
  538.          break;
  539.       case F4:
  540.          return (DSPR);
  541.          break;
  542.       case F5:
  543.          return (DSPD);
  544.          break;
  545.    }
  546.  
  547.    key1 = (char)(key & 0x00ff);
  548.    return (key1);
  549. }/* getKey */
  550.  
  551.  
  552. void errLoad (code)
  553. int code;
  554. {
  555.    switch (code){
  556.       case EMPEGFile:
  557.          printf ("Open error !!\n");
  558.          break;
  559.       case EBitStream:
  560.          printf ("Unknown BitStream !!\n");
  561.          break;
  562.       case EVolumeSize:
  563.       case ESectorSize:
  564.       case EInitCDROM:
  565.       case ESeekTop:
  566.       case EReadCD:
  567.       case EGetStartSector:
  568.       case EGetLastSector:
  569.       case ESeek:
  570.          printf ("Read CDROM error !!\n");
  571.          break;
  572.       case EInitVideo:
  573.          printf ("Error init Video !!\n");
  574.          break;
  575.       case EInitAudio:
  576.          printf ("Error init Audio !!\n");
  577.          break;
  578.       case EDMA:
  579.          printf ("Init DMA error !!\n");
  580.          break;
  581.       case EDecodeAudio:
  582.          printf ("Unknown BitStream !!\n");
  583.          break;
  584.       case ECDReady:
  585.          printf ("CD-ROM not ready !!\n");
  586.          break;
  587.       default:
  588.          printf ("System error !!\n");
  589.          break;
  590.    }
  591. }/* errLoad */
  592.  
  593.  
  594. void errSyntax (void)
  595. {
  596.    printf ("Syntax:\n");
  597.    printf ("MPLAY [-O]\n");
  598.    printf ("   Circle play CDI-FMV disc in the first attached CD-ROM drive.\n");
  599.    printf ("\n");
  600.    printf ("MPLAY -K [n] [-O]\n");
  601.    printf ("   Circle play the nth song of Video CD disc in the first attached\n");
  602.    printf ("   CD-ROM drive if n specified.\n");
  603.    printf ("OR\n");
  604.    printf ("   Circle play KARAOKE disc from 1th song in the first attached\n");
  605.    printf ("   CD-ROM drive if n not specified.\n");
  606.    printf ("\n");
  607.    printf ("MPLAY -F file [-O]\n");
  608.    printf ("   Circle play the specified MPEG file.\n\n");
  609.    printf ("If -O option presented, the MPLAY will not perform the circle play\n");
  610.    printf ("at all of the above case.\n");
  611. }/* errSyntax */
  612.