我目前正在创建一个音乐应用程序,您可以在其中添加新乐器作为音乐序列的曲目。
以下是我添加新曲目时的内容:
MusicPlayerStop(_musicPlayer);
status = MusicSequenceNewTrack(sequence, &tracks[tracksCount]);
timeDiff = 32.f/_tempo;
[self setLoopDuration:currentLoopDuration forPattern:tracks[tracksCount]];
AudioComponentDescription samplerNodeDesc;
samplerNodeDesc.componentManufacturer = (OSType)kAudioUnitManufacturer_Apple;
samplerNodeDesc.componentType = (OSType)kAudioUnitType_MusicDevice;
samplerNodeDesc.componentSubType = (OSType)kAudioUnitSubType_Sampler;
samplerNodeDesc.componentFlags = 0;
samplerNodeDesc.componentFlagsMask = 0;
status = AUGraphAddNode(graph, &samplerNodeDesc, &auNodes[tracksCount]);
status = AUGraphNodeInfo(graph, auNodes[tracksCount], 0, &audioUnits[tracksCount]);
status = AUGraphConnectNodeInput(graph, auNodes[tracksCount], 0, filterNode, 0);
status = MusicTrackSetDestNode(tracks[tracksCount], auNodes[tracksCount]);
int trackId = tracksCount;
tracksCount++;
MusicPlayerStart(_musicPlayer);
return trackId;
以下根本不会产生音频,我可以在这做什么。
非常感谢!
答案 0 :(得分:0)
您需要致电AUGraphUpdate(graph, nil)
;或者,如果你希望图形被阻塞直到它已经添加,你就会为它提供一个指向布尔值的指针,调用线程将等待音频线程添加音频单元。
Boolean updated;
AUGraphUpdate(graph, &updated); //will block until end of next audio cycle
if (updated){
printf("hooray\n");
}