菜鸟教程小白 发表于 2022-12-11 19:56:51

iOS AKMIDISampler 没有音频输出


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

<pre><code>    midiSampler = AKMIDISampler()
    samplerVolume = AKBooster(midiSampler)
    mixer.connect(input: samplerVolume)

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

    mixer.start()
    AudioKit.output = mixer
    do {
      _ = try AudioKit.engine.start()
    } catch {
      print(&#34;AudioKit wouldn&#39;t start!&#34;)
    }
    midiSampler.enableMIDI()
</code></pre>

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

<p>关于如何调试它的任何提示?</p>

<p><strong>更新:</strong></p>

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

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

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

<p>由于 GitHub 页面要求我们确认此处的问题,我真的希望 AudioKit 的人能够回复(这样我就可以避免发布到 GitHub)。我一直在类层次结构上下,试图找出它可能失败的地方,但我什么也没想到。</p>

<p>如果有帮助,我使用的是 iOS 11.3 (beta 15E5201e)、Xcode 9.3 beta 4、macOS 10.13.4 beta 4。由于 11.3 和 10.13.4 似乎现在已经发布,我将在今晚晚些时候更新.如果 iOS 或 Xcode 版本是已知问题,我认为这会出现在 GitHub 上,但没有任何文档记录。</p>

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

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

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

<p><strong>更新 5:</strong> 编写了一个完全非 AudioKit 的版本,基于 AVAudioUnitSampler。同样的问题。同样奇怪的是 <code>session.currentRoute</code> 报告它正在向扬声器播放(它不是)。 Xcode项目中的某些东西是否可能导致这种情况?如果有人有任何想法或想法,我们将不胜感激。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>AudioKit 4.2 中的新 AKSampler 解决了我的问题!也许不完全是“答案”,但绝对是一个解决方案,绝对是一个“采样器”,而且绝对是在 AudioKit 中。所以希望对其他人有所帮助。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS AKMIDISampler 没有音频输出,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/49549611/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/49549611/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS AKMIDISampler 没有音频输出