src/media/audio/audio_core/audio_clock.cc
// The time units here are dest frames, the error factor is a difference in frac_src frames.
// This method is periodically called, to incorporate the current source position error (in
// fractional frames) into a feedback control that tunes the rate-adjustment factor for this clock.
The time units here are dest frames, the error factor is a difference in frac_src frames.
This method is periodically called, to incorporate the current source position error (in
fractional frames) into a feedback control that tunes the rate-adjustment factor for this clock.
The time units here are dest frames the error factor is a difference in frac_src frames . This method is periodically called to incorporate the current source position error ( in fractional frames ) into a feedback control that tunes the rate - adjustment factor for this clock .
void AudioClock::TuneRateForError(Fixed frac_src_error, int64_t dest_frame) {
  FX_CHECK(type_ != Type::Invalid) << "Invalid clock cannot be rate-adjusted";
  FX_CHECK((type_ == Type::Adjustable) || (source_ == Source::Client))
      << "Cannot rate-adjust a static device clock";
  FX_LOGS(TRACE) << __func__ << "(" << frac_src_error.raw_value() << ", " << dest_frame
                 << ") for clock type "
                 << (type_ == Type::Adjustable
                         ? "Adjustable"
                         : (type_ == Type::NonAdjustable ? "Non-adjustable" : "Invalid"));
  rate_adjuster_.TuneForError(dest_frame, frac_src_error.raw_value());
  auto adjustment = rate_adjuster_.Read();
  if (source_ == Source::Device) {
  } else if (type_ == Type::Adjustable) {
  } else {
    adjustment = std::clamp(adjustment, -0.002, 0.002);
    auto adjustment_rate = 1.0 + adjustment;
    rate_adjustment_ = TimelineRate(adjustment_rate);
    FX_LOGS(TRACE) << "Micro-SRC:" << std::fixed << std::setprecision(2) << std::setw(8)
                   << adjustment * 1'000'000.0 << " ppm; frac_error " << frac_src_error.raw_value();
  }
}
void AudioClock :: TuneRateForError ( Fixed frac_src_error , int64_t dest_frame ) { FX_CHECK ( type_ != Type :: Invalid ) << " " ; FX_CHECK ( ( type_ == Type :: Adjustable ) || ( source_ == Source :: Client ) ) << " " ; FX_LOGS ( TRACE ) << __func__ << " " << frac_src_error . raw_value ( ) << " " << dest_frame << " " << ( type_ == Type :: Adjustable ? " " : ( type_ == Type :: NonAdjustable ? " " : " " ) ) ; rate_adjuster_ . TuneForError ( dest_frame , frac_src_error . raw_value ( ) ) ; auto adjustment = rate_adjuster_ . Read ( ) ; if ( source_ == Source :: Device ) { } else if ( type_ == Type :: Adjustable ) { } else { adjustment = std :: clamp ( adjustment , -0.002 , 0.002 ) ; auto adjustment_rate = 1.0 + adjustment ; rate_adjustment_ = TimelineRate ( adjustment_rate ) ; FX_LOGS ( TRACE ) << " " << std :: fixed << std :: setprecision ( 2 ) << std :: setw ( 8 ) << adjustment * 1'000'000.0 << " " << frac_src_error . raw_value ( ) ; } }
The time units here are dest frames, the error factor is a difference in frac_src frames.
The time units here are dest frames the error factor is a difference in frac_src frames .
// Feed into the PID // This is a zero-centric adjustment factor, relative to current rate. // TODO(fxbug.dev/46648): adjust hardware clock rate by rate_adjustment // Return value from rate_adjuster_.Read is a double rate ratio centered on 1.0 // Convert this to a (truncated) PPM value, set_rate_adjust and update the device clock // TODO(fxbug.dev/46651): adjust clock by rate_adjustment // Return value from rate_adjuster_.Read is a double rate ratio centered on 1.0 // Convert this to a (truncated) PPM value, set_rate_adjust and update the client clock // Else if custom: we've already absorbed the rate adjustment; it can be retrieved now.