我正在使用 MusicPlayer API。我知道当您将 .mid 作为序列加载时,API 会为您创建一个默认的 AUGraph,其中包括一个 AUSampler。这个 AUSampler 使用一个简单的基于正弦波的乐器来合成 .mid 中的音符
我的问题是,如何更改 AUSampler 中的默认乐器?我知道您可以使用 SoundFont2 文件 (.sf2) 并使用 AudioUnitSetProperty 方法添加它们。但是,如何访问这个默认的 AUGraph?您是否必须先打开图表才能编辑 AudioUnit,或者打开图表只是为了编辑节点之间的连接?
谢谢:)
最佳答案
我已经写了一个教程,但是 here但这里是流程的概要:
加载声音字体文件的函数(取自 Apple 文档):
-(OSStatus) loadFromDLSOrSoundFont: (NSURL *)bankURL withPatch: (int)presetNumber {
OSStatus result = noErr;
// fill out a bank preset data structure
AUSamplerBankPresetData bpdata;
bpdata.bankURL = (__bridge CFURLRef) bankURL;
bpdata.bankMSB = kAUSampler_DefaultMelodicBankMSB;
bpdata.bankLSB = kAUSampler_DefaultBankLSB;
bpdata.presetID = (UInt8) presetNumber;
// set the kAUSamplerProperty_LoadPresetFromBank property
result = AudioUnitSetProperty([pointer to your AUSampler node here],
kAUSamplerProperty_LoadPresetFromBank,
kAudioUnitScope_Global,
0,
&bpdata,
sizeof(bpdata));
// check for errors
NSCAssert (result == noErr,
@"Unable to set the preset property on the Sampler. Error code:%d '%.4s'",
(int) result,
(const char *)&result);
return result; }
然后您需要从资源文件夹中加载声音字体:
NSURL *presetURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Name of sound font" ofType:@"sf2"]];
// Initialise the sound font
[self loadFromDLSOrSoundFont: (NSURL *)presetURL withPatch: (int)10];
希望这对您有所帮助!
关于iphone - 如何编辑 AUGraph 的默认工具?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9789179/