Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Core Audio What is the difference between AUAudioUnit and AVAudioUnit?

Both the AUAudioUnit and AVAudioUnit APIs look really similar,

what's the difference? When to use which one?

like image 220
Jacky Wang Avatar asked Dec 09 '15 08:12

Jacky Wang


2 Answers

An AVAudioUnit is connected as a node in an AVAudioEngine. An AUAudioUnit is typically connected in an AUGraph. The functionalities should be similar, as both are audio units, but using an AVAudioEngine is the modern way of audio control in iOS and therefore AVAudioUnits have a more modernized API behind them.

I'm sure there are use cases where one can be preferred over the other, but I'd say use AVAudioUnits unless there's something specific you need that they don't provide. The customizability of AUAudioUnits and their processing graph is great, but in my experience comes with a steep learning curve and a lot more code. Many sleepless nights I've spent inspecting my AUGraphs, but AVAudioEngine has been very kind to me.

Also, AVAudioNodes, and therefore AVAudioUnits, are not functional until attached to a AVAudioEngine, however you can set up AUAudioUnits without an AUGraph using render callbacks.

like image 117
tnev Avatar answered Nov 10 '22 04:11

tnev


Note that AUAudioUnit represents a V3 audio unit, even though it starts with 'AU'. It is available in iOS 9. Older APIs also start with 'AU' (such as AUSampler) but they are V2.

In general in your app you should use AVAudioUnit. Note that it is available only in iOS 8+. As tnev mentioned above, you can use the AVAudioNode classes to easily set up AVAudioEngine. You cannot do this with AUAudioUnit.

If you are writing your own audio unit you should use AUAudioUnit by subclassing it.

EDIT: Also use AUAudioUnit if you intend to display the viewController of V3 audio units.

like image 41
bio Avatar answered Nov 10 '22 05:11

bio