Can I subclass AVAudioUnitEffect?

Hi,


Is it possible for me to make my own audio effect by subclassing AVAudioUnitEffect?


What methods do I need to override in order to receive data buffers from the upstream node, and how do I deliver my results to the downstream node?


Thanks,

Frank

Accepted Reply

If you want to write your own audio unit, the correct approach is to subclass AUAudioUnit as NikoloziApps recommended.


But, that does bring up a common question about what AVAudioUnitEffect is -- AVAudioUnitEffect wraps "effect" audio units for use with AVAudioEngine allowing developers to use audio units not represented by specific framework provided wrappers like AVAudioUnitDistortion or AVAudioUnitDelay.


However, the recommended approach is to actually use the AVAudioUnit class method +instantiateWithComponentDescription:options:completionHandler: passing the component description of the audio unit (an effect in the case of this discussion) you're interested in. The returned AVAudioUnit will be the appropriate subclass, so in other words you'll get an instance of AVAudioUnitEffect back wrapping the effect component you asked to instantiate.


From there if you need to, you can ask for audioUnit or AUAudioUnit depending on your needs or connect the node to the engine since AVAudioUnit itself is a subclass of AVAudioNode.


I hope that's helpful.

Replies

You probably want to subclass AUAudioUnit instead

Assuming I did that, where would I put the code that actually transforms the sound?


I don't see any kind of a function I might override that looks like the right place to do the work.


Frank

Wait. AUAudioUnit? I've never heard of that before. I thought the audio engine used AVAudioUnit. AU is from a whole different framework (AudioToolbox vs. AVFoundation). I'm thoroughly confused now. What is relationship between the two? Can I use an AUAudioUnit with my AVAudioEngine? Or do I have to rewrite my entire application?

Hm. I see that AVAudioUnit has a property of type AUAudioUnit, suggesting that the AV version is a wrapper around the AU version.


The property isn't settable, but I assume I can override the getter in my subclass and provide my custom AUAudioUnit there.


Is that the right approach?


Frank

This helped me...


https://github.com/vgorloff/AUHost

If you want to write your own audio unit, the correct approach is to subclass AUAudioUnit as NikoloziApps recommended.


But, that does bring up a common question about what AVAudioUnitEffect is -- AVAudioUnitEffect wraps "effect" audio units for use with AVAudioEngine allowing developers to use audio units not represented by specific framework provided wrappers like AVAudioUnitDistortion or AVAudioUnitDelay.


However, the recommended approach is to actually use the AVAudioUnit class method +instantiateWithComponentDescription:options:completionHandler: passing the component description of the audio unit (an effect in the case of this discussion) you're interested in. The returned AVAudioUnit will be the appropriate subclass, so in other words you'll get an instance of AVAudioUnitEffect back wrapping the effect component you asked to instantiate.


From there if you need to, you can ask for audioUnit or AUAudioUnit depending on your needs or connect the node to the engine since AVAudioUnit itself is a subclass of AVAudioNode.


I hope that's helpful.

Thanks, that's exactly what I was looking for.