Residuals

Enum Residuals 

Source
pub enum Residuals<I> {
    Method0 {
        partitions: Vec<ResidualPartition<0b1111, I>>,
    },
    Method1 {
        partitions: Vec<ResidualPartition<0b11111, I>>,
    },
}
Expand description

Residual values for FIXED or LPC subframes

BitsMeaning
2residual coding method
4partition order
residual partition₀
(residual partition₁)

The residual coding method can be 0 or 1. A coding method of 0 means 4-bit Rice parameters in residual partitions. A coding method of 5 means 5-bit Rice parameters in residual partitions (method 0 is the common case).

The number of residual partitions equals 2ⁿ where n is the partition order.

§Example

use flac_codec::stream::{Residuals, ResidualPartition};
use bitstream_io::{BitReader, BitRead, BigEndian, BitCount};

let data: &[u8] = &[
    0b00_0000_00,  // coding method + partition order + partition
    // residual partition
    0b01010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010001,
    0b00010000,
    0b00000000,
];

let mut r = BitReader::endian(data, BigEndian);

assert_eq!(
    r.parse_using::<Residuals<i32>>((20, 1)).unwrap(),
    // coding method = 0b00
    // partition order = 0b0000, or 1 partition
    Residuals::Method0 {
        partitions: vec![
            ResidualPartition::Standard {
                rice: BitCount::new::<1>(),
                residuals: vec![
                     1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
                     2, 2, 2, 2, 2, 2, 2, 2, 2
                ],
            }
        ],
    },
);

Variants§

§

Method0

Coding method 0

Fields

§partitions: Vec<ResidualPartition<0b1111, I>>

The residual partitions

§

Method1

Coding method 1

Fields

§partitions: Vec<ResidualPartition<0b11111, I>>

The residual partitions

Implementations§

Source§

impl<I> Residuals<I>

Source

pub fn coding_method(&self) -> CodingMethod

The type of coding method in use, either Rice or Rice2

Source

pub fn partition_order(&self) -> u32

The residual block’s partition order

Trait Implementations§

Source§

impl<I: Debug> Debug for Residuals<I>

Source§

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

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

impl<I: SignedInteger> FromBitStreamUsing for Residuals<I>

Source§

type Context = (usize, usize)

Some context to consume when parsing
Source§

type Error = Error

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

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

Parse Self from reader with the given context
Source§

impl<I: PartialEq> PartialEq for Residuals<I>

Source§

fn eq(&self, other: &Residuals<I>) -> 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<I: SignedInteger> ToBitStream for Residuals<I>

Source§

type Error = Error

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

fn to_writer<W: BitWrite + ?Sized>(&self, w: &mut W) -> Result<(), 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<I: Eq> Eq for Residuals<I>

Source§

impl<I> StructuralPartialEq for Residuals<I>

Auto Trait Implementations§

§

impl<I> Freeze for Residuals<I>

§

impl<I> RefUnwindSafe for Residuals<I>
where I: RefUnwindSafe,

§

impl<I> Send for Residuals<I>
where I: Send,

§

impl<I> Sync for Residuals<I>
where I: Sync,

§

impl<I> Unpin for Residuals<I>
where I: Unpin,

§

impl<I> UnwindSafe for Residuals<I>
where I: UnwindSafe,

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.