Struct bwavfile::WaveFmt

source ·
pub struct WaveFmt {
    pub tag: u16,
    pub channel_count: u16,
    pub sample_rate: u32,
    pub bytes_per_second: u32,
    pub block_alignment: u16,
    pub bits_per_sample: u16,
    pub extended_format: Option<WaveFmtExtended>,
}
Expand description

WAV file data format record.

The fmt record contains essential information describing the binary structure of the data segment of the WAVE file, such as sample rate, sample binary format, channel count, etc.

Resources

Implementation of Wave format fmt chunk

Other resources

Fields§

§tag: u16

A tag identifying the codec in use.

If this is 0xFFFE, the codec will be identified by a GUID in extended_format.

§channel_count: u16

Count of audio channels in each frame

§sample_rate: u32

Playback rate of the audio data

In frames per second.

§bytes_per_second: u32

Count of bytes per second

By rule, this is block_alignment * sample_rate

§block_alignment: u16

Count of bytes per audio frame

By rule, this is channel_count * bits_per_sample / 8

§bits_per_sample: u16

Count of bits stored in the file per sample

By rule, bits_per_sample % 8 == 0 for Broadcast-Wave files.

Modern clients will encode unusual sample sizes in normal byte sizes but will set the valid_bits flag in extended format record.

Generally speaking this will be true for all modern wave files, though there was an historical “packed” stereo format of 20 bits per sample, 5 bytes per frame, 5 bytes block alignment.

§extended_format: Option<WaveFmtExtended>

Extended format description

Additional format metadata if channel_count is greater than 2, or if certain codecs are used.

Implementations§

source§

impl WaveFmt

source

pub fn valid_bits_per_sample(&self) -> u16

source

pub fn new_pcm_mono(sample_rate: u32, bits_per_sample: u16) -> Self

Create a new integer PCM format for a monoaural audio stream.

source

pub fn new_pcm_stereo(sample_rate: u32, bits_per_sample: u16) -> Self

Create a new integer PCM format for a standard Left-Right stereo audio stream.

source

pub fn new_pcm_ambisonic( sample_rate: u32, bits_per_sample: u16, channel_count: u16 ) -> Self

Create a new integer PCM format for ambisonic b-format.

source

pub fn new_pcm_multichannel( sample_rate: u32, bits_per_sample: u16, channel_bitmap: u32 ) -> Self

Create a new integer PCM format WaveFmt with a custom channel bitmap.

The order of channels is not important. When reading or writing audio frames you must use the standard multichannel order for Wave files, the numerical order of the cases of ChannelMask.

source

pub fn common_format(&self) -> CommonFormat

Format or codec of the file’s audio data.

The CommonFormat unifies the format tag and the format extension GUID. Use this method to determine the codec.

source

pub fn create_frame_buffer<S: Sample>(&self, length: usize) -> Vec<S>

Create a frame buffer sized to hold length frames for a reader or writer

This is a conveneince method that creates a Vec<i32> with as many elements as there are channels in the underlying stream.

source

pub fn create_raw_buffer(&self, length: usize) -> Vec<u8>

Create a raw byte buffer to hold length blocks from a reader or writer

source

pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32])

Read bytes into frames

source

pub fn channels(&self) -> Vec<ChannelDescriptor>

Channel descriptors for each channel.

Trait Implementations§

source§

impl Clone for WaveFmt

source§

fn clone(&self) -> WaveFmt

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WaveFmt

source§

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

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

impl Copy for WaveFmt

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
source§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,