【发布时间】:2011-02-22 08:36:48
【问题描述】:
我现在正在使用 Java 进行声音处理。在我的项目中,我必须处理流。所以我有很多员工要处理DataLine 和OutputStream 或InputStream。
但对我来说,它们太相似了:(
有人可以帮我解答这个问题吗?提前致谢! 下面是我使用的一些代码:
TargetDataLine line;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int frameSizeInBytes = format.getFrameSize();
int bufferLengthInFrames = line.getBufferSize() / 8;
int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
byte[] data = new byte[bufferLengthInBytes];
int numBytesRead;
try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format, line.getBufferSize());
} catch (LineUnavailableException ex) {
shutDown("Unable to open the line: " + ex);
return;
} catch (SecurityException ex) {
shutDown(ex.toString());
return;
} catch (Exception ex) {
shutDown(ex.toString());
return;
}
line.start();
while (thread != null) {
if ((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
break;
}
out.write(data, 0, numBytesRead);
}
我已经阅读了 TargetDataLine 类的文档,上面写着:“'read(byte[] b, int off, int len)' 从数据线的输入缓冲区中读取音频数据。 "
但是我们在哪里定义它呢?
TargetDataLine 类型的线还没有连接到任何混音器,那么我们怎么知道它是用于哪个混音器的???
【问题讨论】: