FileAudioTarget.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:ether 作者:
@Override
public void stop() throws RenderCommandException {
    byte[] bytes = new byte[buffer.size() * 2];
    for(int i = buffer.size(); --i >= 0;) {
        int val = (int) (buffer.get(i) * Short.MAX_VALUE);
        bytes[i*2+0] = (byte) val;
        bytes[i*2+1] = (byte) (val >> 8);
    }
    AudioInputStream in = new AudioInputStream(new ByteArrayInputStream(bytes), 
            new AudioFormat(sRate, 16, 1, true, false), 
            buffer.size());
    try(FileOutputStream out = new FileOutputStream(file)) {
        AudioSystem.write(in, Type.WAVE, out);
    } catch (IOException e) {
        throw new RenderCommandException(e);
    }
    super.stop();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号