I have an AUGraph consisting of two nodes: AUSampler unit and output unit. I am loading samples to AUSampler from sf2 files. I have multiple sf2 files and want to switch between them in runtime.
Currently I have the following code to set a sf2 file:
- (void) loadSoundFontWithName:(NSString *) name {
CheckError (AUGraphStop(_midiPlayer.graph), "couldn't stop graph");
OSStatus result = noErr;
// fill out a instrument data structure
AUSamplerInstrumentData instdata;
NSString *presetPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat: @"Sampler Files/%@", name]
ofType:@"sf2"];
const char* presetPathC = [presetPath cStringUsingEncoding:NSUTF8StringEncoding];
NSLog (@"presetPathC: %s", presetPathC);
CFURLRef presetURL = CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault,
presetPathC,
[presetPath length],
NO);
instdata.fileURL = presetURL;
instdata.instrumentType = kInstrumentType_DLSPreset;
instdata.bankMSB = kAUSampler_DefaultMelodicBankMSB;
instdata.bankLSB = kAUSampler_DefaultBankLSB;
instdata.presetID = (UInt8) 0;
// set the kAUSamplerProperty_LoadPresetFromBank property
result = AudioUnitSetProperty(_midiPlayer.instrumentUnit,
kAUSamplerProperty_LoadInstrument,
kAudioUnitScope_Global,
0,
&instdata,
sizeof(instdata));
// check for errors
NSCAssert (result == noErr,
@"Unable to set the preset property on the Sampler. Error code:%d '%.4s'",
(int) result,
(const char *)&result);
//===============
CheckError (AUGraphStart(_midiPlayer.graph), "couldn't start graph");
}
It works only if there is not any sounds played at the time of switching to another file. If the property is set while the graph being played, it crashes with EXC_BAD_ACCESS at DLSSample::GetMoreFrames(unsigned long long, unsigned long long, void*) ()
So what is the right way to update this property?
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden