4

In Apple's docs for creating an AUAudio Unit (Here: https://developer.apple.com/documentation/audiotoolbox/auaudiounit/1387570-initwithcomponentdescription) they claim that

A single audio unit subclass may implement multiple audio units—for example, an effect that can also function as a generator, or a cluster of related effects.

There are no examples of this online that I can find. Ideally it would be nice if your answer/solution involved using Swift and AVAudioEngine but I'd happily accept any answer that gets me moving in the right direction.

Thanks in advance.

Aurelius Prochazka
  • 4,510
  • 2
  • 11
  • 34
  • In the 2017 WWDC session on Core Audio, Apple says not to use Swift inside the real-time audio context (the working guts of an AUAudioUnit subclass). – hotpaw2 Oct 16 '17 at 16:31
  • Hello Aurelius, have you made any progress on this topic? – Vanya May 22 '18 at 20:13

1 Answers1

3

I posted some source code to my test app which instantiates an AVAudioUnit generator subclass object using AVAudioEngine, Swift and C, on GitHub here:

https://github.com/hotpaw2/auv3test5

Note that Apple recommends NOT using Swift inside the real-time audio context, so that portion of my source code is written in C, inside an Objective C wrapper class.

If you use initWithComponentDescription:options:error:, you can pass an option to configure your new audio unit subclass object to do whatever (using something like a switch statement on the option).

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • 1
    Let me check out your code and see if it is what I need. Thanks for responding! – Aurelius Prochazka Oct 16 '17 at 22:32
  • 1
    So yeah this is helpful, but it doesn't implement multiple audio units in one unless i am missing something? – Aurelius Prochazka Oct 16 '17 at 22:37
  • See the last paragraph about adding an option. – hotpaw2 Oct 16 '17 at 22:46
  • yeah, sorry but I feel like the hard part of this question remains unanswered. The last paragraph is where I'm unsure of the best way to do things. – Aurelius Prochazka Oct 18 '17 at 06:14
  • @hotpaw2 Do you by chance know how I can make your code to play specific musical notes, like an a C or an F#? Wouldn't I need to figure out the specific hertz for each note? – daniel Feb 09 '19 at 10:50
  • Musical note pitch frequency? That’s a separate question, possibly a duplicate of other questions already answered here on stackoverflow (or Wikipedia) – hotpaw2 Feb 09 '19 at 13:10