More timing improvements.

This commit is contained in:
Christian Speckner 2018-07-02 00:58:32 +02:00
parent 621e0d9d79
commit f728a32731
4 changed files with 27 additions and 21 deletions

View File

@ -742,6 +742,7 @@ void Console::setTIAProperties()
myTIA->setHeight(height);
myEmulationTiming.updateFrameLayout(myTIA->frameLayout());
myEmulationTiming.updateConsoleTiming(myConsoleTiming);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -39,6 +39,7 @@ class AudioSettings;
#include "EventHandlerConstants.hxx"
#include "NTSCFilter.hxx"
#include "EmulationTiming.hxx"
#include "ConsoleTiming.hxx"
#include "frame-manager/AbstractFrameManager.hxx"
/**
@ -54,16 +55,6 @@ struct ConsoleInfo
string DisplayFormat;
};
/**
Contains timing information about the specified console.
*/
enum class ConsoleTiming
{
ntsc, // console with CPU running at 1.193182 MHz, NTSC colours
pal, // console with CPU running at 1.182298 MHz, PAL colours
secam // console with CPU running at 1.187500 MHz, SECAM colours
};
/**
This class represents the entire game console.

View File

@ -29,8 +29,9 @@ namespace {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmulationTiming::EmulationTiming(FrameLayout frameLayout) :
EmulationTiming::EmulationTiming(FrameLayout frameLayout, ConsoleTiming consoleTiming) :
myFrameLayout(frameLayout),
myConsoleTiming(consoleTiming),
myPlaybackRate(44100),
myPlaybackPeriod(512),
myAudioQueueExtraFragments(1),
@ -49,6 +50,15 @@ EmulationTiming& EmulationTiming::updateFrameLayout(FrameLayout frameLayout)
return *this;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmulationTiming& EmulationTiming::updateConsoleTiming(ConsoleTiming consoleTiming)
{
myConsoleTiming = consoleTiming;
recalculate();
return *this;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmulationTiming& EmulationTiming::updatePlaybackRate(uInt32 playbackRate)
{
@ -164,26 +174,26 @@ void EmulationTiming::recalculate()
throw runtime_error("invalid frame layout");
}
float framesPerSecond;
switch (myFrameLayout) {
case FrameLayout::ntsc:
framesPerSecond = mySpeedFactor * 60;
switch (myConsoleTiming) {
case ConsoleTiming::ntsc:
myAudioSampleRate = round(mySpeedFactor * 262 * 76 * 60) / 38;
break;
case FrameLayout::pal:
framesPerSecond = mySpeedFactor * 50;
case ConsoleTiming::pal:
case ConsoleTiming::secam:
myCyclesPerSecond = round(mySpeedFactor * 312 * 76 * 50) / 38;
break;
default:
throw runtime_error("invalid frame layout");
throw runtime_error("invalid console timing");
}
myCyclesPerSecond = myAudioSampleRate * 38;
myCyclesPerFrame = 76 * myLinesPerFrame;
myMaxCyclesPerTimeslice = round(mySpeedFactor * myCyclesPerFrame * 2);
myMinCyclesPerTimeslice = round(mySpeedFactor * myCyclesPerFrame / 2);
myCyclesPerSecond = (round(myCyclesPerFrame * framesPerSecond) / 38) * 38;
myAudioFragmentSize = round(mySpeedFactor * AUDIO_HALF_FRAMES_PER_FRAGMENT * myLinesPerFrame);
myAudioSampleRate = myCyclesPerSecond / 38;
myPrebufferFragmentCount = discreteDivCeil(
myPlaybackPeriod * myAudioSampleRate,

View File

@ -20,14 +20,17 @@
#include "bspf.hxx"
#include "FrameLayout.hxx"
#include "ConsoleTiming.hxx"
class EmulationTiming {
public:
EmulationTiming(FrameLayout frameLayout = FrameLayout::ntsc);
EmulationTiming(FrameLayout frameLayout = FrameLayout::ntsc, ConsoleTiming consoleTiming = ConsoleTiming::ntsc);
EmulationTiming& updateFrameLayout(FrameLayout frameLayout);
EmulationTiming& updateConsoleTiming(ConsoleTiming consoleTiming);
EmulationTiming& updatePlaybackRate(uInt32 playbackRate);
EmulationTiming& updatePlaybackPeriod(uInt32 period);
@ -63,6 +66,7 @@ class EmulationTiming {
private:
FrameLayout myFrameLayout;
ConsoleTiming myConsoleTiming;
uInt32 myPlaybackRate;
uInt32 myPlaybackPeriod;