Load an EXS24 instrument with a CoreAudio AUSampler in iOS6
-
14-07-2021 - |
Question
From looking at the AUSampler API it seems like it should support Garage Band EXS24 instruments. The AudioUnitProperties.h file says the following:
typedef struct AUSamplerInstrumentData {
CFURLRef fileURL;
UInt8 instrumentType;
UInt8 bankMSB;
UInt8 bankLSB;
UInt8 presetID;
} AUSamplerInstrumentData;
Where the instrument type can have the following types:
enum
{
kInstrumentType_DLSPreset = 1,
kInstrumentType_SF2Preset = kInstrumentType_DLSPreset,
kInstrumentType_AUPreset = 2,
kInstrumentType_Audiofile = 3,
kInstrumentType_EXS24 = 4
};
I've tried to load the instrument using the following function:
-(OSStatus) loadFromEXS: (NSString *) path withSampler: (AudioUnit) sampler {
OSStatus result = noErr;
NSURL *presetURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"exs"]];
AUSamplerInstrumentData bpdata = {0};
bpdata.fileURL = (__bridge CFURLRef)(presetURL);
bpdata.instrumentType = kInstrumentType_EXS24;
result = AudioUnitSetProperty(sampler,
kAUSamplerProperty_LoadInstrument,
kAudioUnitScope_Global,
0,
&bpdata,
sizeof(bpdata));
return result;
}
In my resources I have a group which contains the .exs file and a number of .wav samples. This function produces the following error:
GlobalState::LoadEXS24Instrument: Load failed
So does this mean that the EXS file isn't correct? Does it mean that I've not loaded it correctly? Or maybe, this isn't supported in iOS6?
La solution
Yes it seems like it supports the EXS file format. There's one problem however: EXS uses absolute file paths. It does not support relative paths. That means you can't move the .wav samples around, or it will break the EXS instrument. That's my guess why it isn't working.
See this: https://developer.apple.com/library/mac/#technotes/tn2283/_index.html