當前位置: 首頁>>代碼示例>>Java>>正文


Java Soundbank類代碼示例

本文整理匯總了Java中javax.sound.midi.Soundbank的典型用法代碼示例。如果您正苦於以下問題:Java Soundbank類的具體用法?Java Soundbank怎麽用?Java Soundbank使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Soundbank類屬於javax.sound.midi包,在下文中一共展示了Soundbank類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSoundbank

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:AudioFileSoundbankReader.java

示例2: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    synth.openStream(null, null);
    Soundbank defsbk = synth.getDefaultSoundbank();
    if(defsbk != null)
    {
        Instrument ins3 = defsbk.getInstrument(new Patch(0,3));
        Instrument ins10 = defsbk.getInstrument(new Patch(0,10));
        assertTrue(synth.remapInstrument(ins3, ins10));
        Instrument[] loaded = synth.getLoadedInstruments();
        for (int i = 0; i < loaded.length; i++) {
            if(loaded[i].getPatch().getBank() == ins3.getPatch().getBank())
            if(loaded[i].getPatch().getProgram() == ins3.getPatch().getProgram())
            {
                assertEquals(loaded[i].getName(), ins10.getName());
                break;
            }
        }

    }
    synth.close();

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:RemapInstrument.java

示例3: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:TestGetSoundbankInputStream.java

示例4: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ExtraCharInSoundbank.java

示例5: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TestGetSoundbankInputStream2.java

示例6: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TestGetSoundbankInputStream2.java

示例7: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:TestGetSoundbankInputStream.java

示例8: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:UnloadAllInstruments.java

示例9: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:UnloadInstrument.java

示例10: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:UnloadInstruments.java

示例11: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:LoadAllInstruments.java

示例12: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:LoadInstrument.java

示例13: main

import javax.sound.midi.Soundbank; //導入依賴的package包/類
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();

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TestDisableLoadDefaultSoundbank.java

示例14: getSoundbank

import javax.sound.midi.Soundbank; //導入依賴的package包/類
public Soundbank getSoundbank(URL url)
        throws InvalidMidiDataException, IOException {
    try {
        return new SF2Soundbank(url);
    } catch (RIFFInvalidFormatException e) {
        return null;
    } catch(IOException ioe) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:SF2SoundbankReader.java

示例15: getAvailableInstruments

import javax.sound.midi.Soundbank; //導入依賴的package包/類
public Instrument[] getAvailableInstruments() {
    Soundbank defsbk = getDefaultSoundbank();
    if (defsbk == null)
        return new Instrument[0];
    Instrument[] inslist_array = defsbk.getInstruments();
    Arrays.sort(inslist_array, new ModelInstrumentComparator());
    return inslist_array;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:SoftSynthesizer.java


注:本文中的javax.sound.midi.Soundbank類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。