pub enum BlockSize<B> {
Show 15 variants
Samples192,
Samples576,
Samples1152,
Samples2304,
Samples4608,
Uncommon8(B),
Uncommon16(B),
Samples256,
Samples512,
Samples1024,
Samples2048,
Samples4096,
Samples8192,
Samples16384,
Samples32768,
}Expand description
Possible block sizes in a FLAC frame, in samples
Common sizes are stored as a 4-bit value, while uncommon sizes are stored as 8 or 16 bit values.
| Bits | Block Size |
|---|---|
0000 | invalid |
0001 | 192 |
0010 | 576 |
0011 | 1152 |
0100 | 2304 |
0101 | 4606 |
0110 | 8 bit field (+1) |
0111 | 16 bit field (+1) |
1000 | 256 |
1001 | 512 |
1010 | 1024 |
1011 | 2048 |
1100 | 4096 |
1101 | 8192 |
1110 | 16384 |
1111 | 32768 |
Handing uncommon block sizes is why this type is a generic with two different implementations from reading from a bitstream. The first reads common sizes, while the second reads additional bits if necessary.
§Example
use flac_codec::stream::BlockSize;
use bitstream_io::{BitReader, BitRead, BigEndian};
let data: &[u8] = &[
0b0110_1001, // block size + sample rate
0b0000_100_0, // channels + bps + pad
0x00, // frame number
0x13, // uncommon block size (+1)
];
let mut r = BitReader::endian(data, BigEndian);
let block_size = r.parse::<BlockSize<()>>().unwrap(); // reads 0b0110
assert_eq!(
block_size,
BlockSize::Uncommon8(()), // need to read actual block size from end of frame
);
r.skip(4 + 8 + 8).unwrap(); // skip unnecessary bits for this example
assert_eq!(
// read remainder of block size from end of frame
r.parse_using::<BlockSize<u16>>(block_size).unwrap(),
BlockSize::Uncommon8(0x13 + 1),
);Variants§
Samples192
192 samples
Samples576
576 samples
Samples1152
1152 samples
Samples2304
2304 samples
Samples4608
4608 samples
Uncommon8(B)
Uncommon 8 bit sample count + 1
Uncommon16(B)
Uncommon 16 bit sample count + 1
Samples256
256 samples
Samples512
512 samples
Samples1024
1024 samples
Samples2048
2048 samples
Samples4096
4096 samples
Samples8192
8192 samples
Samples16384
16384 samples
Samples32768
32768 samples
Trait Implementations§
Source§impl FromBitStream for BlockSize<()>
impl FromBitStream for BlockSize<()>
Source§impl FromBitStreamUsing for BlockSize<u16>
impl FromBitStreamUsing for BlockSize<u16>
Source§impl<B> ToBitStream for BlockSize<B>
impl<B> ToBitStream for BlockSize<B>
impl<B: Copy> Copy for BlockSize<B>
impl<B: Eq> Eq for BlockSize<B>
impl<B> StructuralPartialEq for BlockSize<B>
Auto Trait Implementations§
impl<B> Freeze for BlockSize<B>where
B: Freeze,
impl<B> RefUnwindSafe for BlockSize<B>where
B: RefUnwindSafe,
impl<B> Send for BlockSize<B>where
B: Send,
impl<B> Sync for BlockSize<B>where
B: Sync,
impl<B> Unpin for BlockSize<B>where
B: Unpin,
impl<B> UnwindSafe for BlockSize<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more