Struct WaveReader

Source
pub struct WaveReader { /* private fields */ }
Expand description
  • The WaveReader is dedicated to reading a WAV file and provides you with samples as you want. Usage:
  • Open a WAV file
  • Get the iterator
  • The iterator excretes the PCM samples with the format you specified.

Implementations§

Source§

impl WaveReader

Source

pub fn open(file_source: &str) -> Result<Self, AudioReadError>

  • Open the WAV file from a file path. No temporary files will be created.
Source

pub fn new(file_source: WaveDataSource) -> Result<Self, AudioReadError>

  • Open the WAV file from a WaveDataSource, if the WaveDataSource is Reader, the WaveReader will create an auto-delete temporary file for the data chunk.
Source

pub fn spec(&self) -> Spec

Provice spec information

Source

pub fn get_fact_data(&self) -> u64

  • The fact data is the number of the total samples in the data chunk.
Source

pub fn get_fmt__chunk(&self) -> &FmtChunk

  • The fmt chunk is to specify the detailed audio file format.
Source

pub fn get_slnt_chunk(&self) -> &Option<SlntChunk>

  • The slnt chunk indicates how long to stay silent.
Source

pub fn get_bext_chunk(&self) -> &Option<BextChunk>

  • The bext chunk has some description, version, time_ref pieces of information, etc.
Source

pub fn get_smpl_chunk(&self) -> &Option<SmplChunk>

  • The smpl chunk has some pieces of information about MIDI notes, pitch, etc.
Source

pub fn get_inst_chunk(&self) -> &Option<InstChunk>

  • The inst chunk has some base_note, gain, velocity, etc.
Source

pub fn get_plst_chunk(&self) -> &Option<PlstChunk>

  • The plst chunk is the playlist, it has a list that each element have cue_point, num_samples, repeats.
Source

pub fn get_trkn_chunk(&self) -> &Option<TrknChunk>

  • The trkn chunk, by the name.
Source

pub fn get_cue__chunk(&self) -> &Option<CueChunk>

  • The cue chunk is with the plst chunk, it has a list that each element have cue_point_id, position, chunk_start, etc.
Source

pub fn get_axml_chunk(&self) -> &Option<String>

  • The axml chunk. I personally don’t know what it is, by the name it looks like some kind of audio XML. It’s a pure string chunk.
Source

pub fn get_ixml_chunk(&self) -> &Option<String>

  • The ixml chunk. I personally don’t know what it is, by the name it looks like some kind of info XML. It’s a pure string chunk.
Source

pub fn get_list_chunk(&self) -> &BTreeSet<ListChunk>

  • The list chunk, it has 2 subtypes, one is INFO, and another is adtl.
  • The INFO subtype is the metadata that contains artist, album, title, etc. It lacks albumartist info.
  • The adtl subtype is with the cue chunk, it’s a list including the label, note, text, file for the playlist.
Source

pub fn get_acid_chunk(&self) -> &Option<AcidChunk>

  • The acid chunk, contains some pieces of information about the rhythm, e.g. num_beats, tempo, etc.
Source

pub fn get_id3__chunk(&self) -> &Option<Tag>

  • Another metadata chunk for the audio file. This covers more metadata than the LIST INFO chunk.
Source

pub fn get_junk_chunks(&self) -> &BTreeSet<JunkChunk>

  • The JUNK chunk, sometimes it’s used for placeholder, sometimes it contains some random data for some random music software to show off.
Source

pub fn create_full_info_cue_data( &self, ) -> Result<BTreeMap<u32, FullInfoCuePoint>, AudioError>

  • If your audio file has plst, cue , and LIST adtl chunks, then BAM you can call this function for full playlist info.
  • Returns Err if some of these chunks are absent.
Source

pub fn frame_iter<S>(&mut self) -> Result<FrameIter<'_, S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame, excretes multi-channel audio frames.
  • Every audio frame is an array that includes one sample for every channel.
  • This iterator supports multi-channel audio files e.g. 5.1 stereo or 7.1 stereo audio files.
  • Since each audio frame is a Vec , it’s expensive in memory and slow.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple frames.
Source

pub fn mono_iter<S>(&mut self) -> Result<MonoIter<'_, S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame, excretes mono-channel samples.
  • This iterator is dedicated to mono audio, it combines every channel into one channel and excretes every single sample as an audio frame.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple samples.
Source

pub fn stereo_iter<S>(&mut self) -> Result<StereoIter<'_, S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame, excretes two-channel stereo frames.
  • This iterator is dedicated to two-channel stereo audio, if the source audio is mono, it duplicates the sample to excrete stereo frames for you. If the source audio is multi-channel audio, this iterator can’t be created.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple samples.
Source

pub fn frame_intoiter<S>(self) -> Result<FrameIntoIter<S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame and consumes the WaveReader, excretes multi-channel audio frames.
  • Every audio frame is an array that includes one sample for every channel.
  • This iterator supports multi-channel audio files e.g. 5.1 stereo or 7.1 stereo audio files.
  • Since each audio frame is a Vec , it’s expensive in memory and slow.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple frames.
Source

pub fn mono_intoiter<S>(self) -> Result<MonoIntoIter<S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame and consumes the WaveReader, excretes mono-channel samples.
  • This iterator is dedicated to mono audio, it combines every channel into one channel and excretes every single sample as an audio frame.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple samples.
Source

pub fn stereo_intoiter<S>(self) -> Result<StereoIntoIter<S>, AudioReadError>
where S: SampleType,

  • Create an iterator for iterating through each audio frame and consumes the WaveReader, excretes two-channel stereo frames.
  • This iterator is dedicated to two-channel stereo audio, if the source audio is mono, it duplicates the sample to excrete stereo frames for you. If the source audio is multi-channel audio, this iterator can’t be created.
  • Besides it’s an iterator, the struct itself provides decode_frames() for batch decode multiple samples.

Trait Implementations§

Source§

impl Debug for WaveReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoIterator for WaveReader

  • The IntoIterator is only for two-channel stereo f32 samples.
Source§

type Item = (f32, f32)

The type of the elements being iterated over.
Source§

type IntoIter = StereoIntoIter<f32>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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>,

Source§

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>,

Source§

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.