我正在研究 iOS 中的 AudioUnits 并尝试实现这样的图表:
------------------ -----
| | | |
-->| 格式转换器 | --->| 总线 0 |
| (变速)| | |
-------------------- | 多通道 |
-------------------- | 搅拌机 |
| | | | --------------------
-->| 格式转换器 | --->| 巴士1 | | |
| (变速)| | | --->| 远程IO | ----->
-------------------- | | | 单位 |
-------------------- | | | |
| | | | --------------------
->| 格式转换器 | --->| 巴士2 |
| (变速)| | |
--------------------- | |
-----------------
首先,我尝试在没有 kAudioUnitSubType_Varispeed Unit 的情况下使用 AudioUnits。它工作正常,声音播放。但现在我想(分别)实现每个声音的音高,这就是为什么我决定添加变速单元来控制每个声音的音高。
我正在使用以下代码:
OSStatus 结果 = noErr;
//................................................................ ......................
// 指定音频单元的音频单元组件描述为
// 添加到图表中。
// 输入输出单元
AudioComponentDescription iOUnitDescription;
iOUnitDescription.componentType = kAudioUnitType_Output;
iOUnitDescription.componentSubType = kAudioUnitSubType_RemoteIO;
iOUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
iOUnitDescription.componentFlags = 0;
iOUnitDescription.componentFlagsMask = 0;
// 多通道混音器单元
AudioComponentDescription MixerUnitDescription;
MixerUnitDescription.componentType = kAudioUnitType_Mixer;
MixerUnitDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
MixerUnitDescription.componentFlags = 0;
MixerUnitDescription.componentFlagsMask = 0;
//变速单元
AudioComponentDescription varispeedUnitDescription;
MixerUnitDescription.componentType = kAudioUnitType_FormatConverter;
MixerUnitDescription.componentSubType = kAudioUnitSubType_Varispeed;
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
MixerUnitDescription.componentFlags = 0;
MixerUnitDescription.componentFlagsMask = 0;
//................................................................ ......................
// 将节点添加到音频处理图。
NSLog(@"添加节点到音频处理图");
AUNode iONode; // I/O 单元的节点
AUNode 混合器节点;// 多通道混合器单元的节点
AUNode 变速Node0;
AUNode 变速Node1;
AUNode 变速Node2;
//................................................................ ......................
// 创建一个新的音频处理图。
结果 = NewAUGraph(&processingGraph);
if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; 返回;}
//................................................................ ......................
// 打开音频处理图
结果 = AUGraphOpen(处理图);
if (noErr != result) {
[self printErrorMessage: @"AUGraphOpen" withStatus: result];
返回;
}
//................................................................ ......................
// 将节点添加到音频处理图中
结果 = AUGraphAddNode(
处理图,
&varispeedUnit描述,
&varispeedNode0);
if (noErr != result) {
[self printErrorMessage: @"AUGraphNewNode failed for varispeedNode0 unit" withStatus: result];
返回;
}
结果 = AUGraphAddNode (
处理图,
&varispeedUnit描述,
&varispeedNode1);
if (noErr != result) {
[self printErrorMessage: @"AUGraphNewNode failed for varispeedNode1 unit" withStatus: result];
返回;
}
结果 = AUGraphAddNode (
处理图,
&varispeedUnit描述,
&varispeedNode2);
if (noErr != result) {
[self printErrorMessage: @"AUGraphNewNode failed for varispeedNode2 unit" withStatus: result];
返回;
}
结果 = AUGraphAddNode (
处理图,
&iOUnit描述,
&iONode);
if (noErr != result) {
[self printErrorMessage: @"AUGraphNewNode failed for I/O unit" withStatus: result];
返回;
}
结果 = AUGraphAddNode (
处理图,
&MixerUnit描述,
&mixer节点);
if (noErr != result) {
[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result];
返回;
}
当我运行应用程序时,出现以下错误:
2013-04-24 21:44:59.335 Drumpads[327:c07] *** AUGraphNewNode 因 varispeedNode0 单元错误而失败:ˇˇ¯+ 2013-04-24 21:44:59.338 Drumpads[327:c07] Error.domain = NSOSStatusErrorDomain, code=-2005, descr =Error Domain=NSOSStatusErrorDomain Code=-2005 “操作无法完成。(OSStatus 错误 - 2005 年。)”
根据 MacErrors.h -2005 表示“badComponentType”。
因此,似乎变速单元甚至无法添加到 AUGraph。一切似乎都正确,所以我不知道为什么添加变速节点会导致错误。
我使用了 developer.apple.com 代码中的示例代码作为参考(我知道,它适用于 OSx,但 Varispeed 现在可用于 iOS5 和 6,所以我决定可以使用此代码作为参考)。
我需要控制每个声音的音调变化。我选择了 Varispeed,但我也阅读了有关 NewTimePitch 节点的信息。我试过 NewTimePitch (在同一张图中),但也没有成功。
有谁知道我的代码有什么问题以及为什么添加变速节点会导致错误?
提前致谢!