Struct Frame

Source
pub struct Frame {
    pub header: FrameHeader,
    pub subframes: Vec<SubframeWidth>,
}
Expand description

A whole FLAC frame

A FLAC frame consists of a header, one or more subframes (each corresponding to a different channel), and concludes with a CRC-16 checksum over all the data in the frame.

┌──────────┬────────┬┄┄┄┄┄┄┄┄┬┄┄┄┬────────┬┄┄┄┄┄┄┄┄┬┄┄┄╮
│ FLAC Tag │ Block₀ │ Block₁ ┆ … ┆ Frame₀ │ Frame₁ ┆ … ┆ FLAC File
└──────────┴────────┴┄┄┄┄┄┄┄┄┴┄┄┄┼────────┼┄┄┄┄┄┄┄┄┴┄┄┄╯
╭────────────────────────────────╯        ╰─────────╮
├──────────────┬───────────┬┄┄┄┄┄┄┄┄┄┄┄┬┄┄┄┬────────┤
│ Frame Header │ Subframe₀ │ Subframe₁ ┆ … ┆ CRC-16 │    FLAC Frame
└──────────────┴───────────┴┄┄┄┄┄┄┄┄┄┄┄┴┄┄┄┴────────┘

§Example

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

let mut data: &[u8] = &[
    // frame header
    0xff, 0xf8, 0x69, 0x08, 0x00, 0x13, 0x64,
    // subframe
    0x00, 0x00, 0x00,
    // CRC-16
    0xd3, 0x3b,
];

assert_eq!(
    Frame::read_subset(&mut data).unwrap(),
    Frame {
        header: 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),
        },
        subframes: vec![
            SubframeWidth::Common(
                Subframe::Constant {
                    block_size: 20,
                    sample: 0x00_00,
                    wasted_bps: 0,
                },
            )
        ],
    },
);

Fields§

§header: FrameHeader

The FLAC frame’s header

§subframes: Vec<SubframeWidth>

A FLAC frame’s sub-frames

Implementations§

Source§

impl Frame

Source

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

Reads new frame from the given reader

Source

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

Reads new frame from the given reader

Subset files are streamable FLAC files whose decoding parameters are fully contained within each frame header.

Source

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

Writes frame to the given writer

Source

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

Writes frame to the given writer

Subset files are streamable FLAC files whose encoding parameters are fully contained within each frame header.

Trait Implementations§

Source§

impl Debug for Frame

Source§

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

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

impl PartialEq for Frame

Source§

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

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

const 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 Eq for Frame

Source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnwindSafe for Frame

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.