Issue with AudioSystem.getSoundbank() plus proposed patch.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Issue with AudioSystem.getSoundbank() plus proposed patch.

Bill Brown
Greetings Audio Devs:

I did not find this issue discussed previously in the archives.  I have run into an issue with the current Openjdk implementation of AudioSystem.getSoundbank() that applies to all three variants File, URL and InputStream.   The current implementation only considers the first valid javax.sound.midi.spi.SoundbankReader  instead of checking the Soundbank instance for use with the loaded or default Synthesizer.  This consideration is arbitrary based on the order in which the SoundBankReader implementations are made available and my be wrong when there are multiple providers for different synths that handle the same file type / format.

The Soundbank returned from the method is only useable by a Synthesizer (the currently loaded Synthesizer) and each Synthesizer's soundbanks are unique for that synthesizer by design (  section "Providing Soundbank File-Reading Services" p. 148).    My current project (code named EMAP) provides a SoundbankReader for the same .sf2 file type as Gervill.  This current MidiSystem.getSoundbank() breaks my app and have not figured out a workaround that doesn't involve the proposed patch. 

Because it is possible to enforce which Synthesizer is used by setting the system property javax.sound.midi.Synthesizer, it should be possible to load a soundbank from a file that is supported by the loaded Synthesizer.  Here is a patch suggestion that can somewhat handle this request without adding a big implementation change:

public static Soundbank getSoundbank(File file) //can be used also for the URLand InputStream signatures
        throws InvalidMidiDataException, IOException {
                SoundbankReader sp = null;
                Soundbank s = null;
                Soundbank validSoundbank = null;

                List providers = getSoundbankReaders();

                for(int i = 0; i < providers.size(); i++) {
                    sp = (SoundbankReader)providers.get(i);
                        s = sp.getSoundbank(file);
                    }catch(IOException io){}
                    catch (InvalidMidiDataException ime){}
                   if( s!= null) {
                        //crosscheck support with the current default synthesizer.
                        //because the soundbank is not much use otherwise.
                        //there may be more than on synth in the system
                        //that supports this file format.
                            Synthesizer synth = (Synthesizer)
                                return s;
                            //still arbitrary at this point but at least we have
                            //checked against the default synthesizer.
                            validSoundbank = s;
                        }catch(MidiUnavailableException e){}
                if(validSoundbank != null){
                    return validSoundbank;
                throw new InvalidMidiDataException("cannot get soundbank from stream");

I think the API would be more robust if it could handle the scenario where there are multiple providers that can handle the same file type.  I think the extra overhead that this patch creates is small compared to the usefullness of being able to get a handle on a Soundbank that will work with the currently loaded Synthesizer.  Another way to handle this issue could be to add signatures and implementations in the API to allow a Synthesizer to load a Soundbank in the same manner as the MidiSystem.  But it you did that, I don't see much use for the MidiSystem versions.

Please consider this patch, or something like it,  for inclusion to the openjdk implementation or possibly provide some workaround for loading a useable Soundbank when there are multiple synths in the system that support the same format. 

Thanks for looking at this..

audio-engine-dev mailing list
[hidden email]