pub struct StreamFormat {
pub sample_rate: f64,
pub sample_format: SampleFormat,
pub flags: LinearPcmFlags,
pub channels: u32,
}Expand description
A representation of the AudioStreamBasicDescription specifically for use with the AudioUnit API.
By using a type specific to the audio unit API, we can remove a lot of unnecessary boilerplate that is normally associated with the AudioStreamBasicDescription.
Seeing as LinearPCM data (the AudioFormat used by the AudioUnit API) implies a single
frame per packet, we can infer many of the fields in an ASBD from the sample type.
bytes_per_packet = size_of::<S>()
bytes_per_frame = size_of::<S>()
frames_per_packet = 1
bits_per_channel = size_of::<S>() / channels_per_frame * 8
A packet is a collection of one or more contiguous frames. In linear PCM audio, a packet is always a single frame.
The canonical formats in Core Audio are as follows:
- iOS input and output: Linear PCM with 16-bit integer samples.
- iOS audio units and other audio processing: Noninterleaved linear PCM with 8.24-bit fixed-point samples
- Mac input and output: Linear PCM with 32-bit floating point samples.
- Mac audio units and other audio processing: Noninterleaved linear PCM with 32-bit floating point samples.
Fields§
§sample_rate: f64The number of frames of audio data per second used to represent a signal.
sample_format: SampleFormatThe sample format used to represent the audio data.
In OS X, Core Audio expects audio data to be in native-endian, 32-bit floating-point, linear PCM format.
iOS uses integer and fixed-point audio data. The result is faster calculations and less battery drain when processing audio. iOS provides a Converter audio unit and inclues the interfaces from Audio Converter Services (TODO: look into exposing this).
flags: LinearPcmFlagsThe format flags for the given StreamFormat.
channels: u32The number of channels.
Implementations§
Source§impl StreamFormat
impl StreamFormat
Sourcepub fn from_asbd(
asbd: AudioStreamBasicDescription,
) -> Result<StreamFormat, Error>
pub fn from_asbd( asbd: AudioStreamBasicDescription, ) -> Result<StreamFormat, Error>
Convert an AudioStreamBasicDescription into a StreamFormat.
Note: audio_unit::StreamFormat exclusively uses the LinearPCM AudioFormat. This is as
specified in the documentation:
Specify kAudioFormatLinearPCM for the mFormatID field. Audio units use uncompressed audio data, so this is the correct format identifier to use whenever you work with audio units.
Audio Unit Hosting Guide for iOS
Returns an Error if the AudioFormat inferred by the ASBD is not LinearPCM.
Returns an Error if the sample format of the asbd cannot be matched to a format supported by SampleFormat.
Sourcepub fn to_asbd(self) -> AudioStreamBasicDescription
pub fn to_asbd(self) -> AudioStreamBasicDescription
Convert a StreamFormat into an AudioStreamBasicDescription.
Note that this function assumes that only packed formats are used.
This only affects I24, since all other formats supported by StreamFormat
are always packed.
Trait Implementations§
Source§impl Clone for StreamFormat
impl Clone for StreamFormat
Source§fn clone(&self) -> StreamFormat
fn clone(&self) -> StreamFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more