Skip to content

Commit 9254570

Browse files
committed
Fix FlacDecoder::total_duration().
It was ignoring the channels count.
1 parent 78142a6 commit 9254570

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/decoder/flac.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ where
4141

4242
let spec = reader.streaminfo();
4343
let sample_rate = spec.sample_rate;
44+
let channels = spec.channels;
4445

4546
// `samples` in FLAC means "inter-channel samples" aka frames
4647
// so we do not divide by `self.channels` here.
4748
let total_duration = spec.samples.map(|s| {
4849
// Calculate duration as (samples * 1_000_000) / sample_rate
4950
// but do the division first to avoid overflow
50-
let sample_rate = sample_rate as u64;
51+
let sample_rate = sample_rate as u64 * channels as u64;
5152
let secs = s / sample_rate;
5253
let nanos = ((s % sample_rate) * 1_000_000_000) / sample_rate;
5354
Duration::new(secs, nanos as u32)

0 commit comments

Comments
 (0)