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:CreateRecordingTap: (Is...

根据您提供的错误信息,AURemoteIO.cppAVAEInternal.h 中出现的问题与音频格式的采样率和通道数有关。具体来说,错误信息表明您尝试使用的音频格式在输入或输出中具有无效的设置。

错误分析

  1. 采样率为0

    • 错误日志显示“0 Hz”,这表示您传递给 AVAudioFormat 的采样率是 0。这是不合法的,因为有效的采样率必须是正数(如 44100 Hz 或 48000 Hz)。
  2. 通道配置

    • 输入和输出都应该有相同数量的通道。确保您的音频配置中输入和输出节点的通道数量一致。

解决方案

请检查并修改您的代码以确保以下几点:

  1. 正确设置采样率: 确保在创建 AVAudioFormat 时为其指定一个有效且非零的采样率。例如:
   // 创建一个有效的音频格式
   AVAudioFormat *audioFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
                                                               sampleRate:44100.0 // 设置一个有效的采样率,例如44100Hz
                                                                 channels:2];     // 使用两个通道(立体声)
  1. 检查 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));

       // 设置其它参数,如流类型、数据格式等...
       
       [self setAudioFormatForRemoteIO:remoteIOUnit withFormat:audioFormat];
       
       // 启动 AURemoteIO
       AudioOutputUnitStart(remoteIOUnit);
   }
  1. 确保节点连接正常

    • 在使用 AVAudioEngine 时,确保所有音频节点之间正确连接,并确认这些节点都能接受定义好的音频格式。
  2. 调试和测试

    • 打印出所使用的格式,以验证每一步设置是否正确:
      NSLog(@"Sample Rate: %f, Channels: %lu", audioFormat.sampleRate, (unsigned long)audioFormat.channelCount);
    
  3. 捕获异常

    • 使用异常处理来捕捉可能导致崩溃的操作,如下例所示,可以帮助更好地理解问题:
      @try {
          // 执行可能引发异常的方法
      } @catch (NSException *exception) {
          NSLog(@"Exception occurred: %@", exception);
      }
    

如果这些建议无法解决问题,请提供更多关于代码逻辑及调用上下文的信息,以便进行进一步分析。


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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?