FrameHeader

Struct FrameHeader 

Source
pub struct FrameHeader {
    pub blocking_strategy: bool,
    pub block_size: BlockSize<u16>,
    pub sample_rate: SampleRate<u32>,
    pub channel_assignment: ChannelAssignment,
    pub bits_per_sample: BitsPerSample,
    pub frame_number: FrameNumber,
}
Expand description

A FLAC frame header

BitsField
15sync code (0b111111111111100)
1blocking_strategy
4block_size
4sample_rate
4channel_assignment
3bits_per_sample
1padding (0)
8-56frame_number
(8 or 16)uncommon block size
(8 or 16)uncommon sample rate
8CRC-8 of header data

§Example

use flac_codec::stream::{
    FrameHeader, BlockSize, SampleRate, ChannelAssignment,
    Independent, BitsPerSample, FrameNumber,
};

let mut data: &[u8] = &[
    0b11111111, 0b1111100_0,  // sync code + blocking
    0b0110_1001,              // block size + sample rate
    0b0000_100_0,             // channels + bps + pad
    0x00,                     // frame number
    0x13,                     // uncommon block size (+1)
    0x64,                     // CRC-8
];

assert_eq!(
    FrameHeader::read_subset(&mut data).unwrap(),
    FrameHeader {
        blocking_strategy: false,
        block_size: BlockSize::Uncommon8(20),
        sample_rate: SampleRate::Hz44100,
        channel_assignment: ChannelAssignment::Independent(
            Independent::Mono
        ),
        bits_per_sample: BitsPerSample::Bps16,
        frame_number: FrameNumber(0),
    },
);

Fields§

§blocking_strategy: bool

The blocking strategy bit

§block_size: BlockSize<u16>

The block size, in samples

§sample_rate: SampleRate<u32>

The sample rate, in Hz

§channel_assignment: ChannelAssignment

How the channels are assigned

§bits_per_sample: BitsPerSample

The number if bits per output sample

§frame_number: FrameNumber

The frame’s number in the stream

Implementations§

Source§

impl FrameHeader

Source

pub fn read<R: Read>( reader: &mut R, streaminfo: &Streaminfo, ) -> Result<Self, Error>

Reads new header from the given reader

Source

pub fn read_subset<R: Read>(reader: &mut R) -> Result<Self, Error>

Reads new header from the given reader

Source

pub fn write<W: Write>( &self, writer: &mut W, streaminfo: &Streaminfo, ) -> Result<(), Error>

Builds header to the given writer

Source

pub fn write_subset<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Builds header to the given writer

Trait Implementations§

Source§

impl Debug for FrameHeader

Source§

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

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

impl FromBitStream for FrameHeader

Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

fn from_reader<R: BitRead + ?Sized>(r: &mut R) -> Result<Self, Self::Error>

Parse Self from reader
Source§

impl FromBitStreamWith<'_> for FrameHeader

Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

type Context = Streaminfo

Some context to use when parsing
Source§

fn from_reader<R: BitRead + ?Sized>( r: &mut R, streaminfo: &Streaminfo, ) -> Result<Self, Self::Error>

Parse Self from reader with the given context
Source§

impl PartialEq for FrameHeader

Source§

fn eq(&self, other: &FrameHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToBitStream for FrameHeader

Source§

type Error = Error

Error generated during building, such as io::Error
Source§

fn to_writer<W: BitWrite + ?Sized>(&self, w: &mut W) -> Result<(), Self::Error>

Generate self to writer
Source§

fn bits<C>(&self) -> Result<C, Self::Error>
where C: Counter, Self: Sized,

Returns length of self in bits, if possible
Source§

fn bits_len<C, E>(&self) -> Result<C, Self::Error>
where C: Counter, E: Endianness, Self: Sized,

👎Deprecated since 4.0.0: use of bits() is preferred
Returns total length of self, if possible
Source§

impl ToBitStreamWith<'_> for FrameHeader

Source§

type Error = Error

Error generated during building, such as io::Error
Source§

type Context = Streaminfo

Some context to use when writing
Source§

fn to_writer<W: BitWrite + ?Sized>( &self, w: &mut W, _streaminfo: &Streaminfo, ) -> Result<(), Self::Error>

Generate self to writer
Source§

fn bits<C>(&self, context: &Self::Context) -> Result<C, Self::Error>
where C: Counter, Self: Sized,

Returns length of self in bits, if possible
Source§

fn bits_len<C, E>(&self, context: &Self::Context) -> Result<C, Self::Error>
where C: Counter, E: Endianness, Self: Sized,

👎Deprecated since 4.0.0: use of len() is preferred
Returns total length of self, if possible
Source§

impl Eq for FrameHeader

Source§

impl StructuralPartialEq for FrameHeader

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.