向后播放 WAV 文件 [英] Play WAV file backward

查看:29
本文介绍了向后播放 WAV 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Java 制作 Braid.如果您倒回时间,声音会倒退.如何向后播放 WAV 文件?也许带有类似 previous() 的流?在 Braid 的网站上你能明白我的意思吗.

I'm making Braid in Java. If you rewind the time, the sound plays backward. How to play a WAV file backwards? Maybe with a stream with something like previous()? On the site of Braid can you see what I mean.

更新:解决了!查看我自己的帖子.

推荐答案

YEEEEEEESSSSS!!!!!!!!!

YEEEEEEESSSSS!!!!!!!!

我自己解决的(14岁!!)
我写过这个类:

I solved it by myself (14 years old!!)
I've written this class:

import java.io.IOException;
import javax.sound.sampled.AudioInputStream;

/**
 *
 * @author Martijn
 */
public class FrameBuffer {

    private byte[][] frames;
    private int frameSize;

    public FrameBuffer(AudioInputStream stream) throws IOException {
        readFrames(stream);
    }

    public byte[] getFrame(int i) {
        return frames[i];
    }

    public int numberFrames()
    {
        return frames.length;
    }

    public int frameSize()
    {
        return frameSize;
    }

    private void readFrames(AudioInputStream stream) throws IOException {
        frameSize = stream.getFormat().getFrameSize();
        frames = new byte[stream.available() / frameSize][frameSize];
        int i = 0;
        for (; i < frames.length; i++)
        {
            byte[] frame = new byte[frameSize];
            int numBytes = stream.read(frame, 0, frameSize);
            if (numBytes == -1)
            {
                break;
            }
            frames[i] = frame;
        }
        System.out.println("FrameSize = " + frameSize);
        System.out.println("Number frames = " + frames.length);
        System.out.println("Number frames read = " + i);
    }
}

然后:

 FrameBuffer frameStream = new FrameBuffer(austream); //austream is the audiostream
 int frame = frameStream.numberFrames() - 1;
 while (frame >= 0) {
      auline.write(frameStream.getFrame(frame), 0, frameStream.frameSize());
      frame--;
 }

这篇关于向后播放 WAV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆