使用AKSequencer和AKSampler链接无声音
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用AKSequencer和AKSampler链接无声音相关的知识,希望对你有一定的参考价值。
我正在使用AudioKit 4.9.5。我正在尝试使用AKSequencer播放音阶。
这是我使用AudioKit的方式。初始化:
AKAudioFile.cleanTempDirectory()
AKSettings.bufferLength = .medium
AKSettings.playbackWhileMuted = true
AKSettings.audioInputEnabled = true
tracker = AKFrequencyTracker(mic)
silence = AKBooster(tracker, gain: 0)
try? AKSettings.setSession(category: .playAndRecord,
with: [.defaultToSpeaker, .mixWithOthers])
mixer = AKMixer(silence, conductor.sampler)
AudioKit.output = mixer
接下来,我正在初始化导体:
init() {
let info = ProcessInfo.processInfo
let begin = info.systemUptime
let soundsFolder = Bundle.main.bundleURL.path
AKSettings.bufferLength = .medium
AKSettings.enableLogging = true
// Signal Chain
sampler = AKSampler()
sampler.loadSFZ(path: soundsFolder, fileName: "Sax.sfz")
sampler.attackDuration = 0.01
sampler.decayDuration = 0.1
sampler.sustainLevel = 0.8
sampler.releaseDuration = 0.5
sequencer = Sequencer(name: "Scale", targetNode: sampler)
let elapsedTime = info.systemUptime - begin
print("Time to setup sampler (elapsedTime) seconds")
}
最后,我的自定义音序器:
self.name = name
self.targetNode = targetNode
self.track = AKSequencerTrack(targetNode: targetNode) //target node is my sampler
self.sequencer = AKSequencer(targetNode: targetNode) //target node is my sampler
这就是我创建曲目的方式:
let newTrack = AKSequencerTrack(targetNode: targetNode)
for step in track.steps {
for note in step.notes {
newTrack.add(noteNumber: MIDINoteNumber(note.rawValue), position: step.position, duration: step.duration)
}
}
self.track = sequencer.addTrack(for: newTrack)
sequencer.tempo = tempo.bpm
sequencer.length = newTrack.length
sequencer.loopEnabled = loopEnabled
我不知道为什么没有声音。也许我在节点链接上缺少某些内容?
答案
只需要轨道在信号链中,就像我在这里的答案:How to play MIDI with AudioKit's new AKSequencer
另一答案
这是一个工作的样本伪人:
let sequencerMixer = AKMixer()
let sampler = AKSampler()
...
sequencer = AKSequencer(targetNode: sampler)
...
let newTrack = sequencer.addTrack(for: sampler)
newTrack >>> sequencerMixer
...
AudioKit.output = AKMixer(sequencerMixer, sampler)
以上是关于使用AKSequencer和AKSampler链接无声音的主要内容,如果未能解决你的问题,请参考以下文章
如何将 AKSequencer 连接到 AKCallbackInstrument?
如何使用 Audiokit 可视化当前的 AKSequencer 位置?