pub struct Streaminfo {
pub minimum_block_size: u16,
pub maximum_block_size: u16,
pub minimum_frame_size: Option<NonZero<u32>>,
pub maximum_frame_size: Option<NonZero<u32>>,
pub sample_rate: u32,
pub channels: NonZero<u8>,
pub bits_per_sample: SignedBitCount<32>,
pub total_samples: Option<NonZero<u64>>,
pub md5: Option<[u8; 16]>,
}Expand description
A STREAMINFO metadata block
This block contains metadata about the stream’s contents.
It must always be present in a FLAC file, must always be the first metadata block in the stream, and must not be present more than once.
| Bits | Field | Meaning |
|---|---|---|
| 16 | minimum_block_size | minimum block size (in samples) in the stream |
| 16 | maximum_block_size | maximum block size (in samples) in the stream |
| 24 | minimum_frame_size | minimum frame size (in bytes) in the stream |
| 24 | maximum_frame_size | maximum frame size (in bytes) in the stream |
| 20 | sample_rate | stream’s sample rate, in Hz |
| 3 | channels | stream’s channel count (+1) |
| 5 | bits_per_sample | stream’s bits-per-sample (+1) |
| 36 | total_samples | stream’s total channel-independent samples |
| 16×8 | md5 | decoded stream’s MD5 sum hash |
§Example
use bitstream_io::{BitReader, BitRead, BigEndian, SignedBitCount};
use flac_codec::metadata::Streaminfo;
use std::num::NonZero;
let data: &[u8] = &[
0x10, 0x00,
0x10, 0x00,
0x00, 0x00, 0x0c,
0x00, 0x00, 0x0c,
0b00001010, 0b11000100, 0b0100_000_0, 0b1111_0000,
0b00000000, 0b00000000, 0b00000000, 0b01010000,
0xf5, 0x3f, 0x86, 0x87, 0x6d, 0xcd, 0x77, 0x83,
0x22, 0x5c, 0x93, 0xba, 0x8a, 0x93, 0x8c, 0x7d,
];
let mut r = BitReader::endian(data, BigEndian);
assert_eq!(
r.parse::<Streaminfo>().unwrap(),
Streaminfo {
minimum_block_size: 0x10_00, // 4096 samples
maximum_block_size: 0x10_00, // 4096 samples
minimum_frame_size: NonZero::new(0x00_00_0c), // 12 bytes
maximum_frame_size: NonZero::new(0x00_00_0c), // 12 bytes
sample_rate: 0b00001010_11000100_0100, // 44100 Hz
channels: NonZero::new(0b000 + 1).unwrap(), // 1 channel
bits_per_sample:
SignedBitCount::new::<{0b0_1111 + 1}>(), // 16 bps
total_samples: NonZero::new(
0b0000_00000000_00000000_00000000_01010000 // 80 samples
),
md5: Some([
0xf5, 0x3f, 0x86, 0x87, 0x6d, 0xcd, 0x77, 0x83,
0x22, 0x5c, 0x93, 0xba, 0x8a, 0x93, 0x8c, 0x7d,
]),
},
);§Important
Changing any of these values to something that differs from the values of the file’s frame headers will render it unplayable, as will moving it anywhere but the first metadata block in the file. Avoid modifying the position and contents of this block unless you know exactly what you are doing.
Fields§
§minimum_block_size: u16The minimum block size (in samples) used in the stream, excluding the last block.
maximum_block_size: u16The maximum block size (in samples) used in the stream, excluding the last block.
minimum_frame_size: Option<NonZero<u32>>The minimum framesize (in bytes) used in the stream.
None indicates the value is unknown.
maximum_frame_size: Option<NonZero<u32>>The maximum framesize (in bytes) used in the stream.
None indicates the value is unknown.
sample_rate: u32Sample rate in Hz
0 indicates a non-audio stream.
channels: NonZero<u8>Number of channels, from 1 to 8
bits_per_sample: SignedBitCount<32>Number of bits-per-sample, from 4 to 32
total_samples: Option<NonZero<u64>>Total number of interchannel samples in stream.
None indicates the value is unknown.
md5: Option<[u8; 16]>MD5 hash of unencoded audio data.
None indicates the value is unknown.
Implementations§
Source§impl Streaminfo
impl Streaminfo
Sourcepub const MAX_FRAME_SIZE: u32 = 16_777_215u32
pub const MAX_FRAME_SIZE: u32 = 16_777_215u32
The maximum size of a frame, in bytes (2²⁴ - 1)
Sourcepub const MAX_SAMPLE_RATE: u32 = 1_048_575u32
pub const MAX_SAMPLE_RATE: u32 = 1_048_575u32
The maximum sample rate, in Hz (2²⁰ - 1)
Sourcepub const MAX_CHANNELS: NonZero<u8>
pub const MAX_CHANNELS: NonZero<u8>
The maximum number of channels (8)
Sourcepub const MAX_TOTAL_SAMPLES: NonZero<u64>
pub const MAX_TOTAL_SAMPLES: NonZero<u64>
The maximum number of total samples (2³⁶ - 1)
Trait Implementations§
Source§impl AsBlockRef for Streaminfo
impl AsBlockRef for Streaminfo
Source§fn as_block_ref(&self) -> BlockRef<'_>
fn as_block_ref(&self) -> BlockRef<'_>
Source§impl Clone for Streaminfo
impl Clone for Streaminfo
Source§fn clone(&self) -> Streaminfo
fn clone(&self) -> Streaminfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more