From 26c2ba50ac08f1dea90b414cbf7ac7df1cf085c1 Mon Sep 17 00:00:00 2001 From: whentze Date: Wed, 15 May 2019 03:12:47 +0200 Subject: [PATCH] Add a correct implementation of `total_duration` to `FlacDecoder`. --- src/decoder/flac.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/decoder/flac.rs b/src/decoder/flac.rs index 3ca2291..01111c3 100644 --- a/src/decoder/flac.rs +++ b/src/decoder/flac.rs @@ -18,6 +18,7 @@ where bits_per_sample: u32, sample_rate: u32, channels: u16, + samples: Option, } impl FlacDecoder @@ -43,6 +44,7 @@ where bits_per_sample: spec.bits_per_sample, sample_rate: spec.sample_rate, channels: spec.channels as u16, + samples: spec.samples, }) } } @@ -68,7 +70,9 @@ where #[inline] fn total_duration(&self) -> Option { - None + // `samples` in FLAC means "inter-channel samples" aka frames + // so we do not divide by `self.channels` here. + self.samples.map(|s| Duration::from_micros(s * 1_000_000 / self.sample_rate as u64)) } }