[Scummvm-cvs-logs] CVS: scummvm/backends/PalmOS/Src cd_msa.cpp,1.3,1.3.2.1 cd_msa.h,1.2,1.2.2.1 cdaudio.h,1.2,1.2.2.1

Chris Apers chrilith at users.sourceforge.net
Fri Jun 18 07:32:59 CEST 2004


Update of /cvsroot/scummvm/scummvm/backends/PalmOS/Src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24189

Modified Files:
      Tag: branch-0-6-0
	cd_msa.cpp cd_msa.h cdaudio.h 
Log Message:
Revamped MSA CD player, now time is based on Sound Unit (SU). More compatible

Index: cd_msa.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/PalmOS/Src/cd_msa.cpp,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- cd_msa.cpp	20 Jan 2004 13:54:46 -0000	1.3
+++ cd_msa.cpp	18 Jun 2004 14:31:56 -0000	1.3.2.1
@@ -21,14 +21,24 @@
  */
 #include <SonyClie.h>
 #include "stdafx.h"
-#include "scumm.h"
 #include "common/system.h"
 #include "cd_msa.h"
-#include "start.h"	// for appFileCreator
+#include "start.h"	// for appFileCreat
+
+static void doErr(Err e, const Char *msg) {
+	Char err[100];
+	StrPrintF(err, "%ld : " , e);
+	StrCat(err,msg);
+	FrmCustomAlert(1000,err,0,0);
+}
 
 MsaCDPlayer::MsaCDPlayer(OSystem *sys) {
 	_sys = sys;
 	_msaRefNum = sysInvalidRefNum;
+
+	_msaLoops = 0;
+	_msaStopTime = 0;
+	_msaTrackEndSu = 0;
 }
 
 bool MsaCDPlayer::init() {
@@ -42,37 +52,23 @@
 				if (error == sysErrLibNotFound)
 					error = SysLibLoad(sonySysFileTMsaLib, sonySysFileCMsaLib, &_msaRefNum);
 
+			// FIXME : still don't understand how this lib works, it seems to be very unstable
+			// and with the very bad documentation provided by Sony it's difficult to find out why
+			// this doesn't work the same way on build-in MP3 device and external MP3 devices
 			if (!error) {
-//				Char buf[100];
-//				StrPrintF(buf,"MSA refNum %ld, Try to open lib ...", refNum);
-//				FrmCustomAlert(1000,buf,0,0);
-				MsaLibClose(_msaRefNum, msaLibOpenModeAlbum);	// close the lib if we previously let it open (?) Need to add Notify for sonySysNotifyMsaEnforceOpenEvent just in case ...
+				//MsaLibClose(_msaRefNum, msaLibOpenModeAlbum);	// close the lib if we previously let it open (?) Need to add Notify for sonySysNotifyMsaEnforceOpenEvent just in case ...
 				error = MsaLibOpen(_msaRefNum, msaLibOpenModeAlbum);			
-/*				switch (error) {
-				case msaErrAlreadyOpen:
-					FrmCustomAlert(1000,"msaErrAlreadyOpen",0,0);
-					break;
-				case msaErrMemory:
-					FrmCustomAlert(1000,"msaErrMemory",0,0);
-					break;
-				case msaErrDifferentMode:
-					FrmCustomAlert(1000,"msaErrDifferentMode",0,0);
-					break;
-				case expErrCardNotPresent:
-					FrmCustomAlert(1000,"expErrCardNotPresent",0,0);
-					break;
-				}
-*/
-				if (error == msaErrAlreadyOpen)
-					error = MsaLibEnforceOpen(_msaRefNum, msaLibOpenModeAlbum, appFileCreator);
+
+				//if (error == msaErrAlreadyOpen)
+				//	error = MsaLibEnforceOpen(_msaRefNum, msaLibOpenModeAlbum, appFileCreator);
 			
-				error = (error != msaErrStillOpen) ? error : errNone;
+				//error = (error != msaErrStillOpen) ? error : errNone;
 			}
 		//}
 	}
 
-	if (error)
-		_msaRefNum = sysInvalidRefNum;
+//	if (error)
+//		_msaRefNum = sysInvalidRefNum;
 
 	_isInitialized = (_msaRefNum != sysInvalidRefNum);
 	initInternal();
@@ -83,16 +79,10 @@
 	if (!_isInitialized)
 		return;
 
-	// Beeeeeep !!!
-//	MsaOutCapabilityType capability;
-//	MsaOutInit(_msaRefNum);
-//	MsaOutGetCapability(_msaRefNum, &capability);
-//	MsaOutSetBeepLevel(_msaRefNum, capability.beepMaxLebel);
-//	MsaOutStartBeep(_msaRefNum, 1000, msaOutBeepPatternOK);
-
 	Err e;
-	UInt32 dummy, albumIterater = albumIteratorStart;
 	Char nameP[256];
+	UInt32 dummy, albumIterater = albumIteratorStart;
+
 	MemSet(&_msaAlbum, sizeof(_msaAlbum), 0);
 	_msaAlbum.maskflag = msa_INF_ALBUM;
 	_msaAlbum.code = msa_LANG_CODE_ASCII;
@@ -100,11 +90,7 @@
 	_msaAlbum.fileNameLength = 256;
 
 	e = MsaAlbumEnumerate(_msaRefNum, &albumIterater, &_msaAlbum);
-//	if (e) doErr(e, "MsaAlbumEnumerate");
 	e = MsaSetAlbum(_msaRefNum, _msaAlbum.albumRefNum, &dummy);
-//	if (e) doErr(e, "MsaSetAlbum");
-//	e = MsaGetPBRate(_msaRefNum, &_msaPBRate);
-//	if (e) doErr(e, "MsaGetPBRate");
 
 	// TODO : use RMC to control volume
 	// move this to setSolume
@@ -130,68 +116,60 @@
 
 	MsaPBStatus pb;
 	MsaGetPBStatus(_msaRefNum, &pb);
-	return (_msaLoops != 0 && (_sys->get_msecs() < _msaEndTime || pb.status != msa_STOPSTATUS));
+	return (_msaLoops != 0 && (pb.currentSU < _msaTrackEndSu || pb.status != msa_STOPSTATUS));
 }
 
 void MsaCDPlayer::update() {
 	if (!_isInitialized)
 		return;
 
+	// get playback status
+	MsaPBStatus pb;
+	MsaGetPBStatus(_msaRefNum, &pb);
+
 	// stop replay upon request of stop_cdrom()
 	if (_msaStopTime != 0 && _sys->get_msecs() >= _msaStopTime) {
 		MsaStop(_msaRefNum, true);
 		_msaLoops = 0;
 		_msaStopTime = 0;
-		_msaEndTime = 0;
+		_msaTrackEndSu = 0;
 		return;
 	}
 
-	// not fully played
-	if (_sys->get_msecs() < _msaEndTime)
-		return;
+	// not fully played nad still playing the correct track
+	// (when playing a full track the return SU is not correct
+	// and so we need to check if we are still playing the correct track)
+	if (pb.currentSU < _msaTrackEndSu) {
+		UInt16 trackNo;
+		MsaPBListIndexToTrackNo(_msaRefNum, pb.currentpblistindex, &trackNo);
+		if (trackNo == _msaTrack)
+			return;
+	}
+
+	MsaStop(_msaRefNum, true);
 		
-	if (_msaLoops == 0) {
-		MsaStop(_msaRefNum, true);
+	if (_msaLoops == 0)
 		return;
-	}
 
 	// track ends and last play, force stop if still playing
-	if (_msaLoops != 1) {
-		MsaPBStatus pb;
-		MsaGetPBStatus(_msaRefNum, &pb);
-	 	if (pb.status != msa_STOPSTATUS) {
-//			debug(0,"Stop It now");
-			MsaStop(_msaRefNum, true);
-			return;
-		}
+/*	if (_msaLoops != 1 && pb.status != msa_STOPSTATUS) {
+		MsaStop(_msaRefNum, true);
+		return;
 	}
-
+*/
 	// loop again ?
-	if (_msaLoops > 0) {
-		MsaStop(_msaRefNum, true); // stop if loop=0
+	if (_msaLoops > 0)
 		_msaLoops--;
-	}
 
 	// loop if needed
 	if (_msaLoops != 0) {
-		MsaStop(_msaRefNum, true);
-//		debug(0,"Next loop : %d", _msaLoops);
-
-		_msaEndTime = _sys->get_msecs() + _msaTrackLength;
-		if (_msaStartFrame == 0 && _msaEndFrame == 0)
+		if (_msaStartFrame == 0 && _msaDuration == 0)
 			MsaPlay(_msaRefNum, _msaTrack, 0, msa_PBRATE_SP);
 		else
-			MsaPlay(_msaRefNum, _msaTrack, _msaTrackStart, msa_PBRATE_SP);
+			MsaPlay(_msaRefNum, _msaTrack, _msaTrackStartSu, msa_PBRATE_SP);
 	}
 }
 
-static void doErr(Err e, const Char *msg) {
-	Char err[100];
-	StrPrintF(err, "%ld : " , e);
-	StrCat(err,msg);
-	FrmCustomAlert(1000,err,0,0);
-}
-
 void MsaCDPlayer::stop() {	/* Stop CD Audio in 1/10th of a second */
 	if (!_isInitialized)
 		return;
@@ -201,24 +179,6 @@
 	return;
 }
 
-// frames are 1/75 sec
-#define CD_FPS 75
-#define TO_MSECS(frame)	((UInt32)((frame) * 1000 / CD_FPS))
-// consider frame at 1/1000 sec
-#define TO_SEC(msecs)	((UInt16)((msecs) / 1000))
-#define TO_MIN(msecs)	((UInt16)(TO_SEC((msecs)) / 60))
-#define FROM_MIN(mins)	((UInt32)((mins) * 60 * 1000))
-#define FROM_SEC(secs)	((UInt32)((secs) * 1000))
-
-#define FRAMES_TO_MSF(f, M,S,F) {                                       \
-        int value = f;                                                  \
-        *(F) = value%CD_FPS;                                            \
-        value /= CD_FPS;                                                \
-        *(S) = value%60;                                                \
-        value /= 60;                                                    \
-        *(M) = value;                                                   \
-}
-
 void MsaCDPlayer::play(int track, int num_loops, int start_frame, int duration) {
 	if (!_isInitialized)
 		return;
@@ -226,87 +186,67 @@
 	if (!num_loops && !start_frame)
 		return;
 	
-	Err e;
-	
-/*
-	if (start_frame > 0)
-		start_frame += CD_FPS >> 1;
-*/
-	if (duration > 0)
-		duration += 5;
-
-//	debug(0, ">> Request : track %d / loops : %d / start : %d / duration : %d", track, num_loops, start_frame, duration);
-	
-	_msaLoops = num_loops;
 	_msaTrack = track + gVars->music.firstTrack - 1;	// first track >= 1 ?, not 0 (0=album)
+	_msaLoops = num_loops;
 	_msaStartFrame = TO_MSECS(start_frame);
-	_msaEndFrame = TO_MSECS(duration);
-
-//	debug(0, ">> To MSECS : start : %d / duration : %d", _msaStartFrame, _msaEndFrame);
+	_msaDuration = TO_MSECS(duration);
 
-	// if gVars->MP3 audio track
-//	Err e;
+	Err e;	
 	MemHandle trackH;
 
 	// stop current play if any
 	MsaStop(_msaRefNum, true);
+	_msaStopTime = 0;
+
 	// retreive track infos
 	e = MsaGetTrackInfo(_msaRefNum, _msaTrack, 0, msa_LANG_CODE_ASCII, &trackH);
-//	if (e) doErr(e, "MsaGetTrackInfo");
+
 	// track exists
 	if (!e && trackH) {
-		MsaTime tTime;
+		MsaTime msaTime;
+		MsaTrackInfo *trackP;
 		UInt32 SU, fullLength;
-		MsaTrackInfo *tiP;
 	
-		// FIXME : this enable MsaSuToTime to return the right value
+		// FIXME (?) : this enable MsaSuToTime to return the right value in some cases
 		MsaPlay(_msaRefNum, _msaTrack, 0, msa_PBRATE_SP);
 		MsaStop(_msaRefNum, true);
 		
-		tiP = (MsaTrackInfo *)MemHandleLock(trackH);	
-		MsaSuToTime(_msaRefNum, tiP->totalsu, &tTime);
-		SU = tiP->totalsu;
-		MemPtrUnlock(tiP);
+		// get the msa time 
+		trackP = (MsaTrackInfo *)MemHandleLock(trackH);	
+		MsaSuToTime(_msaRefNum, trackP->totalsu, &msaTime);
+		SU = trackP->totalsu;
+		MemPtrUnlock(trackP);
 		MemHandleFree(trackH);
 		
-//		debug(0, ">> SU of track : %d (%d%:%d.%d)", SU, tTime.minute, tTime.second, tTime.frame);
-
-//		Char buf[200];
-//		StrPrintF(buf,"Track : %ld - %ld%:%ld.%ld (%ld)", track, tTime.minute, tTime.second, tTime.frame, SU);
-//		FrmCustomAlert(1000,buf,0,0);
-
-		_msaStopTime = 0;
-		fullLength = FROM_MIN(tTime.minute) + FROM_SEC(tTime.second) + tTime.frame;
+		// MSA frame in milli-seconds 
+		fullLength  = FROM_MIN(msaTime.minute);
+		fullLength += FROM_SEC(msaTime.second);
+		fullLength += msaTime.frame;
 
-//		debug(0, ">> Full length : %d", fullLength);
-		
-		if (_msaEndFrame > 0) {
-			_msaTrackLength = _msaEndFrame;
+		if (_msaDuration > 0) {
+			_msaTrackLength = _msaDuration;
 		} else if (_msaStartFrame > 0) {
 			_msaTrackLength = fullLength;
 			_msaTrackLength -= _msaStartFrame;
 		} else {
 			_msaTrackLength = fullLength;
 		}
-		
+				
 		// try to play the track
 		if (start_frame == 0 && duration == 0) {
 			MsaPlay(_msaRefNum, _msaTrack, 0, msa_PBRATE_SP);
+			_msaTrackEndSu = SU;
 		} else {
 			// FIXME : MsaTimeToSu doesn't work ... (may work with previous FIXME)
-			_msaTrackStart = (UInt32) ((float)(_msaStartFrame) / ((float)fullLength / (float)SU));
-//			debug(0, ">> start at (float) : %d", _msaTrackStart);
-/*
-UInt32 f;
-			FRAMES_TO_MSF(start_frame, &tTime.minute, &tTime.second, &f)
-			tTime.frame = 0;
-			MsaTimeToSu(_msaRefNum, &tTime, &SU);
-			debug(0, ">> start at (MsaTimeToSu) : %d", SU);
-*/
-			MsaPlay(_msaRefNum, _msaTrack, _msaTrackStart, msa_PBRATE_SP);
-		}
+			_msaTrackStartSu = (UInt32) ((float)(_msaStartFrame)  / ((float)fullLength / (float)SU));
+			_msaTrackEndSu	 = (UInt32) ((float)(_msaTrackLength) / ((float)fullLength / (float)SU));
+			_msaTrackEndSu	+= _msaTrackStartSu;
+			
+			if (_msaTrackEndSu > SU)
+				_msaTrackEndSu = SU;
 
-		_msaEndTime = _sys->get_msecs() + _msaTrackLength;
-//		debug(0, ">> track length : %d / end : %d", _msaTrackLength, _msaEndTime);
+			MsaPlay(_msaRefNum, _msaTrack, _msaTrackStartSu, msa_PBRATE_SP);
+		}
 	}
+	// TODO : use default track length if track not found
 }

Index: cd_msa.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/PalmOS/Src/cd_msa.h,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- cd_msa.h	6 Jan 2004 12:45:25 -0000	1.2
+++ cd_msa.h	18 Jun 2004 14:31:56 -0000	1.2.2.1
@@ -48,15 +48,15 @@
 	UInt16 _msaLoops;
 
 	UInt32 _msaStopTime;
-	UInt32 _msaEndTime;
 
 	UInt32 _msaStartFrame;
-	UInt32 _msaEndFrame;
+	UInt32 _msaDuration;
 
 	UInt16 _msaTrack;
-	UInt32 _msaTrackStart;
+	UInt32 _msaTrackStartSu, _msaTrackEndSu;
 	UInt32 _msaTrackLength;
 
  };
  
- #endif
\ No newline at end of file
+ #endif
+ 
\ No newline at end of file

Index: cdaudio.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/PalmOS/Src/cdaudio.h,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- cdaudio.h	6 Jan 2004 12:45:25 -0000	1.2
+++ cdaudio.h	18 Jun 2004 14:31:56 -0000	1.2.2.1
@@ -25,6 +25,14 @@
 
 #include "common/system.h"
 
+// CD frames are 1/75 sec
+#define CD_FPS			75
+#define TO_MSECS(frame)	((UInt32)((frame) * 1000 / CD_FPS))
+
+// consider frame at 1/1000 sec
+#define FROM_MIN(mins)	((UInt32)((mins) * 60 * 1000))
+#define FROM_SEC(secs)	((UInt32)((secs) * 1000))
+
 class CDAudio {
 public:	
 	CDAudio() {
@@ -53,4 +61,4 @@
 	bool _isInitialized;
 };
 
-#endif
\ No newline at end of file
+#endif





More information about the Scummvm-git-logs mailing list