admsyn/ofxAudioUnit

Connecting multichannel input to taps

jasonlevine opened this issue · 2 comments

Hi Adam,

I'm trying to connect the inputs from an instance of ofxAudioUnitInput set to a multichannel device to multiple taps. The goal is to have the samples from each live input in realtime.

When i try this:
input.connectTo(*taps[i], 0, i);
I get an error: No matching member function for call to 'connectTo'

However this is the only member function:
ofxAudioUnit& connectTo(ofxAudioUnit &otherUnit, int destinationBus = 0, int sourceBus = 0); using ofxAudioUnit::connectTo; // for connectTo(ofxAudioUnitTap&)

So how would I go about connecting my ofxAudioUnitInput to multiple ofxAudioUnitTaps?

trying to hack a ofxAudioUnitDSPNode& ofxAudioUnitInput::connectTo(ofxAudioUnitDSPNode &destination, int destinationBus, int sourceBus) function together, when I noticed that the current connectTo function for ofxAudioUnitInput doesn't appear to make use of the sourceBus parameter:

// ----------------------------------------------------------
ofxAudioUnit& ofxAudioUnitInput::connectTo(ofxAudioUnit &otherUnit, int destinationBus, int sourceBus)
// ----------------------------------------------------------
{
    AudioStreamBasicDescription ASBD;
    UInt32 ASBDSize = sizeof(ASBD);

    OFXAU_PRINT(AudioUnitGetProperty(otherUnit,
                                     kAudioUnitProperty_StreamFormat,
                                     kAudioUnitScope_Input,
                                     destinationBus,
                                     &ASBD,
                                     &ASBDSize),
                "getting hardware input destination's format");

    OFXAU_PRINT(AudioUnitSetProperty(*_unit,
                                     kAudioUnitProperty_StreamFormat,
                                     kAudioUnitScope_Output,
                                     1,
                                     &ASBD,
                                     sizeof(ASBD)),
                "setting hardware input's output format");

    AURenderCallbackStruct callback = {PullCallback, &_impl->ctx};
    otherUnit.setRenderCallback(callback, destinationBus);
    return otherUnit;
}

is ofxAudioInput set up for devices with multiple inputs?

Hey Jason, it's been long enough since I wrote this that I don't really know the answers off hand. Here's some thoughts though:

  • the missing source bus param may be a bug, but I think the input will only ever have one source bus. Note that a bus is not the same as a channel, so you can have (for example) 5.1 channel audio on one bus. I think the source bus param is just there to keep the API consistent with other units which may actually have multiple busses
  • related, do you actually need multiple taps, or is it fine to have one tap taking all the channels?
  • the ofxAudioUnitInput is a bit of a special case, since it dumps everything into a circular buffer and has stuff pulled from there (instead of directly hooking it up to downstream units)
  • you can use the AUSplitter to create a copy of the input, giving you two busses to work with. This'll get real awkward if you want a bunch of busses though

Let me know how it goes