#[non_exhaustive]pub struct AudioFormat {
pub codec: Codec,
pub sample_rate: u32,
pub channels: u8,
pub bit_depth: u8,
pub codec_header: Option<Vec<u8>>,
}Expand description
The audio format a stream announces.
The fields are the wire values of the stream announcement, unchanged. For Codec::Pcm the
samples are signed 16-bit little-endian when bit_depth is 16, interleaved by channel; other
depths keep the same convention scaled to the announced width.
The struct is non-exhaustive so a later protocol revision can add a field without breaking a
sink implementation. A sink only receives it from Sink::open.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.codec: CodecCodec of the stream.
sample_rate: u32Sample rate in hertz.
channels: u8Number of interleaved channels.
bit_depth: u8Bits per sample; meaningful for Codec::Pcm and Codec::Flac.
codec_header: Option<Vec<u8>>Codec header carried by the stream announcement, decoded from its base64 form.
For FLAC this is the fLaC marker followed by STREAMINFO; a decoder needs it before the
first frame. Absent for PCM and Opus. The bytes are exactly what the server sent.
Implementations§
Source§impl AudioFormat
impl AudioFormat
Sourcepub fn pcm(sample_rate: u32, channels: u8, bit_depth: u8) -> AudioFormat
pub fn pcm(sample_rate: u32, channels: u8, bit_depth: u8) -> AudioFormat
Builds a PCM format.
Samples are interleaved by channel and encoded as signed little-endian integers of
bit_depth bits, which is what the specification’s PCM convention describes; 24-bit samples
are packed as three bytes.
The values are not validated. A server must support PCM at 16 bit, one or two channels and 44.1 or 48 kHz, and may support others, so a format outside that is for the host to judge: a zero channel count or a bit depth that is not a whole number of bytes describes no stream.