Convert get_latency_pcm to get_latency_ms in sample_pipeline

This commit is contained in:
JasonLG1979 2023-06-21 21:11:37 -05:00
parent 9861a582a6
commit 3bcf5498d2
3 changed files with 7 additions and 5 deletions

View file

@ -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)
}

View file

@ -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(

View file

@ -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<()> {