diff --git a/src/emucore/tia/frame-manager/JitterEmulation.cxx b/src/emucore/tia/frame-manager/JitterEmulation.cxx index 55c5d23fe..682b882e4 100644 --- a/src/emucore/tia/frame-manager/JitterEmulation.cxx +++ b/src/emucore/tia/frame-manager/JitterEmulation.cxx @@ -16,6 +16,11 @@ //============================================================================ #include +using std::abs; +using std::max; +using std::min; +using std::pow; +using std::round; #include "JitterEmulation.hxx" @@ -37,24 +42,24 @@ void JitterEmulation::setSensitivity(Int32 sensitivity) myLastFrameScanlines = myLastFrameVsyncCycles = myUnstableCount = myJitter = 0; mySensitivity = BSPF::clamp(sensitivity, MIN_SENSITIVITY, MAX_SENSITIVITY); - const float factor = std::pow(static_cast(mySensitivity - MIN_SENSITIVITY) / (MAX_SENSITIVITY - MIN_SENSITIVITY), 1.5); + const float factor = pow(static_cast(mySensitivity - MIN_SENSITIVITY) / (MAX_SENSITIVITY - MIN_SENSITIVITY), 1.5); - myScanlineDelta = std::round(MAX_SCANLINE_DELTA - (MAX_SCANLINE_DELTA - MIN_SCANLINE_DELTA) * factor); - myVsyncCycles = std::round(MIN_VSYNC_CYCLES + (MAX_VSYNC_CYCLES - MIN_VSYNC_CYCLES) * factor); - myVsyncDelta1 = std::round(MAX_VSYNC_DELTA_1 - (MAX_VSYNC_DELTA_1 - MIN_VSYNC_DELTA_1) * factor); + myScanlineDelta = round(MAX_SCANLINE_DELTA - (MAX_SCANLINE_DELTA - MIN_SCANLINE_DELTA) * factor); + myVsyncCycles = round(MIN_VSYNC_CYCLES + (MAX_VSYNC_CYCLES - MIN_VSYNC_CYCLES) * factor); + myVsyncDelta1 = round(MAX_VSYNC_DELTA_1 - (MAX_VSYNC_DELTA_1 - MIN_VSYNC_DELTA_1) * factor); #ifdef VSYNC_LINE_JITTER - myVsyncDelta2 = std::round(MIN_VSYNC_DELTA_2 + (MAX_VSYNC_DELTA_2 - MIN_VSYNC_DELTA_2) * factor); + myVsyncDelta2 = round(MIN_VSYNC_DELTA_2 + (MAX_VSYNC_DELTA_2 - MIN_VSYNC_DELTA_2) * factor); #endif - myUnstableFrames = std::round(MAX_UNSTABLE_FRAMES - (MAX_UNSTABLE_FRAMES - MIN_UNSTABLE_FRAMES) * factor); - myJitterLines = std::round(MIN_JITTER_LINES + (MAX_JITTER_LINES - MIN_JITTER_LINES) * factor); - myVsyncLines = std::round(MIN_VSYNC_LINES + (MAX_VSYNC_LINES - MIN_VSYNC_LINES) * factor); + myUnstableFrames = round(MAX_UNSTABLE_FRAMES - (MAX_UNSTABLE_FRAMES - MIN_UNSTABLE_FRAMES) * factor); + myJitterLines = round(MIN_JITTER_LINES + (MAX_JITTER_LINES - MIN_JITTER_LINES) * factor); + myVsyncLines = round(MIN_VSYNC_LINES + (MAX_VSYNC_LINES - MIN_VSYNC_LINES) * factor); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JitterEmulation::frameComplete(Int32 scanlineCount, Int32 vsyncCycles) { #ifdef DEBUG_BUILD - const int vsyncLines = std::round((vsyncCycles - 2) / 76.0); + const int vsyncLines = round((vsyncCycles - 2) / 76.0); cerr << "TV jitter " << myJitter << " - " << scanlineCount << ", " << vsyncCycles << ", " << vsyncLines << endl; #endif @@ -63,11 +68,11 @@ void JitterEmulation::frameComplete(Int32 scanlineCount, Int32 vsyncCycles) const bool vsyncCyclesStable = vsyncCycles >= myVsyncCycles; // Handle inconsistency of vsync cycles and around half lines #ifdef VSYNC_LINE_JITTER - const Int32 minLines = std::round((vsyncCycles - 2 - myVsyncDelta2) / 76.0); - const Int32 maxLines = std::round((vsyncCycles - 2 + myVsyncDelta2) / 76.0); - const Int32 minLastLines = std::round((myLastFrameVsyncCycles - 2 - myVsyncDelta2) / 76.0); - const Int32 maxLastLines = std::round((myLastFrameVsyncCycles - 2 + myVsyncDelta2) / 76.0); - const bool vsyncLinesStable = std::abs(vsyncCycles - myLastFrameVsyncCycles) < myVsyncDelta1 + const Int32 minLines = round((vsyncCycles - 2 - myVsyncDelta2) / 76.0); + const Int32 maxLines = round((vsyncCycles - 2 + myVsyncDelta2) / 76.0); + const Int32 minLastLines = round((myLastFrameVsyncCycles - 2 - myVsyncDelta2) / 76.0); + const Int32 maxLastLines = round((myLastFrameVsyncCycles - 2 + myVsyncDelta2) / 76.0); + const bool vsyncLinesStable = abs(vsyncCycles - myLastFrameVsyncCycles) < myVsyncDelta1 && minLines == maxLastLines && maxLines == minLastLines; #else const bool vsyncLinesStable = abs(vsyncCycles - myLastFrameVsyncCycles) < myVsyncDelta1; @@ -85,14 +90,14 @@ void JitterEmulation::frameComplete(Int32 scanlineCount, Int32 vsyncCycles) && abs(myJitter) < static_cast(myRandom.next() % myJitterLines)) { // Repeated invalid frames cause randomly repeated jitter - myJitter = std::max(std::min(scanlineDifference, myJitterLines), -myYStart); + myJitter = max(min(scanlineDifference, myJitterLines), -myYStart); } } if(!vsyncCyclesStable) { // If VSYNC length is too low, the frame rolls permanently down, speed depending on missing cycles - const Int32 jitter = std::max( - std::min(std::round(scanlineCount * (1 - static_cast(vsyncCycles) / myVsyncCycles)), + const Int32 jitter = max( + min(round(scanlineCount * (1 - static_cast(vsyncCycles) / myVsyncCycles)), myJitterLines), myJitterRecovery + 1); // Roll at least one scanline @@ -109,7 +114,7 @@ void JitterEmulation::frameComplete(Int32 scanlineCount, Int32 vsyncCycles) myJitter += vsyncCycles > myLastFrameVsyncCycles ? myVsyncLines : -myVsyncLines; #endif } - myJitter = std::max(myJitter, -myYStart); + myJitter = max(myJitter, -myYStart); } } else @@ -118,9 +123,9 @@ void JitterEmulation::frameComplete(Int32 scanlineCount, Int32 vsyncCycles) // Only recover during stable frames if(myJitter > 0) - myJitter = std::max(myJitter - myJitterRecovery, 0); + myJitter = max(myJitter - myJitterRecovery, 0); else if(myJitter < 0) - myJitter = std::min(myJitter + myJitterRecovery, 0); + myJitter = min(myJitter + myJitterRecovery, 0); } myLastFrameScanlines = scanlineCount; @@ -142,7 +147,7 @@ bool JitterEmulation::save(Serializer& out) const } catch(...) { - cerr << "ERROR: JitterEmulation::save" << std::endl; + cerr << "ERROR: JitterEmulation::save" << endl; return false; } @@ -165,7 +170,7 @@ bool JitterEmulation::load(Serializer& in) } catch (...) { - cerr << "ERROR: JitterEmulation::load" << std::endl; + cerr << "ERROR: JitterEmulation::load" << endl; return false; }