本文整理汇总了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;
}
}
示例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();
}
示例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();
}
}
示例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.");
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
}
示例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;
}