pub enum ChannelAssignment {
Independent(Independent),
LeftSide,
SideRight,
MidSide,
}Expand description
How the channels are assigned in a FLAC frame
| Bits | Channel Assingment |
|---|---|
0000 | 1 mono channel |
0001 | 2 independent channels |
0010 | 3 independent channels |
0011 | 4 independent channels |
0100 | 5 independent channels |
0101 | 6 independent channels |
0110 | 7 independent channels |
0111 | 8 independent channels |
1000 | left channel, side channel |
1001 | side channel, right channel |
1010 | mid channel, side channel |
1011 | invalid channel assignment |
1100 | invalid channel assignment |
1101 | invalid channel assignment |
1110 | invalid channel assignment |
1111 | invalid channel assignment |
§Example
use flac_codec::stream::{ChannelAssignment, Independent};
use bitstream_io::{BitReader, BitRead, BigEndian};
let data: &[u8] = &[
0b0000_100_0, // channels + bps + pad
];
let mut r = BitReader::endian(data, BigEndian);
assert_eq!(
r.parse::<ChannelAssignment>().unwrap(),
ChannelAssignment::Independent(Independent::Mono),
);The samples in the side channel can be calculated like:
sideᵢ = leftᵢ - rightᵢ
This requires that the side channel have one additional bit-per-sample during decoding, since the difference between the left and right channels could overflow if the two are at opposite extremes.
And with a bit of math, we can see that:
rightᵢ = leftᵢ - sideᵢ
or:
leftᵢ = sideᵢ + rightᵢ
For transforming left-side and side-right assignments back to left-right for output.
The samples in the mid channel can be calculated like:
midᵢ = (leftᵢ + rightᵢ) ÷ 2
Mid-side assignment can be restored to left-right like:
sumᵢ = midᵢ × 2 + |sideᵢ| % 2
leftᵢ = (sumᵢ + sideᵢ) ÷ 2
rightᵢ = (sumᵢ - sideᵢ) ÷ 2
The mid channel does not require any additional bits to decode, since the average cannot exceed either channel.
Variants§
Independent(Independent)
Channels are stored independently
LeftSide
Channel 0 is stored verbatim, channel 1 derived from both
SideRight
Channel 0 is derived from both, channel 1 is stored verbatim
MidSide
Channel 0 is averaged from both, channel 1 is derived from both
Implementations§
Trait Implementations§
Source§impl Clone for ChannelAssignment
impl Clone for ChannelAssignment
Source§fn clone(&self) -> ChannelAssignment
fn clone(&self) -> ChannelAssignment
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ChannelAssignment
Source§impl Debug for ChannelAssignment
impl Debug for ChannelAssignment
Source§impl Display for ChannelAssignment
impl Display for ChannelAssignment
impl Eq for ChannelAssignment
Source§impl FromBitStream for ChannelAssignment
impl FromBitStream for ChannelAssignment
Source§impl PartialEq for ChannelAssignment
impl PartialEq for ChannelAssignment
Source§fn eq(&self, other: &ChannelAssignment) -> bool
fn eq(&self, other: &ChannelAssignment) -> bool
self and other values to be equal, and is used by ==.