#[repr(C)]pub struct Spec {
pub format: Format,
pub rate: u32,
pub channels: u8,
}
Expand description
A sample format and attribute specification.
Fields§
§format: Format
The sample format.
rate: u32
The sample rate. (e.g. 44100).
channels: u8
Audio channels. (1 for mono, 2 for stereo, …).
Implementations§
Source§impl Spec
impl Spec
Sourcepub const CHANNELS_MAX: u8 = 32u8
pub const CHANNELS_MAX: u8 = 32u8
Maximum number of allowed channels.
Sourcepub fn init(&mut self)
pub fn init(&mut self)
Initializes the specified sample spec.
The sample spec will have a defined state but is_valid()
will fail for
it.
Sourcepub fn format_is_valid(&self) -> bool
pub fn format_is_valid(&self) -> bool
Checks only if the format attribute is valid.
Or in other words that the client library running on the end user system accepts it.
Sourcepub fn rate_is_valid(&self) -> bool
pub fn rate_is_valid(&self) -> bool
Checks only if the rate is within the supported range.
Sourcepub fn channels_are_valid(&self) -> bool
pub fn channels_are_valid(&self) -> bool
Checks only if the channel count is within the supported range.
Sourcepub fn bytes_per_second(&self) -> usize
pub fn bytes_per_second(&self) -> usize
Gets the amount of bytes that constitute playback of one second of audio, with the specified sample type.
Sourcepub fn frame_size(&self) -> usize
pub fn frame_size(&self) -> usize
Gets the size of a frame.
Sourcepub fn sample_size(&self) -> usize
pub fn sample_size(&self) -> usize
Gets the size of a sample.
Sourcepub fn bytes_to_usec(&self, length: u64) -> MicroSeconds
pub fn bytes_to_usec(&self, length: u64) -> MicroSeconds
Calculates the time it would take to play a buffer of the specified size.
The return value will always be rounded down for non-integral return values.
Note, the underlying calculation may overflow for very large values.
Sourcepub fn usec_to_bytes(&self, t: MicroSeconds) -> usize
pub fn usec_to_bytes(&self, t: MicroSeconds) -> usize
Calculates the size of a buffer required, for playback duration of the time specified.
The return value will always be rounded down for non-integral return values.
Note, the underlying calculation may overflow for very large values.