02fentym 02fentym - 2 months ago 40
Objective-C Question

Loading Sampler Instrument Failing In El Capitan

I've written a Mac app using SpriteKit. My sampler instrument, which is an

AVAudioUnitSampler
, is no longer loading for some reason. This problem only came about since I've updated my system to El Capitan from Yosemite. I haven't touched the code since I was running Yosemite. My deployment target is still Yosemite, although I changed it to El Cap and it crashes. Any ideas?

Here's the stack trace:

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


Here's the code where I load the sampler:

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");
}
...

Answer

answer migrated from comments

loadSoundBankInstrumentAtURL is reporting kAudioUnitErr_InvalidPropertyValue because "Unable to find patch 0 bank 0x78/0". Maybe the piano sound font file isn't considered valid on elcap?

Out of interest, can you try loading it on the main dispatch queue? Or without the dispatch_async?

Being callable from multiple threads is a difficult requirement (and did anybody actually claim that AVAudioUnitSampler was threadsafe?), so it wouldn't surprise me if that was the cause of your woes.

Comments