pub struct WavReader<R> { /* private fields */ }Expand description
Streaming WAV decoder over any io::Read.
Construction parses the RIFF header, the fmt chunk, and every chunk
up to and including the data chunk header. Samples are then decoded
from a 64 KiB block buffer that is refilled with bulk reads clamped to
the declared data boundary, so the underlying reader is never read
past the end of the audio payload.
Implementations§
Source§impl<R: Read> WavReader<R>
impl<R: Read> WavReader<R>
Sourcepub fn new(reader: R) -> Result<Self>
pub fn new(reader: R) -> Result<Self>
Parse the headers from reader and position it at the first sample.
Fails on a malformed container (Error::Format), an encoding
outside the crate’s scope (Error::Unsupported), or a stream that
ends inside the headers (Error::Io).
Sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Total number of samples across all channels the data chunk declares.
For a stream the declared count can exceed what exists. The sample iterators report that shortfall as an error.
Sourcepub fn samples<S: Sample>(&mut self) -> Samples<'_, R, S> ⓘ
pub fn samples<S: Sample>(&mut self) -> Samples<'_, R, S> ⓘ
Iterate over the remaining samples, borrowing the reader.
Items are Result<S>. The first error fuses the iterator. A type
that cannot represent the file’s samples yields one
Error::TooWide.
Sourcepub fn into_samples<S: Sample>(self) -> IntoSamples<R, S> ⓘ
pub fn into_samples<S: Sample>(self) -> IntoSamples<R, S> ⓘ
Iterate over the remaining samples, consuming the reader.
Sourcepub fn read_samples<S: Sample>(&mut self, buf: &mut [S]) -> Result<usize>
pub fn read_samples<S: Sample>(&mut self, buf: &mut [S]) -> Result<usize>
Decode samples into buf and return how many were written.
The buffer is filled completely unless the data chunk ends first,
so a count below buf.len() means the end of the audio, and Ok(0)
on a later call confirms it. A stream that ends before the declared
data size returns Err instead of a short count.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Return the underlying reader.
Bytes pulled into the block buffer but not yet yielded are lost.