From 886d923e30525e6bde1633a2261c9f21e5c5daba Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 10 Feb 2020 23:30:32 -0500 Subject: [PATCH] Attempts to permit fixed speed multiplication. --- ClockReceiver/ScanSynchroniser.hpp | 15 ++++++++++++--- OSBindings/SDL/main.cpp | 10 +++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ClockReceiver/ScanSynchroniser.hpp b/ClockReceiver/ScanSynchroniser.hpp index aed4b67da..be2682c44 100644 --- a/ClockReceiver/ScanSynchroniser.hpp +++ b/ClockReceiver/ScanSynchroniser.hpp @@ -33,7 +33,7 @@ class ScanSynchroniser { // Check out the machine's current frame time. // If it's within 3% of a non-zero integer multiple of the // display rate, mark this time window to be split over the sync. - ratio_ = frame_duration / scan_status.field_duration; + ratio_ = (frame_duration * base_multiplier_) / scan_status.field_duration; const double integer_ratio = round(ratio_); if(integer_ratio > 0.0) { ratio_ /= integer_ratio; @@ -54,13 +54,21 @@ class ScanSynchroniser { // // ... with one slight caveat, which is that it is desireable to adjust phase here, to align vertical sync points. // So the set speed multiplier may be adjusted slightly to aim for that. - double speed_multiplier = 1.0 / ratio_; + double speed_multiplier = 1.0 / (ratio_ / base_multiplier_); if(scan_status.current_position > 0.0) { if(scan_status.current_position < 0.5) speed_multiplier /= phase_adjustment_ratio; else speed_multiplier *= phase_adjustment_ratio; } speed_multiplier_ = (speed_multiplier_ * 0.95) + (speed_multiplier * 0.05); - return speed_multiplier_; + return speed_multiplier_ * base_multiplier_; + } + + void set_base_speed_multiplier(double multiplier) { + base_multiplier_ = multiplier; + } + + double get_base_speed_multiplier() { + return base_multiplier_; } private: @@ -69,6 +77,7 @@ class ScanSynchroniser { // Managed local state. double speed_multiplier_ = 1.0; + double base_multiplier_ = 1.0; // Temporary storage to bridge the can_synchronise -> next_speed_multiplier gap. double ratio_ = 1.0; diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 79757175e..3b683fa21 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -74,6 +74,10 @@ struct MachineRunner { frame_lock_.clear(); } + void set_speed_multiplier(double multiplier) { + scan_synchroniser_.set_base_speed_multiplier(multiplier); + } + std::mutex *machine_mutex; Machine::DynamicMachine *machine; @@ -127,6 +131,7 @@ struct MachineRunner { crt_machine->run_for(double(time_now - vsync_time) / 1e9); } else { + crt_machine->set_speed_multiplier(scan_synchroniser_.get_base_speed_multiplier()); crt_machine->run_for(double(time_now - last_time_) / 1e9); } last_time_ = time_now; @@ -565,13 +570,12 @@ int main(int argc, char *argv[]) { char *end; double speed = strtod(speed_string, &end); - if(end-speed_string != strlen(speed_string)) { + if(size_t(end - speed_string) != strlen(speed_string)) { std::cerr << "Unable to parse speed: " << speed_string << std::endl; } else if(speed <= 0.0) { std::cerr << "Cannot run at speed " << speed_string << "; speeds must be positive." << std::endl; } else { - machine->crt_machine()->set_speed_multiplier(speed); - // TODO: what if not a 'CRT' machine? Likely rests on resolving this project's machine naming policy. + machine_runner.set_speed_multiplier(speed); } }