2

I am writing a simple iOS app with Audio Units. I want to add a reverberation effect. So the graph looks like RemoteIO_Input -> Reverb -> RemoveIO_Output. But I am getting an error when trying to set up a stream format for the reverb unit - kAudioUnitErr_FormatNotSupported. That code works fine without using the reverb unit (single remote IO in graph) so other configuration seems fine and I am not providing their code.

UPD: iOS 6 is used

So questions:

  1. Are there restrictions for the allowed formats?

  2. What format params should I use?

  3. Should set the format in any scope of RemoteIO output element?

Thanks for attention.

CODE: Descriptions:

desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;

descRev.componentType = kAudioUnitType_Effect;
descRev.componentSubType = kAudioUnitSubType_Reverb2;
descRev.componentFlags = 0;
descRev.componentFlagsMask = 0;
descRev.componentManufacturer = kAudioUnitManufacturer_Apple;

Graph set up

NewAUGraph(&graph);
AUNode ioNode;
AUNode rNode;
AUGraphAddNode(graph, &desc, &ioNode);
AUGraphAddNode(graph, &descRev, &rNode);
AUGraphOpen(graph);
AUGraphConnectNodeInput(graph, ioNode, 1, rNode, 0);
AUGraphConnectNodeInput(graph, rNode, 0, ioNode, 0);

Format description and set up

   // Describe format
audioFormat.mSampleRate         = rate;//44100.00;
audioFormat.mFormatID           = kAudioFormatLinearPCM;
audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket    = 1;
audioFormat.mChannelsPerFrame   = 1;
audioFormat.mBitsPerChannel     = 16;
audioFormat.mBytesPerPacket     = 2;
audioFormat.mBytesPerFrame      = 2;

    OSStatus err = AudioUnitSetProperty(unit,
                                  kAudioUnitProperty_StreamFormat,
                                  kAudioUnitScope_Output,
                                  kInputBus,
                                  &audioFormat,
                                  sizeof(audioFormat));
    if (noErr != err) {
        [self showStatus:err];
    }

    err = AudioUnitSetProperty(unitRev,
                           kAudioUnitProperty_StreamFormat,
                           kAudioUnitScope_Input,
                           0,
                           &audioFormat,
                           sizeof(audioFormat));
    if (noErr != err) {
        [self showStatus:err];
    }
Max Komarychev
  • 2,836
  • 1
  • 21
  • 32

1 Answers1

5

Are there restrictions for the allowed formats?

Yes, and they're usually quite strict.

What format params should I use?

You'll have the most luck either using the units' default ASBD, or using one based off of the pre-built sets of flags (kAudioFormatFlagsAudioUnitCanonical and kAudioFormatFlagsCanonical). As in, instead of making up your own format like this:

audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;

You would do this:

audioFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;

Generally speaking, if you just hook up two units to each other, they'll be able to sort it out for themselves. If you need to supply your own audio, you'll have to specify the input format (and it'll likely need to be based off ofkAudioFormatFlagsAudioUnitCanonical, which is non-interleaved linear PCM with each sample being represented as a fixed 8.24 number in an SInt32 container).

If you need more flexibility, you can stick an AUConverter audio unit before your reverb unit, since the AUConverter will be able to handle many more input formats (such as proper floating point samples). Note that this comes with the caveat of increased processing since the AUConverter will have to convert the audio format in real-time.

You can see a full ASBD example on the Core Audio Essentials page under the heading Canonical Audio Data Formats.

Should set the format in any scope of RemoteIO output element?

If your reverb unit is connected directly to the RemoteIO output, the units should be able to sort it out for themselves.

admsyn
  • 1,431
  • 8
  • 19