关于avfoundation:iOS音频单元混响流格式问题-10868 kAudioUnitErr_FormatNotSupported

iOS Audio units reverb stream format issue -10868 kAudioUnitErr_FormatNotSupported

我正在用音频单元编写一个简单的iOS应用。我想添加混响效果。
因此该图看起来像RemoteIO_Input-> Reverb-> RemoveIO_Output。
但是尝试为混响单元-kAudioUnitErr_FormatNotSupported设置流格式时遇到错误。
该代码在不使用混响单元(图形中的单个远程IO)的情况下可以正常工作,因此其他配置似乎很好,我没有提供其代码。

UPD:使用iOS 6

所以问题:

  • 允许的格式是否有限制?

  • 我应该使用哪种格式的参数?

  • 是否应在RemoteIO输出元素的任何范围内设置格式?

  • 感谢您的关注。

    代码:
    说明:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    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;

    图形设置

    1
    2
    3
    4
    5
    6
    7
    8
    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);

    格式说明和设置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
       // 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];
        }

    Are there restrictions for the allowed formats?

    是的,它们通常非常严格。

    What format params should I use?

    使用单元的默认ASBD或使用基于预构建的标志集(kAudioFormatFlagsAudioUnitCanonicalkAudioFormatFlagsCanonical)中的一个,您将获得最大的运气。像这样,而不是像这样编排自己的格式:

    1
    audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;

    您将执行以下操作:

    1
    audioFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;

    通常来说,如果您仅将两个单元相互连接,它们便可以自行解决。如果需要提供自己的音频,则必须指定输入格式(并且可能需要基于kAudioFormatFlagsAudioUnitCanonical,它是非交织的线性PCM,每个样本均表示为固定的8.24 SInt32容器中的数字)。

    如果需要更大的灵活性,可以将AUConverter音频单元放在混响单元之前,因为AUConverter将能够处理更多的输入格式(例如正确的浮点样本)。请注意,这伴随着处理量的增加,因为AUConverter将必须实时转换音频格式。

    您可以在Core Audio Essentials页面上的Canonical Audio Data Formats标题下看到完整的ASBD示例。

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

    如果您的混响单元直接连接到RemoteIO输出,则这些单元应能够自行对其进行分类。