• 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
How to correctly update AUSampler's loadInstrument property?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to correctly update AUSampler's loadInstrument property?


  • Subject: How to correctly update AUSampler's loadInstrument property?
  • From: Dmitry Klochkov <email@hidden>
  • Date: Sat, 12 Sep 2015 14:31:24 +0300

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

  • Follow-Ups:
    • Re: How to correctly update AUSampler's loadInstrument property?
      • From: Douglas Scott <email@hidden>
  • Prev by Date: IOAudio kext - separate user clients?
  • Next by Date: Re: How to correctly update AUSampler's loadInstrument property?
  • Previous by thread: IOAudio kext - separate user clients?
  • Next by thread: Re: How to correctly update AUSampler's loadInstrument property?
  • Index(es):
    • Date
    • Thread