简体   繁体   English

向后播放WAV文件

[英]Play WAV file backward

I'm making Braid in Java. 我正在用Java 编写Braid If you rewind the time, the sound plays backward. 如果您回放时间,声音会向后播放。 How to play a WAV file backwards? 如何向后播放WAV文件? Maybe with a stream with something like previous() ? 也许使用像previous()类的流? On the site of Braid can you see what I mean. 在Braid的网站上你能看出我的意思吗?

Update: Solved! 更新: 解决了! See my own post. 看我自己的帖子。

YEEEEEEESSSSS!!!!!!!! YEEEEEEESSSSS !!!!!!!!

I solved it by myself (14 years old!!) 我自己解决了(14岁!!)
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);
    }
}

And then: 然后:

 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--;
 }

If the WAV contains PCM, reverse the order of the PCM samples. 如果WAV包含PCM,则反转PCM样本的顺序。 If it contains some other format it can be a lot more complex; 如果它包含一些其他格式,它可能会复杂得多; probably easiest to just convert it to PCM first. 可能最容易将它首先转换为PCM。

For more information on the WAV format, see this site . 有关WAV格式的更多信息,请访问此站点

Use Windows Sound Recorder (in Start --> Programs --> Accessories --> Entertainment). 使用Windows录音机(在开始 - >程序 - >附件 - >娱乐中)。

It has a feature (Effects (menu) --> Reverse) to reverse a .WAV file. 它有一个功能(效果(菜单) - >反转)来反转.WAV文件。 You could save the reversed file with a different name, and then open the appropriate one in your program. 您可以使用其他名称保存反转文件,然后在程序中打开相应的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM