gpt4 book ai didi

java - 向后播放 WAV 文件

转载 作者:IT老高 更新时间:2023-10-28 20:35:23 26 4
gpt4 key购买 nike

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

更新:已解决!请参阅我自己的帖子。

最佳答案

我自己解决了

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

关于java - 向后播放 WAV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1267488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com