swift - 创建 AKDelay 时,_AVAE_Check : required condition is false: [AVAudioEngine. mm :353:AttachNode: (node ! = nil)]

标签 swift macos audiokit

我有一个最小的 MacOS 应用程序(一个 View Controller + 一个按钮),其代码如下(基本上是来自 AudioKit's playground 的复制粘贴):

public class Player {

    static let playRate = 2.0
    static let scale = [0, 2, 4, 5, 7, 9, 11, 12]

    var pluckedString: AKPluckedString! = nil
    var delay: AKDelay! = nil
    var reverb: AKReverb! = nil
    var performance: AKPeriodicFunction! = nil

    public init() {
        pluckedString = AKPluckedString()

        delay = AKDelay(pluckedString) // <- objc_exception_throw here
        delay.time = 1.5 / Player.playRate
        delay.dryWetMix = 0.3
        delay.feedback = 0.2

        reverb = AKReverb(delay)

        performance = AKPeriodicFunction(frequency: Player.playRate) {
            var note = Player.scale.randomElement()
            let octave = [2, 3, 4, 5].randomElement() * 12
            if random(0, 10) < 1.0 { note += 1 }
            if !Player.scale.contains(note % 12) { print("ACCIDENT!") }

            let frequency = (note + octave).midiNoteToFrequency()
            if random(0, 6) > 1.0 {
                self.pluckedString.trigger(frequency: frequency)
            }
        }
    }

}

问题是调用 AKDelay(pluckedString) 会产生 ObjC 异常:

AKPluckedString.swift:init(frequency:amplitude:lowestFrequency:):94:Parameter Tree Failed
[avae] AVAEInternal.h:70:_AVAE_Check: required condition is false: [AVAudioEngine.mm:353:AttachNode: (node != nil)]
[General] required condition is false: node != nil
[General] (
    0   CoreFoundation                      0x00007fff49d8d00b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fff7096bc76 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff49d92da2 +[NSException raise:format:arguments:] + 98
    3   AVFAudio                            0x00007fff4610b75e _Z19AVAE_RaiseExceptionP8NSStringz + 158
    4   AVFAudio                            0x00007fff460ab1a2 _Z11_AVAE_CheckPKciS0_S0_b + 330
    5   AVFAudio                            0x00007fff4611f2e7 _ZN17AVAudioEngineImpl10AttachNodeEP11AVAudioNodeb + 63
    6   AVFAudio                            0x00007fff4611f267 -[AVAudioEngine attachNode:] + 67
    7   AudioKit                            0x000000010051de01 globalinit_33_0214DCBA62A4B4A95DF14CC0DE6A86C6_func60 + 13249
    8   AudioKit                            0x000000010051f24d globalinit_33_0214DCBA62A4B4A95DF14CC0DE6A86C6_func60 + 18445
    9   AudioKit                            0x0000000100512284 block_copy_helper.12 + 4852
    10  AudioKit                            0x0000000100519119 block_copy_helper.12 + 33161
    11  AudioKit                            0x0000000100639e8f block_copy_helper.12 + 38463
    12  AudioKit                            0x00000001006397ca block_copy_helper.12 + 36730
...

我该如何解决这个问题?

我正在使用 AudioKit 4.0.4/Swift 4.0.3/XCode 9.2 (9C40b)。

最佳答案

是因为您的应用程序沙箱已打开吗?我的 Xcode (9.2) 默认为应用程序沙箱(项目的“功能”选项卡)。这会导致 AudioKit 出现此错误。

关于swift - 创建 AKDelay 时,_AVAE_Check : required condition is false: [AVAudioEngine. mm :353:AttachNode: (node ! = nil)],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48569446/

相关文章:

arrays - swift iOS - 无法从 tracker.Frequency Audiokit 输出创建数组

ios - 尝试将 AudioKit 框架上传到 GitHub

swift 3.1.1.-在 linux copyItem 上发布(atPath :toPath:) is not yet implemented

ios - 快速自定义 NSURLProtocol 错误

json - 打开应用程序时如何加载数据?

macos - Delphi XE2 Firemonkey 示例应用程序未在 MAC 上运行

macOS Catalina 上的 AudioKit 4.9.3 : AKFrequencyTracker() & AKMicrophoneTracker() give bogus amplitude & frequency

swift - 如何在 Swift 中创建通用闭包

swift - 空初始 View Controller ,未调用 viewWillAppear() 和 viewDidAppear()

python - 在制作 boost.python helloword 演示时不安全地使用相对 rpath libboost.dylib?