AudioUnit

Struct AudioUnit 

Source
pub struct AudioUnit { /* private fields */ }
Expand description

A rust representation of the objc2_audio_toolbox::AudioUnit, including a pointer to the current rendering callback.

Find the original Audio Unit Programming Guide here.

Implementations§

Source§

impl AudioUnit

Source

pub fn set_render_callback<F, D>(&mut self, f: F) -> Result<(), Error>
where F: FnMut(Args<D>) -> Result<(), ()> + 'static, D: Data,

Pass a render callback (aka “Input Procedure”) to the AudioUnit.

Source

pub fn set_input_callback<F, D>(&mut self, f: F) -> Result<(), Error>
where F: FnMut(Args<D>) -> Result<(), ()> + 'static, D: Data,

Pass an input callback (aka “Input Procedure”) to the AudioUnit.

Source

pub fn free_render_callback(&mut self) -> Option<Box<InputProcFnWrapper>>

Retrieves ownership over the render callback and returns it where it can be re-used or safely dropped.

Source

pub fn free_input_callback(&mut self) -> Option<Box<InputProcFnWrapper>>

Retrieves ownership over the input callback and returns it where it can be re-used or safely dropped.

Source§

impl AudioUnit

Source

pub fn new<T>(ty: T) -> Result<AudioUnit, Error>
where T: Into<Type>,

Construct a new AudioUnit with any type that may be automatically converted into Type.

Here is a list of compatible types:

To construct the AudioUnit with some component flags, see AudioUnit::new_with_flags.

Note: the AudioUnit is constructed with the kAudioUnitManufacturer_Apple Manufacturer Identifier, as this is the only Audio Unit Manufacturer Identifier documented by Apple in the AudioUnit reference (see here).

Source

pub fn new_with_flags<T>( ty: T, flags: u32, mask: u32, ) -> Result<AudioUnit, Error>
where T: Into<Type>,

The same as AudioUnit::new but with the given component flags and mask.

Source

pub fn initialize(&mut self) -> Result<(), Error>

On successful initialization, the audio formats for input and output are valid and the audio unit is ready to render. During initialization, an audio unit allocates memory according to the maximum number of audio frames it can produce in response to a single render call.

Usually, the state of an audio unit (such as its I/O formats and memory allocations) cannot be changed while an audio unit is initialized.

Source

pub fn uninitialize(&mut self) -> Result<(), Error>

Before you change an initialize audio unit’s processing characteristics, such as its input or output audio data format or its sample rate, you must first uninitialize it. Calling this function deallocates the audio unit’s resources.

After calling this function, you can reconfigure the audio unit and then call AudioUnitInitialize to reinitialize it.

Source

pub fn set_property<T>( &mut self, id: u32, scope: Scope, elem: Element, maybe_data: Option<&T>, ) -> Result<(), Error>

Sets the value for some property of the AudioUnit.

To clear an audio unit property value, set the data parameter with None::<()>.

Clearing properties only works for those properties that do not have a default value.

For more on “properties” see the reference.

Available in iOS 2.0 and later.

§Parameters
  • id: The identifier of the property.
  • scope: The audio unit scope for the property.
  • elem: The audio unit element for the property.
  • maybe_data: The value that you want to apply to the property.
Source

pub fn get_property<T>( &self, id: u32, scope: Scope, elem: Element, ) -> Result<T, Error>

Gets the value of an AudioUnit property.

Available in iOS 2.0 and later.

§Parameters
  • id: The identifier of the property.
  • scope: The audio unit scope for the property.
  • elem: The audio unit element for the property.
Source

pub fn start(&mut self) -> Result<(), Error>

Starts an I/O AudioUnit, which in turn starts the audio unit processing graph that it is connected to.

Available in OS X v10.0 and later.

Source

pub fn stop(&mut self) -> Result<(), Error>

Stops an I/O AudioUnit, which in turn stops the audio unit processing graph that it is connected to.

Available in OS X v10.0 and later.

Source

pub fn set_sample_rate(&mut self, sample_rate: f64) -> Result<(), Error>

Set the AudioUnit’s sample rate.

Available in iOS 2.0 and later.

Source

pub fn sample_rate(&self) -> Result<f64, Error>

Get the AudioUnit’s sample rate.

Source

pub fn set_stream_format( &mut self, stream_format: StreamFormat, scope: Scope, element: Element, ) -> Result<(), Error>

Sets the current StreamFormat for the AudioUnit.

Core Audio uses slightly different defaults depending on the platform.

From the 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
Source

pub fn stream_format( &self, scope: Scope, element: Element, ) -> Result<StreamFormat, Error>

Return the current Stream Format for the AudioUnit.

Source

pub fn output_stream_format(&self) -> Result<StreamFormat, Error>

Return the current output Stream Format for the AudioUnit.

Source

pub fn input_stream_format(&self) -> Result<StreamFormat, Error>

Return the current input Stream Format for the AudioUnit.

Trait Implementations§

Source§

impl AsMut<*mut OpaqueAudioComponentInstance> for AudioUnit

Source§

fn as_mut(&mut self) -> &mut InnerAudioUnit

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<*mut OpaqueAudioComponentInstance> for AudioUnit

Source§

fn as_ref(&self) -> &InnerAudioUnit

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Drop for AudioUnit

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for AudioUnit

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> 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, 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,