iphone - 如何编辑 AUGraph 的默认工具?

标签 iphone c ios audio core-audio

我正在使用 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/

相关文章:

c - VxWorks 堆栈帧异常大

c - For 循环一直有效,直到我添加 printf(在 C 中)

ios - 如果稍后将 Storyboard 添加到项目中,为什么 singleView 应用程序不加载 Storyboard ?

iphone - iOS项目如何继承XIB文件?

c - 局部数组和数组索引变量如何存在于内存中?

ios - 如何将 ios 项目目标从 9.2 设置为 9.3?

ios - 使用 Realm 对象保存用户

iphone - 在 iOS5 中使用 Storyboard 时,如何将数据从一个文本字段传递到另一个文本字段?

iphone - 在 willAnimateRotationToInterfaceOrientation 中禁用动画?

ios - UITextView UITextViewTextDidChangeNotification 未在文本的编程更改中调用