0

Assuming I've got AVAudioInputNode with N channels (In the current example it's 4) I want to connect it to my custom AUv3 audio unit where I could manipulate them, how could I achieve that?

I've tried

Hardcoding channel format in my AUv3 extension to take, for example, 4 channels like so resulting in 4097 error when instantiating the unit.

- (void)setupAudioBuses {
    // Create the output bus first
    AVAudioFormat *format = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:4];
    _outputBus = [[AUAudioUnitBus alloc] initWithFormat:format error:nil];
    _outputBus.maximumChannelCount = UINT_MAX;
    
    // Create the input and output busses.
    _inputBus.init(format, UINT_MAX);
    
    // Create the input and output bus arrays.
    _inputBusArray  = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self
                                                             busType:AUAudioUnitBusTypeInput
                                                              busses: @[_inputBus.bus]];
    // then an array with it
    _outputBusArray = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self
                                                             busType:AUAudioUnitBusTypeOutput
                                                              busses: @[_outputBus]];
}

I've also tried to setup the format like so but got the same error.

AudioStreamBasicDescription asbd;
    memset(&asbd, 0, sizeof(asbd));
    asbd.mSampleRate = 44100.0; // Sample rate
    asbd.mFormatID = kAudioFormatLinearPCM; // Linear PCM format
    asbd.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; // Canonical format flags
    asbd.mChannelsPerFrame = 4; // Number of channels
    asbd.mBitsPerChannel = 32; // Number of bits per channel
    asbd.mBytesPerFrame = (asbd.mBitsPerChannel / 8) * asbd.mChannelsPerFrame;
    asbd.mFramesPerPacket = 1;
    asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket;

    // Create an AVAudioFormat using the ASBD
    AVAudioFormat *format = [[AVAudioFormat alloc] initWithStreamDescription:&asbd];

If I leave it as 2 channel format there and I connect inputNode to it like this, it throws error -10875 failed call": "err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph, *GetInputNode()).

engine.connect(inputNode, to: myAU, fromBus: 0, format: inputNode.outputFormat(forBus: 0))
            
engine.connect(myAU, to: mixerNode, format: myAU.outputFormat(forBus: 0)

If I do it like so it doesn't throw an error but in that case it's connecting only the first 2 channels to my AU

engine.connect(inputNode, to: myAU, fromBus: 0, format: myAY.inputFormat(forBus: 0))
            
engine.connect(myAU, to: mixerNode, format: myAU.outputFormat(forBus: 0)

Also, one more note is that if I connect input node with inputNode.outputFormat(forBus: 0 (4 channel) to mainMixer it doesn't crash on engine.start()

I really need to be able to receive any number of channels in my audio unit :( Is it even possible?

0 Answers0