mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
Fix WavDecoder::total_duration
(#383)
This commit is contained in:
parent
f6bb97e0d3
commit
ba78af2070
1 changed files with 11 additions and 4 deletions
|
@ -11,6 +11,7 @@ where
|
||||||
R: Read + Seek,
|
R: Read + Seek,
|
||||||
{
|
{
|
||||||
reader: SamplesIterator<R>,
|
reader: SamplesIterator<R>,
|
||||||
|
total_duration: Duration,
|
||||||
sample_rate: u32,
|
sample_rate: u32,
|
||||||
channels: u16,
|
channels: u16,
|
||||||
}
|
}
|
||||||
|
@ -27,15 +28,22 @@ where
|
||||||
|
|
||||||
let reader = WavReader::new(data).unwrap();
|
let reader = WavReader::new(data).unwrap();
|
||||||
let spec = reader.spec();
|
let spec = reader.spec();
|
||||||
|
let len = reader.len() as u64;
|
||||||
let reader = SamplesIterator {
|
let reader = SamplesIterator {
|
||||||
reader,
|
reader,
|
||||||
samples_read: 0,
|
samples_read: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let sample_rate = spec.sample_rate;
|
||||||
|
let channels = spec.channels;
|
||||||
|
let total_duration =
|
||||||
|
Duration::from_micros((1_000_000 * len) / (sample_rate as u64 * channels as u64));
|
||||||
|
|
||||||
Ok(WavDecoder {
|
Ok(WavDecoder {
|
||||||
reader,
|
reader,
|
||||||
sample_rate: spec.sample_rate,
|
total_duration,
|
||||||
channels: spec.channels,
|
sample_rate,
|
||||||
|
channels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn into_inner(self) -> R {
|
pub fn into_inner(self) -> R {
|
||||||
|
@ -114,8 +122,7 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn total_duration(&self) -> Option<Duration> {
|
fn total_duration(&self) -> Option<Duration> {
|
||||||
let ms = self.len() as u64 * 1000 / (self.channels as u64 * self.sample_rate as u64);
|
Some(self.total_duration)
|
||||||
Some(Duration::from_millis(ms))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue