private void loadSoundBank(File soundbankFile) { try { synthesizer.close(); Soundbank sb = MidiSystem.getSoundbank(soundbankFile); synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); System.out.println("soundbank added: " + sb); if (sb != null) { System.out.println("soundbank supported: " + synthesizer.isSoundbankSupported(sb)); boolean bInstrumentsLoaded = synthesizer.loadAllInstruments(sb); System.out.println("Instruments loaded: " + bInstrumentsLoaded); } } catch (MidiUnavailableException e) { e.printStackTrace(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
void init_midi(LContext lcontext) { if (!midiSynthInitialized) { midiSynthInitialized = true; try { midiSynth = MidiSystem.getSynthesizer(); midiSynth.open(); if (midiSynth.getDefaultSoundbank() == null) { ((LContext) lcontext).canvas.setMessage ("Reading sound bank from server. Please wait..."); if (lcontext != null) { /* empty */ } URL url = new URL(((LContext) lcontext).codeBase + "soundbank.gm"); Soundbank soundbank = MidiSystem.getSoundbank(url); if (soundbank != null) { midiSynth.loadAllInstruments(soundbank); ((LContext) lcontext).canvas.setMessage(""); } else { midiSynth.close(); midiSynth = null; } } } catch (MidiUnavailableException midiunavailableexception) { midiunavailableexception.printStackTrace(); midiSynth = null; } catch (MalformedURLException malformedurlexception) { malformedurlexception.printStackTrace(); midiSynth = null; } catch (InvalidMidiDataException invalidmididataexception) { invalidmididataexception.printStackTrace(); midiSynth = null; } catch (IOException ioexception) { ioexception.printStackTrace(); midiSynth = null; } catch (AccessControlException accesscontrolexception) { accesscontrolexception.printStackTrace(); midiSynth = null; } if (midiSynth != null) { MidiChannel[] midichannels = midiSynth.getChannels(); for (int i = 0; i < midichannels.length; i++) { if (midichannels[i] != null) midichannels[i].programChange(0); } } else ((LContext) lcontext).canvas.setMessage ("No soundbank; note & drum commands disabled."); } }
public static void main(String[] args) throws Exception { InputStream sb = getInputStream("ding.sf2"); soundbank = MidiSystem.getSoundbank(sb); sb.close(); InputStream si = getInputStream("expresso.mid"); sequence = MidiSystem.getSequence(si); si.close(); AudioFormat format; Map<String, Object> info = new HashMap<String, Object>(); { format = new AudioFormat(22050, 16, 2, true, false); test(format, info); format = new AudioFormat(44100, 16, 2, true, false); test(format, info); } { format = new AudioFormat(44100, 8, 2, true, false); test(format, info); format = new AudioFormat(44100, 16, 2, true, false); test(format, info); format = new AudioFormat(44100, 24, 2, true, false); test(format, info); } { format = new AudioFormat(44100, 16, 1, true, false); test(format, info); format = new AudioFormat(44100, 16, 2, true, false); test(format, info); } { format = new AudioFormat(44100, 16, 2, true, false); info.clear(); info.put("control rate", 100f); test(format, info); info.clear(); info.put("control rate", 147f); test(format, info); } { format = new AudioFormat(44100, 16, 2, true, false); info.clear(); info.put("interpolation", "point"); test(format, info); info.clear(); info.put("interpolation", "linear"); test(format, info); info.clear(); info.put("interpolation", "cubic"); test(format, info); } { format = new AudioFormat(44100, 16, 2, true, false); info.clear(); info.put("max polyphony", 4); test(format, info); info.clear(); info.put("max polyphony", 16); test(format, info); info.clear(); } }
private Soundbank loadSoundbank(final File soundbankFile) throws MidiUnavailableException, InvalidMidiDataException, IOException { return MidiSystem.getSoundbank(soundbankFile); }