pub struct WavReader<R> { /* private fields */ }
Expand description
A reader that reads the WAVE format from the underlying reader.
A WavReader
is a streaming reader. It reads data from the underlying
reader on demand, and it reads no more than strictly necessary. No internal
buffering is performed on the underlying reader, but this can easily be
added by wrapping the reader in an io::BufReader
. The open
constructor
takes care of this for you.
Implementations
sourceimpl<R> WavReader<R>where
R: Read,
impl<R> WavReader<R>where
R: Read,
sourcepub fn new(reader: R) -> Result<WavReader<R>>
pub fn new(reader: R) -> Result<WavReader<R>>
Attempts to create a reader that reads the WAVE format.
The header is read immediately. Reading the data will be done on demand.
sourcepub fn samples<'wr, S: Sample>(&'wr mut self) -> WavSamples<'wr, R, S>ⓘNotable traits for WavSamples<'wr, R, S>impl<'wr, R, S> Iterator for WavSamples<'wr, R, S>where
R: Read,
S: Sample, type Item = Result<S>;
pub fn samples<'wr, S: Sample>(&'wr mut self) -> WavSamples<'wr, R, S>ⓘNotable traits for WavSamples<'wr, R, S>impl<'wr, R, S> Iterator for WavSamples<'wr, R, S>where
R: Read,
S: Sample, type Item = Result<S>;
R: Read,
S: Sample, type Item = Result<S>;
Returns an iterator over all samples.
The channel data is interleaved. The iterator is streaming. That is, if you call this method once, read a few samples, and call this method again, the second iterator will not start again from the beginning of the file, it will continue where the first iterator stopped.
The type S
must have at least spec().bits_per_sample
bits,
otherwise every iteration will return an error. All bit depths up to
32 bits per sample can be decoded into an i32
, but if you know
beforehand that you will be reading a file with 16 bits per sample, you
can save memory by decoding into an i16
.
The type of S
(int or float) must match spec().sample_format
,
otherwise every iteration will return an error.
sourcepub fn into_samples<S: Sample>(self) -> WavIntoSamples<R, S>ⓘNotable traits for WavIntoSamples<R, S>impl<R, S> Iterator for WavIntoSamples<R, S>where
R: Read,
S: Sample, type Item = Result<S>;
pub fn into_samples<S: Sample>(self) -> WavIntoSamples<R, S>ⓘNotable traits for WavIntoSamples<R, S>impl<R, S> Iterator for WavIntoSamples<R, S>where
R: Read,
S: Sample, type Item = Result<S>;
R: Read,
S: Sample, type Item = Result<S>;
Same as samples
, but takes ownership of the WavReader
.
See samples()
for more info.
sourcepub fn duration(&self) -> u32
pub fn duration(&self) -> u32
Returns the duration of the file in samples.
The duration is independent of the number of channels. It is expressed in units of samples. The duration in seconds can be obtained by dividing this number by the sample rate. The duration is independent of how many samples have been read already.
sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Returns the number of values that the sample iterator will yield.
The length of the file is its duration (in samples) times the number of
channels. The length is independent of how many samples have been read
already. To get the number of samples left, use len()
on the
samples()
iterator.
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Destroys the WavReader
and returns the underlying reader.
sourcepub fn seek(&mut self, time: u32) -> Result<()>where
R: Seek,
pub fn seek(&mut self, time: u32) -> Result<()>where
R: Seek,
Seek to the given time within the file.
The given time is measured in number of samples (independent of the
number of channels) since the beginning of the audio data. To seek to
a particular time in seconds, multiply the number of seconds with
WavSpec::sample_rate
. The given time should not exceed the duration of
the file (returned by duration()
). The behavior when seeking beyond
duration()
depends on the reader’s Seek
implementation.
This method requires that the inner reader R
implements Seek
.