Struct hound::WavReader

source ·
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§

source§

impl<R> WavReader<R>
where R: Read,

source

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.

source

pub fn spec(&self) -> WavSpec

Returns information about the WAVE file.

source

pub fn samples<'wr, S: Sample>(&'wr mut self) -> WavSamples<'wr, R, 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.

source

pub fn into_samples<S: Sample>(self) -> WavIntoSamples<R, S>

Same as samples, but takes ownership of the WavReader.

See samples() for more info.

source

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.

source

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.

source

pub fn into_inner(self) -> R

Destroys the WavReader and returns the underlying reader.

source

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.

source§

impl WavReader<BufReader<File>>

source

pub fn open<P: AsRef<Path>>(filename: P) -> Result<WavReader<BufReader<File>>>

Attempts to create a reader that reads from the specified file.

This is a convenience constructor that opens a File, wraps it in a BufReader and then constructs a WavReader from it.

Auto Trait Implementations§

§

impl<R> Freeze for WavReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for WavReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for WavReader<R>
where R: Send,

§

impl<R> Sync for WavReader<R>
where R: Sync,

§

impl<R> Unpin for WavReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for WavReader<R>
where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.