StreamFormat

Struct StreamFormat 

Source
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.

from Core Audio Overview

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: f64

The number of frames of audio data per second used to represent a signal.

§sample_format: SampleFormat

The 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: LinearPcmFlags

The format flags for the given StreamFormat.

§channels: u32

The number of channels.

Implementations§

Source§

impl StreamFormat

Source

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.

Source

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

Source§

fn clone(&self) -> StreamFormat

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StreamFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for StreamFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,