pub enum SampleRate<R> {
Show 15 variants
Streaminfo(u32),
Hz88200,
Hz176400,
Hz192000,
Hz8000,
Hz16000,
Hz22050,
Hz24000,
Hz32000,
Hz44100,
Hz48000,
Hz96000,
KHz(R),
Hz(R),
DHz(R),
}Expand description
Possible sample rates in a FLAC frame
Common rates are stored as a 4-bit value, while uncommon rates are stored as 8 or 16 bit values. Sample rates defined in the STREAMINFO metadata block are only possible on a “non-subset” stream, which is not streamable.
| Bits | Sample Rate |
|---|---|
0000 | get from STREAMINFO |
0001 | 88200 Hz |
0010 | 176400 Hz |
0011 | 192000 Hz |
0100 | 8000 Hz |
0101 | 16000 Hz |
0110 | 22050 Hz |
0111 | 24000 Hz |
1000 | 32000 Hz |
1001 | 44100 Hz |
1010 | 48000 Hz |
1011 | 96000 Hz |
1100 | read 8 bits, in kHz |
1101 | read 16 bits, in Hz |
1110 | read 16 bits, in 10s of Hz |
1111 | invalid sample rate |
Handing uncommon frame rates is why this type is a generic with multiple implementations from reading from a bitstream. The first reads common rates, while the second reads additional bits if necessary.
§Example
use flac_codec::stream::SampleRate;
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);
r.skip(4).unwrap(); // skip block size
let sample_rate = r.parse::<SampleRate<()>>().unwrap(); // reads 0b1001
assert_eq!(
sample_rate,
SampleRate::Hz44100, // got defined sample rate
);
r.skip(8 + 8 + 8).unwrap(); // skip unnecessary bits for this example
assert_eq!(
// since our rate is defined, no need to read additional bits
r.parse_using::<SampleRate<u32>>(sample_rate).unwrap(),
SampleRate::Hz44100,
);Variants§
Streaminfo(u32)
Get rate from STREAMINFO metadata block
Hz88200
88200 Hz
Hz176400
176,400 Hz
Hz192000
192,000 Hz
Hz8000
8,000 Hz
Hz16000
16,000 Hz
Hz22050
22,050 Hz
Hz24000
24,000 Hz
Hz32000
32,000 Hz
Hz44100
44,100 Hz
Hz48000
48,000 Hz
Hz96000
96,000 Hz
KHz(R)
8-bit value in kHz
Hz(R)
16-bit value in Hz
DHz(R)
16-bit value * 10 in Hz
Trait Implementations§
Source§impl<R: Clone> Clone for SampleRate<R>
impl<R: Clone> Clone for SampleRate<R>
Source§fn clone(&self) -> SampleRate<R>
fn clone(&self) -> SampleRate<R>
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<R: Debug> Debug for SampleRate<R>
impl<R: Debug> Debug for SampleRate<R>
Source§impl Display for SampleRate<u32>
impl Display for SampleRate<u32>
Source§impl From<SampleRate<u32>> for u32
impl From<SampleRate<u32>> for u32
Source§fn from(rate: SampleRate<u32>) -> Self
fn from(rate: SampleRate<u32>) -> Self
Converts to this type from the input type.
Source§impl FromBitStream for SampleRate<()>
impl FromBitStream for SampleRate<()>
Source§impl FromBitStreamUsing for SampleRate<()>
Reads the raw sample rate bits, which need to be finalized
impl FromBitStreamUsing for SampleRate<()>
Reads the raw sample rate bits, which need to be finalized
Source§impl FromBitStreamUsing for SampleRate<u32>
impl FromBitStreamUsing for SampleRate<u32>
Source§impl<R: PartialEq> PartialEq for SampleRate<R>
impl<R: PartialEq> PartialEq for SampleRate<R>
Source§impl<R> ToBitStream for SampleRate<R>
Writes the raw sample rate bits
impl<R> ToBitStream for SampleRate<R>
Writes the raw sample rate bits
impl<R: Copy> Copy for SampleRate<R>
impl<R: Eq> Eq for SampleRate<R>
impl<R> StructuralPartialEq for SampleRate<R>
Auto Trait Implementations§
impl<R> Freeze for SampleRate<R>where
R: Freeze,
impl<R> RefUnwindSafe for SampleRate<R>where
R: RefUnwindSafe,
impl<R> Send for SampleRate<R>where
R: Send,
impl<R> Sync for SampleRate<R>where
R: Sync,
impl<R> Unpin for SampleRate<R>where
R: Unpin,
impl<R> UnwindSafe for SampleRate<R>where
R: 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