How is the AVAudioSession API tied to the AudioUnit/Component API?

How is the AVAudioSession API tied to the AudioUnit/Component API?

For example, do I need an AVAudioSession configured and enabled before searching for a system Audio Unit? Before instantionating one? Before starting one? Ect.

Accepted Reply

AVAudioSession is the framework used to configure your apps audio behavior and expressing the intentions for your apps audio usage to the system. AVAudioSession doesn't actually produce or consume audio data but is generally required by all but the most trivial applications that use audio on the system.


So while not directly tied into APIs that touch audio data, as a quick example, if you haven't configured your AVAudioSession for recording (i.e. input device is required for my app) by setting the AVAudioSessionCategoryRecord catagory, trying to use an audio API that needs access to the internal mic will fail.


I suggest reading the Audio Session Programming Guide and the AVAudioSessionreference for full details. There are also a number of WWDC videos that specifically discuss audio session.

Replies

AVAudioSession is the framework used to configure your apps audio behavior and expressing the intentions for your apps audio usage to the system. AVAudioSession doesn't actually produce or consume audio data but is generally required by all but the most trivial applications that use audio on the system.


So while not directly tied into APIs that touch audio data, as a quick example, if you haven't configured your AVAudioSession for recording (i.e. input device is required for my app) by setting the AVAudioSessionCategoryRecord catagory, trying to use an audio API that needs access to the internal mic will fail.


I suggest reading the Audio Session Programming Guide and the AVAudioSessionreference for full details. There are also a number of WWDC videos that specifically discuss audio session.

Thanks @theanalogkid, saving me again 🙂


Perhaps I should have just asked the more specific question I had.


Do I need to set the shared audio session to active before initializing my audio unit state?


Thanks,

Zach

No, it's not specifically a requirement when just finding and initializing AUs for you to go active, there is a default state (See: Audio Session Default Behavior & Why a Default Audio Session Usually Isn’t What You Want sections of the Programming Guide). But, for almost all except the most basic uses that's not going to be enough to allow an app to handle the complexities of audio interaction on the platforms.

Of course, was never going to leave the Audio Session in the default state 😝


So, is the following OK:

  • Initialize Audio Session, set preffered values, ect.
  • Find, and initialize an AU
  • Set the Audio Sessio to active
  • Start the AU


Or should is it safer to explicitly have an Audio Session active before doing anything with AUs?


Thanks,

Zach