views:

707

answers:

3

Hi,

I'm making Braid in Java. If you rewind the time, the sound plays backward Does somebody now how to play a wav backward? Maybe with a stream with something like previous()??? On the site of braid can you see what I mean.

Solved!!: See my own post!!!!!!

Thanks

+1  A: 

If the WAV contains PCM, reverse the order of the PCM samples. If it contains some other format it can be a lot more complex; probably easiest to just convert it to PCM first.

For more information on the WAV format, see this site.

bdonlan
Thanks for your fast reply. But I don't know how to do that with the PCM's. Maybe you can write an exemple or a site where I can find some information?
Martijn Courteaux
I added a link to a description of the WAV format; if you're having problems ask specific questions about the parts you're having trouble understanding.
bdonlan
Thanks I'll try something. And a very great site.
Martijn Courteaux
A: 

Use Windows Sound Recorder (in Start --> Programs --> Accessories --> Entertainment).

It has a feature (Effects (menu) --> Reverse) to reverse a .WAV file. You could save the reversed file with a different name, and then open the appropriate one in your program.

Steven
they're to many soundfiles (+50) to reverse them all. I thought allready ont it, but...
Martijn Courteaux
+5  A: 

YEEEEEEESSSSS!!!!!!!!

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

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--;
 }
Martijn Courteaux
@Martijn Courteaux great :)
c0mrade