简体   繁体   English

使用 AVAudioSequencer 将 MIDI 发送到第三方 AUv3 乐器

[英]Using AVAudioSequencer to send MIDI to third-party AUv3 instruments

I'm having trouble controlling third-party AUv3 instruments with MIDI using AVAudioSequencer (iOS 12.1.4, Swift 4.2, Xcode 10.1) and would appreciate your help.我在使用AVAudioSequencer (iOS 12.1.4、Swift 4.2、Xcode 10.1)通过 MIDI 控制第三方 AUv3 乐器时遇到问题,非常感谢您的帮助。

What I'm doing currently:我目前在做什么:

  • Get all AUs of type kAudioUnitType_MusicDevice .获取kAudioUnitType_MusicDevice类型的所有 AU。

  • Instantiate one and connect it to the AVAudioEngine .实例化一个并将其连接到AVAudioEngine

  • Create some notes, and put them on a MusicTrack .创建一些音符,并将它们放在MusicTrack

  • Hand the track data over to an AVAudioSequencer connected to the engine.将轨道数据AVAudioSequencer连接到引擎的AVAudioSequencer

  • Set the destinationAudioUnit of the track to my selected Audio Unit.将轨道的destinationAudioUnit设置为我选择的音频单元。

So far, so good, but...到目前为止,一切都很好,但是......

When I play the sequence using AVAudioSequencer it plays fine the first time, using the selected Audio Unit.当我使用AVAudioSequencer播放序列时,它第一次使用选定的音频单元播放正常。 On the second time I get either silence, or a sine wave sound (and I wonder who is making that).第二次我得到了沉默或正弦波的声音(我想知道是谁在做的)。 I'm thinking the Audio Unit should not be going out of scope in between playbacks of the sequence, but I do stop the engine and restart it again for the new round.我认为音频单元不应该在序列回放之间超出范围,但我确实停止了引擎并再次重新启动以进行新一轮。 (But it should even be possible to swap AUs while the engine is running, so I think this is OK.) (但甚至应该可以在引擎运行时交换 AU,所以我认为这没问题。)

Are there some steps that I'm missing?是否有一些我遗漏的步骤? I would love to include code, but it is really hard to condense it down to its essence from a wall of text.我很想包含代码,但真的很难从一堵文本墙将其浓缩为它的本质。 But if you want to ask for specifics, I can answer.但是如果你要问具体的,我可以回答。 Or if you can point me to a working example that shows how to reliably send MIDI to AUv3 using AVAudioSequencer , that would be great.或者,如果您可以向我指出一个工作示例,该示例展示了如何使用AVAudioSequencer可靠地将 MIDI 发送到 AUv3,那就太好了。

Is AVAudioSequencer even supposed to work with other Audio Units than Apple's? AVAudioSequencer甚至应该与 Apple 以外的其他音频单元一起使用吗? Or should I start looking for other ways to send MIDI over to AUv3?或者我应该开始寻找其他方式将 MIDI 发送到 AUv3?

I should add that I can consistently send MIDI to the AUv3 using the InstrumentPlayer method from Apple's AUv3Host sample, but that involves a concurrent thread, and results in all sorts of UI sync and timing problems.我应该补充一点,我可以使用 Apple 的 AUv3Host 示例中的InstrumentPlayer方法将 MIDI 始终发送到 AUv3,但这涉及并发线程,并导致各种 UI 同步和计时问题。

EDIT: I added an example project to GitHub: https://github.com/jerekapyaho/so54753738编辑:我在 GitHub 上添加了一个示例项目: https : //github.com/jerekapyaho/so54753738

It seems that it's now working in iPadOS 13.7, but I don't think I'm doing anything that different than earlier, except this loads a MIDI file from the bundle, instead of generating it from data on the fly.似乎它现在可以在 iPadOS 13.7 中运行,但我认为我没有做任何与之前不同的事情,除了从包中加载 MIDI 文件,而不是从动态数据生成它。

If someone still has iOS 12, it would be interesting to know if it's broken there, but working on iOS 13.x (x = ?)如果有人仍然有 iOS 12,那么知道它是否在那里坏了会很有趣,但是在 iOS 13.x (x = ?)

In case you are using AVAudioUnitSampler as an audio unit instrument, the sine tone happens when you stop and start the audio engine without reloading the preset.如果您使用AVAudioUnitSampler作为音频单元乐器,当您停止和启动音频引擎而不重新加载预设时,会发生正AVAudioUnitSampler Whenever you start the engine you need to load any instruments back into the sampler (eg a SoundFont), otherwise you may hear the sine.每当您启动引擎时,您都需要将任何乐器加载回采样器(例如 SoundFont),否则您可能会听到正弦音。 This is an issue with the Apple AUSampler, not with 3rd party instruments.这是 Apple AUSampler 的问题,而不是第 3 方乐器的问题。

Btw you can test it under iOS 12 using the simulator.顺便说一句,您可以使用模拟器在 iOS 12 下对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM