Struct coreaudio::audio_unit::stream_format::StreamFormat [] [src]

pub struct StreamFormat {
    pub sample_rate: f64,
    pub sample_format: SampleFormat,
    pub flags: LinearPCMFlags,
    pub channels_per_frame: u32,

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::() bytes_per_frame = size_of::() frames_per_packet = 1 bits_per_channel = size_of::() * 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.


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 xpects 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 channels_per_frame: u32


impl StreamFormat

fn from_asbd(asbd: AudioStreamBasicDescription) -> Result<StreamFormatError>

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 type kkkkkkkkkkkkkkkkkkkkkk

fn to_asbd(self) -> AudioStreamBasicDescription

Convert a StreamFormat into an AudioStreamBasicDescription.

Trait Implementations

impl Debug for StreamFormat

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Clone for StreamFormat

fn clone(&self) -> StreamFormat

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl Copy for StreamFormat