• 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 set the bank for the kAudioUnitSubType_MIDISynth AU
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to set the bank for the kAudioUnitSubType_MIDISynth AU


  • Subject: How to set the bank for the kAudioUnitSubType_MIDISynth AU
  • From: Dmitry Klochkov via Coreaudio-api <email@hidden>
  • Date: Sun, 13 Oct 2019 22:01:30 +0300

I am using kAudioUnitSubType_MIDISynth Audio Unit in my iOS app.

I successfully loaded Fluid R3 GM soundfont into it and I figured out how
to select a preset for a specific channel.

I am able to use all presets of the soundfont from the bank 0. But the
percussion presets, which I also what to use, are in the bank 128 (as I see
in the Polyphone app).

I could not find any documentation on how to do it. I tried to send bank
select messages to the unit, but had no success with it.

Here is the method I currently use to set the preset and the bank:

-(*void*) setPreset:(UInt32) preset bank:(UInt32) bank forChannel:(UInt8)
channel forInstrumentUnit:(AudioUnit) instrumentUnit {



    // set the instrumentUnit into mode when it loads the requested preset
into memory

    UInt32 preloadEnabled = 1;

    OSStatus err = AudioUnitSetProperty(

                               instrumentUnit,

                               kAUMIDISynthProperty_EnablePreload,

                               kAudioUnitScope_Global,

                               0,

                               &preloadEnabled,

                               *sizeof*(preloadEnabled));



    *if* (err) {

        NSLog(@"Unable to set enablePreload property: %@", @(err));

    }


    // Send bank load message MSB

UInt32 ccCommand = 0xB0 | channel;

UInt32 bankMsb = bank >> 7;

err = MusicDeviceMIDIEvent(instrumentUnit, ccCommand, 0, bankMsb, 0);

*if* (err) {

NSLog(@"Failed to load preset: %@ in %s.", @(err), *__PRETTY_FUNCTION__*);

}

UInt32 bankLsb = bank & 0x7F;

err = MusicDeviceMIDIEvent(instrumentUnit, ccCommand, 0x20, bankLsb, 0);


*if* (err) {

NSLog(@"Failed to load preset: %@ in %s.", @(err), *__PRETTY_FUNCTION__*);

}





    // request preset on the channel to load it into memory(but it is not
activated here)

UInt32 pcCommand = 0xC0 | channel;

err = MusicDeviceMIDIEvent(instrumentUnit, pcCommand, preset, 0, 0);

*if* (err) {

NSLog(@"Failed to load preset: %@ in %s.", @(err), *__PRETTY_FUNCTION__*);

}



    // set instrumentUnit into regular mode when the requested preset is
activetad for the specified channel

    preloadEnabled = 0; //disable preload property

    err = AudioUnitSetProperty(

                               instrumentUnit,

                               kAUMIDISynthProperty_EnablePreload,

                               kAudioUnitScope_Global,

                               0,

                               &preloadEnabled,

                               *sizeof*(preloadEnabled));



    *if* (err) {

        NSLog(@"Unable to set enablePreload property: %@", @(err));

    }



    // repeat programm change command to actually activate the presed for
the channel after it has been loaded in the previous steps

    err = MusicDeviceMIDIEvent(instrumentUnit, pcCommand, preset, 0, 0);



    *if* (err) {

        NSLog(@"Failed to activate preset: %@ in %s.", @(err),
*__PRETTY_FUNCTION__*);

    }

}


Could you please tell if the MIDISynth unit supports soundfonts with
multiple banks, and what is the correct way to set a bank for a specific
channel?


Best regards,

Dmitry
 _______________________________________________
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 set the bank for the kAudioUnitSubType_MIDISynth AU
      • From: Dmitry Klochkov via Coreaudio-api <email@hidden>
  • Prev by Date: A/V Sync with low-latency audio effects
  • Next by Date: Re: How to set the bank for the kAudioUnitSubType_MIDISynth AU
  • Previous by thread: A/V Sync with low-latency audio effects
  • Next by thread: Re: How to set the bank for the kAudioUnitSubType_MIDISynth AU
  • Index(es):
    • Date
    • Thread