我正在iOS中学习AudioUnits并试图实现这样的图表:
------------------- ----------------- | | | | -->| FormatConverter | --->| bus 0 | | (Varispeed) | | | -------------------- | Multichannel | -------------------- | Mixer Unit | | | | | -------------------- -->| FormatConverter | --->| bus 1 | | | | (Varispeed) | | | --->| Remote IO | -----> -------------------- | | | Unit | -------------------- | | | | | | | | -------------------- ->| FormatConverter | --->| bus 2 | | (Varispeed) | | | --------------------- | | -----------------
首先,我尝试使用没有kAudioUnitSubType_Varispeed单元的AudioUnits。它工作正常,声音播放。 但现在我想实现每个声音的音高(单独),这就是为什么我决定添加Varispeed单位来控制每个声音的音高。
我正在使用以下代码:
OSStatus result = noErr; //............................................................................ // Specify the audio unit component descriptions for the audio units to be // added to the graph. // I/O unit AudioComponentDescription iOUnitDescription; iOUnitDescription.componentType = kAudioUnitType_Output; iOUnitDescription.componentSubType = kAudioUnitSubType_RemoteIO; iOUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; iOUnitDescription.componentFlags = 0; iOUnitDescription.componentFlagsMask = 0; // Multichannel mixer unit AudioComponentDescription MixerUnitDescription; MixerUnitDescription.componentType = kAudioUnitType_Mixer; MixerUnitDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer; MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; MixerUnitDescription.componentFlags = 0; MixerUnitDescription.componentFlagsMask = 0; // Varispeed unit AudioComponentDescription varispeedUnitDescription; MixerUnitDescription.componentType = kAudioUnitType_FormatConverter; MixerUnitDescription.componentSubType = kAudioUnitSubType_Varispeed; MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; MixerUnitDescription.componentFlags = 0; MixerUnitDescription.componentFlagsMask = 0; //............................................................................ // Add nodes to the audio processing graph. NSLog (@"Adding nodes to audio processing graph"); AUNode iONode; // node for I/O unit AUNode mixerNode; // node for Multichannel Mixer unit AUNode varispeedNode0; AUNode varispeedNode1; AUNode varispeedNode2; //............................................................................ // Create a new audio processing graph. result = NewAUGraph(&processingGraph); if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;} //............................................................................ // Open the audio processing graph result = AUGraphOpen(processingGraph); if (noErr != result) { [self printErrorMessage: @"AUGraphOpen" withStatus: result]; return; } //............................................................................ // Add the nodes to the audio processing graph result = AUGraphAddNode( processingGraph, &varispeedUnitDescription, &varispeedNode0); if (noErr != result) { [self printErrorMessage: @"AUGraphNewNode failed for varispeedNode0 unit" withStatus: result]; return; } result = AUGraphAddNode ( processingGraph, &varispeedUnitDescription, &varispeedNode1); if (noErr != result) { [self printErrorMessage: @"AUGraphNewNode failed for varispeedNode1 unit" withStatus: result]; return; } result = AUGraphAddNode ( processingGraph, &varispeedUnitDescription, &varispeedNode2); if (noErr != result) { [self printErrorMessage: @"AUGraphNewNode failed for varispeedNode2 unit" withStatus: result]; return; } result = AUGraphAddNode ( processingGraph, &iOUnitDescription, &iONode); if (noErr != result) { [self printErrorMessage: @"AUGraphNewNode failed for I/O unit" withStatus: result]; return; } result = AUGraphAddNode ( processingGraph, &MixerUnitDescription, &mixerNode); if (noErr != result) { [self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return; }
当我运行app时,我遇到以下错误:
2013-04-24 21:44:59.335 Drumpads[327:c07] *** AUGraphNewNode failed for varispeedNode0 unit error: ˇˇ¯+ 2013-04-24 21:44:59.338 Drumpads[327:c07] Error.domain = NSOSStatusErrorDomain, code=-2005, descr =Error Domain=NSOSStatusErrorDomain Code=-2005 "The operation couldn’t be completed. (OSStatus error -2005.)"
根据MacErrors.h -2005表示'badComponentType'。
所以似乎Varispeed Unit甚至无法添加到AUGraph。一切似乎都是正确的,所以我不知道为什么添加Varispeed节点会导致错误。
我使用sample code from developers.apple.com代码作为参考(我知道,它适用于OSx,但Varispeed现在可用于iOS5和6,因此我决定可以使用此代码作为参考)。
我需要控制每个声音的音高变化。我选择了Varispeed,但我也读过NewTimePitch Nodes。我尝试过NewTimePitch(在同一图表中),但也没有成功。
有人知道我的代码有什么问题吗?为什么添加Varispeed Node会导致错误?
提前致谢!
答案 0 :(得分:2)
经过一天的研究并试图找到有关FormatConverter和Varispeed的更多信息并阅读大量信息后,我终于找到了答案。
当然很难解决它,但幸运的是我! LOL
这是我以前的代码:
AudioComponentDescription varispeedUnitDescription;
MixerUnitDescription.componentType = kAudioUnitType_FormatConverter;
MixerUnitDescription.componentSubType = kAudioUnitSubType_Varispeed;
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
MixerUnitDescription.componentFlags = 0;
MixerUnitDescription.componentFlagsMask = 0;
这是新的:
AudioComponentDescription varispeedUnitDescription;
varispeedUnitDescription.componentType = kAudioUnitType_FormatConverter;
varispeedUnitDescription.componentSubType = kAudioUnitSubType_Varispeed;
varispeedUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
varispeedUnitDescription.componentFlags = 0;
varispeedUnitDescription.componentFlagsMask = 0;
所以...这是非常糟糕的组件类型(-2005),因为varispeedUnitDescription实际上没有被正确描述。