0

I'm using an AUGraph (I know, it is a deprecated API ) to mix several audio sources and apply effects. This works fine for a single output, but I cannot add a secondary output to my graph.

I read on the internets, that this is a know limitation, which one can work around by using subgraphs, each withs its dedicated output.

Can anyone confirm wether this is indeed true? If so, pointers to sample code would be more than welcome.

iljawascoding
  • 1,090
  • 9
  • 20
  • Have you investigated aggregate devices? – sbooth Sep 02 '21 at 17:02
  • Hey Ilja, mixing more than one source into one output is exactly what I am trying to do in a side-project. I stumbled over the huge amount of (deprecated) frameworks and that stopped my enthusiasm. Can you tell what made you pick AUGraph? Maybe that’s the right choice for me, too – Christian Beer Sep 02 '21 at 17:25
  • As far as I understand, aggregate devices have to be setup in one of Apple utilities. That's too cumbersome for end users. Also, switching output devices on the fly would be quite difficult. – iljawascoding Sep 03 '21 at 09:17
  • @ChristianBeer I also want to add different audio filters to the inputs. It looks like AUGraph seems to be the simplest API for that, even tough its deprecated. – iljawascoding Sep 03 '21 at 09:18
  • 1
    Aggregate devices can be created programmatically too - but I believe the only substantial documentation from Apple will be in the headers like `AudioHardware.h`. A couple of answers here touch on it, e.g. https://stackoverflow.com/questions/35469569/how-can-i-programmatically-create-a-multi-output-device-in-os-x. I have done it as well, though recall running into some issues (perhaps some properties are set asynchronously?) – user1325158 Sep 03 '21 at 23:52

1 Answers1

2

Audio Units and AUGraphs are based on a "pull" model. Each output pulls input through the graph at its desired rate.

For two unrelated outputs (e.g. 2 USB audio devices using 2 separate oscillator chips or crystals), that could mean 2 slightly different sample rates, even when both are configured for 44.1k (etc.). And a single graph can only run at one rate.

You could try installing a tap on one of the audio unit outputs, copying its output samples into a circular buffer, and pulling from that fifo buffer for the second audio output unit. An appropriate errors concealment strategy for the sample rate mismatches (eventually causing underflow or overflow issues) may be required.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Thanks for your insights. My gut feeling is that two identically configured AudioGraphs, both with their own outputs, would be easier to implement. – iljawascoding Sep 03 '21 at 09:24