My use case is to play a MIDI file using a backing SF2 instrument. I have a SF2 file that contains sound samples for just one ethnic instrument. However, I am not able to successfully load that soundbank into the AVAudioUnitSampler instance.
I have been able to successfully load a popular GM soundfont (using the sample code found on the internet). Below is the code snippet that works fine.
_sf2URL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"GeneralUser GS MuseScore v1.442"ofType:@"sf2"]];
[_sampler loadSoundBankInstrumentAtURL:_sf2URL program:6 bankMSB: kAUSampler_DefaultMelodicBankMSB bankLSB:0error:&error];
However, for my sf2 file, the load fails. So, I am pretty confident that the issue is with supplying the right values for the below parameters of the loadSoundankInstrumentAtURL method:
c) Soundbank LSB
I tried several combinations, but none worked. I would like to understand a proven approach to get the right values for these parameters. May be to use a soundfont editor and look for some specific values in there?
Appreciate your help.
If your bank has only one instrument, it seems likely that it is at program 0.
Virtually none of these banks *actually* use the 0x78, 0x79 bank numbers that are exposed via the API -- these are the General MIDI Version 2 bank numbers. The code uses those values to interpret what it finds in the bank file, because there are many different numbering systems out there (and the loading system tries a few possibilities). If yours is really different, you will have to give it the exact MSB and LSB values to get it to load.
There used to be SF2 editors out there which would let you examine the bank numbers, etc. I don't know if they still exist.
You could also repeat your test, using program 0 and then walking through all the bank permutations (127*127, but hey, the computer does all the work).
-DS