在iOS6中使用Arisraph的Varispeed audiounit
我正在学习iOS中的AudioUnits并试图实现这样的图形:
------------------- ----------------- | | | | -->| FormatConverter | --->| bus 0 | | (Varispeed) | | | -------------------- | Multichannel | -------------------- | Mixer Unit | | | | | -------------------- -->| FormatConverter | --->| bus 1 | | | | (Varispeed) | | | --->| Remote IO | -----> -------------------- | | | Unit | -------------------- | | | | | | | | -------------------- ->| FormatConverter | --->| bus 2 | | (Varispeed) | | | --------------------- | | -----------------
首先,我尝试在没有kAudioUnitSubType_Varispeed Unit的情况下使用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; }
当我运行应用程序时,出现以下错误:
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节点会导致错误。
我使用了来自developers.apple.com代码的示例代码作为参考(我知道,这是针对OSx的,但Varispeed现在可用于iOS5和6,因此我决定使用此代码作为参考)。
我需要控制每个声音的音高变化。 我选择了Varispeed,但我也读过NewTimePitch节点。 我试过NewTimePitch(在同一张图中),但也没有成功。
有人知道我的代码有什么问题,以及为什么添加Varispeed节点会导致错误?
提前致谢!
经过一天的研究,并试图找到更多有关FormatConverter和Varispeed的信息,并阅读了很多信息,我终于找到了答案。
当然,修理它是非常困难的,但幸运的是我! 大声笑
这是我以前的代码:
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实际上没有正确描述。
链接地址: http://www.djcxy.com/p/62307.html上一篇: Varispeed audiounit to AUGraph in iOS6
下一篇: How to write Output of AUGraph to an External AudioFile of WAV or AIF formats?