ios - Inter App Audio 技术 : make effect node and instrument node independent

标签 ios objective-c core-audio avaudiosession

我正在编写一个使用 Core Audio 新 iOS 7 Inter App Audio 技术 的 HOST 应用程序。在 Inter-App Audio Examples 的帮助下,我设法获得了乐器应用程序和效果器应用程序。 .

问题在于效果节点 依赖 于乐器节点。我想使效果节点和乐器节点独立

这是我的尝试。

if (desc.componentType == kAudioUnitType_RemoteEffect) {
//            if ([self isRemoteInstrumentConnected]) {
                if (!_engineStarted)                                    // Check if session is active
                    [self checkStartOrStopEngine];
                
                if ([self isGraphStarted])                              // Check if graph is running and or is created, if so, stop it
                    [self checkStartStopGraph];
                
                if ([self checkGraphInitialized ])                      // Check if graph has been inititialized if so, uninitialize it.
                    Check(AUGraphUninitialize(hostGraph));
                
                Check (AUGraphAddNode (hostGraph, &desc, &effectNode)); // Add remote instrument

                //Disconnect previous chain
               // Check(AUGraphDisconnectNodeInput(hostGraph, mixerNode, remoteBus));
                
                //Connect the effect node to the mixer on the remoteBus
                Check(AUGraphConnectNodeInput (hostGraph, effectNode, 0, mixerNode, remoteBus));
                
                //Connect the remote instrument node to the effect node on bus 0
                Check(AUGraphConnectNodeInput (hostGraph, instrumentNode, 0, effectNode, 0));
                
                //Grab audio units from the graph
                Check(AUGraphNodeInfo(hostGraph, effectNode, 0, &effect));
                currentUnit = &effect;
            }

if (currentUnit) {
            Check (AudioUnitSetProperty (*currentUnit,                  // Set stereo format
                                         kAudioUnitProperty_StreamFormat,
                                         kAudioUnitScope_Output,
                                         playerBus,
                                         &stereoStreamFormat,
                                         sizeof (stereoStreamFormat)));
            UInt32 maxFrames = 4096;
            Check(AudioUnitSetProperty(*currentUnit,
                                       kAudioUnitProperty_MaximumFramesPerSlice,
                                       kAudioUnitScope_Global, playerBus,
                                       &maxFrames,
                                       sizeof(maxFrames)));
            
            [self addAudioUnitPropertyListeners:*currentUnit];          // Add property listeners to audio unit
            Check(AUGraphInitialize (hostGraph));                       // Initialize the graph

            [self checkStartStopGraph];                                 //Start the graph
        }
        
        [_connectedNodes addObject:rau];

但是我的应用程序在这一行崩溃了 --

Check(AUGraphInitialize (hostGraph));

我得到的错误,

ConnectAudioUnit failed with error

-10860 Initialize failed with error

-10860 error -10860 from AUGraphInitialize (hostGraph)


注意:- 为了更好地理解,我还附上了代码部分的屏幕截图。

enter image description here

编辑 1 :-

- (void)createGraph {
    // 1
    NewAUGraph(&hostGraph);

    // 2
    AudioComponentDescription iOUnitDescription;
    iOUnitDescription.componentType =
    kAudioUnitType_Output;
    iOUnitDescription.componentSubType =
    kAudioUnitSubType_RemoteIO;
    iOUnitDescription.componentManufacturer =
    kAudioUnitManufacturer_Apple;
    iOUnitDescription.componentFlags = 0;
    iOUnitDescription.componentFlagsMask = 0;
    AUGraphAddNode(hostGraph, &iOUnitDescription, &outNode);

    // 3
    AUGraphOpen(hostGraph);

    // 4
    Check(AUGraphNodeInfo(hostGraph, outNode, 0, &outputUnit));
    // 5
    AudioStreamBasicDescription format;
    format.mChannelsPerFrame = 2;
    format.mSampleRate =
    [[AVAudioSession sharedInstance] sampleRate];
    format.mFormatID = kAudioFormatLinearPCM;
    format.mFormatFlags =
    kAudioFormatFlagsNativeFloatPacked |
    kAudioFormatFlagIsNonInterleaved;
    format.mBytesPerFrame = sizeof(Float32);
    format.mBytesPerPacket = sizeof(Float32);
    format.mBitsPerChannel = 32;
    format.mFramesPerPacket = 1;

    AudioUnitSetProperty(mixerUnit,
                         kAudioUnitProperty_StreamFormat,
                         kAudioUnitScope_Output,
                         1,
                         &format,
                         sizeof(format));

    AudioUnitSetProperty(mixerUnit,
                         kAudioUnitProperty_StreamFormat,
                         kAudioUnitScope_Input,
                         0,
                         &format,
                         sizeof(format));
    CAShow(hostGraph);
}

最佳答案

所以你看到的错误,根据 apple docs , 是由于 找不到指定的节点

看起来您已经使用了您链接的 Apple 示例应用程序,只是删除了一点以尝试删除 1 个节点,但我不相信它那么简单。该示例的文档清楚地指出这两个节点是相关的。仅更改添加 remotes 方法是不够的,因为 host 仍在尝试创建两者,如您看到的错误所示。

从这里file在示例项目中,您只显示对 addRemoteAU 所做的更改,但您还需要对 createGraph 进行更改,因为那是 hostGraph 用它的节点初始化。如果您仅使用 1 个节点初始化图,那么在 addRemoteAU 中您应该不会再看到由于未找到节点而导致的错误,因为此时的图不会期望有两个节点(它会现在从它的创造)。

关于ios - Inter App Audio 技术 : make effect node and instrument node independent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256725/

相关文章:

ios - 创建 "add-player" View - Swift

ios - 在 Swift 中检查获取的对象是图像还是视频

ios - Cocoapod podspec引用iOS和OSX项目

objective-c - 以编程方式加载 nib2 时,从 nib1 调用 awakeFromNib

ios - AudioKit AKParametricEQ 滤波器类型

macos - kAudioDevicePropertyBufferFrameSizeRange返回{0,0}

ios - 使 UIImageView 透明并在触摸时显示其下方的 UIImageView

ios - Xcode 6.0/6.1 和使用客户端配置文件构建

IOS SDK - 如何截屏tableView的内容?

iphone - 使用AudioQueueStart()时延迟