X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Fpi_controller.cc;h=0d9e5b8c37e43ba1cfed3a9f44468742e58b5639;hb=2b9dc7b380bb4e40171067f42b4010970869a57d;hp=baee5a972a31414f54ffb2ca78a0bd34ebcf993c;hpb=f938687f8798d094c99cd4308ad6aa1c467e4a97;p=ardour.git diff --git a/libs/ardour/pi_controller.cc b/libs/ardour/pi_controller.cc index baee5a972a..0d9e5b8c37 100644 --- a/libs/ardour/pi_controller.cc +++ b/libs/ardour/pi_controller.cc @@ -56,10 +56,11 @@ PIController::~PIController () } double -PIController::get_ratio (int fill_level) +PIController::get_ratio (int fill_level, int period_size) { double offset = fill_level; double this_catch_factor = catch_factor; + double this_catch_factor2 = catch_factor2 * 4096.0/(double)period_size; // Save offset. @@ -96,7 +97,7 @@ PIController::get_ratio (int fill_level) // u(t) = K * (e(t) + 1/T \int e(t') dt') // Kp = 1/catch_factor and T = catch_factor2 Ki = Kp/T current_resample_factor - = static_resample_factor - smooth_offset / this_catch_factor - offset_integral / this_catch_factor / catch_factor2; + = static_resample_factor - smooth_offset / this_catch_factor - offset_integral / this_catch_factor / this_catch_factor2; // Now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt. current_resample_factor = floor((current_resample_factor - resample_mean) * controlquant + 0.5) / controlquant + resample_mean; @@ -151,7 +152,7 @@ PIChaser::~PIChaser() { } double -PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control ) { +PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control, int period_size ) { feed_estimator( chasetime_measured, chasetime ); std::cerr << (double)chasetime_measured/48000.0 << " " << chasetime << " " << slavetime << " "; @@ -159,7 +160,7 @@ PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nfram double fine; nframes64_t massaged_chasetime = chasetime + (nframes64_t)( (double)(slavetime_measured - chasetime_measured) * crude ); - fine = pic->get_ratio( slavetime - massaged_chasetime ); + fine = pic->get_ratio( slavetime - massaged_chasetime, period_size ); if (in_control) { if (fabs(fine-crude) > crude*speed_threshold) { std::cout << "reset to " << crude << " fine = " << fine << "\n";