javax.sound.midi.Soundbank Java Examples
The following examples show how to use
javax.sound.midi.Soundbank.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtraCharInSoundbank.java From openjdk-jdk9 with GNU General Public License v2.0 | 7 votes |
public static void main(String[] args) throws Exception { // the internal synthesizer needs a soundcard to work properly if (!isSoundcardInstalled()) { return; } Synthesizer theSynth = MidiSystem.getSynthesizer(); System.out.println("Got synth: "+theSynth); theSynth.open(); try { Soundbank theSoundbank = theSynth.getDefaultSoundbank(); System.out.println("Got soundbank: "+theSoundbank); theSynth.loadAllInstruments(theSoundbank); try { if (!checkInstrumentNames(theSynth)) { throw new Exception("Test failed"); } } finally { theSynth.unloadAllInstruments(theSoundbank); } } finally { theSynth.close(); } System.out.println("Test passed."); }
Example #2
Source File: TestGetSoundbankInputStream.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank dls = new DLSSoundbankReader().getSoundbank(bis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #3
Source File: TestGetSoundbankInputStream.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank sf2 = new SF2SoundbankReader().getSoundbank(bis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #4
Source File: TestGetSoundbankInputStream.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank sf2 = new SF2SoundbankReader().getSoundbank(bis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #5
Source File: UnloadAllInstruments.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); synth.loadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length != 0); synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #6
Source File: TestDisableLoadDefaultSoundbank.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if (defsbk != null) { assertTrue(defsbk.getInstruments().length == synth .getLoadedInstruments().length); } synth.close(); Map<String, Object> p = new HashMap<String, Object>(); p.put("load default soundbank", false); synth.openStream(null, p); if (defsbk != null) { assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #7
Source File: TestGetSoundbankInputStream.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank dls = new DLSSoundbankReader().getSoundbank(bis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #8
Source File: TestGetSoundbankInputStream2.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #9
Source File: UnloadAllInstruments.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); synth.loadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length != 0); synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #10
Source File: UnloadInstruments.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); synth.unloadInstruments(sbk, new Patch[] {ins2.getPatch()}); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #11
Source File: TestGetSoundbankInputStream2.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank dls = new DLSSoundbankReader().getSoundbank(badis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #12
Source File: TestGetSoundbankInputStream2.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank dls = new DLSSoundbankReader().getSoundbank(badis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #13
Source File: LoadInstrument.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); } synth.close(); }
Example #14
Source File: UnloadInstrument.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); synth.unloadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #15
Source File: AudioFileSoundbankReader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public Soundbank getSoundbank(File file) throws InvalidMidiDataException, IOException { try { AudioInputStream ais = AudioSystem.getAudioInputStream(file); ais.close(); ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(file, 0, file.length()), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (UnsupportedAudioFileException e1) { return null; } catch (IOException e) { return null; } }
Example #16
Source File: TestGetSoundbankInputStream2.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #17
Source File: UnloadAllInstruments.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); synth.loadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length != 0); synth.unloadAllInstruments(defsbk); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #18
Source File: TestDisableLoadDefaultSoundbank.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if (defsbk != null) { assertTrue(defsbk.getInstruments().length == synth .getLoadedInstruments().length); } synth.close(); Map<String, Object> p = new HashMap<String, Object>(); p.put("load default soundbank", false); synth.openStream(null, p); if (defsbk != null) { assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
Example #19
Source File: LoadInstrument.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); } synth.close(); }
Example #20
Source File: AudioFileSoundbankReader.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public Soundbank getSoundbank(File file) throws InvalidMidiDataException, IOException { try { AudioInputStream ais = AudioSystem.getAudioInputStream(file); ais.close(); ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(file, 0, file.length()), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (UnsupportedAudioFileException e1) { return null; } catch (IOException e) { return null; } }
Example #21
Source File: LoadAllInstruments.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadAllInstruments(sbk); assertTrue(synth.getLoadedInstruments().length == 2); } synth.close(); }
Example #22
Source File: TestGetSoundbankInputStream2.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank dls = new DLSSoundbankReader().getSoundbank(badis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
Example #23
Source File: AudioFileSoundbankReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(AudioInputStream ais) throws InvalidMidiDataException, IOException { try { byte[] buffer; if (ais.getFrameLength() == -1) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[1024 - (1024 % ais.getFormat().getFrameSize())]; int ret; while ((ret = ais.read(buff)) != -1) { baos.write(buff, 0, ret); } ais.close(); buffer = baos.toByteArray(); } else { buffer = new byte[(int) (ais.getFrameLength() * ais.getFormat().getFrameSize())]; new DataInputStream(ais).readFully(buffer); } ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(buffer), ais.getFormat(), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (Exception e) { return null; } }
Example #24
Source File: SoftSynthesizer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public boolean loadAllInstruments(Soundbank soundbank) { List<ModelInstrument> instruments = new ArrayList<ModelInstrument>(); for (Instrument ins: soundbank.getInstruments()) { if (ins == null || !(ins instanceof ModelInstrument)) { throw new IllegalArgumentException( "Unsupported instrument: " + ins); } instruments.add((ModelInstrument)ins); } return loadInstruments(instruments); }
Example #25
Source File: DLSSoundbankReader.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(URL url) throws InvalidMidiDataException, IOException { try { return new DLSSoundbank(url); } catch (RIFFInvalidFormatException e) { return null; } catch(IOException ioe) { return null; } }
Example #26
Source File: SF2SoundbankReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(URL url) throws InvalidMidiDataException, IOException { try { return new SF2Soundbank(url); } catch (RIFFInvalidFormatException e) { return null; } catch(IOException ioe) { return null; } }
Example #27
Source File: AudioFileSoundbankReader.java From Bytecoder with Apache License 2.0 | 5 votes |
public Soundbank getSoundbank(AudioInputStream ais) throws InvalidMidiDataException, IOException { try { byte[] buffer; if (ais.getFrameLength() == -1) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[1024 - (1024 % ais.getFormat().getFrameSize())]; int ret; while ((ret = ais.read(buff)) != -1) { baos.write(buff, 0, ret); } ais.close(); buffer = baos.toByteArray(); } else { buffer = new byte[(int) (ais.getFrameLength() * ais.getFormat().getFrameSize())]; new DataInputStream(ais).readFully(buffer); } ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(buffer), ais.getFormat(), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (Exception e) { return null; } }
Example #28
Source File: DLSSoundbankReader.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(URL url) throws InvalidMidiDataException, IOException { try { return new DLSSoundbank(url); } catch (RIFFInvalidFormatException e) { return null; } catch(IOException ioe) { return null; } }
Example #29
Source File: TestGetSoundbankUrl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); URL url = file.toURI().toURL(); Soundbank dls = new DLSSoundbankReader().getSoundbank(url); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); }
Example #30
Source File: DLSSoundbankReader.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(URL url) throws InvalidMidiDataException, IOException { try { return new DLSSoundbank(url); } catch (RIFFInvalidFormatException e) { return null; } catch(IOException ioe) { return null; } }