I have a minimal MacOS app (one view controller + one button) with the following code (basically a copy-paste from 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)
}
}
}
}
The problem is that call to AKDelay(pluckedString)
produces ObjC exception:
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
...
How can I fix this?
I am using AudioKit 4.0.4 / Swift 4.0.3 / XCode 9.2 (9C40b).
答案 0 :(得分:4)
是因为您的App Sandbox已启用?我的Xcode(9.2)默认为App Sandbox(项目的功能选项卡)。这导致AudioKit出现此错误。