播放我使用的是 AVAudioUnitSampler:
sampler.stopNote(note, onChannel: channel)
但要停止我不想使用:
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(0.7 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC))
{
sampler.stopNote(note, onChannel: channel)
}
什么是更好的解决方案? 谢谢
最佳答案
您可以创建一个 MusicSequence,其中的每个事件都将由 MusicPlayer 安排。
您可以使用 AVMIDIPlayer,但您需要将 MusicSequence 转换为数据,因为它不会直接理解 MusicSequence。
如果您想通过按下按钮来模拟音符打开并通过按钮释放来模拟音符关闭,请使用 MusicDeviceMIDIEvent。
let status = MusicDeviceMIDIEvent(midisynthUnit, noteCommand, noteNum, velocity, 0)
您可能想阅读 this有关使用 AVAudioUnitSampler 的更多信息。
关于ios - 如何播放具有确定持续时间的 MIDI 音符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40958659/