[Audio-engine-dev] Issue with AudioSystem.getSoundbank() plus proposed patch.

Bill Brown wbrown at colorfulsoftware.com
Thu Nov 20 19:04:50 PST 2008


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 (
http://www.j2ee.me/j2se/1.3/pdf/javasound.pdf  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);
                    try{
                        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.
                        try{
                            Synthesizer synth = (Synthesizer)
                            getDefaultDeviceWrapper(Synthesizer.class);
                            if(synth.isSoundbankSupported(s)){
                                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..
Bill.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/audio-engine-dev/attachments/20081120/89375f08/attachment.html 


More information about the audio-engine-dev mailing list