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


Java AudioInputStream.close方法代码示例

本文整理汇总了Java中javax.sound.sampled.AudioInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java AudioInputStream.close方法的具体用法?Java AudioInputStream.close怎么用?Java AudioInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.AudioInputStream的用法示例。


在下文中一共展示了AudioInputStream.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
@Override
public void run() {
    log("ConversionThread[" + num + "] started.");
    try {
        InputStream inStream = new ByteArrayInputStream(pcmBuffer);

        AudioInputStream pcmStream = new AudioInputStream(
                inStream, pcmFormat, AudioSystem.NOT_SPECIFIED);
        AudioInputStream alawStream = AudioSystem.getAudioInputStream(alawFormat, pcmStream);

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        int read = 0;
        byte[] data = new byte[4096];
        while((read = alawStream.read(data)) != -1) {
            outStream.write(data, 0, read);
       }
       alawStream.close();
       resultArray = outStream.toByteArray();
    } catch (Exception ex) {
        log("ConversionThread[" + num + "] exception:");
        log(ex);
    }
    log("ConversionThread[" + num + "] completed.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:AlawEncoderSync.java

示例2: loadByteAudio

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
private byte[] loadByteAudio(AudioInputStream ais, int toRead)
{
	int totalRead = 0;
	byte[] rawBytes = new byte[toRead];
	try
	{
		// we have to read in chunks because the decoded stream won't
		// read more than about 2000 bytes at a time
		while (totalRead < toRead)
		{
			int actualRead = ais.read(rawBytes, totalRead, toRead	- totalRead);
			if (actualRead < 1)
				break;
			totalRead += actualRead;
		}
		ais.close();
	}
	catch (Exception ioe)
	{
		error("Error loading file into memory: " + ioe.getMessage());
	}
	debug("Needed to read " + toRead + " actually read " + totalRead);
	return rawBytes;
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:25,代码来源:JSMinim.java

示例3: getSoundbank

import javax.sound.sampled.AudioInputStream; //导入方法依赖的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

示例4: loadSound

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
/**
 * WAV files only
 * 
 * @param name
 *            Name to store sound as
 * @param file
 *            Sound file
 */
public static void loadSound(String name, String file) {
	try {
		System.out.print("Loading sound file: \"" + file + "\" into clip: \"" + name + "\", ");
		BufferedInputStream in = new BufferedInputStream(SoundPlayer.class.getResourceAsStream(file));
		AudioInputStream ain = AudioSystem.getAudioInputStream(in);

		Clip c = AudioSystem.getClip();
		c.open(ain);
		c.setLoopPoints(0, -1);
		clips.put(name, c);
		ain.close();
		in.close();
		System.out.println("Done.");
	} catch (Exception e) {
		System.out.println("Failed. (" + e.getMessage() + ")");
	}
}
 
开发者ID:Keabot-Studios,项目名称:Caritemere,代码行数:26,代码来源:SoundPlayer.java

示例5: readStream

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
private void readStream(AudioInputStream as) throws IOException {

        DirectBAOS baos = new DirectBAOS();
        byte buffer[] = new byte[16384];
        int bytesRead = 0;
        int totalBytesRead = 0;

        // this loop may throw an IOException
        while( true ) {
            bytesRead = as.read(buffer, 0, buffer.length);
            if (bytesRead <= 0) {
                as.close();
                break;
            }
            totalBytesRead += bytesRead;
            baos.write(buffer, 0, bytesRead);
        }
        loadedAudio = baos.getInternalBuffer();
        loadedAudioByteLength = totalBytesRead;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:JavaSoundAudioClip.java

示例6: loadFloatAudio

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
private FloatSampleBuffer loadFloatAudio(AudioInputStream ais, int toRead)
{
	FloatSampleBuffer samples = new FloatSampleBuffer();
	int totalRead = 0;
	byte[] rawBytes = new byte[toRead];
	try
	{
		// we have to read in chunks because the decoded stream won't
		// read more than about 2000 bytes at a time
		while (totalRead < toRead)
		{
			int actualRead = ais.read(rawBytes, totalRead, toRead	- totalRead);
			if (actualRead < 1)
       {
				break;
       }
			totalRead += actualRead;
		}
		ais.close();
	}
	catch (Exception ioe)
	{
		error("Error loading file into memory: " + ioe.getMessage());
	}
	debug("Needed to read " + toRead + " actually read " + totalRead);
	samples.initFromByteArray(rawBytes, 0, totalRead, ais.getFormat());
	return samples;
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:29,代码来源:JSMinim.java

示例7: close

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
@Override
public void close() throws IOException
{
    AudioInputStream astream  = weak_stream_link.get();
    if(astream != null)
        astream.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:SoftSynthesizer.java

示例8: start

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
public long start() throws Exception {
    AudioFormat format = new AudioFormat(44100, 16, 2, true, false);

    if (addLen) {
        staticLen+=(int) (staticLen/5)+1000;
    } else {
        staticLen-=(int) (staticLen/5)+1000;
    }
    if (staticLen>8*44100*4) {
        staticLen = 8*44100*4;
        addLen=!addLen;
    }
    if (staticLen<1000) {
        staticLen = 1000;
        addLen=!addLen;
    }
    int len = staticLen;
    len -= (len % 4);
    out("  Test program: preparing to play back "+len+" bytes == "+bytes2Ms(len, format)+"ms audio...");

    byte[] fakedata=new byte[len];
    InputStream is = new ByteArrayInputStream(fakedata);
    AudioInputStream ais = new AudioInputStream(is, format, fakedata.length/format.getFrameSize());

    DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat());
    clip = (Clip) AudioSystem.getLine(info);
    clip.addLineListener(this);

    out("  Test program: opening clip="+((clip==null)?"null":clip.toString()));
    clip.open(ais);
    ais.close();
    out("  Test program: starting clip="+((clip==null)?"null":clip.toString()));
    clip.start();
    return bytes2Ms(fakedata.length, format);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ClipLinuxCrash2.java

示例9: close

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
@Override
public void close() {
    if (!isOpen())
        return;

    sendEvent(new LineEvent(this, LineEvent.Type.CLOSE,
            AudioSystem.NOT_SPECIFIED));

    SoftAudioPusher pusher_to_be_closed = null;
    AudioInputStream pusher_stream_to_be_closed = null;
    synchronized (control_mutex) {
        if (pusher != null) {
            pusher_to_be_closed = pusher;
            pusher_stream_to_be_closed = pusher_stream;
            pusher = null;
            pusher_stream = null;
        }
    }

    if (pusher_to_be_closed != null) {
        // Pusher must not be closed synchronized against control_mutex
        // this may result in synchronized conflict between pusher and
        // current thread.
        pusher_to_be_closed.stop();

        try {
            pusher_stream_to_be_closed.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    synchronized (control_mutex) {

        if (mainmixer != null)
            mainmixer.close();
        open = false;

        if (sourceDataLine != null) {
            sourceDataLine.drain();
            sourceDataLine.close();
            sourceDataLine = null;
        }

    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:SoftMixingMixer.java

示例10: close

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
public void close() {
    if (!isOpen())
        return;

    sendEvent(new LineEvent(this, LineEvent.Type.CLOSE,
            AudioSystem.NOT_SPECIFIED));

    SoftAudioPusher pusher_to_be_closed = null;
    AudioInputStream pusher_stream_to_be_closed = null;
    synchronized (control_mutex) {
        if (pusher != null) {
            pusher_to_be_closed = pusher;
            pusher_stream_to_be_closed = pusher_stream;
            pusher = null;
            pusher_stream = null;
        }
    }

    if (pusher_to_be_closed != null) {
        // Pusher must not be closed synchronized against control_mutex
        // this may result in synchronized conflict between pusher and
        // current thread.
        pusher_to_be_closed.stop();

        try {
            pusher_stream_to_be_closed.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    synchronized (control_mutex) {

        if (mainmixer != null)
            mainmixer.close();
        open = false;

        if (sourceDataLine != null) {
            sourceDataLine.drain();
            sourceDataLine.close();
            sourceDataLine = null;
        }

    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:SoftMixingMixer.java

示例11: close

import javax.sound.sampled.AudioInputStream; //导入方法依赖的package包/类
public void close() throws IOException
{
    AudioInputStream astream  = weak_stream_link.get();
    if(astream != null)
        astream.close();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:SoftSynthesizer.java


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