在 El Capitan 中加载采样器乐器失败
Loading Sampler Instrument Failing In El Capitan
我使用 SpriteKit 编写了一个 Mac 应用程序。我的采样器乐器 AVAudioUnitSampler
由于某种原因不再加载。这个问题只是在我将系统从 Yosemite 更新到 El Capitan 后才出现的。我从运行Yosemite开始就没碰过代码。我的部署目标仍然是 Yosemite,尽管我将其更改为 El Cap 并且它崩溃了。有什么想法吗?
这是堆栈跟踪:
2016-09-12 10:59:01.134 Playground[66431:1254259] removed
2016-09-12 10:59:03.747 Playground[66431:1254301] sampler loaded
2016-09-12 10:59:03.848 Playground[66431:1254285] 10:59:03.848 ERROR: 93: BankEntry::LoadInstrument: Unable to find patch 0 bank 0x78/0
2016-09-12 10:59:03.848 Playground[66431:1254285] 10:59:03.848 ERROR: 486: DLS/SF2 bank load failed
2016-09-12 10:59:03.859 Playground[66431:1254285] 10:59:03.859 ERROR: AVAudioUnitSampler.mm:163: -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:]: error -10851
2016-09-12 10:59:03.861 Playground[66431:1254285] An uncaught exception was raised
2016-09-12 10:59:03.861 Playground[66431:1254285] error -10851
2016-09-12 10:59:03.861 Playground[66431:1254285] (
0 CoreFoundation 0x00007fff946594f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff9c4da73c objc_exception_throw + 48
2 CoreFoundation 0x00007fff9465e1ca +[NSException raise:format:arguments:] + 106
3 libAVFAudio.dylib 0x00007fff9b29ce13 _Z19AVAE_RaiseExceptionP8NSStringz + 176
4 libAVFAudio.dylib 0x00007fff9b2d5dae -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:] + 317
5 Playground 0x0000000100017800 __41-[MIDIController loadSoundFontInstrument]_block_invoke + 96
6 libdispatch.dylib 0x00000001003a1070 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x0000000100393cc5 _dispatch_client_callout + 8
8 libdispatch.dylib 0x0000000100398457 _dispatch_root_queue_drain + 2934
9 libdispatch.dylib 0x00000001003978a5 _dispatch_worker_thread3 + 106
10 libsystem_pthread.dylib 0x00000001003f6336 _pthread_wqthread + 1129
11 libsystem_pthread.dylib 0x00000001003f3f91 start_wqthread + 13
)
2016-09-12 10:59:03.861 Playground[66431:1254285] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10851'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff946594f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff9c4da73c objc_exception_throw + 48
2 CoreFoundation 0x00007fff9465e1ca +[NSException raise:format:arguments:] + 106
3 libAVFAudio.dylib 0x00007fff9b29ce13 _Z19AVAE_RaiseExceptionP8NSStringz + 176
4 libAVFAudio.dylib 0x00007fff9b2d5dae -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:] + 317
5 Playground 0x0000000100017800 __41-[MIDIController loadSoundFontInstrument]_block_invoke + 96
6 libdispatch.dylib 0x00000001003a1070 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x0000000100393cc5 _dispatch_client_callout + 8
8 libdispatch.dylib 0x0000000100398457 _dispatch_root_queue_drain + 2934
9 libdispatch.dylib 0x00000001003978a5 _dispatch_worker_thread3 + 106
10 libsystem_pthread.dylib 0x00000001003f6336 _pthread_wqthread + 1129
11 libsystem_pthread.dylib 0x00000001003f3f91 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我加载采样器的代码:
MIDIController.h
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
@interface MIDIController : NSObject
@property NSMutableArray *notes;
@property NSMutableArray *keyboard;
@property CFStringRef endpointName;
@property AVAudioUnitSampler *sampler;
-(int)uniqueNotesPlayed;
-(void) loadSampler;
-(void) unloadSampler;
@end
MIDIController.m
...
-(void) loadSampler {
// Instatiate audio engine
_engine = [[AVAudioEngine alloc] init];
_mixer = [_engine mainMixerNode];
_sampler = [[AVAudioUnitSampler alloc] init];
[self loadSoundFontInstrument];
[self makeEngineConnections];
[self startEngine];
}
-(void) loadSoundFontInstrument {
if (_sampler != nil) {
NSString *instrument = [[GameData sharedGameData].settings valueForKey:@"instrument"];
NSURL *piano = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:instrument ofType:@"sf2"]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[_sampler loadSoundBankInstrumentAtURL:piano program:0 bankMSB:0x79 bankLSB:0 error:nil];
});
}
else
NSLog(@"ERROR: Sampler has not been initialized");
}
...
从评论迁移的答案
loadSoundBankInstrumentAtURL
报告 kAudioUnitErr_InvalidPropertyValue
因为 "Unable to find patch 0 bank 0x78/0"。也许钢琴声音字体文件在 elcap 上被认为无效?
出于兴趣,您可以尝试将其加载到主调度队列中吗?或者没有 dispatch_async
?
可从多个线程调用是一个困难的要求(有人真的声称 AVAudioUnitSampler
是线程安全的吗?),所以如果这是您的问题的原因,我不会感到惊讶。
我使用 SpriteKit 编写了一个 Mac 应用程序。我的采样器乐器 AVAudioUnitSampler
由于某种原因不再加载。这个问题只是在我将系统从 Yosemite 更新到 El Capitan 后才出现的。我从运行Yosemite开始就没碰过代码。我的部署目标仍然是 Yosemite,尽管我将其更改为 El Cap 并且它崩溃了。有什么想法吗?
这是堆栈跟踪:
2016-09-12 10:59:01.134 Playground[66431:1254259] removed
2016-09-12 10:59:03.747 Playground[66431:1254301] sampler loaded
2016-09-12 10:59:03.848 Playground[66431:1254285] 10:59:03.848 ERROR: 93: BankEntry::LoadInstrument: Unable to find patch 0 bank 0x78/0
2016-09-12 10:59:03.848 Playground[66431:1254285] 10:59:03.848 ERROR: 486: DLS/SF2 bank load failed
2016-09-12 10:59:03.859 Playground[66431:1254285] 10:59:03.859 ERROR: AVAudioUnitSampler.mm:163: -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:]: error -10851
2016-09-12 10:59:03.861 Playground[66431:1254285] An uncaught exception was raised
2016-09-12 10:59:03.861 Playground[66431:1254285] error -10851
2016-09-12 10:59:03.861 Playground[66431:1254285] (
0 CoreFoundation 0x00007fff946594f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff9c4da73c objc_exception_throw + 48
2 CoreFoundation 0x00007fff9465e1ca +[NSException raise:format:arguments:] + 106
3 libAVFAudio.dylib 0x00007fff9b29ce13 _Z19AVAE_RaiseExceptionP8NSStringz + 176
4 libAVFAudio.dylib 0x00007fff9b2d5dae -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:] + 317
5 Playground 0x0000000100017800 __41-[MIDIController loadSoundFontInstrument]_block_invoke + 96
6 libdispatch.dylib 0x00000001003a1070 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x0000000100393cc5 _dispatch_client_callout + 8
8 libdispatch.dylib 0x0000000100398457 _dispatch_root_queue_drain + 2934
9 libdispatch.dylib 0x00000001003978a5 _dispatch_worker_thread3 + 106
10 libsystem_pthread.dylib 0x00000001003f6336 _pthread_wqthread + 1129
11 libsystem_pthread.dylib 0x00000001003f3f91 start_wqthread + 13
)
2016-09-12 10:59:03.861 Playground[66431:1254285] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10851'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff946594f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff9c4da73c objc_exception_throw + 48
2 CoreFoundation 0x00007fff9465e1ca +[NSException raise:format:arguments:] + 106
3 libAVFAudio.dylib 0x00007fff9b29ce13 _Z19AVAE_RaiseExceptionP8NSStringz + 176
4 libAVFAudio.dylib 0x00007fff9b2d5dae -[AVAudioUnitSampler loadSoundBankInstrumentAtURL:program:bankMSB:bankLSB:error:] + 317
5 Playground 0x0000000100017800 __41-[MIDIController loadSoundFontInstrument]_block_invoke + 96
6 libdispatch.dylib 0x00000001003a1070 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x0000000100393cc5 _dispatch_client_callout + 8
8 libdispatch.dylib 0x0000000100398457 _dispatch_root_queue_drain + 2934
9 libdispatch.dylib 0x00000001003978a5 _dispatch_worker_thread3 + 106
10 libsystem_pthread.dylib 0x00000001003f6336 _pthread_wqthread + 1129
11 libsystem_pthread.dylib 0x00000001003f3f91 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我加载采样器的代码:
MIDIController.h
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
@interface MIDIController : NSObject
@property NSMutableArray *notes;
@property NSMutableArray *keyboard;
@property CFStringRef endpointName;
@property AVAudioUnitSampler *sampler;
-(int)uniqueNotesPlayed;
-(void) loadSampler;
-(void) unloadSampler;
@end
MIDIController.m
...
-(void) loadSampler {
// Instatiate audio engine
_engine = [[AVAudioEngine alloc] init];
_mixer = [_engine mainMixerNode];
_sampler = [[AVAudioUnitSampler alloc] init];
[self loadSoundFontInstrument];
[self makeEngineConnections];
[self startEngine];
}
-(void) loadSoundFontInstrument {
if (_sampler != nil) {
NSString *instrument = [[GameData sharedGameData].settings valueForKey:@"instrument"];
NSURL *piano = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:instrument ofType:@"sf2"]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[_sampler loadSoundBankInstrumentAtURL:piano program:0 bankMSB:0x79 bankLSB:0 error:nil];
});
}
else
NSLog(@"ERROR: Sampler has not been initialized");
}
...
从评论迁移的答案
loadSoundBankInstrumentAtURL
报告 kAudioUnitErr_InvalidPropertyValue
因为 "Unable to find patch 0 bank 0x78/0"。也许钢琴声音字体文件在 elcap 上被认为无效?
出于兴趣,您可以尝试将其加载到主调度队列中吗?或者没有 dispatch_async
?
可从多个线程调用是一个困难的要求(有人真的声称 AVAudioUnitSampler
是线程安全的吗?),所以如果这是您的问题的原因,我不会感到惊讶。