本文整理汇总了Java中com.sun.media.sound.AudioSynthesizer.open方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSynthesizer.open方法的具体用法?Java AudioSynthesizer.open怎么用?Java AudioSynthesizer.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.media.sound.AudioSynthesizer
的用法示例。
在下文中一共展示了AudioSynthesizer.open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.media.sound.AudioSynthesizer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
Receiver recv = synth.getReceiver();
assertTrue(recv != null);
ShortMessage sm = new ShortMessage();
sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
synth.open(new DummySourceDataLine(), null);
recv.send(sm, -1);
synth.close();
try
{
recv.send(sm, -1);
throw new RuntimeException("Exception not thrown!");
}
catch(Exception e)
{
// Just checking if exception is thrown
}
}
示例2: render
import com.sun.media.sound.AudioSynthesizer; //导入方法依赖的package包/类
/**
* Render sequence using selected or default soundbank into wave audio file.
*/
public static void render(Sequence sequence, OutputStream out) throws MidiUnavailableException
{
try
{
// Find available AudioSynthesizer.
AudioSynthesizer synth = SynthesizerFactory.findAudioSynthesizer();
if (synth == null)
{
throw new MidiUnavailableException("Failed to find appropriate synthesizer");
}
// Open AudioStream from AudioSynthesizer.
boolean opened = synth.isOpen();
if (opened)
synth.close();
AudioInputStream stream = synth.openStream(null, null);
SynthesizerFactory.initLotroSynthesizer(synth);
// Play Sequence into AudioSynthesizer Receiver.
double total = send(sequence, synth.getReceiver());
// Calculate how long the WAVE file needs to be.
long len = (long) (stream.getFormat().getFrameRate() * (total + 4));
stream = new AudioInputStream(stream, stream.getFormat(), len);
// Write WAVE file to disk.
AudioSystem.write(stream, AudioFileFormat.Type.WAVE, out);
// We are finished, close synthesizer.
synth.close();
if (opened)
synth.open();
}
catch (Exception e)
{
e.printStackTrace();
}
}