Skip to content

Commit 77909e3

Browse files
committed
player: add time measurement options
1 parent 91b6542 commit 77909e3

14 files changed

+80
-20
lines changed

player.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static UINT32 masterVol = 0x10000; // fixed point 16.16
9595
static UINT8 showTags = 1;
9696
static bool showFileInfo = false;
9797
static UINT8 logLevel = DEVLOG_INFO;
98+
static UINT8 pbTimeMode = PLAYTIME_LOOP_INCL | PLAYTIME_TIME_FILE;
9899

99100
static PlayerA mainPlr;
100101

@@ -364,7 +365,7 @@ int main(int argc, char* argv[])
364365
pState = "Playing";
365366
if (vgmPcmStrms == NULL || vgmPcmStrms->empty())
366367
{
367-
printf("%s %.2f / %.2f ... \r", pState, mainPlr.GetCurTime(1), mainPlr.GetTotalTime(1));
368+
printf("%s %.2f / %.2f ... \r", pState, mainPlr.GetCurTime(pbTimeMode), mainPlr.GetTotalTime(pbTimeMode));
368369
}
369370
else
370371
{
@@ -377,7 +378,7 @@ int main(int argc, char* argv[])
377378
if (pbMode.length() == 1)
378379
pbMode = "";
379380
printf("%s %.2f / %.2f [%02X / %02X at %4.1f KHz%s] ... \r",
380-
pState, mainPlr.GetCurTime(1), mainPlr.GetTotalTime(1),
381+
pState, mainPlr.GetCurTime(pbTimeMode), mainPlr.GetTotalTime(pbTimeMode),
381382
1 + strmDev->lastItem, strmDev->maxItems, strmDev->freq / 1000.0,
382383
pbMode.c_str());
383384
}
@@ -509,6 +510,7 @@ Sound Chip ID:
509510
T param - show tags (0/D/OFF - off, 1/E/ON - on)
510511
FI param - show file information (see above)
511512
LL param - set log level (0..5 = off/error/warn/info/debug/trace, see emu/EmuStructs.h)
513+
TD param - set time display mode (bit mask: 0/1 = exclude/include loops, 0/2 = file/playback time, 4 = with fade time)
512514
Q - quit
513515
P - player configuration
514516
SPD param - set playback speed (1.0 = 100%)
@@ -913,7 +915,7 @@ static void DoChipControlMode(PlayerBase* player)
913915
char* tokenStr;
914916

915917
// Tags / FileInfo
916-
printf("Command [T/FI/LL data]: ");
918+
printf("Command [T/FI/LL/TD data]: ");
917919
fgets(line, 0x80, stdin);
918920
StripNewline(line);
919921

@@ -951,6 +953,12 @@ static void DoChipControlMode(PlayerBase* player)
951953
if (endPtr > tokenStr)
952954
logLevel = newLevel;
953955
}
956+
else if (! strcmp(line, "TD"))
957+
{
958+
UINT8 newTimeMode = (UINT8)strtoul(tokenStr, &endPtr, 0);
959+
if (endPtr > tokenStr)
960+
pbTimeMode = newTimeMode;
961+
}
954962
else if (! strcmp(line, "Q"))
955963
mode = -1;
956964
else

player/droplayer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ UINT8 DROPlayer::SetSampleRate(UINT32 sampleRate)
541541
return 0x00;
542542
}
543543

544+
double DROPlayer::GetPlaybackSpeed(void) const
545+
{
546+
return _playOpts.genOpts.pbSpeed / (double)0x10000;
547+
}
548+
544549
UINT8 DROPlayer::SetPlaybackSpeed(double speed)
545550
{
546551
_playOpts.genOpts.pbSpeed = (UINT32)(0x10000 * speed);

player/droplayer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class DROPlayer : public PlayerBase
113113

114114
//UINT32 GetSampleRate(void) const;
115115
UINT8 SetSampleRate(UINT32 sampleRate);
116+
double GetPlaybackSpeed(void) const;
116117
UINT8 SetPlaybackSpeed(double speed);
117118
//void SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam);
118119
UINT32 Tick2Sample(UINT32 ticks) const;

player/gymplayer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ UINT8 GYMPlayer::SetSampleRate(UINT32 sampleRate)
485485
return 0x00;
486486
}
487487

488+
double GYMPlayer::GetPlaybackSpeed(void) const
489+
{
490+
return _playOpts.genOpts.pbSpeed / (double)0x10000;
491+
}
492+
488493
UINT8 GYMPlayer::SetPlaybackSpeed(double speed)
489494
{
490495
_playOpts.genOpts.pbSpeed = (UINT32)(0x10000 * speed);

player/gymplayer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class GYMPlayer : public PlayerBase
8989

9090
//UINT32 GetSampleRate(void) const;
9191
UINT8 SetSampleRate(UINT32 sampleRate);
92+
double GetPlaybackSpeed(void) const;
9293
UINT8 SetPlaybackSpeed(double speed);
9394
//void SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam);
9495
UINT32 Tick2Sample(UINT32 ticks) const;

player/playera.cpp

+28-13
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,44 @@ UINT32 PlayerA::GetCurPos(UINT8 unit) const
300300
return _player->GetCurPos(unit);
301301
}
302302

303-
double PlayerA::GetCurTime(UINT8 includeLoops) const
303+
double PlayerA::GetCurTime(UINT8 flags) const
304304
{
305305
if (_player == NULL)
306306
return -1.0;
307+
307308
// using samples here, as it may be more accurate than the (possibly low-resolution) ticks
308-
double ticks = _player->Sample2Second(_player->GetCurPos(PLAYPOS_SAMPLE));
309-
if (! includeLoops)
310-
{
311-
UINT32 curLoop = _player->GetCurLoop();
312-
if (curLoop > 0)
313-
ticks -= _player->Tick2Second(_player->GetLoopTicks() * curLoop);
314-
}
315-
return ticks;
309+
double secs = _player->Sample2Second(_player->GetCurPos(PLAYPOS_SAMPLE));
310+
UINT32 curLoop = _player->GetCurLoop();
311+
if (! (flags & PLAYTIME_LOOP_INCL) && curLoop > 0)
312+
secs -= _player->Tick2Second(_player->GetLoopTicks() * curLoop);
313+
314+
if (! (flags & PLAYTIME_TIME_PBK))
315+
secs *= _player->GetPlaybackSpeed();
316+
return secs;
316317
}
317318

318-
double PlayerA::GetTotalTime(UINT8 includeLoops) const
319+
double PlayerA::GetTotalTime(UINT8 flags) const
319320
{
320321
if (_player == NULL)
321322
return -1.0;
322-
if (includeLoops)
323-
return _player->Tick2Second(_player->GetTotalPlayTicks(_config.loopCount));
323+
324+
double secs;
325+
if (flags & PLAYTIME_LOOP_INCL)
326+
secs = _player->Tick2Second(_player->GetTotalPlayTicks(_config.loopCount));
324327
else
325-
return _player->Tick2Second(_player->GetTotalPlayTicks(1));
328+
secs = _player->Tick2Second(_player->GetTotalPlayTicks(1));
329+
if (secs < 0.0) // indicates infinite runtime
330+
return secs;
331+
332+
// Fade and silence time are unaffected by playback speed and thus must be applied before speed scaling.
333+
if ((flags & PLAYTIME_WITH_FADE) && _player->GetLoopTicks() > 0)
334+
secs += _player->Sample2Second(GetFadeSamples());
335+
if (flags & PLAYTIME_WITH_SLNC)
336+
secs += _player->Sample2Second(GetEndSilenceSamples());
337+
338+
if (! (flags & PLAYTIME_TIME_PBK))
339+
secs *= _player->GetPlaybackSpeed();
340+
return secs;
326341
}
327342

328343
UINT32 PlayerA::GetCurLoop(void) const

player/playera.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
#define PLAYSTATE_FADE 0x10 // is fading
1111
#define PLAYSTATE_FIN 0x20 // finished playing (file end + fading + trailing silence)
1212

13+
#define PLAYTIME_LOOP_EXCL 0x00 // excluding loops, jumps back in time when the file loops
14+
#define PLAYTIME_LOOP_INCL 0x01 // including loops, no jumping back
15+
#define PLAYTIME_TIME_FILE 0x00 // file time, progresses slower/faster when playback speed is adjusted
16+
#define PLAYTIME_TIME_PBK 0x02 // playback time, file duration will be longer/shorter when playback speed is adjusted
17+
#define PLAYTIME_WITH_FADE 0x10 // include fade out time (looping songs only)
18+
#define PLAYTIME_WITH_SLNC 0x20 // include silence after songs
19+
1320
// TODO: find a proper name for this class
1421
class PlayerA
1522
{
@@ -54,8 +61,8 @@ class PlayerA
5461
void SetLogCallback(PLAYER_LOG_CB cbFunc, void* cbParam);
5562
UINT8 GetState(void) const;
5663
UINT32 GetCurPos(UINT8 unit) const;
57-
double GetCurTime(UINT8 includeLoops) const;
58-
double GetTotalTime(UINT8 includeLoops) const;
64+
double GetCurTime(UINT8 flags) const;
65+
double GetTotalTime(UINT8 flags) const;
5966
UINT32 GetCurLoop(void) const;
6067
double GetLoopTime(void) const;
6168
PlayerBase* GetPlayer(void);

player/playerbase.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ UINT8 PlayerBase::SetSampleRate(UINT32 sampleRate)
6464
return 0x00;
6565
}
6666

67+
double PlayerBase::GetPlaybackSpeed(void) const
68+
{
69+
return -1; // not implemented
70+
}
71+
6772
UINT8 PlayerBase::SetPlaybackSpeed(double speed)
6873
{
69-
return 0xFF; // not yet supported
74+
return 0xFF; // not implemented
7075
}
7176

7277
void PlayerBase::SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam)

player/playerbase.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class PlayerBase
130130

131131
virtual UINT32 GetSampleRate(void) const;
132132
virtual UINT8 SetSampleRate(UINT32 sampleRate);
133+
virtual double GetPlaybackSpeed(void) const;
133134
virtual UINT8 SetPlaybackSpeed(double speed);
134135
virtual void SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam);
135136
virtual void SetFileReqCallback(PLAYER_FILEREQ_CB cbFunc, void* cbParam);

player/s98player.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ UINT8 S98Player::SetSampleRate(UINT32 sampleRate)
739739
return 0x00;
740740
}
741741

742+
double S98Player::GetPlaybackSpeed(void) const
743+
{
744+
return _playOpts.genOpts.pbSpeed / (double)0x10000;
745+
}
746+
742747
UINT8 S98Player::SetPlaybackSpeed(double speed)
743748
{
744749
_playOpts.genOpts.pbSpeed = (UINT32)(0x10000 * speed);

player/s98player.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class S98Player : public PlayerBase
8989

9090
//UINT32 GetSampleRate(void) const;
9191
UINT8 SetSampleRate(UINT32 sampleRate);
92+
double GetPlaybackSpeed(void) const;
9293
UINT8 SetPlaybackSpeed(double speed);
9394
//void SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam);
9495
UINT32 Tick2Sample(UINT32 ticks) const;

player/vgmplayer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,11 @@ UINT8 VGMPlayer::SetSampleRate(UINT32 sampleRate)
737737
return 0x00;
738738
}
739739

740+
double VGMPlayer::GetPlaybackSpeed(void) const
741+
{
742+
return _playOpts.genOpts.pbSpeed / (double)0x10000;
743+
}
744+
740745
UINT8 VGMPlayer::SetPlaybackSpeed(double speed)
741746
{
742747
_playOpts.genOpts.pbSpeed = (UINT32)(0x10000 * speed);

player/vgmplayer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class VGMPlayer : public PlayerBase
167167

168168
//UINT32 GetSampleRate(void) const;
169169
UINT8 SetSampleRate(UINT32 sampleRate);
170+
double GetPlaybackSpeed(void) const;
170171
UINT8 SetPlaybackSpeed(double speed);
171172
//void SetEventCallback(PLAYER_EVENT_CB cbFunc, void* cbParam);
172173
//void SetFileReqCallback(PLAYER_FILEREQ_CB cbFunc, void* cbParam);

vgm2wav.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static void frames_to_little_endian(UINT8 *data, unsigned int frame_count) {
611611
repack_int24le(&data[3], &data[3]);
612612
break;
613613
}
614-
defafult: /* 16 */ {
614+
default: /* 16 */ {
615615
repack_int16le(&data[0], &data[0]);
616616
repack_int16le(&data[2], &data[2]);
617617
break;

0 commit comments

Comments
 (0)