More timing tuning, coding style.

This commit is contained in:
Christian Speckner 2018-05-06 23:45:21 +02:00
parent a58db7e62d
commit 6cc8a22978
3 changed files with 59 additions and 21 deletions

View File

@ -553,6 +553,9 @@ void Console::initializeAudio()
{
myOSystem.sound().close();
myEmulationTiming.updatePlaybackPeriod(myOSystem.sound().getSampleRate());
myEmulationTiming.updatePlaybackPeriod(myOSystem.sound().getFragmentSize());
createAudioQueue();
myTIA->setAudioQueue(myAudioQueue);
@ -708,7 +711,7 @@ void Console::createAudioQueue()
{
myAudioQueue = make_shared<AudioQueue>(
myEmulationTiming.audioFragmentSize(),
myEmulationTiming.audioQueueCapacity(myOSystem.sound().getSampleRate(), myOSystem.sound().getFragmentSize()),
myEmulationTiming.audioQueueCapacity(),
myProperties.get(Cartridge_Sound) == "STEREO",
myEmulationTiming.audioSampleRate()
);

View File

@ -24,26 +24,46 @@ namespace {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmulationTiming::EmulationTiming(FrameLayout frameLayout) : frameLayout(frameLayout) {}
EmulationTiming::EmulationTiming(FrameLayout frameLayout) :
myFrameLayout(frameLayout),
myPlaybackRate(44100),
myPlaybackPeriod(512)
{}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EmulationTiming::updateFrameLayout(FrameLayout frameLayout) {
this->frameLayout = frameLayout;
void EmulationTiming::updateFrameLayout(FrameLayout frameLayout)
{
myFrameLayout = frameLayout;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::maxCyclesPerTimeslice() const {
return (3 * cyclesPerFrame()) / 2;
void EmulationTiming::updatePlaybackRate(uInt32 playbackRate)
{
myPlaybackRate = playbackRate;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::minCyclesPerTimeslice() const {
void EmulationTiming::updatePlaybackPeriod(uInt32 playbackPeriod)
{
myPlaybackPeriod = playbackPeriod;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::maxCyclesPerTimeslice() const
{
return 2 * cyclesPerFrame();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::minCyclesPerTimeslice() const
{
return cyclesPerFrame() / 2;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::linesPerFrame() const {
switch (frameLayout) {
uInt32 EmulationTiming::linesPerFrame() const
{
switch (myFrameLayout) {
case FrameLayout::ntsc:
return 262;
@ -56,13 +76,15 @@ uInt32 EmulationTiming::linesPerFrame() const {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::cyclesPerFrame() const {
uInt32 EmulationTiming::cyclesPerFrame() const
{
return 76 * linesPerFrame();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::framesPerSecond() const {
switch (frameLayout) {
uInt32 EmulationTiming::framesPerSecond() const
{
switch (myFrameLayout) {
case FrameLayout::ntsc:
return 60;
@ -75,29 +97,34 @@ uInt32 EmulationTiming::framesPerSecond() const {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::cyclesPerSecond() const {
uInt32 EmulationTiming::cyclesPerSecond() const
{
return cyclesPerFrame() * framesPerSecond();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::audioFragmentSize() const {
uInt32 EmulationTiming::audioFragmentSize() const
{
return AUDIO_HALF_FRAMES_PER_FRAGMENT * linesPerFrame();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::audioSampleRate() const {
uInt32 EmulationTiming::audioSampleRate() const
{
return 2 * linesPerFrame() * framesPerSecond();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::audioQueueCapacity(uInt32 playbackRate, uInt32 playbackFragmentSize) const {
uInt32 capacity = (playbackFragmentSize * audioSampleRate()) / (audioFragmentSize() * playbackRate) + 1;
uInt32 EmulationTiming::audioQueueCapacity() const
{
uInt32 capacity = (myPlaybackPeriod * audioSampleRate()) / (audioFragmentSize() * myPlaybackRate) + 1;
uInt32 minCapacity = (maxCyclesPerTimeslice() * audioSampleRate()) / (audioFragmentSize() * cyclesPerSecond()) + 1;
return std::max(prebufferFragmentCount() + 1, QUEUE_CAPACITY_SAFETY_FACTOR * std::max(capacity, minCapacity));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 EmulationTiming::prebufferFragmentCount() const {
return PREBUFFER_FRAGMENT_COUNT;
uInt32 EmulationTiming::prebufferFragmentCount() const
{
return (myPlaybackPeriod * audioSampleRate()) / (audioFragmentSize() * myPlaybackRate) + PREBUFFER_FRAGMENT_COUNT;
}

View File

@ -28,6 +28,10 @@ class EmulationTiming {
void updateFrameLayout(FrameLayout frameLayout);
void updatePlaybackRate(uInt32 playbackRate);
void updatePlaybackPeriod(uInt32 period);
uInt32 maxCyclesPerTimeslice() const;
uInt32 minCyclesPerTimeslice() const;
@ -44,13 +48,17 @@ class EmulationTiming {
uInt32 audioSampleRate() const;
uInt32 audioQueueCapacity(uInt32 playbackRate, uInt32 playbackFragmentSize) const;
uInt32 audioQueueCapacity() const;
uInt32 prebufferFragmentCount() const;
private:
FrameLayout frameLayout;
FrameLayout myFrameLayout;
uInt32 myPlaybackRate;
uInt32 myPlaybackPeriod;
};