iOS AKMIDISampler 没有音频输出

标签 ios avfoundation audiokit

我在 iOS (11.3) 上使用带有音色字体的 AKMIDISampler,但我无法获得音频输出。 目前,设置是最小的:

    midiSampler = AKMIDISampler()
    samplerVolume = AKBooster(midiSampler)
    mixer.connect(input: samplerVolume)

    let bundlePath = Bundle.main.bundlePath
    let soundPath = ("\(bundlePath)/Sounds/GigaPiano")
    do { _ = try self.midiSampler.loadSoundFont(soundPath, preset: 0, bank: 0) }
    catch { print("Error loading soundfont") }

    mixer.start()
    AudioKit.output = mixer
    do {
        _ = try AudioKit.engine.start()
    } catch {
        print("AudioKit wouldn't start!")
    }
    midiSampler.enableMIDI()

在 AKMIDISampler.handleMIDI() 中设置断点表明 MIDI 数据正在到达那里,因此它似乎一定是音频问题。加载音色没有错误。此外,出于绝望,我添加了 AKBooster,仅仅是因为它出现在示例应用程序中;没有它也一样。

关于如何调试它的任何提示?

更新:

如评论中所述,我确实有音频,但非常安静、失真,并且通过主 iPhone 扬声器——只有听筒。我当前的最小代码(对声音字体加载有一些防御)是:

    midiSampler = AKMIDISampler()
    mixer = AKMixer(midiSampler)
    let bundlePath = Bundle.main.bundlePath
    let soundPath = ("\(bundlePath)/Sounds/KorgTritonPiano")
    do { _ = try self.midiSampler.loadSoundFont(soundPath, preset: 0, bank: 0) }
    catch {
        print("Failed in loadSoundFont. Try loadMelodicSoundFont...")
        do { _ = try self.midiSampler.loadMelodicSoundFont(soundPath, preset: 0) }
        catch { print("Error loading soundfont") }
    }
    AudioKit.output = mixer
    do { try AKSettings.setSession(category: .playAndRecord, with: .mixWithOthers) }
    catch { print("Can't update session info...") }
    do {
        _ = try AudioKit.start()
    } catch {
        print("AudioKit wouldn't start!")
    }
    midiSampler.enableMIDI()

正如评论中还提到的那样,最小的 AKOscillator 和一个直接连接到 AudioKit.output 的 AKEnvelope 确实会从扬声器发出声音。所以这与 AKMIDISampler 或 AKSampler(?) 有关。我注意到这个问题过去曾出现过并已关闭,但也许 iOS 11.3 正在重新打破某些东西?

由于 GitHub 页面要求我们确认此处的问题,我真的希望 AudioKit 的人能够做出回应(这样我就可以避免发布到 GitHub)。我一直在类层次结构中上下移动,试图找出它可能失败的地方,但我一无所获。

如果有帮助,我正在使用 iOS 11.3(测试版 15E5201e)、Xcode 9.3 测试版 4、macOS 10.13.4 测试版 4。由于 11.3 和 10.13.4 似乎现在已发布,我将在今晚晚些时候更新.如果 iOS 或 Xcode 版本是已知问题,我假设它会出现在 GitHub 上,但没有任何记录。

更新 2:将 Xcode、iOS、macOS 更新到最新版本,没有任何变化。

更新 3: 使用 AVAudioSession.sharedInstance().currentRoute.outputs 记录设备, 从 AKMIDIPlayer.handleMIDI() , 表示选择了扬声器。我完全被难住了。这可能是 Apple 的错误吗?

更新 4: 故意将输出设置为 PlayAndRecord (即 <Device: Receiver (Built-In Receiver)> )不输出任何内容,并将其设置为扬声器输出到接收器。也许我的开发手机中风了... SubUpdate: 不,在另一部 iPhone 上验证了相同的行为。我受够了。将看看我是否可以从我的项目中拉出 AK 并直接从 AVFoundation 构建采样器。和我看到的没什么不同。至少到那时我会确定 AK 是否参与其中。

更新 5:基于 AVAudioUnitSampler 编写了一个完全非 AudioKit 版本。同样的问题。同样奇怪的是 session.currentRoute报告它正在向扬声器播放(实际上不是)。是否有可能是 Xcode 项目中的某些东西导致了这种情况?如果有人有任何想法或想法,我们将不胜感激任何和所有帮助。

最佳答案

AudioKit 4.2 中新的 AKSampler 解决了我的问题!也许不完全是一个“答案”,但绝对是一个解决方案,绝对是一个“采样器”,而且绝对是在 AudioKit 中。所以希望对其他人有帮助。

关于iOS AKMIDISampler 没有音频输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49549611/

相关文章:

ios - UICollectionViewCell 不保留 ARC

带有 AVCaptureVideoDataOutput 的 iOS 应用程序在 App Store 版本中崩溃

ios - 使用预编译框架更新 AudioKit for Swift 5

ios - 导入 AudioKit 框架给出 "' x' is not a member type of 'AudioKit' 错误

ios - 什么是 iOS 包 ID

android - 是否有可能在 Flutter 中动态启动 Firebase?

ios - 使用 Xcode 4 部署到 iOS 3.1.3 设备

ios - 检测带有圆角的卡片边缘

ios - 无法在 swift 2 中使用 AVCaptureVideoDataOutput 通过 CGDataProviderCopyData 获取像素数据

swift - 有没有办法在 watchOS 上运行 AudioKit?