尝试使用Audiokit中的AKMIDISampler调试神秘的正弦波 [英] Trying to debug mystery sinewave using AKMIDISampler in Audiokit

查看:125
本文介绍了尝试使用Audiokit中的AKMIDISampler调试神秘的正弦波的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着是上一页问题,我不再使用AKSampler转到AKMIDISampler中使用的功能.让我的循环再次起作用(在此 Google网上论坛帖子的帮助下) ,但我正在播放正弦波(当MIDISampler找不到源文件时会发生这种情况).

Following on from a previous issue, I stopped using AKSampler to move to the functionality used in AKMIDISampler. Got my loops working again (with help from this Google Groups post), but I have a sinewave playing (which happens when the MIDISampler can't find it's source file).

我定位的源文件不是问题,因为它们都可以正常播放.正弦波来自过程中的其他位置,但是我看不到哪里...

It's not an issue with the source files I'm targeting because they all play OK. The sinewave is coming from somewhere else in the process, but I can't see where...

请帮助8•)

(经过简化和编辑的代码仅显示相关详细信息-请与我们联系以取得澄清)

(Simplified and edited code to show only relevant details - please get in touch for any clarification)

var MIDISamplePlayer = AKMIDISampler()
var sequencer: AKSequencer?
var mixer: AKMixer!

// initialise the mixer
mixer = AKMixer()

do  {
        audiofile = try AKAudioFile(readFileName: SoundFilename as! String, 
        baseDir: .resources)
    } catch let error as NSError {
        print("There's an error: \(error)")
    }

do {
       try sprite.MIDISamplePlayer.loadAudioFile(audiofile)
    } catch let error as NSError {
       print("There's an error: \(error)")
    }

sprite.tracker = AKAmplitudeTracker(sprite.MIDISamplePlayer)
mixer.connect(to:sprite.tracker, bus: mixer.nextInput.bus)

sequencer = AKSequencer(filename: POPmidi)
sequencer?.enableLooping()

let midi = AKMIDI()

for i in 0..<popCount {
    gPOPs[i].MIDISamplePlayer.enableMIDI(midi.client, name: "MIDISample_\(i)")
    mixer.connect(gPOPs[i].MIDISamplePlayer)
    sequencer!.tracks[i].setMIDIOutput(gPOPs[i].MIDISamplePlayer.midiIn)
}

AudioKit.start()
sequencer!.play()

推荐答案

我发现了此问题的原因.我了解到,当给MIDI音序器一定数量的MIDI音轨时,它会创建一个额外的音轨.在我的midi文件中有4首曲目时,音序器给了我5首.这条额外的曲目是针对节奏的(如在此处找到).

I found out the cause of this issue. I learnt that the MIDI sequencer was creating an extra track when I gave it a specific number of MIDI tracks; for four tracks in my midi file, the sequencer was giving me five. This extra track is for tempo (as discovered here).

我还了解到,我的第一首曲目已从我的.plist文件中忽略了(在该文件中,我设置了不同歌曲的词干)...........................................................................................................................................................................

I also learnt that my first track was being ignored from my .plist (where I set up the stems for different songs).

我假设第一个音轨用于速度音轨,并且在.plist中创建了五个音轨以匹配音序器时,正弦波音消失了.

My assumption that the first track is being used for the tempo track was tested, and when I created five tracks in my .plist to match the sequencer, the sinewave tone disappeared.

这导致了变通办法.为此,我复制了.plist中的第一个样本(无论如何都将其忽略),然后将表示此声音的精灵隐藏在屏幕外.目前,此方法有效,但是如果有人对如何控制此速度轨道及其在AKSequencer中的用法有任何想法,我想知道更多.

This lead to a workaround hack. I did this by duplicating the first sample in my .plist, which was being ignored anyway, and then hiding the sprite that represented this sound off screen. This works for now, but if anyone has an idea of how to control this tempo track and its use in AKSequencer I’d love to know more.

简而言之: 确保MIDI文件具有您要使用的确切曲目数量.创建相同数量的AKMIDISampler以在AKSequencer中使用,为速度轨道添加一个.然后请注意,音序器中的第一个音轨是速度音轨,将无法播放样本.

So in short: Make sure that the MIDI file has exact number of tracks that you want to use. Create the same number of AKMIDISampler to use in AKSequencer adding one for tempo track. Then beware that the first track in the sequencer is the tempo track and will not work playing samples.

这篇关于尝试使用Audiokit中的AKMIDISampler调试神秘的正弦波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆