2012-01-20 60 views
3

我试图设置一个高通滤波器,但AUGraphStart给我-10863,当我尝试。我根本找不到多少文件。这里是我设置过滤器的意图:为CoreAudio设置效果音频单元

- (void)initializeAUGraph{ 
    AUNode outputNode; 
    AUNode mixerNode; 
    AUNode effectNode; 
    NewAUGraph(&mGraph); 
    // Create AudioComponentDescriptions for the AUs we want in the graph 
    // mixer component 
    AudioComponentDescription mixer_desc; 
    mixer_desc.componentType = kAudioUnitType_Mixer; 
    mixer_desc.componentSubType = kAudioUnitSubType_AU3DMixerEmbedded; 
    mixer_desc.componentFlags = 0; 
    mixer_desc.componentFlagsMask = 0; 
    mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple; 
    // output component 
    AudioComponentDescription output_desc; 
    output_desc.componentType = kAudioUnitType_Output; 
    output_desc.componentSubType = kAudioUnitSubType_RemoteIO; 
    output_desc.componentFlags = 0; 
    output_desc.componentFlagsMask = 0; 
    output_desc.componentManufacturer = kAudioUnitManufacturer_Apple; 
    //effect component 
    AudioComponentDescription effect_desc; 
    effect_desc.componentType = kAudioUnitType_Effect; 
    effect_desc.componentSubType = kAudioUnitSubType_HighPassFilter; 
    effect_desc.componentFlags = 0; 
    effect_desc.componentFlagsMask = 0; 
    effect_desc.componentManufacturer = kAudioUnitManufacturer_Apple; 
    // Add nodes to the graph to hold our AudioUnits 
    AUGraphAddNode(mGraph, &output_desc, &outputNode); 
    AUGraphAddNode(mGraph, &mixer_desc, &mixerNode); 
    AUGraphAddNode(mGraph, &effect_desc, &effectNode); 
    // Connect the nodes 
    AUGraphConnectNodeInput(mGraph, mixerNode, 0, effectNode, 0); 
    AUGraphConnectNodeInput(mGraph, effectNode, 0, outputNode, 0); 
    //Open Graph 
    AUGraphOpen(mGraph); 
    // Get a link to the mixer AU 
    AUGraphNodeInfo(mGraph, mixerNode, NULL, &mMixer); 
    // Get a link to the effect AU 
    AUGraphNodeInfo(mGraph, effectNode, NULL, &mEffect); 
    //Setup buses 
    size_t numbuses = track_count; 
    UInt32 size = sizeof(numbuses); 
    AudioUnitSetProperty(mMixer, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &numbuses, size); 
    //Setup Stream Format Data 
    AudioStreamBasicDescription desc; 
    size = sizeof(desc); 
    // Setup Stream Format 
    desc.mSampleRate = kGraphSampleRate; 
    desc.mFormatID = kAudioFormatLinearPCM; 
    desc.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; 
    desc.mBitsPerChannel = sizeof(AudioSampleType) * 8; // AudioSampleType == 16 bit signed ints 
    desc.mChannelsPerFrame = 1; 
    desc.mFramesPerPacket = 1; 
    desc.mBytesPerFrame = sizeof(AudioSampleType); 
    desc.mBytesPerPacket = desc.mBytesPerFrame; 
    // Loop through and setup a callback for each source you want to send to the mixer. 
    for (int i = 0; i < numbuses; ++i) { 
     // Setup render callback struct 
     AURenderCallbackStruct renderCallbackStruct; 
     renderCallbackStruct.inputProc = &renderInput; 
     renderCallbackStruct.inputProcRefCon = self; 
     // Connect the callback to the mixer input channel 
     AUGraphSetNodeInputCallback(mGraph, mixerNode, i, &renderCallbackStruct); 
     // Apply Stream Data 
     AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,i,&desc,size); 
     AudioUnitSetParameter(mMixer, k3DMixerParam_Distance, kAudioUnitScope_Input, i, rand() % 6, 0); 
     rotation[i] = rand() % 360; 
     rotation_speed[i] = rand() % 5; 
     AudioUnitSetParameter(mMixer, k3DMixerParam_Azimuth, kAudioUnitScope_Input, i, rotation[i], 0); 
     AudioUnitSetParameter(mMixer, k3DMixerParam_Elevation, kAudioUnitScope_Input, i, 30, 0); 
    } 
    // Reset stream fromat data to 0 
    memset (&desc, 0, sizeof (desc)); 
    // Setup output stream format 
    desc.mSampleRate = kGraphSampleRate; 
    // Apply Stream Data to Output 
    AudioUnitSetProperty(mEffect,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,0,&desc,size); 
    AudioUnitSetProperty(mEffect,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Output,0,&desc,size); 
    AudioUnitSetProperty(mMixer,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Output,0,&desc,size); 
    //All done so initialise 
    AUGraphInitialize(mGraph); 
} 

它可以工作,当我删除高通滤波器。我如何获得过滤器的工作?

谢谢。

PS:3D立面应该什么都不做?

+0

我已经得到了这个10863错误之前。“kAudioUnitErr_CannotDoInCurrentContext”http://developer.apple.com/library/mac/#documentation/AudioUnit/Reference/AUComponentServicesReference/Reference/reference.html。我还没有找到详细的解释,但 – dubbeat

回答

1

并非所有在OSX上可用的音频单元均可在iOS上使用。实际上,只有少数是。根据以下文档,iOS不支持高通滤波器效果:http://developer.apple.com/library/ios/#documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/UsingSpecificAudioUnits/UsingSpecificAudioUnits.html#//apple_ref/doc/uid/TP40009492-CH17-SW1

“iPod EQ单元(子类型kAudioUnitSubType_AUiPodEQ)是iOS 4中提供的唯一效果单元。”

请注意,它提到了iOS4。但是我无法找到任何关于iOS的更新版本的文档。

+1

没有(这是超级过时)。但是从iOS 5开始,iOS中也有很多新的效果单元。 –

3

如果你仍然有问题...你应该在mixernode和效果节点之间添加一个转换器单元,并将它的输入格式设置为混音器输出和输出格式为你从audiounitgetproperty获得的格式(converternode )