Struct hound::WavReader
[−]
[src]
pub struct WavReader<R> { // some fields omitted }
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.
Methods
impl<R> WavReader<R> where R: Read
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.
fn spec(&self) -> WavSpec
Returns information about the WAVE file.
fn samples<'wr, S: Sample>(&'wr mut self) -> WavSamples<'wr, R, S>
Returns an iterator over all samples.
The channel data is 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
.
fn into_samples<S: Sample>(self) -> WavIntoSamples<R, S>
Same as samples
, but takes ownership of the WavReader
.
See samples()
for more info.
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.
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.
fn into_inner(self) -> R
Destroys the WavReader
and returns the underlying reader.