当前位置: 首页>>代码示例>>Java>>正文


Java AudioSynthesizer.open方法代码示例

本文整理汇总了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
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:GetReceiver2.java

示例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();
	}
}
 
开发者ID:digero,项目名称:maestro,代码行数:44,代码来源:MidiToWav.java


注:本文中的com.sun.media.sound.AudioSynthesizer.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。