diff options
author | Chris Apers | 2004-05-25 13:01:08 +0000 |
---|---|---|
committer | Chris Apers | 2004-05-25 13:01:08 +0000 |
commit | 290ddb6f78b31291f3c14304b85870c1072c213b (patch) | |
tree | cb7e79ae30841e1edc998511c89a425b422b3a35 /backends | |
parent | 8e2d5ad56f5fe2faa3c3abd74e89607b7a4ad8e0 (diff) | |
download | scummvm-rg350-290ddb6f78b31291f3c14304b85870c1072c213b.tar.gz scummvm-rg350-290ddb6f78b31291f3c14304b85870c1072c213b.tar.bz2 scummvm-rg350-290ddb6f78b31291f3c14304b85870c1072c213b.zip |
Revamped MSA CD player, now time is based on Sound Unit (SU). More compatible
svn-id: r13857
Diffstat (limited to 'backends')
-rw-r--r-- | backends/PalmOS/Src/cd_msa.cpp | 220 | ||||
-rw-r--r-- | backends/PalmOS/Src/cd_msa.h | 5 |
2 files changed, 82 insertions, 143 deletions
diff --git a/backends/PalmOS/Src/cd_msa.cpp b/backends/PalmOS/Src/cd_msa.cpp index 09b6d2eb5d..8879ce8cf1 100644 --- a/backends/PalmOS/Src/cd_msa.cpp +++ b/backends/PalmOS/Src/cd_msa.cpp @@ -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 @@ bool MsaCDPlayer::init() { 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 @@ void MsaCDPlayer::initInternal() { 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 @@ void MsaCDPlayer::initInternal() { _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 @@ bool MsaCDPlayer::poll() { 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 @@ void MsaCDPlayer::stop() { /* Stop CD Audio in 1/10th of a second */ 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 @@ void MsaCDPlayer::play(int track, int num_loops, int start_frame, int duration) 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); - + _msaTrack = track + gVars->CD.firstTrack - 1; // first track >= 1 ?, not 0 (0=album) _msaLoops = num_loops; - _msaTrack = track + gVars->music.firstTrack - 1; // first track >= 1 ?, not 0 (0=album) _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); + // MSA frame in milli-seconds + fullLength = FROM_MIN(msaTime.minute); + fullLength += FROM_SEC(msaTime.second); + fullLength += msaTime.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; - -// 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 } diff --git a/backends/PalmOS/Src/cd_msa.h b/backends/PalmOS/Src/cd_msa.h index f6eaa0c5d0..29e8703272 100644 --- a/backends/PalmOS/Src/cd_msa.h +++ b/backends/PalmOS/Src/cd_msa.h @@ -48,13 +48,12 @@ UInt16 _msaLoops; UInt32 _msaStopTime; - UInt32 _msaEndTime; UInt32 _msaStartFrame; - UInt32 _msaEndFrame; + UInt32 _msaDuration; UInt16 _msaTrack; - UInt32 _msaTrackStart; + UInt32 _msaTrackStartSu, _msaTrackEndSu; UInt32 _msaTrackLength; }; |