• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to correctly update AUSampler's loadInstrument property?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to correctly update AUSampler's loadInstrument property?


  • Subject: Re: How to correctly update AUSampler's loadInstrument property?
  • From: Douglas Scott <email@hidden>
  • Date: Mon, 14 Sep 2015 10:31:40 -0700

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@hidden> 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@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >How to correctly update AUSampler's loadInstrument property? (From: Dmitry Klochkov <email@hidden>)

  • Prev by Date: How to correctly update AUSampler's loadInstrument property?
  • Next by Date: A Design question, using swift and objective-c
  • Previous by thread: How to correctly update AUSampler's loadInstrument property?
  • Next by thread: A Design question, using swift and objective-c
  • Index(es):
    • Date
    • Thread