Ok, I got it working somehow, but still can not fully understand what is going on there.
I tried changing the bank number assigned to the drum preset inside the soundfont using Polyphone app. The sound bank was set to 128 and I set it to 1. And then when I tried to load this updated soundfont into the AUMIDISynth I got the following error messages: *BankEntry::LoadInstrument: Unable to find patch 0 bank 0x78/0* *EXCEPTION (-10851): "LoadInstrument: Failed to load patch from bank"* *DLS/SF2 bank load failed* So I reverted updated bank number back to 128 and instead of sending a bank select message with value 128, I sent it with value 0x78(which is 120 in decimal). And voila! She preset loaded! Also to got the bank selection working I need to update my code so it doesn't send bank select using two messages(MSB and LSB) but only sends the provided bank value as MSB MusicDeviceMIDIEvent(instrumentUnit, 0xB0 | channel, 0, bank, 0) So I am wondering is there any meaningful explanation why bank number 128 became 120 after the soundfont was loaded into AUMIDISynth? Best wishes, Dmitry On Sun, Oct 13, 2019 at 10:01 PM Dmitry Klochkov <[email protected]> wrote: > 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 protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com This email sent to [email protected]
