audio: master-clock playback timing, output clock compensation, buffer config, interpolated speed
- playback timer uses the audio output device as its master clock: the PortAudio callback counts consumed frames (including underrun zero-fill) so video cannot drift away from what is heard; wall clock remains as fallback when no clocked output is running - output clock compensates for device output latency; new Preferences > Audio buffer size setting (0 = auto) - SampleBuffer::speed() now uses linear interpolation instead of nearest-neighbor sampling - regression tests: audio-clock driven timer (fwd/rev/speed), wall clock fallback, interpolation correctness
This commit is contained in:
@@ -28,16 +28,36 @@ namespace olive
|
||||
|
||||
void ViewerPlaybackTimer::start(const int64_t &start_timestamp,
|
||||
const int &playback_speed,
|
||||
const double &timebase)
|
||||
const double &timebase,
|
||||
const PlaybackAudioClock *audio_clock)
|
||||
{
|
||||
timer_.start();
|
||||
start_timestamp_ = start_timestamp;
|
||||
playback_speed_ = playback_speed;
|
||||
timebase_ = timebase * 1000;
|
||||
audio_clock_ = audio_clock;
|
||||
}
|
||||
|
||||
int64_t ViewerPlaybackTimer::get_timestamp_now() const
|
||||
{
|
||||
// The audio output clock is the master clock when available: sound card
|
||||
// consumption is what the viewer must stay in sync with, and unlike the
|
||||
// wall clock it cannot drift away from what is actually heard
|
||||
if (audio_clock_) {
|
||||
const double audio_seconds = audio_clock_->seconds();
|
||||
if (audio_seconds >= 0.0) {
|
||||
// At speeds other than 1x the audio tempo is scaled, so one
|
||||
// output second corresponds to |speed| timeline seconds. The
|
||||
// result is already in timeline frames, so it is applied
|
||||
// signed rather than multiplied by the speed again.
|
||||
const double timeline_ms =
|
||||
audio_seconds * 1000.0 * qAbs(playback_speed_);
|
||||
const int64_t frames_since_start = qFloor(timeline_ms / timebase_);
|
||||
return start_timestamp_ +
|
||||
frames_since_start * (playback_speed_ < 0 ? -1 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t real_time = timer_.elapsed();
|
||||
|
||||
int64_t frames_since_start =
|
||||
|
||||
Reference in New Issue
Block a user