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
- RFC 3261 (June 1998) “WAVE and AVI Codec Registries”
- Sampler Metadata
- Audio File Format Specifications (September 2022) Prof. Peter Kabal, MMSP Lab, ECE, McGill University
- Multimedia Programming Interface and Data Specifications 1.0 (August 1991), IBM Corporation and Microsoft Corporation
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
impl WaveFmt
pub fn valid_bits_per_sample(&self) -> u16
sourcepub fn new_pcm_mono(sample_rate: u32, bits_per_sample: u16) -> Self
pub fn new_pcm_mono(sample_rate: u32, bits_per_sample: u16) -> Self
Create a new integer PCM format for a monoaural audio stream.
sourcepub fn new_pcm_stereo(sample_rate: u32, bits_per_sample: u16) -> Self
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.
sourcepub fn new_pcm_ambisonic(
sample_rate: u32,
bits_per_sample: u16,
channel_count: u16
) -> Self
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.
sourcepub fn new_pcm_multichannel(
sample_rate: u32,
bits_per_sample: u16,
channel_bitmap: u32
) -> Self
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.
sourcepub fn common_format(&self) -> CommonFormat
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.
sourcepub fn create_frame_buffer<S: Sample>(&self, length: usize) -> Vec<S>
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.
sourcepub fn create_raw_buffer(&self, length: usize) -> Vec<u8>
pub fn create_raw_buffer(&self, length: usize) -> Vec<u8>
Create a raw byte buffer to hold length
blocks from a reader or
writer
sourcepub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32])
pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32])
Read bytes into frames
sourcepub fn channels(&self) -> Vec<ChannelDescriptor>
pub fn channels(&self) -> Vec<ChannelDescriptor>
Channel descriptors for each channel.