使用 AKKeyboardView 的钢琴音符

Piano notes with AKKeyboardView

我是 AudioKit 的新手 - 我可以使用 AKKeyboardView 使用 AKOscillatorBank 来弹奏音符,但我希望音频听起来更像三角钢琴。加载 .wav 文件似乎会使音符断断续续。我也改变了便条信封。如何将大钢琴音符映射到 AKKeyboardView 键上?

您不容易从振荡器中获得钢琴音色。您可能想改用 soundfont。您可以将 sf2(我相信不是 sf3)加载到 AKAppleSampler 中,并使用 AKKeyboardDelegate 触发它,就像您对 AKOscillatorBank 所做的那样。 MuseScore has list of soundfont file links,其中许多使用开源许可证。

首先将 sf2 文件添加到您的项目中,然后设置 AKAppleSampler:

let sampler = AKAppleSampler()
// note that if you're using a GM soundfont, 'Grand Piano' will be preset 0
sampler.loadMelodicSoundFont("NameOfSoundFontWithoutExtension", preset: 0)