ZBLOG

我的代码如下: AURemoteIO.cpp:1162 failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, deinterleaved> inf< 2 ch, 0 Hz, Float32, deinterleaved>) AVAEInternal.h:76 required condition is false: [AVAEGraphNode.mm:832:Creat...

根据您提供的错误信息,问题主要出在音频配置上。错误代码 -10851 表示有一个参数无效,并且“0 Hz”的采样率是不被允许的。以下是一些可能的原因和解决方法:

1. 确保有效的采样率

确保您的音频格式具有正确的非零采样率。例如,通常可以使用44100Hz或48000Hz作为标准值。

AVAudioFormat *audioFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
                                                               sampleRate:44100.0 // 设置一个有效的采样率
                                                                 channels:2];     // 使用两个通道(立体声)

2. 检查 AURemoteIO 的设置

如果您正在使用 AURemoteIO,请确保在启用输入和输出之前已经正确配置了它。

// 创建 AURemoteIO 实例
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;

AudioComponent comp = AudioComponentFindNext(NULL, &desc);
if (comp) {
    AudioUnit remoteIOUnit;
    AudioComponentInstanceNew(comp, &remoteIOUnit);

    // 启用输入和输出(可选择性地)
    UInt32 enableInput = 1; 
    AudioUnitSetProperty(remoteIOUnit,
                         kAURemoteIOProperty_SetEnableInput,
                         kAudioUnitScope_Global,
                         0,
                         &enableInput,
                         sizeof(enableInput));

    UInt32 enableOutput = 1; 
    AudioUnitSetProperty(remoteIOUnit,
                         kAURemoteIOProperty_SetEnableOutput,
                         kAudioUnitScope_Global,
                         0,
                         &enableOutput,
                         sizeof(enableOutput));
    
    // 确保连接正确并且 audio format 设置妥当。
}

3. 检查音频流格式

确保你设置的音频格式在输入和输出中是一致的。如果你定义了某个特定的 AVAudioFormat,确保所有节点都能接受该格式,并且它们之间能正常工作。

4. 调试信息

添加日志以捕获重要状态信息,以便在调试时能够清楚看到当前所用音频格式以及是否有任何异常:

NSLog(@"Sample Rate: %f, Channels: %lu", audioFormat.sampleRate, (unsigned long)audioFormat.channelCount);

示例完整代码片段

下面是一个简化版,可以参考如何初始化 AURemoteIO 和设置相关参数:

#import <AVFoundation/AVFoundation.h>

// 在合适的位置(如视图控制器中)进行初始化
- (void)setupRemoteIO {
    AudioComponentDescription desc;
    desc.componentType = kAudioUnitType_Output;
    desc.componentSubType = kAudioUnitSubType_RemoteIO;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;

    AudioComponent comp = AudioComponentFindNext(NULL, &desc);
    
    if (comp) {
        AudioUnit remoteIOUnit;
        OSStatus status = AudioComponentInstanceNew(comp, &remoteIOUnit);
        if (status != noErr) {
            NSLog(@"Error creating AURemoteIO instance: %d", status);
            return; 
        }

        // 启用输入和输出
        UInt32 enableInput = 1; 
        status = AudioUnitSetProperty(remoteIOUnit,
                                      kAURemoteIOProperty_SetEnableInput,
                                      kAudioUnitScope_Global,
                                      0,
                                      &enableInput,
                                      sizeof(enableInput));
        
        UInt32 enableOutput = 1; 
        status |= AudioUnitSetProperty(remoteIOUnit,
                                       kAURemoteIOProperty_SetEnableOutput,
                                       kAudioUnitScope_Global,
                                       0,
                                       &enableOutput,
                                       sizeof(enableOutput));

        AVAudioFormat *audioFormat =
            [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
                                               sampleRate:44100.0 // 有效采样率
                                                 channels:2];
        
       // 后续设置相关参数...
        
       NSLog(@"Remote IO setup with Sample Rate: %f and Channels: %lu",
             audioFormat.sampleRate, (unsigned long)audioFormat.channelCount);
       
       // 开始处理音频...
       OSStatus startStatus = AudioOutputUnitStart(remoteIOUnit);
       if (startStatus != noErr) {
           NSLog(@"Error starting Remote IO Unit: %d", startStatus);
       }
   } else {
       NSLog(@"No Remote IO component found");
   }
}

如果这些步骤不能解决您的问题,请提供更多代码或上下文,以便更深入地分析。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=21238

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?