home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
vrac
/
visvideo.zip
/
MPLAY.C_
/
MPLAY.bin
Wrap
Text File
|
1994-08-30
|
17KB
|
612 lines
/*
* MPEG Master DOS Demo program.
*
* Syntax:
*
* mplay [-O]
* Circle play CDI-FMV disc in the first attached CD-ROM drive.
*
* mplay -K [n] [-O]
* Circle play the nth song of KARAOKE disc in the first attached
* CD-ROM drive if n specified.
*
* Circle play KARAOKE disc from 1th song in the first attached
* CD-ROM drive if n not specified.
*
* mplay -F file [-O]
* Circle play the specified MPEG file.
*
* If -O option presented, the MPLAY will not perform the circle play
* at all of the above case.
*
*/
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "mpeg.h"
#include "music.h"
// Define Version number
static char Version[20] = "Ver2.8";
#define SPACE 0x20
#define UPAR 1
#define DNAR 2
#define DSPL 3 // F2
#define DSPU 4 // F3
#define DSPR 5 // F4
#define DSPD 6 // F5
static int defVol = 0xfc; // default volume, 0db
static int defBass = 0xf6; // default bass, 0db
static int defTreble = 0xf6; // default treble, 0db
static int nVol; // current volume
static int nBass; // current bass
static int nTreble; // current treble
static int nStereo; // current stereo
static int minVol = 0xda;
static int maxVol = 0xfe;
static int minBass = 0xf2;
static int maxBass = 0xfb;
static int minTre = 0xf2;
static int maxTre = 0xfa;
static int nSongs;
static BOOL fMute = FALSE;
static BOOL playing = FALSE;
static BOOL pause = FALSE;
static int dspMode = VGA;
static int cdType; // ALL, KARAOKE, CDIFMV
static BOOL showOnVGA = FALSE;
static int sync = 1; // 0 for scsi bus, 1 for at bus
// function prototype
int hotkeyProcess (void);
char getKey (void);
void errLoad (int);
void errSyntax (void);
void getINIStr (LPSTR);
int initMpeg (void);
void main (argc,argv)
int argc;
char *argv[];
{
int rtn = 0;
int media = 0; // 1 for KARAOKE or CDI-FMV disc, 0 otherwise
int cdi = 0; // 1 for CDI-FMV disc, 0 otherwise
int cddrv_no = 0;
int songIndex = 1;
char mpgFile[128];
char name[128];
BOOL done = FALSE;
int Repet= 0;
BOOL playStatus = TRUE;
BOOL firstPlay = TRUE;
int err;
if (argc == 1){
cdType = CDIFMV;
cdi = 1;
}
else
if (argc == 2){
if (!strcmpi (argv[1],"-K")){
cdType = KARAOKE;
nSongs = 0;
songIndex = 1;
}
else // play all disc
if (!strcmpi (argv[1],"-O")){
cdType = CDIFMV;
cdi = 1;
Repet =1;
}
else{
errSyntax ();
exit (1);
}
}
else
if (argc == 3){
if (!strcmpi (argv[1],"-F")){
if (strcmpi (argv[2],"-O")){
cdType = ALL;
strcpy (mpgFile,argv[2]);
}
else{
errSyntax ();
exit (1);
}
}
else
if (!strcmpi (argv[1],"-K")){
if (strcmpi (argv[2],"-O")){
cdType = KARAOKE;
songIndex = atoi (argv[2]);
nSongs = 1;
}
else{
cdType = KARAOKE;
nSongs = 0;
songIndex = 1;
Repet=1;
}
}
else{
errSyntax ();
exit (1);
}
}
else
if (argc == 4){
if (!strcmpi (argv[1],"-F")){
if (!strcmpi (argv[3],"-O")){
cdType = ALL;
strcpy (mpgFile,argv[2]);
Repet=1;
}
else{
errSyntax ();
exit (1);
}
}
else{
if (!strcmpi (argv[1],"-K")){
if (!strcmpi (argv[3],"-O")){
cdType = KARAOKE;
songIndex = atoi (argv[2]);
nSongs = 1;
Repet=1;
}
}
else{
errSyntax ();
exit (1);
}
}
}
else{
errSyntax ();
exit (1);
}
if (initMpeg ()){
printf ("Error initial MPEG Master board. !!\n");
exit (1);
}
if (cdType == KARAOKE || cdType == CDIFMV){
media = 1;
cddrv_no = WMpegGetCDDriveID ();
if (cddrv_no == EMSCDEX){
printf ("MSCDEX not installed !!\n");
exit (1);
}
if (cddrv_no == EDRIVE){
printf ("CD-ROM drive not attached !!\n");
exit (1);
}
if ((cdType == KARAOKE) && !nSongs)
nSongs = WMpegGetCDSongs ((WORD)cddrv_no);
}
printf ("╒════════════════════════════════════════════════════════════════╕\n");
printf ("│ Visionetics MPEG Master Demo program │\n");
printf ("│ %7s │\n",Version);
printf ("╞════════════════════════════════════════════════════════════════╡\n");
printf ("│ P -- Normal play. 1 -- Spatial. │\n");
printf ("│ Q -- Exit. 2 -- Linear. │\n");
printf ("│ U -- Pause. 3 -- Pseudo. │\n");
printf ("│ F -- Fast forward. 4 -- Mono. │\n");
printf ("│ L -- Slow motion. M -- Mute on/off. │\n");
printf ("│ V -- Adjust volume. │\n");
printf ("│ T -- Adjust treble. │\n");
printf ("│ B -- Adjust bass. │\n");
printf ("│ Up arrow -- Increase desired volume control. │\n");
printf ("│ Dn arrow -- Decrease desired volume control. │\n");
printf ("│ [SPACE] -- Toggle VIDEO/VGA display. │\n");
printf ("│ [F2] -- Adjust display screen left to 1 pixel │\n");
printf ("│ [F3] -- Adjust display screen up to 1 line │\n");
printf ("│ [F4] -- Adjust display screen right to 1 pixel │\n");
printf ("│ [F5] -- Adjust display screen down to 1 line │\n");
printf ("╘════════════════════════════════════════════════════════════════╛\n");
printf ("Loading ");
if (cdType == CDIFMV){
printf ("CDI-FMV disc...\n");
strcpy (name,"1");
}else if (cdType == KARAOKE){
printf ("KARAOKE disc...\n");
sprintf (name,"%d",songIndex);
}else{
printf ("%s...\n",mpgFile);
strcpy (name,mpgFile);
}
while (!done){
playing = TRUE;
pause = FALSE;
rtn = WMpegLoad (media,name,(WORD)cddrv_no,sync,cdi);
if (rtn < 0){
errLoad (rtn);
break;
}
Mute ((BYTE)fMute);
WMpegCommand (NPF);
if (WMpegPlayEnable ((LPMSFTime)NULL)){
printf ("Error Init DSP !! (May be incorrect path)\n");
break;
}
if (firstPlay){
Volume ((BYTE)nVol);
Bass ((BYTE)nBass);
Treble ((BYTE)nTreble);
Stereo ((BYTE)nStereo);
if (showOnVGA){
WMpegSwitcher (VIDEO);
dspMode = VIDEO;
}
firstPlay = FALSE;
}
if (playStatus){
printf ("Playing ");
if (cdType == KARAOKE){
printf ("song #%s",name);
if (nSongs <= 1)
playStatus = FALSE;
}else
playStatus = FALSE;
printf ("...\n");
}
while (1){
if (!(err = WMpegTransfer ())){ // play to end
if (cdType == KARAOKE){
if (nSongs != 1){
songIndex = (songIndex > nSongs) ? 1 : songIndex++;
sprintf (name,"%d",songIndex);
}
}
WMpegCommand (STP);
break;
}else if (err > 1){ // fatal error on video
printf ("Video error %d !!!\n",err);
done = TRUE;
break;
}
if ( Repet==1 )
done = TRUE;
if (hotkeyProcess ()){ // exit
done = TRUE;
break;
}
}
}
printf ("Stop.\n");
WMpegSwitcher (VGA);
WMpegCommand (STP); // stop
WMpegAudioEnable (FALSE); // disable audio
WMpegExit ();
exit (0);
}/* main */
#define F2 0x3c00
#define F3 0x3d00
#define F4 0x3e00
#define F5 0x3f00
#define iVOLUME 17
#define iTREBLE 18
#define iBASS 19
static int idVol = iVOLUME; // current volume id
/*
* Process hot key.
*
* f, F Fast forward play.
* l, L Slow motion play.
* m, M Mute on/off.
* p, P Normal play.
* q, Q Stop play and exit program.
* s, S Stop play.
* u, U Pause.
* SPACE Toggle VIDEO/VGA display.
*/
int hotkeyProcess (void)
{
int key;
if (!playing)
return (0);
if (kbhit ()){
key = getKey ();
switch (key){
case 'F': // fast forward
case 'f':
WMpegCommand (FMF);
break;
case 'L': // slow motion
case 'l':
WMpegCommand(SMF);
break;
case 'M': // mute
case 'm':
fMute = !fMute;
Mute ((BYTE)fMute);
break;
case 'P': // normal play
case 'p':
WMpegCommand (NPF);
break;
case 'Q': // exit
case 'q':
return (1);
case 'U': // pause
case 'u':
pause = !pause;
if (pause)
WMpegCommand (PAU);
else
WMpegCommand (NPF);
break;
case SPACE:
if (dspMode == VGA)
dspMode = VIDEO;
else
dspMode = VGA;
WMpegSwitcher (dspMode);
break;
case '1':
nStereo = SPATIAL_STEREO;
Stereo ((BYTE)nStereo);
break;
case '2':
nStereo = LINEAR_STEREO;
Stereo ((BYTE)nStereo);
break;
case '3':
nStereo = PSEUDO_STEREO;
Stereo ((BYTE)nStereo);
break;
case '4':
nStereo = FORCED_MONO;
Stereo ((BYTE)nStereo);
break;
case 'V': // volume control
case 'v':
idVol = iVOLUME;
break;
case 'T':
case 't':
idVol = iTREBLE;
break;
case 'B':
case 'b':
idVol = iBASS;
break;
case UPAR:
switch (idVol){
case iVOLUME:
nVol++;
nVol = (nVol > maxVol) ? maxVol : nVol;
Volume ((BYTE)nVol);
break;
case iTREBLE:
nTreble++;
nTreble = (nTreble > maxTre) ? maxTre : nTreble;
Treble ((BYTE)nTreble);
break;
case iBASS:
nBass++;
nBass = (nBass > maxBass) ? maxBass : nBass;
Bass ((BYTE)nBass);
break;
}
break;
case DNAR:
switch (idVol){
case iVOLUME:
nVol--;
nVol = (nVol < minVol) ? minVol : nVol;
Volume ((BYTE)nVol);
break;
case iTREBLE:
nTreble--;
nTreble = (nTreble < minTre) ? minTre : nTreble;
Treble ((BYTE)nTreble);
break;
case iBASS:
nBass--;
nBass = (nBass < minBass) ? minBass : nBass;
Bass ((BYTE)nBass);
break;
}
break;
case DSPL: // adjust display screen left to 1 pixel
WMpegAdjustScreen (SCREEN_LF);
break;
case DSPU: // adjust display screen up to 1 line
WMpegAdjustScreen (SCREEN_UP);
break;
case DSPR: // adjust display screen right to 1 pixel
WMpegAdjustScreen (SCREEN_RT);
break;
case DSPD: // adjust display screen down to 1 line
WMpegAdjustScreen (SCREEN_DN);
break;
default:
break;
}
}
return (0);
}/* hotkeyProcess */
char pStr[128];
int initMpeg (void)
{
int rtn;
nVol = defVol;
nBass = defBass;
nTreble = defTreble;
getINIStr ((LPSTR)"Stereo");
if (!strcmp (pStr,(LPSTR)"Spatial"))
nStereo = SPATIAL_STEREO;
else if (!strcmp (pStr,(LPSTR)"Mono"))
nStereo = FORCED_MONO;
else if (!strcmp (pStr,(LPSTR)"Pseudo"))
nStereo = PSEUDO_STEREO;
else
nStereo = LINEAR_STEREO;
getINIStr ((LPSTR)"ShowOnVGA");
if (!strcmpi (pStr,(LPSTR)"yes"))
showOnVGA = TRUE;
else
showOnVGA = FALSE;
getINIStr ("BusType");
if (!strcmpi (pStr,"SCSI"))
sync = 0;
else
sync = 1;
if (rtn = WMpegInit (0))
return (rtn);
WMpegAudioEnable (TRUE);
return (0);
}/* initMpeg */
void getINIStr (key)
LPSTR key;
{
int rtn;
rtn = GetPrivateProfileString ((LPCSTR)"UserDef", // Section
(LPCSTR)key, // Entry
(LPCSTR)NULL, // Default string
(LPSTR)pStr, // string returned
(int)128, // length
(LPCSTR)"dosmpeg.ini" // Initialize filename
);
if (!rtn)
pStr[0] = '\0';
}/* getINIStr */
char getKey (void)
{
union REGS r;
int key;
char key1;
r.h.ah = 0;
key = int86 (0x16,&r,&r);
switch (key){
case 0x4800:
return ((char)UPAR);
break;
case 0x5000:
return ((char)DNAR);
break;
case F2:
return (DSPL);
break;
case F3:
return (DSPU);
break;
case F4:
return (DSPR);
break;
case F5:
return (DSPD);
break;
}
key1 = (char)(key & 0x00ff);
return (key1);
}/* getKey */
void errLoad (code)
int code;
{
switch (code){
case EMPEGFile:
printf ("Open error !!\n");
break;
case EBitStream:
printf ("Unknown BitStream !!\n");
break;
case EVolumeSize:
case ESectorSize:
case EInitCDROM:
case ESeekTop:
case EReadCD:
case EGetStartSector:
case EGetLastSector:
case ESeek:
printf ("Read CDROM error !!\n");
break;
case EInitVideo:
printf ("Error init Video !!\n");
break;
case EInitAudio:
printf ("Error init Audio !!\n");
break;
case EDMA:
printf ("Init DMA error !!\n");
break;
case EDecodeAudio:
printf ("Unknown BitStream !!\n");
break;
case ECDReady:
printf ("CD-ROM not ready !!\n");
break;
default:
printf ("System error !!\n");
break;
}
}/* errLoad */
void errSyntax (void)
{
printf ("Syntax:\n");
printf ("MPLAY [-O]\n");
printf (" Circle play CDI-FMV disc in the first attached CD-ROM drive.\n");
printf ("\n");
printf ("MPLAY -K [n] [-O]\n");
printf (" Circle play the nth song of Video CD disc in the first attached\n");
printf (" CD-ROM drive if n specified.\n");
printf ("OR\n");
printf (" Circle play KARAOKE disc from 1th song in the first attached\n");
printf (" CD-ROM drive if n not specified.\n");
printf ("\n");
printf ("MPLAY -F file [-O]\n");
printf (" Circle play the specified MPEG file.\n\n");
printf ("If -O option presented, the MPLAY will not perform the circle play\n");
printf ("at all of the above case.\n");
}/* errSyntax */