Not all AudioUnitProperties are guaranteed to be settable on an active or 
initialized AU — in this way they are very different from Parameters.  You seem 
to have answered your own question:  You should make sure that no notes are 
active when this property is set.  The AUSampler attempts to shut off all notes 
when this property is being set.

However, it would be worth you filing a radar, including a sample app that 
demonstrates the crash.

-DS

> On Sep 12, 2015, at 4:31 AM, Dmitry Klochkov <[email protected]> wrote:
> 
> 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 protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/coreaudio-api/douglas_scott%40apple.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to