diff --git a/playback/src/audio_backend/pulseaudio.rs b/playback/src/audio_backend/pulseaudio.rs index b1b93822..35d25f38 100644 --- a/playback/src/audio_backend/pulseaudio.rs +++ b/playback/src/audio_backend/pulseaudio.rs @@ -137,7 +137,7 @@ impl Sink for PulseAudioSink { .and_then(|sink| { sink.get_latency() .ok() - .map(|micro_sec| (micro_sec.as_secs_f64() * SAMPLE_RATE as f64).round() as u64) + .map(|micro_sec| (micro_sec.as_secs_f64() * SAMPLE_RATE as f64) as u64) }) .unwrap_or(0) } diff --git a/playback/src/resampler.rs b/playback/src/resampler.rs index 3c1392b3..f9da63b0 100644 --- a/playback/src/resampler.rs +++ b/playback/src/resampler.rs @@ -119,8 +119,7 @@ impl MonoResampler for MonoSincResampler { let delay_line_latency = (interpolation_quality.get_interpolation_coefficients_length() as f64 - * spec.resample_factor_reciprocal) - .round() as u64; + * spec.resample_factor_reciprocal) as u64; Self { interpolator: WindowedSincInterpolator::new( diff --git a/playback/src/sample_pipeline.rs b/playback/src/sample_pipeline.rs index 4be796ce..34a71fc1 100644 --- a/playback/src/sample_pipeline.rs +++ b/playback/src/sample_pipeline.rs @@ -1,4 +1,5 @@ use crate::{ + MS_PER_PAGE, audio_backend::{Sink, SinkResult}, config::PlayerConfig, convert::Converter, @@ -36,8 +37,10 @@ impl SamplePipeline { } } - pub fn get_latency_pcm(&mut self) -> u64 { - self.sink.get_latency_pcm() + self.resampler.get_latency_pcm() + pub fn get_latency_ms(&mut self) -> u32 { + let total_latency_pcm = self.sink.get_latency_pcm() + self.resampler.get_latency_pcm(); + + (total_latency_pcm as f64 * MS_PER_PAGE) as u32 } pub fn start(&mut self) -> SinkResult<()> {