Skip to content

Commit

Permalink
fix playback time scaling bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ValleyBell committed Dec 22, 2023
1 parent 77909e3 commit 167db16
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ static void DoChipControlMode(PlayerBase* player)

droplay->GetPlayerOptions(playOpts);

printf("Command [OPL3 data]: ");
printf("Command [SPD/OPL3 data]: ");
fgets(line, 0x80, stdin);
StripNewline(line);

Expand Down
7 changes: 4 additions & 3 deletions player/droplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,14 @@ UINT8 DROPlayer::SetPlaybackSpeed(double speed)

void DROPlayer::RefreshTSRates(void)
{
_tsMult = _outSmplRate;
_ttMult = 1;
_tsDiv = _tickFreq;
if (_playOpts.genOpts.pbSpeed != 0 && _playOpts.genOpts.pbSpeed != 0x10000)
{
_tsMult *= 0x10000;
_ttMult *= 0x10000;
_tsDiv *= _playOpts.genOpts.pbSpeed;
}
_tsMult = _ttMult * _outSmplRate;
if (_tsMult != _lastTsMult ||
_tsDiv != _lastTsDiv)
{
Expand Down Expand Up @@ -592,7 +593,7 @@ double DROPlayer::Tick2Second(UINT32 ticks) const
{
if (ticks == (UINT32)-1)
return -1.0;
return ticks / (double)_tickFreq;
return (INT64)(ticks * _ttMult) / (double)(INT64)_tsDiv;
}

UINT8 DROPlayer::GetState(void) const
Expand Down
2 changes: 1 addition & 1 deletion player/droplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DROPlayer : public PlayerBase
// tick/sample conversion rates
UINT64 _tsMult;
UINT64 _tsDiv;

UINT64 _ttMult;
UINT64 _lastTsMult;
UINT64 _lastTsDiv;

Expand Down
7 changes: 4 additions & 3 deletions player/gymplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,14 @@ UINT8 GYMPlayer::SetPlaybackSpeed(double speed)

void GYMPlayer::RefreshTSRates(void)
{
_tsMult = _outSmplRate;
_ttMult = 1;
_tsDiv = _tickFreq;
if (_playOpts.genOpts.pbSpeed != 0 && _playOpts.genOpts.pbSpeed != 0x10000)
{
_tsMult *= 0x10000;
_ttMult *= 0x10000;
_tsDiv *= _playOpts.genOpts.pbSpeed;
}
_tsMult = _ttMult * _outSmplRate;
if (_tsMult != _lastTsMult ||
_tsDiv != _lastTsDiv)
{
Expand Down Expand Up @@ -536,7 +537,7 @@ double GYMPlayer::Tick2Second(UINT32 ticks) const
{
if (ticks == (UINT32)-1)
return -1.0;
return ticks / (double)_tickFreq;
return (INT64)(ticks * _ttMult) / (double)(INT64)_tsDiv;
}

UINT8 GYMPlayer::GetState(void) const
Expand Down
2 changes: 1 addition & 1 deletion player/gymplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class GYMPlayer : public PlayerBase
// tick/sample conversion rates
UINT64 _tsMult;
UINT64 _tsDiv;

UINT64 _ttMult;
UINT64 _lastTsMult;
UINT64 _lastTsDiv;

Expand Down
7 changes: 4 additions & 3 deletions player/s98player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,14 @@ UINT8 S98Player::SetPlaybackSpeed(double speed)

void S98Player::RefreshTSRates(void)
{
_tsMult = _outSmplRate * _fileHdr.tickMult;
_ttMult = _fileHdr.tickMult;
_tsDiv = _fileHdr.tickDiv;
if (_playOpts.genOpts.pbSpeed != 0 && _playOpts.genOpts.pbSpeed != 0x10000)
{
_tsMult *= 0x10000;
_ttMult *= 0x10000;
_tsDiv *= _playOpts.genOpts.pbSpeed;
}
_tsMult = _ttMult * _outSmplRate;
if (_tsMult != _lastTsMult ||
_tsDiv != _lastTsDiv)
{
Expand Down Expand Up @@ -790,7 +791,7 @@ double S98Player::Tick2Second(UINT32 ticks) const
{
if (ticks == (UINT32)-1)
return -1.0;
return ticks * _fileHdr.tickMult / (double)_fileHdr.tickDiv;
return (INT64)(ticks * _ttMult) / (double)(INT64)_tsDiv;
}

UINT8 S98Player::GetState(void) const
Expand Down
2 changes: 1 addition & 1 deletion player/s98player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class S98Player : public PlayerBase
// tick/sample conversion rates
UINT64 _tsMult;
UINT64 _tsDiv;

UINT64 _ttMult;
UINT64 _lastTsMult;
UINT64 _lastTsDiv;

Expand Down
6 changes: 2 additions & 4 deletions player/vgmplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,21 +752,19 @@ UINT8 VGMPlayer::SetPlaybackSpeed(double speed)

void VGMPlayer::RefreshTSRates(void)
{
_tsMult = _outSmplRate;
_ttMult = 1;
_tsDiv = _ttDiv = 44100;
_tsDiv = 44100;
if (_playOpts.playbackHz && _fileHdr.recordHz)
{
_tsMult *= _fileHdr.recordHz;
_ttMult *= _fileHdr.recordHz;
_tsDiv *= _playOpts.playbackHz;
}
if (_playOpts.genOpts.pbSpeed != 0 && _playOpts.genOpts.pbSpeed != 0x10000)
{
_tsMult *= 0x10000;
_ttMult *= 0x10000;
_tsDiv *= _playOpts.genOpts.pbSpeed;
}
_tsMult = _ttMult * _outSmplRate;
if (_tsMult != _lastTsMult ||
_tsDiv != _lastTsDiv)
{
Expand Down
2 changes: 0 additions & 2 deletions player/vgmplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ class VGMPlayer : public PlayerBase
UINT64 _tsMult;
UINT64 _tsDiv;
UINT64 _ttMult;
UINT64 _ttDiv;

UINT64 _lastTsMult;
UINT64 _lastTsDiv;

Expand Down

0 comments on commit 167db16

Please sign in to comment.